From 20719767bc04ab72ae1c1d0751caff960b984ac9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Ber=C3=A1nek?= Date: Sat, 5 Jul 2025 10:55:12 +0200 Subject: [PATCH] Use stage auto-bump when cross-checking on stage 1 --- src/bootstrap/src/core/build_steps/check.rs | 22 +++++++++++---------- src/bootstrap/src/core/builder/tests.rs | 9 ++------- 2 files changed, 14 insertions(+), 17 deletions(-) diff --git a/src/bootstrap/src/core/build_steps/check.rs b/src/bootstrap/src/core/build_steps/check.rs index 555a02ac5872..40632f35bd77 100644 --- a/src/bootstrap/src/core/build_steps/check.rs +++ b/src/bootstrap/src/core/build_steps/check.rs @@ -1,7 +1,5 @@ //! Implementation of compiling the compiler and standard library, in "check"-based modes. -use build_helper::exit; - use crate::core::build_steps::compile::{ add_to_sysroot, run_cargo, rustc_cargo, rustc_cargo_env, std_cargo, std_crates_for_run_make, }; @@ -264,19 +262,23 @@ fn prepare_compiler_for_check( build_compiler } Mode::ToolRustc | Mode::Codegen => { + // FIXME: this is a hack, see description of Mode::Rustc below + let stage = if host == target { builder.top_stage - 1 } else { builder.top_stage }; // When checking tool stage N, we check it with compiler stage N-1 - let build_compiler = builder.compiler(builder.top_stage - 1, host); + let build_compiler = builder.compiler(stage, host); builder.ensure(Rustc::new(builder, build_compiler, target)); build_compiler } Mode::Rustc => { - if builder.top_stage < 2 && host != target { - eprintln!("Cannot do a cross-compilation check of rustc on stage 1, use stage 2"); - exit!(1); - } - - // When checking the stage N compiler, we want to do it with the stage N-1 compiler - builder.compiler(builder.top_stage - 1, host) + // This is a horrible hack, because we actually change the compiler stage numbering + // here. If you do `x check --stage 1 --host FOO`, we build stage 1 host rustc, + // and use that to check stage 1 FOO rustc (which actually makes that stage 2 FOO + // rustc). + // + // FIXME: remove this and either fix cross-compilation check on stage 2 (which has a + // myriad of other problems) or disable cross-checking on stage 1. + let stage = if host == target { builder.top_stage - 1 } else { builder.top_stage }; + builder.compiler(stage, host) } Mode::Std => { // When checking std stage N, we want to do it with the stage N compiler diff --git a/src/bootstrap/src/core/builder/tests.rs b/src/bootstrap/src/core/builder/tests.rs index f0dba1a85f34..a6bd531fd14b 100644 --- a/src/bootstrap/src/core/builder/tests.rs +++ b/src/bootstrap/src/core/builder/tests.rs @@ -1299,7 +1299,6 @@ mod snapshot { let ctx = TestCtx::new(); insta::assert_snapshot!( ctx.config("check") - .stage(2) .targets(&[TEST_TRIPLE_1]) .hosts(&[TEST_TRIPLE_1]) .render_steps(), @r" @@ -1307,7 +1306,6 @@ mod snapshot { [build] rustc 0 -> rustc 1 [build] rustc 1 -> std 1 [build] rustc 1 -> std 1 - [build] llvm [check] rustc 1 -> rustc 2 [check] rustc 1 -> Rustdoc 2 [check] rustc 1 -> cranelift 2 @@ -1318,12 +1316,9 @@ mod snapshot { [check] rustc 0 -> MiroptTestTools 1 [check] rustc 1 -> Rustfmt 2 [check] rustc 1 -> rust-analyzer 2 - [build] rustc 1 -> rustc 2 - [build] rustc 2 -> std 2 - [build] rustc 2 -> std 2 - [check] rustc 2 -> TestFloatParse 3 + [check] rustc 1 -> TestFloatParse 2 [check] rustc 0 -> FeaturesStatusDump 1 - [check] rustc 2 -> std 2 + [check] rustc 1 -> std 1 "); }