diff --git a/src/bootstrap/src/core/build_steps/compile.rs b/src/bootstrap/src/core/build_steps/compile.rs index 09bb2e35bdaa2..0239bfecb1456 100644 --- a/src/bootstrap/src/core/build_steps/compile.rs +++ b/src/bootstrap/src/core/build_steps/compile.rs @@ -1387,8 +1387,10 @@ pub fn rustc_cargo_env( let building_is_expensive = crate::core::build_steps::llvm::prebuilt_llvm_config(builder, target, false) .should_build(); - // `top_stage == stage` might be false for `check --stage 1`, if we are building the stage 1 compiler - let can_skip_build = builder.kind == Kind::Check && builder.top_stage == build_stage; + + // If we are doing a check build using the pre-built stage 0 compiler, + // there should be no need to build LLVM. + let can_skip_build = builder.kind == Kind::Check && build_stage == 0; let should_skip_build = building_is_expensive && can_skip_build; if !should_skip_build { rustc_llvm_env(builder, cargo, target) diff --git a/src/bootstrap/src/core/builder/tests.rs b/src/bootstrap/src/core/builder/tests.rs index 51a906496923b..85a0f800e6ec0 100644 --- a/src/bootstrap/src/core/builder/tests.rs +++ b/src/bootstrap/src/core/builder/tests.rs @@ -630,6 +630,46 @@ fn any_debug() { assert_eq!(x.downcast_ref::(), Some(&MyStruct { x: 7 })); } +#[test] +fn test_check_compiler_doesnt_build_llvm() { + // Checking the stage 1 compiler uses the bootstrap compiler, and therefore + // should not need to build LLVM. + { + let config = configure_with_args( + &["check", "compiler", "--stage=1"], + &[TEST_TRIPLE_1], + &[TEST_TRIPLE_1], + ); + let mut cache = run_build(&config.paths.clone(), config); + + assert!(!cache.contains::()); + } + + // Checking the stage 1 library uses the stage 1 compiler, so it will need LLVM. + { + let config = configure_with_args( + &["check", "library", "--stage=1"], + &[TEST_TRIPLE_1], + &[TEST_TRIPLE_1], + ); + let mut cache = run_build(&config.paths.clone(), config); + + assert!(cache.contains::()); + } + + // Checking the stage 2 compiler uses the stage 1 compiler, so it will need LLVM. + { + let config = configure_with_args( + &["check", "compiler", "--stage=2"], + &[TEST_TRIPLE_1], + &[TEST_TRIPLE_1], + ); + let mut cache = run_build(&config.paths.clone(), config); + + assert!(cache.contains::()); + } +} + /// These tests use insta for snapshot testing. /// See bootstrap's README on how to bless the snapshots. mod snapshot { @@ -1294,7 +1334,6 @@ mod snapshot { ctx.config("check") .path("compiler") .render_steps(), @r" - [build] llvm [check] rustc 0 -> rustc 1 [check] rustc 0 -> cranelift 1 [check] rustc 0 -> gcc 1 @@ -1324,7 +1363,6 @@ mod snapshot { .path("compiler") .stage(1) .render_steps(), @r" - [build] llvm [check] rustc 0 -> rustc 1 [check] rustc 0 -> cranelift 1 [check] rustc 0 -> gcc 1 @@ -1360,6 +1398,7 @@ 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 @@ -1456,7 +1495,6 @@ mod snapshot { .paths(&["library", "compiler"]) .args(&args) .render_steps(), @r" - [build] llvm [check] rustc 0 -> rustc 1 [check] rustc 0 -> cranelift 1 [check] rustc 0 -> gcc 1 @@ -1470,7 +1508,6 @@ mod snapshot { ctx.config("check") .path("miri") .render_steps(), @r" - [build] llvm [check] rustc 0 -> rustc 1 [check] rustc 0 -> Miri 1 "); @@ -1491,7 +1528,6 @@ mod snapshot { .path("miri") .stage(1) .render_steps(), @r" - [build] llvm [check] rustc 0 -> rustc 1 [check] rustc 0 -> Miri 1 "); @@ -1544,7 +1580,6 @@ mod snapshot { ctx.config("check") .path("rustc_codegen_cranelift") .render_steps(), @r" - [build] llvm [check] rustc 0 -> rustc 1 [check] rustc 0 -> cranelift 1 [check] rustc 0 -> gcc 1 @@ -1558,7 +1593,6 @@ mod snapshot { ctx.config("check") .path("rust-analyzer") .render_steps(), @r" - [build] llvm [check] rustc 0 -> rustc 1 [check] rustc 0 -> rust-analyzer 1 ");