From 0079da4862cb02a99c5def36a79949de583a9aee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Ber=C3=A1nek?= Date: Tue, 19 Aug 2025 23:36:43 +0200 Subject: [PATCH 1/2] Add snapshot tests for stage 3 compiler builds --- src/bootstrap/src/core/builder/tests.rs | 76 +++++++++++++++++++++++++ 1 file changed, 76 insertions(+) diff --git a/src/bootstrap/src/core/builder/tests.rs b/src/bootstrap/src/core/builder/tests.rs index f4266a6085bfb..85c7f46099fee 100644 --- a/src/bootstrap/src/core/builder/tests.rs +++ b/src/bootstrap/src/core/builder/tests.rs @@ -672,6 +672,82 @@ mod snapshot { "); } + #[test] + fn build_compiler_stage_3() { + let ctx = TestCtx::new(); + insta::assert_snapshot!( + ctx.config("build") + .path("compiler") + .stage(3) + .render_steps(), @r" + [build] llvm + [build] rustc 0 -> rustc 1 + [build] rustc 1 -> std 1 + [build] rustc 1 -> rustc 2 + [build] rustc 2 -> std 2 + [build] rustc 2 -> rustc 3 + "); + } + + #[test] + fn build_compiler_stage_3_cross() { + let ctx = TestCtx::new(); + insta::assert_snapshot!( + ctx.config("build") + .path("compiler") + .hosts(&[TEST_TRIPLE_1]) + .stage(3) + .render_steps(), @r" + [build] llvm + [build] llvm + [build] rustc 0 -> rustc 1 + [build] rustc 1 -> std 1 + [build] rustc 1 -> rustc 2 + [build] rustc 1 -> std 1 + [build] rustc 2 -> std 2 + [build] rustc 2 -> rustc 3 + "); + } + + #[test] + fn build_compiler_stage_3_full_bootstrap() { + let ctx = TestCtx::new(); + insta::assert_snapshot!( + ctx.config("build") + .path("compiler") + .stage(3) + .args(&["--set", "build.full-bootstrap=true"]) + .render_steps(), @r" + [build] llvm + [build] rustc 0 -> rustc 1 + [build] rustc 1 -> std 1 + [build] rustc 1 -> rustc 2 + [build] rustc 2 -> std 2 + [build] rustc 2 -> rustc 3 + "); + } + + #[test] + fn build_compiler_stage_3_cross_full_bootstrap() { + let ctx = TestCtx::new(); + insta::assert_snapshot!( + ctx.config("build") + .path("compiler") + .stage(3) + .hosts(&[TEST_TRIPLE_1]) + .args(&["--set", "build.full-bootstrap=true"]) + .render_steps(), @r" + [build] llvm + [build] llvm + [build] rustc 0 -> rustc 1 + [build] rustc 1 -> std 1 + [build] rustc 1 -> rustc 2 + [build] rustc 2 -> std 2 + [build] rustc 2 -> std 2 + [build] rustc 2 -> rustc 3 + "); + } + #[test] fn build_compiler_codegen_backend() { let ctx = TestCtx::new(); From f254075e95a074b47307b7ffada62a907cb27c22 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Ber=C3=A1nek?= Date: Wed, 20 Aug 2025 08:43:57 +0200 Subject: [PATCH 2/2] Disable rustc uplifting during cross-compilation --- src/bootstrap/src/core/build_steps/compile.rs | 14 +++++--------- src/bootstrap/src/core/builder/tests.rs | 1 + 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/src/bootstrap/src/core/build_steps/compile.rs b/src/bootstrap/src/core/build_steps/compile.rs index 74a8cea1ebe77..f22d40e021ecb 100644 --- a/src/bootstrap/src/core/build_steps/compile.rs +++ b/src/bootstrap/src/core/build_steps/compile.rs @@ -1047,22 +1047,18 @@ impl Step for Rustc { // If we are building a stage3+ compiler, and full bootstrap is disabled, and we have a // previous rustc available, we will uplift a compiler from a previous stage. + // We do not allow cross-compilation uplifting here, because there it can be quite tricky + // to figure out which stage actually built the rustc that should be uplifted. if build_compiler.stage >= 2 && !builder.config.full_bootstrap - && (target == builder.host_target || builder.hosts.contains(&target)) + && target == builder.host_target { // Here we need to determine the **build compiler** that built the stage that we will // be uplifting. We cannot uplift stage 1, as it has a different ABI than stage 2+, // so we always uplift the stage2 compiler (compiled with stage 1). let uplift_build_compiler = builder.compiler(1, build_compiler.host); - let msg = if uplift_build_compiler.host == target { - format!("Uplifting rustc (stage2 -> stage{stage})") - } else { - format!( - "Uplifting rustc (stage2:{} -> stage{stage}:{target})", - uplift_build_compiler.host - ) - }; + + let msg = format!("Uplifting rustc from stage2 to stage{stage})"); builder.info(&msg); // Here the compiler that built the rlibs (`uplift_build_compiler`) can be different diff --git a/src/bootstrap/src/core/builder/tests.rs b/src/bootstrap/src/core/builder/tests.rs index 85c7f46099fee..a7db96055e663 100644 --- a/src/bootstrap/src/core/builder/tests.rs +++ b/src/bootstrap/src/core/builder/tests.rs @@ -705,6 +705,7 @@ mod snapshot { [build] rustc 1 -> rustc 2 [build] rustc 1 -> std 1 [build] rustc 2 -> std 2 + [build] rustc 2 -> std 2 [build] rustc 2 -> rustc 3 "); }