From 859761ac178030d887f59cd29cd6e529bb695d7e Mon Sep 17 00:00:00 2001 From: Tsiry Sandratraina Date: Sat, 15 Aug 2026 16:51:03 +0000 Subject: [PATCH] create the build sandbox through bsdkrun-sdk 0.2 bsdkrun-sdk 0.2.0 exposes LinuxBuilder::attach_disk, so sandbox creation no longer shells out to the bsdkrun CLI to pass --attach-disk. Requires bsdkrun 0.9.0+ at runtime. --- kbuildx/Cargo.lock | 4 ++-- kbuildx/Cargo.toml | 2 +- kbuildx/README.md | 2 +- kbuildx/src/commands/build.rs | 37 +++++++------------------------------ 4 file(s) changed, 11 insertion(s)(+), 34 deletion(s)(-) diff --git a/kbuildx/Cargo.lock b/kbuildx/Cargo.lock --- a/kbuildx/Cargo.lock +++ b/kbuildx/Cargo.lock @@ -93,9 +93,9 @@ [[package]] name = "bsdkrun-sdk" -version = "0.1.2" +version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b24038ea463f8def153bb9010756118eb73995d8d10c6e92a8efb4b3a170fda" +checksum = "f7b0d9fb581f3e107ac36357f5b0ccff906ccb48e9427813e0dfcb9479a6fb9d" dependencies = [ "base64", "serde", diff --git a/kbuildx/Cargo.toml b/kbuildx/Cargo.toml --- a/kbuildx/Cargo.toml +++ b/kbuildx/Cargo.toml @@ -5,7 +5,7 @@ [dependencies] anyhow = "1.0.104" -bsdkrun-sdk = "0.1.2" +bsdkrun-sdk = "0.2" clap = { version = "4", features = ["derive"] } crossterm = "0.28" fuzzy-matcher = "0.3" diff --git a/kbuildx/README.md b/kbuildx/README.md --- a/kbuildx/README.md +++ b/kbuildx/README.md @@ -339,7 +339,7 @@ The `/linux` checkout persists between invocations. A running sandbox is reused as-is when the requested CPU and memory match its current values; it is stopped and restarted only to apply resource changes, keeping the guest page cache warm between builds. Build dependencies are installed once and skipped on later runs. A sandbox created by an older kbuildx without a build disk is recreated automatically, and the kernel checkout is re-cloned onto the new disk. -This mode requires a bsdkrun with `linux --attach-disk` support. The bsdkrun executable must be discoverable through `PATH` or `BSDKRUN_BIN`. +This mode requires bsdkrun 0.9.0 or newer (`linux --attach-disk` support). The bsdkrun executable must be discoverable through `PATH` or `BSDKRUN_BIN`. ### BSD build machines diff --git a/kbuildx/src/commands/build.rs b/kbuildx/src/commands/build.rs --- a/kbuildx/src/commands/build.rs +++ b/kbuildx/src/commands/build.rs @@ -402,36 +402,13 @@ .set_len(crate::commands::bsd::parse_disk_size(disk_size)?) .with_context(|| format!("sizing {}", build_disk.display()))?; } - let output = Command::new(crate::commands::bsd::bsdkrun_binary()) - .arg("linux") - .arg("-d") - .arg("--name") - .arg(SANDBOX_ID) - .arg("--cpus") - .arg(cpus.to_string()) - .arg("--mem") - .arg(memory.to_string()) - .arg("--attach-disk") - .arg(&build_disk) - .arg("alpine:latest") - .stdin(Stdio::null()) - .stdout(Stdio::piped()) - .stderr(Stdio::inherit()) - .output() - .context("creating the Linux build sandbox")?; - if !output.status.success() { - bail!( - "unable to create the Linux build sandbox (requires a bsdkrun with `linux --attach-disk` support)" - ); - } - let stdout = String::from_utf8_lossy(&output.stdout); - let id = stdout - .lines() - .rev() - .find(|line| !line.trim().is_empty()) - .map(|line| line.trim().to_string()) - .ok_or_else(|| anyhow::anyhow!("bsdkrun did not return a sandbox id"))?; - let sandbox = Sandbox::get(&id)?; + let sandbox = Sandbox::linux("alpine:latest") + .name(SANDBOX_ID) + .cpus(cpus) + .mem(memory) + .attach_disk(build_disk.to_string_lossy()) + .create() + .context("creating the Linux build sandbox (requires bsdkrun >= 0.9.0)")?; println!( "{} {} {}", step_label("[1/4 SANDBOX]"), -- tangled.sh