From f774c2aee76ea345604853cb9ad6458ff4c6e30f Mon Sep 17 00:00:00 2001 From: Alyssa Ross Date: Sun, 16 Aug 2026 00:09:33 +0200 Subject: [PATCH 1/7] fix(xtask): cargo-vendor compatibility MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit cargo-vendor puts the dependencies next to the `Cargo.lock` file. They are not used when not calling cargo-build from the same directory. Co-authored-by: Martin Kröning --- xtask/src/build.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xtask/src/build.rs b/xtask/src/build.rs index 8259e3d152..07fd4d2005 100644 --- a/xtask/src/build.rs +++ b/xtask/src/build.rs @@ -74,8 +74,8 @@ impl Build { eprintln!("Building hermit-builtins"); let mut cargo = crate::cargo(); cargo + .current_dir("hermit-builtins") .arg("build") - .arg("--manifest-path=hermit-builtins/Cargo.toml") .arg("--profile") .arg(self.cargo_build.artifact.builtins_profile_path_component()) .args(self.cargo_build.artifact.arch.builtins_cargo_args()) From 38f6628c67c82970d4e200e223068dd1e7b0f1ef Mon Sep 17 00:00:00 2001 From: Alyssa Ross Date: Sun, 16 Aug 2026 00:13:37 +0200 Subject: [PATCH 2/7] fix(xtask): don't remove `RUSTC_BOOTSTRAP` env var MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This environment enables nightly Rust features on stable. This is used on Nix, for example. Co-authored-by: Martin Kröning --- xtask/src/main.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/xtask/src/main.rs b/xtask/src/main.rs index e32fc94b9e..e0f148dbe1 100644 --- a/xtask/src/main.rs +++ b/xtask/src/main.rs @@ -99,7 +99,9 @@ fn sanitize(cmd: &str) -> Command { env::vars() .filter(|(key, _value)| { key.starts_with("CARGO") && !key.starts_with("CARGO_HOME") - || key.starts_with("RUST") && !key.starts_with("RUSTUP_HOME") + || key.starts_with("RUST") + && !key.starts_with("RUSTUP_HOME") + && !key.starts_with("RUSTC_BOOTSTRAP") }) .for_each(|(key, _value)| { cmd.env_remove(&key); From 115a5c5a7d5702b02ded3f5e88e86bd82fefa1ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Kr=C3=B6ning?= Date: Sun, 16 Aug 2026 10:24:18 +0200 Subject: [PATCH 3/7] fix(xtask): accept not finding rustup Co-authored-by: Alyssa Ross --- xtask/src/arch.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/xtask/src/arch.rs b/xtask/src/arch.rs index b8e61fb0dc..2a83078a10 100644 --- a/xtask/src/arch.rs +++ b/xtask/src/arch.rs @@ -30,7 +30,11 @@ impl Arch { rustup.args(["target", "add", self.triple()]); eprintln!("$ {rustup:?}"); - let status = rustup.status()?; + let status = match rustup.status() { + Ok(status) => status, + Err(err) if err.kind() == io::ErrorKind::NotFound => return Ok(()), + Err(err) => return Err(err), + }; assert!(status.success()); Ok(()) From ff7d2eff18733dc336029f69d33719f1e408c84e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Kr=C3=B6ning?= Date: Sun, 16 Aug 2026 10:48:56 +0200 Subject: [PATCH 4/7] refactor(xtask): return `Option` from `LlvmTools::new()` --- xtask/src/binutil.rs | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/xtask/src/binutil.rs b/xtask/src/binutil.rs index 5d7d8abbe2..28c5213808 100644 --- a/xtask/src/binutil.rs +++ b/xtask/src/binutil.rs @@ -1,9 +1,9 @@ -use std::io; use std::path::PathBuf; use std::sync::LazyLock; pub fn binutil(name: &str) -> Option { - static LLVM_TOOLS: LazyLock = LazyLock::new(|| LlvmTools::new().unwrap()); + static LLVM_TOOLS: LazyLock = + LazyLock::new(|| LlvmTools::new().expect("llvm-tools should be found")); LLVM_TOOLS.tool(name) } @@ -13,12 +13,12 @@ struct LlvmTools { } impl LlvmTools { - pub fn new() -> io::Result { + pub fn new() -> Option { let mut rustc = crate::rustc(); rustc.args(["--print", "sysroot"]); eprintln!("$ {rustc:?}"); - let output = rustc.output()?; + let output = rustc.output().unwrap(); assert!(output.status.success()); let sysroot = String::from_utf8(output.stdout).unwrap(); @@ -27,18 +27,14 @@ impl LlvmTools { .collect::(); let example_exe = exe("objdump"); - for entry in rustlib.read_dir()? { - let bin = entry?.path().join("bin"); + for entry in rustlib.read_dir().unwrap() { + let bin = entry.unwrap().path().join("bin"); if bin.join(&example_exe).exists() { - return Ok(Self { bin }); + return Some(Self { bin }); } } - Err(io::Error::new( - io::ErrorKind::NotFound, - "Could not find llvm-tools component\n\ - \n\ - Maybe the rustup component `llvm-tools` is missing? Install it through: `rustup component add llvm-tools`", - )) + + None } pub fn tool(&self, name: &str) -> Option { From 59bad18690adf3c91f66ae74d79ffdca0254a48c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Kr=C3=B6ning?= Date: Sun, 16 Aug 2026 10:58:10 +0200 Subject: [PATCH 5/7] refactor(xtask): call binutils by their LLVM name Co-authored-by: Alyssa Ross --- xtask/src/archive.rs | 14 ++++++++------ xtask/src/binutil.rs | 4 ++-- xtask/src/ci/qemu.rs | 4 ++-- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/xtask/src/archive.rs b/xtask/src/archive.rs index 30f82e93b0..faba351205 100644 --- a/xtask/src/archive.rs +++ b/xtask/src/archive.rs @@ -49,8 +49,10 @@ impl Archive { }; let all_symbols = { - let nm = crate::binutil("nm").unwrap(); - let stdout = cmd!(sh, "{nm} --export-symbols {archive}").output()?.stdout; + let llvm_nm = crate::binutil("llvm-nm").unwrap(); + let stdout = cmd!(sh, "{llvm_nm} --export-symbols {archive}") + .output()? + .stdout; String::from_utf8(stdout)? }; @@ -79,8 +81,8 @@ impl Archive { let rename_path = archive.with_extension("redefine-syms"); sh.write_file(&rename_path, symbol_renames)?; - let objcopy = crate::binutil("objcopy").unwrap(); - cmd!(sh, "{objcopy} --redefine-syms={rename_path} {archive}").run()?; + let llvm_objcopy = crate::binutil("llvm-objcopy").unwrap(); + cmd!(sh, "{llvm_objcopy} --redefine-syms={rename_path} {archive}").run()?; sh.remove_path(&rename_path)?; @@ -92,8 +94,8 @@ impl Archive { let archive = self.as_ref(); let file = file.as_ref(); - let ar = crate::binutil("ar").unwrap(); - cmd!(sh, "{ar} qL {archive} {file}").run()?; + let llvm_ar = crate::binutil("llvm-ar").unwrap(); + cmd!(sh, "{llvm_ar} qL {archive} {file}").run()?; Ok(()) } diff --git a/xtask/src/binutil.rs b/xtask/src/binutil.rs index 28c5213808..2b9f5225ac 100644 --- a/xtask/src/binutil.rs +++ b/xtask/src/binutil.rs @@ -26,7 +26,7 @@ impl LlvmTools { .iter() .collect::(); - let example_exe = exe("objdump"); + let example_exe = exe("llvm-objdump"); for entry in rustlib.read_dir().unwrap() { let bin = entry.unwrap().path().join("bin"); if bin.join(&example_exe).exists() { @@ -45,5 +45,5 @@ impl LlvmTools { fn exe(name: &str) -> String { let exe_suffix = std::env::consts::EXE_SUFFIX; - format!("llvm-{name}{exe_suffix}") + format!("{name}{exe_suffix}") } diff --git a/xtask/src/ci/qemu.rs b/xtask/src/ci/qemu.rs index b656d79883..9916c5e3b5 100644 --- a/xtask/src/ci/qemu.rs +++ b/xtask/src/ci/qemu.rs @@ -780,8 +780,8 @@ fn check_rftrace(image: &Path) -> Result<()> { let sh = crate::sh()?; let image_name = image.file_name().unwrap().to_str().unwrap(); - let nm = crate::binutil("nm").unwrap(); - let symbols = cmd!(sh, "{nm} --demangle --numeric-sort {image}") + let llvm_nm = crate::binutil("llvm-nm").unwrap(); + let symbols = cmd!(sh, "{llvm_nm} --demangle --numeric-sort {image}") .output()? .stdout; sh.write_file(format!("shared/tracedir/{image_name}.sym"), symbols)?; From 5dd9340177d080f9380f80fb6e2eedf53ed103e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Kr=C3=B6ning?= Date: Sun, 16 Aug 2026 11:06:49 +0200 Subject: [PATCH 6/7] fix(xtask): fall back to system LLVM tools Co-authored-by: Alyssa Ross --- xtask/src/archive.rs | 6 +++--- xtask/src/binutil.rs | 10 ++++++---- xtask/src/ci/qemu.rs | 2 +- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/xtask/src/archive.rs b/xtask/src/archive.rs index faba351205..08474e2216 100644 --- a/xtask/src/archive.rs +++ b/xtask/src/archive.rs @@ -49,7 +49,7 @@ impl Archive { }; let all_symbols = { - let llvm_nm = crate::binutil("llvm-nm").unwrap(); + let llvm_nm = crate::binutil("llvm-nm"); let stdout = cmd!(sh, "{llvm_nm} --export-symbols {archive}") .output()? .stdout; @@ -81,7 +81,7 @@ impl Archive { let rename_path = archive.with_extension("redefine-syms"); sh.write_file(&rename_path, symbol_renames)?; - let llvm_objcopy = crate::binutil("llvm-objcopy").unwrap(); + let llvm_objcopy = crate::binutil("llvm-objcopy"); cmd!(sh, "{llvm_objcopy} --redefine-syms={rename_path} {archive}").run()?; sh.remove_path(&rename_path)?; @@ -94,7 +94,7 @@ impl Archive { let archive = self.as_ref(); let file = file.as_ref(); - let llvm_ar = crate::binutil("llvm-ar").unwrap(); + let llvm_ar = crate::binutil("llvm-ar"); cmd!(sh, "{llvm_ar} qL {archive} {file}").run()?; Ok(()) diff --git a/xtask/src/binutil.rs b/xtask/src/binutil.rs index 2b9f5225ac..4282ac130e 100644 --- a/xtask/src/binutil.rs +++ b/xtask/src/binutil.rs @@ -1,11 +1,13 @@ use std::path::PathBuf; use std::sync::LazyLock; -pub fn binutil(name: &str) -> Option { - static LLVM_TOOLS: LazyLock = - LazyLock::new(|| LlvmTools::new().expect("llvm-tools should be found")); +pub fn binutil(name: &str) -> PathBuf { + static LLVM_TOOLS: LazyLock> = LazyLock::new(LlvmTools::new); - LLVM_TOOLS.tool(name) + LLVM_TOOLS + .as_ref() + .and_then(|llvm_tools| llvm_tools.tool(name)) + .unwrap_or(PathBuf::from(name)) } struct LlvmTools { diff --git a/xtask/src/ci/qemu.rs b/xtask/src/ci/qemu.rs index 9916c5e3b5..fe509c13c4 100644 --- a/xtask/src/ci/qemu.rs +++ b/xtask/src/ci/qemu.rs @@ -780,7 +780,7 @@ fn check_rftrace(image: &Path) -> Result<()> { let sh = crate::sh()?; let image_name = image.file_name().unwrap().to_str().unwrap(); - let llvm_nm = crate::binutil("llvm-nm").unwrap(); + let llvm_nm = crate::binutil("llvm-nm"); let symbols = cmd!(sh, "{llvm_nm} --demangle --numeric-sort {image}") .output()? .stdout; From 4cee2bc9d8e56aa8697d993836aa130fd79e3f6e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Kr=C3=B6ning?= Date: Sun, 16 Aug 2026 11:30:51 +0200 Subject: [PATCH 7/7] fix(build.rs): fall back to system LLVM tools Co-authored-by: Alyssa Ross --- build.rs | 41 +++++++++++++++++++++++------------------ 1 file changed, 23 insertions(+), 18 deletions(-) diff --git a/build.rs b/build.rs index 15d1a73786..5bc3fb2b2e 100644 --- a/build.rs +++ b/build.rs @@ -27,8 +27,8 @@ fn assemble_x86_64_smp_boot() -> Result<()> { let boot_bc = out_dir.join("boot.bc"); let boot_bin = out_dir.join("boot.bin"); - let llvm_as = binutil("llvm-as")?; - let rust_lld = binutil("rust-lld")?; + let llvm_as = binutil("llvm-as"); + let lld = lld(); let assembly = fs::read_to_string(boot_s)?; @@ -55,7 +55,7 @@ module asm " .with_context(|| format!("Failed to run llvm-as from {}", llvm_as.display()))?; assert!(status.success()); - let status = Command::new(&rust_lld) + let status = Command::new(&lld) .arg("-flavor") .arg("gnu") .arg("--image-base=0x8000") @@ -65,27 +65,32 @@ module asm " .arg(&boot_bin) .arg(&boot_bc) .status() - .with_context(|| format!("Failed to run rust-lld from {}", rust_lld.display()))?; + .with_context(|| format!("Failed to run lld from {}", lld.display()))?; assert!(status.success()); println!("cargo:rerun-if-changed={}", boot_s.display()); Ok(()) } -fn binutil(name: &str) -> Result { +fn lld() -> PathBuf { + let rust_lld = binutil("rust-lld"); + + if rust_lld.exists() { + return rust_lld; + } + + binutil("lld") +} + +fn binutil(name: &str) -> PathBuf { let exe = format!("{name}{}", env::consts::EXE_SUFFIX); - let path = LlvmTools::new() - .map_err(|err| match err { - llvm_tools::Error::NotFound => anyhow!( - "Could not find llvm-tools component\n\ - \n\ - Maybe the rustup component `llvm-tools` is missing? Install it through: `rustup component add llvm-tools`" - ), - err => anyhow!("{err:?}"), - })? - .tool(&exe) - .ok_or_else(|| anyhow!("could not find {exe}"))?; - - Ok(path) + if let Some(tool) = LlvmTools::new() + .ok() + .and_then(|llvm_tools| llvm_tools.tool(&exe)) + { + return tool; + } + + PathBuf::from(exe) }