Skip to content

Commit ddfea62

Browse files
Auto merge of #144011 - Zalathar:check-compiler-no-llvm, r=<try>
bootstrap: Don't trigger an LLVM build from check builds using the stage 0 compiler Coming back to r-l/r development after a few weeks away, I found a major regression in my dev workflows: running `x check compiler` (either manually or via rust-analyzer) would have the side-effect of building LLVM, even though that shouldn't be necessary. For my main build directory this would be a minor annoyance, but for my separate rust-analyzer build directory it's a huge problem because it causes a completely separate build of LLVM, which takes a long time and should be completely unnecessary. --- After some investigation, I tracked down the problem to the `can_skip_build` check in this code: https://github.com/rust-lang/rust/blob/3014e79f9c8d5510ea7b3a3b70d171d0948b1e96/src/bootstrap/src/core/build_steps/compile.rs#L1382-L1396 Historically, this would skip the LLVM build for stage 0 check builds. But after the recent stage 0 std redesign and some associated check stage renumbering (e.g. #143048), the condition `builder.top_stage == build_stage` is now false, because `top_stage` is 1 (due to the renumbering) but `build_stage` is 0 (because a “stage 1” non-library check build still uses the stage 0 compiler). --- Because this is a critical contributor roadblock for me, I have tried to fix this in a relatively narrow way. It's possible that all of this surrounding logic could be greatly simplified (especially in light of the stage redesign changes), but I didn't want this fix to be held back by scope creep. --- (Zulip thread: https://rust-lang.zulipchat.com/#narrow/channel/326414-t-infra.2Fbootstrap/topic/Bootstrap.20incorrectly.20building.20LLVM.20for.20check.20builds/near/528991035) r? Kobzol try-job: x86_64-mingw-1 try-job: x86_64-mingw-2
2 parents f21fbac + bf75472 commit ddfea62

File tree

4 files changed

+50
-24
lines changed

4 files changed

+50
-24
lines changed

src/bootstrap/src/core/build_steps/check.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ impl Step for CodegenBackend {
350350
cargo
351351
.arg("--manifest-path")
352352
.arg(builder.src.join(format!("compiler/rustc_codegen_{backend}/Cargo.toml")));
353-
rustc_cargo_env(builder, &mut cargo, target, build_compiler.stage);
353+
rustc_cargo_env(builder, &mut cargo, target);
354354

355355
let _guard = builder.msg_check(format!("rustc_codegen_{backend}"), target, None);
356356

src/bootstrap/src/core/build_steps/compile.rs

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1316,15 +1316,10 @@ pub fn rustc_cargo(
13161316
cargo.env("RUSTC_WRAPPER", ccache);
13171317
}
13181318

1319-
rustc_cargo_env(builder, cargo, target, build_compiler.stage);
1319+
rustc_cargo_env(builder, cargo, target);
13201320
}
13211321

