-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathbuild.rs
47 lines (38 loc) · 1.14 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
use libbpf_cargo::SkeletonBuilder;
use std::{env, path::PathBuf};
const PROBES_SRC: &str = "src/bpf/probes.bpf.c";
const PROTOS: &[&str] = &[
"edgebitapis/edgebit/agent/v1alpha/token_service.proto",
"edgebitapis/edgebit/agent/v1alpha/inventory_service.proto",
];
fn build_protos() -> Result<(), Box<dyn std::error::Error>> {
let includes: &[&str] = &[];
tonic_build::configure().compile(PROTOS, includes)?;
for proto in PROTOS {
println!("cargo:rerun-if-changed={proto}");
}
Ok(())
}
fn build_bpf() -> Result<(), Box<dyn std::error::Error>> {
let mut out =
PathBuf::from(env::var_os("OUT_DIR").expect("OUT_DIR must be set in build script"));
out.push("probes.skel.rs");
SkeletonBuilder::new()
.source(PROBES_SRC)
.clang("clang")
.build_and_generate(&out)?;
println!("cargo:rerun-if-changed={PROBES_SRC}");
Ok(())
}
fn build() -> Result<(), Box<dyn std::error::Error>> {
build_bpf()?;
build_protos()?;
Ok(())
}
fn main() -> Result<(), Box<dyn std::error::Error>> {
if let Err(e) = build() {
eprintln!("{e}");
return Err(e);
}
Ok(())
}