Fix build script deadlock in release mode

This commit is contained in:
David Venhoff 2025-08-12 15:51:51 +02:00
parent e2d9fadcc8
commit 50a6339ee4

View File

@ -4,16 +4,21 @@ use std::process::Command;
fn main() { fn main() {
println!("cargo:rerun-if-changed=client"); println!("cargo:rerun-if-changed=client");
build_client();
let out_dir = env::var("OUT_DIR").unwrap(); let out_dir = env::var("OUT_DIR").unwrap();
let client_bin = build_client(&out_dir);
setup_nyx(&out_dir); setup_nyx(&out_dir);
create_nyx_workdir(&out_dir); create_nyx_workdir(&out_dir, &client_bin);
} }
#[track_caller] #[track_caller]
fn shell(cwd: impl AsRef<Path>, command_string: &str) { fn shell(cwd: impl AsRef<Path>, command_string: &str) {
println!(
"cargo:warning=Running ({}) {command_string}",
cwd.as_ref().display()
);
let cwd = cwd.as_ref(); let cwd = cwd.as_ref();
let mut parts = command_string.split(" "); let mut parts = command_string.split(" ");
let command_name = parts.next().unwrap(); let command_name = parts.next().unwrap();
@ -34,8 +39,14 @@ fn shell(cwd: impl AsRef<Path>, command_string: &str) {
} }
} }
fn build_client() { /// Builds the client and returns the path to its binary
shell("client", "cargo build --release"); fn build_client(out_dir: &str) -> String {
// Change the target dir to avoid a cargo target dir deadlock
shell(
"client",
&format!("cargo build --release --target-dir {out_dir}/client_target"),
);
format!("{out_dir}/client_target/release/client")
} }
/// Downloads and compiles qemu-nyx and packer and compiles them for the current architecture /// Downloads and compiles qemu-nyx and packer and compiles them for the current architecture
@ -71,13 +82,12 @@ fn setup_nyx(out_dir: &str) {
} }
} }
fn create_nyx_workdir(out_dir: &str) { fn create_nyx_workdir(out_dir: &str, client_bin: &str) {
// Create the directory and move required binaries to it // Create the directory and move required binaries to it
let repository_root = env::var("CARGO_MANIFEST_DIR").unwrap();
shell( shell(
out_dir, out_dir,
&format!( &format!(
"python3 packer/packer/nyx_packer.py {repository_root}/target/release/client build afl processor_trace --fast_reload_mode --purge" "python3 packer/packer/nyx_packer.py {client_bin} build afl processor_trace --fast_reload_mode --purge"
), ),
); );