31 lines
1.3 KiB
Rust
31 lines
1.3 KiB
Rust
|
|
use std::{env, path::PathBuf, process::Command};
|
||
|
|
|
||
|
|
fn main()
|
||
|
|
{
|
||
|
|
let manifest_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
|
||
|
|
let workspace_root = manifest_dir.parent().unwrap();
|
||
|
|
let out_dir = PathBuf::from(env::var("OUT_DIR").unwrap());
|
||
|
|
|
||
|
|
// Recompile si les sources kernel-land changent
|
||
|
|
println!("cargo:rerun-if-changed=../kernel-land/src");
|
||
|
|
|
||
|
|
// Lance la compilation depuis kernel-land/ pour utiliser son .cargo/config.toml
|
||
|
|
// (target = bpfel-unknown-none, build-std = core)
|
||
|
|
// CARGO_TARGET_DIR séparé pour éviter le deadlock sur le file lock du workspace parent
|
||
|
|
let ebpf_target_dir = workspace_root.join("target/ebpf");
|
||
|
|
let status = Command::new("cargo")
|
||
|
|
.current_dir(workspace_root.join("kernel-land"))
|
||
|
|
.env("CARGO_TARGET_DIR", &ebpf_target_dir)
|
||
|
|
.args(["build", "--release"])
|
||
|
|
.status()
|
||
|
|
.expect("Échec du lancement de cargo pour kernel-land");
|
||
|
|
|
||
|
|
assert!(status.success(), "Compilation de kernel-land eBPF échouée");
|
||
|
|
|
||
|
|
// Copie l'ELF produit dans OUT_DIR pour que include_bytes! puisse l'embarquer
|
||
|
|
let ebpf_elf = ebpf_target_dir.join("bpfel-unknown-none/release/kernel-land");
|
||
|
|
|
||
|
|
std::fs::copy(&ebpf_elf, out_dir.join("kernel-land.bpf"))
|
||
|
|
.expect("Impossible de copier l'ELF eBPF dans OUT_DIR");
|
||
|
|
}
|