-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.rs
43 lines (36 loc) · 1.47 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
// The custom build script, used to (1) generate the Rust classes for the
// protobuf implementation and (2) use pbjson for proto3 JSON serialization.
use std::{env, path::PathBuf};
fn main() -> Result<(), anyhow::Error> {
let root = PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("protos");
let proto_files = [
"varfish/v1/common/misc.proto",
"varfish/v1/seqvars/output.proto",
"varfish/v1/seqvars/query.proto",
"varfish/v1/seqvars/output.proto",
"varfish/v1/strucvars/clinvar.proto",
"varfish/v1/strucvars/bgdb.proto",
]
.iter()
.map(|f| root.join(f))
.collect::<Vec<_>>();
// Tell cargo to recompile if any of these proto files are changed
for proto_file in &proto_files {
println!("cargo:rerun-if-changed={}", proto_file.display());
}
let descriptor_path: PathBuf =
PathBuf::from(env::var("OUT_DIR").unwrap()).join("proto_descriptor.bin");
prost_build::Config::new()
// Save descriptors to file
.file_descriptor_set_path(&descriptor_path)
// Override prost-types with pbjson-types
.compile_well_known_types()
.extern_path(".google.protobuf", "::pbjson_types")
// Define the protobuf files to compile.
.compile_protos(&proto_files, &[root])?;
let descriptor_set = std::fs::read(descriptor_path).unwrap();
pbjson_build::Builder::new()
.register_descriptors(&descriptor_set)?
.build(&[".varfish"])?;
Ok(())
}