forked from ChainSafe/forest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.rs
41 lines (35 loc) · 1.05 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
40
41
// Copyright 2019-2023 ChainSafe Systems
// SPDX-License-Identifier: Apache-2.0, MIT
use protobuf_codegen::Customize;
use std::path::PathBuf;
use walkdir::WalkDir;
const PROTO_DIR: &str = "proto";
const CARGO_OUT_DIR: &str = "proto";
fn main() -> anyhow::Result<()> {
generate_protobuf_code()
}
fn generate_protobuf_code() -> anyhow::Result<()> {
println!("cargo:rerun-if-changed=proto");
protobuf_codegen::Codegen::new()
.pure()
.cargo_out_dir(CARGO_OUT_DIR)
.inputs(get_proto_inputs()?.as_slice())
.include(PROTO_DIR)
.customize(Customize::default().lite_runtime(true))
.run()?;
Ok(())
}
fn get_proto_inputs() -> anyhow::Result<Vec<PathBuf>> {
let mut inputs = Vec::new();
for entry in WalkDir::new(PROTO_DIR).into_iter().flatten() {
let path = entry.path();
if path.is_file() {
if let Some(ext) = path.extension() {
if ext == "proto" {
inputs.push(path.into());
}
}
}
}
Ok(inputs)
}