-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathbuild.rs
68 lines (61 loc) · 2.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
fn main() {
#[cfg(target_os = "linux")]
bpf::generate();
}
#[cfg(target_os = "linux")]
mod bpf {
use libbpf_cargo::SkeletonBuilder;
// `SOURCES` lists all BPF programs and the sampler that contains them.
// Each entry `(sampler, program)` maps to a unique path in the `samplers`
// directory.
const SOURCES: &[(&str, &str)] = &[
("blockio", "latency"),
("blockio", "requests"),
("cpu", "frequency"),
("cpu", "perf"),
("cpu", "usage"),
("network", "traffic"),
("scheduler", "runqueue"),
("syscall", "counts"),
("syscall", "latency"),
("tcp", "connect_latency"),
("tcp", "packet_latency"),
("tcp", "receive"),
("tcp", "retransmit"),
("tcp", "traffic"),
];
pub fn generate() {
let out_dir = std::env::var("OUT_DIR").unwrap();
let target_arch = std::env::var("CARGO_CFG_TARGET_ARCH").unwrap();
for (sampler, prog) in SOURCES {
let src = format!("src/samplers/{sampler}/linux/{prog}/mod.bpf.c");
let tgt = format!("{out_dir}/{sampler}_{prog}.bpf.rs");
if target_arch == "x86_64" {
SkeletonBuilder::new()
.source(&src)
.clang_args([
"-Isrc/common/bpf/x86_64",
"-fno-unwind-tables",
"-D__TARGET_ARCH_x86",
])
.build_and_generate(&tgt)
.unwrap();
} else if target_arch == "aarch64" {
SkeletonBuilder::new()
.source(&src)
.clang_args([
"-Isrc/common/bpf/aarch64",
"-fno-unwind-tables",
"-D__TARGET_ARCH_arm64",
])
.build_and_generate(&tgt)
.unwrap();
} else {
panic!("BPF support only available for x86_64 and aarch64 architectures");
}
println!("cargo:rerun-if-changed={src}");
}
println!("cargo:rerun-if-changed=src/common/bpf/histogram.h");
println!("cargo:rerun-if-changed=src/common/bpf/vmlinux.h");
}
}