From 3abe5f9dbef7046d8c63b7c2f782ebe6142881ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Ber=C3=A1nek?= Date: Fri, 8 Aug 2025 08:56:51 +0200 Subject: [PATCH 1/2] Add snapshot test for cross-compilation cargo build --- src/bootstrap/src/core/builder/tests.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/bootstrap/src/core/builder/tests.rs b/src/bootstrap/src/core/builder/tests.rs index 5361347da9047..41fdb905e6a97 100644 --- a/src/bootstrap/src/core/builder/tests.rs +++ b/src/bootstrap/src/core/builder/tests.rs @@ -975,6 +975,21 @@ mod snapshot { .render_steps(), @"[build] rustc 0 -> cargo 1 "); } + #[test] + fn build_cargo_cross() { + let ctx = TestCtx::new(); + insta::assert_snapshot!( + ctx.config("build") + .paths(&["cargo"]) + .hosts(&[TEST_TRIPLE_1]) + .render_steps(), @r" + [build] llvm + [build] rustc 0 -> rustc 1 + [build] rustc 1 -> std 1 + [build] rustc 1 -> cargo 2 + "); + } + #[test] fn dist_default_stage() { let ctx = TestCtx::new(); From 9eb9b5a191807e823ade467902f5e663f6ba9341 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Ber=C3=A1nek?= Date: Fri, 8 Aug 2025 08:57:44 +0200 Subject: [PATCH 2/2] Build host library when cross-compiling `ToolTarget` tools --- src/bootstrap/src/core/build_steps/tool.rs | 8 ++++++-- src/bootstrap/src/core/builder/tests.rs | 1 + 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/bootstrap/src/core/build_steps/tool.rs b/src/bootstrap/src/core/build_steps/tool.rs index 7b0ef942abecf..aa00cd03c5bb7 100644 --- a/src/bootstrap/src/core/build_steps/tool.rs +++ b/src/bootstrap/src/core/build_steps/tool.rs @@ -334,7 +334,8 @@ pub fn prepare_tool_cargo( /// Determines how to build a `ToolTarget`, i.e. which compiler should be used to compile it. /// The compiler stage is automatically bumped if we need to cross-compile a stage 1 tool. pub enum ToolTargetBuildMode { - /// Build the tool using rustc that corresponds to the selected CLI stage. + /// Build the tool for the given `target` using rustc that corresponds to the top CLI + /// stage. Build(TargetSelection), /// Build the tool so that it can be attached to the sysroot of the passed compiler. /// Since we always dist stage 2+, the compiler that builds the tool in this case has to be @@ -366,7 +367,10 @@ pub(crate) fn get_tool_target_compiler( } else { // If we are cross-compiling a stage 1 tool, we cannot do that with a stage 0 compiler, // so we auto-bump the tool's stage to 2, which means we need a stage 1 compiler. - builder.compiler(build_compiler_stage.max(1), builder.host_target) + let build_compiler = builder.compiler(build_compiler_stage.max(1), builder.host_target); + // We also need the host stdlib to compile host code (proc macros/build scripts) + builder.std(build_compiler, builder.host_target); + build_compiler }; builder.std(compiler, target); compiler diff --git a/src/bootstrap/src/core/builder/tests.rs b/src/bootstrap/src/core/builder/tests.rs index 41fdb905e6a97..1914e24fa35a1 100644 --- a/src/bootstrap/src/core/builder/tests.rs +++ b/src/bootstrap/src/core/builder/tests.rs @@ -985,6 +985,7 @@ mod snapshot { .render_steps(), @r" [build] llvm [build] rustc 0 -> rustc 1 + [build] rustc 1 -> std 1 [build] rustc 1 -> std 1 [build] rustc 1 -> cargo 2 ");