-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.rs
More file actions
34 lines (27 loc) · 1015 Bytes
/
build.rs
File metadata and controls
34 lines (27 loc) · 1015 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// (c) Copyright 2021-2022 Christian Saide
// SPDX-License-Identifier: GPL-3.0
use std::env;
use std::path::PathBuf;
const PROTO_DIR: &str = "./proto/";
fn main() -> Result<(), Box<dyn std::error::Error>> {
let out_dir = PathBuf::from(env::var("OUT_DIR").unwrap());
let files = std::fs::read_dir(PROTO_DIR).expect("failed to list proto files.");
for file in files {
let file = file.expect("failed to read file path");
let file = file.path();
let file_name = String::from(
file.file_name()
.expect("failed to determine filename of current path")
.to_str()
.unwrap(),
);
let descriptor_name = file_name.replace(".proto", "_descriptor.bin");
tonic_build::configure()
.build_client(true)
.build_server(true)
.file_descriptor_set_path(out_dir.join(descriptor_name))
.format(true)
.compile(&[file], &[PROTO_DIR])?;
}
Ok(())
}