forked from substrait-io/substrait-rs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.rs
52 lines (42 loc) · 1.49 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
42
43
44
45
46
47
48
49
50
51
52
// SPDX-License-Identifier: Apache-2.0
use std::error::Error;
#[cfg(feature = "pbjson")]
use std::{env, fs, path::PathBuf};
#[cfg(feature = "pbjson")]
use pbjson_build::Builder;
use prost_build::Config;
use walkdir::{DirEntry, WalkDir};
const PROTO_ROOT: &str = "substrait/proto";
fn main() -> Result<(), Box<dyn Error>> {
// for use in docker build where file changes can be wonky
println!("cargo:rerun-if-env-changed=FORCE_REBUILD");
let protos = WalkDir::new(PROTO_ROOT)
.into_iter()
.filter_map(Result::ok)
.filter(|entry| {
entry.file_type().is_file()
&& entry
.path()
.extension()
.filter(|extension| extension == &"proto")
.is_some()
})
.map(DirEntry::into_path)
.inspect(|entry| {
println!("cargo:rerun-if-changed={}", entry.display());
})
.collect::<Vec<_>>();
#[cfg(feature = "pbjson")]
let descriptor_path = PathBuf::from(env::var("OUT_DIR").unwrap()).join("proto_descriptor.bin");
let mut cfg = Config::new();
#[cfg(feature = "pbjson")]
cfg.file_descriptor_set_path(&descriptor_path)
.compile_well_known_types()
.extern_path(".google.protobuf", "::pbjson_types");
cfg.compile_protos(&protos, &[PROTO_ROOT])?;
#[cfg(feature = "pbjson")]
Builder::new()
.register_descriptors(&fs::read(&descriptor_path)?)?
.build(&[".substrait"])?;
Ok(())
}