forked from igor110055/order_book_combining
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.rs
39 lines (29 loc) · 1.12 KB
/
build.rs
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
35
36
37
38
39
use std::path::PathBuf;
use std::{env, fs, io};
/// Base loosely on.
/// See: https://blog.aqd.is/2021/07/rust-protobuf
///
/// License: https://creativecommons.org/licenses/by-sa/4.0/legalcode
fn main() -> io::Result<()> {
let proto_folder = "proto";
// Load the files in the resources/proto directory.
let proto_path = project_root()?.join("resources").join(proto_folder);
// Save the server output in target/proto/server/*.rs
let server_out_dir = PathBuf::from(".").join("src").join(proto_folder);
fs::create_dir_all(server_out_dir.clone())?;
let proto_include_dir = proto_path.clone();
let paths = fs::read_dir(proto_path).unwrap();
// If the filenames change that the build script stays the same!
for path in paths {
let path_buf = path.unwrap().path();
tonic_build::configure()
.build_server(true)
.out_dir(server_out_dir.as_path())
.compile(&[&path_buf.as_path()], &[&proto_include_dir])?;
}
println!("cargo:rerun-if-changed=./resources/proto");
Ok(())
}
fn project_root() -> io::Result<PathBuf> {
env::current_dir()
}