-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.rs
58 lines (47 loc) · 1.65 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
53
54
55
56
57
58
use prost_build::Config;
use std::env;
use std::fs::create_dir_all;
use std::path::{Path, PathBuf};
fn main() {
let cargo = PathBuf::from(env::var("CARGO").unwrap());
let out_dir = PathBuf::from(env::var("OUT_DIR").unwrap());
compile_protobufs(&out_dir);
compile_ebpf_programs(&cargo, &out_dir);
println!("cargo:rustc-env=CHALK_OVERFLOW_DEPTH=200");
}
fn compile_protobufs(out_dir: &Path) {
let proto_dir = &out_dir.join("proto");
rerun_if_changed(&proto_dir.to_str().unwrap());
let mut cfg = Config::new();
cfg.protoc_arg("--experimental_allow_proto3_optional");
create_dir_all(&proto_dir).expect("failed to create proto dir");
tonic_build::configure()
.type_attribute(".", "#[derive(serde::Serialize, serde::Deserialize)]")
.out_dir(&proto_dir)
.compile_with_config(
cfg,
&[
"proto/v1alpha1/engine.proto",
"proto/v1alpha1/resource.proto",
"proto/v1alpha1/runtime.proto",
"proto/v1alpha1/state.proto",
],
&["proto"],
)
.expect("failed to generate spec");
}
fn compile_ebpf_programs(cargo: &Path, out_dir: &Path) {
let probes = Path::new("cosi-probes");
let target_dir = out_dir.join("target");
cargo_bpf_lib::build(&cargo, &probes, &target_dir, Vec::new())
.expect("failed to compile probes");
cargo_bpf_lib::probe_files(&probes)
.expect("failed to list probe files")
.iter()
.for_each(|file| {
rerun_if_changed(file.as_str());
});
}
fn rerun_if_changed(path: &str) {
println!("cargo:rerun-if-changed={}", path)
}