Skip to content

Commit e028e7f

Browse files
authored
Merge pull request #52 from Perun-Engineering/fix/ebpf-build-lock-deadlock
fix(core): give nested eBPF build.rs cargo invocation its own target dir
2 parents 03bd428 + 07f050e commit e028e7f

2 files changed

Lines changed: 16 additions & 8 deletions

File tree

oom-watcher/build.rs

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@ fn main() {
2525

2626
println!("cargo:warning=Building eBPF program...");
2727

28+
// Build into a dedicated target dir: the outer `cargo build` holds the
29+
// lock on the workspace's target dir for the whole session, and this
30+
// nested cargo invocation would otherwise block acquiring the same lock
31+
// (build.rs, in turn, blocks waiting for this process) — a deadlock.
32+
let ebpf_target_dir = workspace_root.join("target/ebpf-subbuild");
33+
2834
// Build the eBPF program
2935
let mut cmd = Command::new("cargo");
3036
cmd.arg("+nightly")
@@ -34,6 +40,8 @@ fn main() {
3440
.arg("oom-watcher-ebpf")
3541
.arg("--target")
3642
.arg("bpfel-unknown-none")
43+
.arg("--target-dir")
44+
.arg(&ebpf_target_dir)
3745
.arg("-Z")
3846
.arg("build-std=core")
3947
.current_dir(&workspace_root);
@@ -53,9 +61,9 @@ fn main() {
5361

5462
// Look for the eBPF binary in multiple possible locations
5563
let possible_paths = vec![
56-
workspace_root.join("target/bpfel-unknown-none/release/oom-watcher-ebpf"),
57-
PathBuf::from("../target/bpfel-unknown-none/release/oom-watcher-ebpf"),
58-
PathBuf::from("target/bpfel-unknown-none/release/oom-watcher-ebpf"),
64+
ebpf_target_dir.join("bpfel-unknown-none/release/oom-watcher-ebpf"),
65+
PathBuf::from("../target/ebpf-subbuild/bpfel-unknown-none/release/oom-watcher-ebpf"),
66+
PathBuf::from("target/ebpf-subbuild/bpfel-unknown-none/release/oom-watcher-ebpf"),
5967
];
6068

6169
let mut found_path = None;
@@ -93,10 +101,10 @@ fn main() {
93101
println!("cargo:warning= {}", path.display());
94102
}
95103

96-
// List contents of workspace target directory
97-
let workspace_target = workspace_root.join("target/bpfel-unknown-none/release/");
98-
println!("cargo:warning=Contents of {}:", workspace_target.display());
99-
if let Ok(entries) = fs::read_dir(&workspace_target) {
104+
// List contents of the eBPF build's target directory
105+
let ebpf_release_dir = ebpf_target_dir.join("bpfel-unknown-none/release/");
106+
println!("cargo:warning=Contents of {}:", ebpf_release_dir.display());
107+
if let Ok(entries) = fs::read_dir(&ebpf_release_dir) {
100108
for entry in entries.flatten() {
101109
println!("cargo:warning= {}", entry.file_name().to_string_lossy());
102110
}

oom-watcher/src/source.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ mod ebpf_source {
4040

4141
#[cfg(debug_assertions)]
4242
let mut bpf = Ebpf::load(include_bytes_aligned!(
43-
"../../target/bpfel-unknown-none/release/oom-watcher-ebpf"
43+
"../../target/ebpf-subbuild/bpfel-unknown-none/release/oom-watcher-ebpf"
4444
))?;
4545
#[cfg(not(debug_assertions))]
4646
let mut bpf = Ebpf::load(include_bytes_aligned!(concat!(

0 commit comments

Comments
 (0)