-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.rs
38 lines (33 loc) · 1.23 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
use std::env;
use std::path::PathBuf;
use std::process::Command;
fn main() {
// libvirt dynamic library
println!("cargo:rustc-link-lib=dylib=virt");
// git hash
let output = Command::new("git")
.args(&["rev-parse", "HEAD"])
.output()
.unwrap();
let git_hash = String::from_utf8(output.stdout).unwrap();
println!("cargo:rustc-env=GIT_HASH={}", git_hash);
// should we generate protos
let run_build = env::var("GENERATE_PROTOS")
.map(|v| v == "1")
.unwrap_or(false);
if run_build {
let out_dir = PathBuf::from("proto/generated");
tonic_build::configure()
.include_file("mod.rs")
.out_dir(out_dir.clone())
.file_descriptor_set_path(out_dir.join("externalgrpc_descriptor.bin"))
.compile(&["proto/externalgrpc.proto"], &["proto/k8s.io", "proto/"])
.unwrap();
let official_out_dir = PathBuf::from(env::var("OUT_DIR").unwrap());
tonic_build::configure()
.include_file("mod.rs")
.file_descriptor_set_path(official_out_dir.join("externalgrpc_descriptor.bin"))
.compile(&["proto/externalgrpc.proto"], &["proto/k8s.io", "proto/"])
.unwrap();
}
}