1322-
pub fn rustc_cargo_env(
1323-
builder: &Builder<'_>,
1324-
cargo: &mut Cargo,
1325-
target: TargetSelection,
1326-
build_stage: u32,
1327-
) {
1322+
pub fn rustc_cargo_env(builder: &Builder<'_>, cargo: &mut Cargo, target: TargetSelection) {
13281323
// Set some configuration variables picked up by build scripts and
13291324
// the compiler alike
13301325
cargo
@@ -1384,13 +1379,12 @@ pub fn rustc_cargo_env(
13841379
// detected that LLVM is already built and good to go which helps prevent
13851380
// busting caches (e.g. like #71152).
13861381
if builder.config.llvm_enabled(target) {
1387-
let building_is_expensive =
1382+
let building_llvm_is_expensive =
13881383
crate::core::build_steps::llvm::prebuilt_llvm_config(builder, target, false)
13891384
.should_build();
1390-
// `top_stage == stage` might be false for `check --stage 1`, if we are building the stage 1 compiler
1391-
let can_skip_build = builder.kind == Kind::Check && builder.top_stage == build_stage;
1392-
let should_skip_build = building_is_expensive && can_skip_build;
1393-
if !should_skip_build {
1385+
1386+
let skip_llvm = (builder.kind == Kind::Check) && building_llvm_is_expensive;
1387+
if !skip_llvm {
13941388
rustc_llvm_env(builder, cargo, target)
13951389
}
13961390
}
@@ -1665,7 +1659,7 @@ impl Step for CodegenBackend {
16651659
cargo
16661660
.arg("--manifest-path")
16671661
.arg(builder.src.join(format!("compiler/rustc_codegen_{backend}/Cargo.toml")));
1668-
rustc_cargo_env(builder, &mut cargo, target, compiler.stage);
1662+
rustc_cargo_env(builder, &mut cargo, target);
16691663

16701664
// Ideally, we'd have a separate step for the individual codegen backends,
16711665
// like we have in tests (test::CodegenGCC) but that would require a lot of restructuring.

src/bootstrap/src/core/build_steps/test.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3386,7 +3386,7 @@ impl Step for CodegenCranelift {
33863386
cargo
33873387
.arg("--manifest-path")
33883388
.arg(builder.src.join("compiler/rustc_codegen_cranelift/build_system/Cargo.toml"));
3389-
compile::rustc_cargo_env(builder, &mut cargo, target, compiler.stage);
3389+
compile::rustc_cargo_env(builder, &mut cargo, target);
33903390

33913391
// Avoid incremental cache issues when changing rustc
33923392
cargo.env("CARGO_BUILD_INCREMENTAL", "false");
@@ -3518,7 +3518,7 @@ impl Step for CodegenGCC {
35183518
cargo
35193519
.arg("--manifest-path")
35203520
.arg(builder.src.join("compiler/rustc_codegen_gcc/build_system/Cargo.toml"));
3521-
compile::rustc_cargo_env(builder, &mut cargo, target, compiler.stage);
3521+
compile::rustc_cargo_env(builder, &mut cargo, target);
35223522
add_cg_gcc_cargo_flags(&mut cargo, &gcc);
35233523

35243524
// Avoid incremental cache issues when changing rustc

src/bootstrap/src/core/builder/tests.rs

Lines changed: 40 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -630,6 +630,46 @@ fn any_debug() {
630630
assert_eq!(x.downcast_ref::<MyStruct>(), Some(&MyStruct { x: 7 }));
631631
}
632632

633+
#[test]
634+
fn test_check_compiler_doesnt_build_llvm() {
635+
// Checking the stage 1 compiler uses the bootstrap compiler, and therefore
636+
// should not need to build LLVM.
637+
{
638+
let config = configure_with_args(
639+
&["check", "compiler", "--stage=1"],
640+
&[TEST_TRIPLE_1],
641+
&[TEST_TRIPLE_1],
642+
);
643+
let mut cache = run_build(&config.paths.clone(), config);
644+
645+
assert!(!cache.contains::<llvm::Llvm>());
646+
}
647+
648+
// Checking the stage 1 library uses the stage 1 compiler, so it will need LLVM.
649+
{
650+
let config = configure_with_args(
651+
&["check", "library", "--stage=1"],
652+
&[TEST_TRIPLE_1],
653+
&[TEST_TRIPLE_1],
654+
);
655+
let mut cache = run_build(&config.paths.clone(), config);
656+
657+
assert!(cache.contains::<llvm::Llvm>());
658+
}
659+
660+
// Checking the stage 2 compiler uses the stage 1 compiler, so it will need LLVM.
661+
{
662+
let config = configure_with_args(
663+
&["check", "compiler", "--stage=2"],
664+
&[TEST_TRIPLE_1],
665+
&[TEST_TRIPLE_1],
666+
);
667+
let mut cache = run_build(&config.paths.clone(), config);
668+
669+
assert!(cache.contains::<llvm::Llvm>());
670+
}
671+
}
672+
633673
/// These tests use insta for snapshot testing.
634674
/// See bootstrap's README on how to bless the snapshots.
635675
mod snapshot {
@@ -1294,7 +1334,6 @@ mod snapshot {
12941334
ctx.config("check")
12951335
.path("compiler")
12961336
.render_steps(), @r"
1297-
[build] llvm <host>
12981337
[check] rustc 0 <host> -> rustc 1 <host>
12991338
[check] rustc 0 <host> -> cranelift 1 <host>
13001339
[check] rustc 0 <host> -> gcc 1 <host>
@@ -1304,7 +1343,6 @@ mod snapshot {
13041343
ctx.config("check")
13051344
.path("rustc")
13061345
.render_steps(), @r"
1307-
[build] llvm <host>
13081346
[check] rustc 0 <host> -> rustc 1 <host>
13091347
");
13101348
}
@@ -1324,7 +1362,6 @@ mod snapshot {
13241362
.path("compiler")
13251363
.stage(1)
13261364
.render_steps(), @r"
1327-
[build] llvm <host>
13281365
[check] rustc 0 <host> -> rustc 1 <host>
13291366
[check] rustc 0 <host> -> cranelift 1 <host>
13301367
[check] rustc 0 <host> -> gcc 1 <host>
@@ -1456,7 +1493,6 @@ mod snapshot {
14561493
.paths(&["library", "compiler"])
14571494
.args(&args)
14581495
.render_steps(), @r"
1459-
[build] llvm <host>
14601496
[check] rustc 0 <host> -> rustc 1 <host>
14611497
[check] rustc 0 <host> -> cranelift 1 <host>
14621498
[check] rustc 0 <host> -> gcc 1 <host>
@@ -1470,7 +1506,6 @@ mod snapshot {
14701506
ctx.config("check")
14711507
.path("miri")
14721508
.render_steps(), @r"
1473-
[build] llvm <host>
14741509
[check] rustc 0 <host> -> rustc 1 <host>
14751510
[check] rustc 0 <host> -> Miri 1 <host>
14761511
");
@@ -1491,7 +1526,6 @@ mod snapshot {
14911526
.path("miri")
14921527
.stage(1)
14931528
.render_steps(), @r"
1494-
[build] llvm <host>
14951529
[check] rustc 0 <host> -> rustc 1 <host>
14961530
[check] rustc 0 <host> -> Miri 1 <host>
14971531
");
@@ -1544,7 +1578,6 @@ mod snapshot {
15441578
ctx.config("check")
15451579
.path("rustc_codegen_cranelift")
15461580
.render_steps(), @r"
1547-
[build] llvm <host>
15481581
[check] rustc 0 <host> -> rustc 1 <host>
15491582
[check] rustc 0 <host> -> cranelift 1 <host>
15501583
[check] rustc 0 <host> -> gcc 1 <host>
@@ -1558,7 +1591,6 @@ mod snapshot {
15581591
ctx.config("check")
15591592
.path("rust-analyzer")
15601593
.render_steps(), @r"
1561-
[build] llvm <host>
15621594
[check] rustc 0 <host> -> rustc 1 <host>
15631595
[check] rustc 0 <host> -> rust-analyzer 1 <host>
15641596
");

0 commit comments

Comments
 (0)