Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 15 additions & 7 deletions oom-watcher/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ fn main() {

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

// Build into a dedicated target dir: the outer `cargo build` holds the
// lock on the workspace's target dir for the whole session, and this
// nested cargo invocation would otherwise block acquiring the same lock
// (build.rs, in turn, blocks waiting for this process) — a deadlock.
let ebpf_target_dir = workspace_root.join("target/ebpf-subbuild");

// Build the eBPF program
let mut cmd = Command::new("cargo");
cmd.arg("+nightly")
Expand All @@ -34,6 +40,8 @@ fn main() {
.arg("oom-watcher-ebpf")
.arg("--target")
.arg("bpfel-unknown-none")
.arg("--target-dir")
.arg(&ebpf_target_dir)
.arg("-Z")
.arg("build-std=core")
.current_dir(&workspace_root);
Expand All @@ -53,9 +61,9 @@ fn main() {

// Look for the eBPF binary in multiple possible locations
let possible_paths = vec![
workspace_root.join("target/bpfel-unknown-none/release/oom-watcher-ebpf"),
PathBuf::from("../target/bpfel-unknown-none/release/oom-watcher-ebpf"),
PathBuf::from("target/bpfel-unknown-none/release/oom-watcher-ebpf"),
ebpf_target_dir.join("bpfel-unknown-none/release/oom-watcher-ebpf"),
PathBuf::from("../target/ebpf-subbuild/bpfel-unknown-none/release/oom-watcher-ebpf"),
PathBuf::from("target/ebpf-subbuild/bpfel-unknown-none/release/oom-watcher-ebpf"),
];

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

// List contents of workspace target directory
let workspace_target = workspace_root.join("target/bpfel-unknown-none/release/");
println!("cargo:warning=Contents of {}:", workspace_target.display());
if let Ok(entries) = fs::read_dir(&workspace_target) {
// List contents of the eBPF build's target directory
let ebpf_release_dir = ebpf_target_dir.join("bpfel-unknown-none/release/");
println!("cargo:warning=Contents of {}:", ebpf_release_dir.display());
if let Ok(entries) = fs::read_dir(&ebpf_release_dir) {
for entry in entries.flatten() {
println!("cargo:warning= {}", entry.file_name().to_string_lossy());
}
Expand Down
2 changes: 1 addition & 1 deletion oom-watcher/src/source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ mod ebpf_source {

#[cfg(debug_assertions)]
let mut bpf = Ebpf::load(include_bytes_aligned!(
"../../target/bpfel-unknown-none/release/oom-watcher-ebpf"
"../../target/ebpf-subbuild/bpfel-unknown-none/release/oom-watcher-ebpf"
))?;
#[cfg(not(debug_assertions))]
let mut bpf = Ebpf::load(include_bytes_aligned!(concat!(
Expand Down