forked from gen0sec/synapse
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.rs
More file actions
43 lines (34 loc) · 1.52 KB
/
build.rs
File metadata and controls
43 lines (34 loc) · 1.52 KB
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
// build.rs
use std::env;
use std::ffi::OsStr;
use std::path::{Path, PathBuf};
use libbpf_cargo::SkeletonBuilder;
const SRC: &str = "src/bpf/filter.bpf.c";
const HEADER_DIR: &str = "src/bpf";
fn main() {
println!("cargo:rerun-if-changed={}", SRC);
println!("cargo:rerun-if-changed={}/filter.h", HEADER_DIR);
let arch = env::var("CARGO_CFG_TARGET_ARCH").expect("CARGO_CFG_TARGET_ARCH must be set");
let vmlinux_include = vmlinux::include_path_root().join(arch);
assert!(Path::new(&vmlinux_include).exists(), "vmlinux.h not found");
let bpf_include = Path::new(&env::var("CARGO_MANIFEST_DIR").unwrap()).join(HEADER_DIR);
// ✅ Construct full output path in OUT_DIR
let out_dir = PathBuf::from(env::var("OUT_DIR").unwrap());
let skel_path = out_dir.join("filter.skel.rs");
// ✅ Pass the full path to build_and_generate
SkeletonBuilder::new()
.source(SRC)
.clang_args([
OsStr::new("-I"),
vmlinux_include.as_os_str(),
OsStr::new("-I"),
bpf_include.as_os_str(),
OsStr::new("-O2"), // Enable level 2 optimizations
OsStr::new("-g"), // Keep debug info for verifier
OsStr::new("-Wall"), // Enable all warnings
OsStr::new("-Wextra"), // Extra warnings
])
.build_and_generate(skel_path.to_str().expect("Invalid UTF-8 in path"))
.expect("Failed to generate skeleton");
println!("✅ Wrote skeleton to: {:?}", skel_path);
}