-
Notifications
You must be signed in to change notification settings - Fork 3
/
build.rs
55 lines (53 loc) · 1.7 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
fn main() {
#[cfg(feature = "ebpf")]
{
use std::{
env,
ffi::{OsStr, OsString},
path::PathBuf,
};
use libbpf_cargo::SkeletonBuilder;
const BPF_SRC: &str = "src/bpf/tracexec_system.bpf.c";
let manifest_dir =
PathBuf::from(env::var_os("CARGO_MANIFEST_DIR").expect("CARGO_MANIFEST_DIR not set"));
let bpf_src = manifest_dir.join(BPF_SRC);
let skel_out = manifest_dir
.clone()
.join("src")
.join("bpf")
.join("tracexec_system.skel.rs");
let arch = env::var("CARGO_CFG_TARGET_ARCH").expect("CARGO_CFG_TARGET_ARCH not set");
let arch_define = OsStr::new(match arch.as_str() {
"x86_64" => "TRACEXEC_TARGET_X86_64",
"riscv64" => "TRACEXEC_TARGET_RISCV64",
"aarch64" => "TRACEXEC_TARGET_AARCH64",
_ => panic!("Arch {arch} is not supported for now"),
});
let max_cpus = 64;
let max_cpus_define = OsString::from(format!("MAX_CPUS={max_cpus}"));
let include_dir = manifest_dir.join("include");
let mut clang_args = vec![
// vmlinux.h
OsStr::new("-I"),
include_dir.as_os_str(),
OsStr::new("-D"),
arch_define,
OsStr::new("-D"),
&max_cpus_define,
];
if cfg!(any(feature = "ebpf-debug", debug_assertions)) {
clang_args.push(OsStr::new("-DEBPF_DEBUG"));
}
if cfg!(feature = "ebpf-no-rcu-kfuncs") {
clang_args.push(OsStr::new("-DNO_RCU_KFUNCS"));
}
SkeletonBuilder::new()
.source(bpf_src)
.clang_args(clang_args)
.build_and_generate(&skel_out)
.unwrap();
println!("cargo:rerun-if-changed={BPF_SRC}");
println!("cargo:rerun-if-changed=src/bpf/common.h");
println!("cargo:rerun-if-changed=src/bpf/interface.h");
}
}