From 5b1bcdb45312a7eb21beae6c097ecef721249c8d Mon Sep 17 00:00:00 2001 From: Valentin Haudiquet Date: Tue, 23 Dec 2025 17:19:41 +0100 Subject: [PATCH] exp: cross #7 --- src/deb/cross.rs | 26 ++++++++++++++++++++++++++ src/deb/local.rs | 5 +++++ src/deb/mod.rs | 6 ++++++ 3 files changed, 37 insertions(+) diff --git a/src/deb/cross.rs b/src/deb/cross.rs index 3a8434b..7a3ebf7 100644 --- a/src/deb/cross.rs +++ b/src/deb/cross.rs @@ -38,6 +38,20 @@ impl EphemeralContextGuard { return Err(format!("mmdebstrap failed for series {}", series).into()); } + // Mount '/dev' inside the chroot + let status = context::current() + .command("sudo") + .arg("mount") + .arg("--bind") + .arg("/dev") + .arg(format!("{}/dev", chroot_path.display())) + .status()?; + if !status.success() { + // Clean up on failure + let _ = std::fs::remove_dir_all(&chroot_path); + return Err("Failed to mount /dev inside chroot".into()); + } + // Switch to an ephemeral context to build the package in the chroot context::manager().set_current_ephemeral(Context::new(ContextConfig::Unshare { path: chroot_path.to_string_lossy().to_string(), @@ -59,6 +73,18 @@ impl Drop for EphemeralContextGuard { log::error!("Failed to restore context {}: {}", self.previous_context, e); } + // Unmount '/dev' inside the chroot + let status = context::current() + .command("sudo") + .arg("umount") + .arg(format!("{}/dev", &self.chroot_path.display())) + .status(); + if status.is_err() || !status.unwrap().success() { + // If we fail to umount, then we can't remove (would remove /dev/xx on host) + log::error!("Failed to umount /dev inside chroot. Not cleaning up."); + return; + } + // Remove chroot directory // We use the restored context to execute the cleanup command let result = context::current() diff --git a/src/deb/local.rs b/src/deb/local.rs index aa0ba70..17242fa 100644 --- a/src/deb/local.rs +++ b/src/deb/local.rs @@ -52,6 +52,11 @@ pub fn build( .arg("fakeroot"); if cross { cmd.arg(format!("crossbuild-essential-{arch}")); + cmd.arg(format!("libc6-{arch}-cross")); + cmd.arg(format!("libc6-dev-{arch}-cross")); + cmd.arg("dpkg-cross"); + cmd.arg(format!("libc6:{arch}")); + cmd.arg(format!("libc6-dev:{arch}")); } let status = cmd.status()?; if !status.success() { diff --git a/src/deb/mod.rs b/src/deb/mod.rs index c41e333..2737152 100644 --- a/src/deb/mod.rs +++ b/src/deb/mod.rs @@ -144,4 +144,10 @@ mod tests { async fn test_deb_hello_ubuntu_end_to_end() { test_build_end_to_end("hello", "noble", None, false).await; } + + #[tokio::test] + #[cfg(target_arch = "x86_64")] + async fn test_deb_hello_ubuntu_cross_end_to_end() { + test_build_end_to_end("hello", "noble", Some("riscv64"), true).await; + } }