Skip to content

Commit 7a217e1

Browse files
committed
Don't trigger an LLVM build from check builds using the stage 0 compiler
1 parent 8388b31 commit 7a217e1

File tree

2 files changed

+19
-18
lines changed

2 files changed

+19
-18
lines changed

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

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1323,7 +1323,7 @@ pub fn rustc_cargo_env(
13231323
builder: &Builder<'_>,
13241324
cargo: &mut Cargo,
13251325
target: TargetSelection,
1326-
build_stage: u32,
1326+
_build_stage: u32,
13271327
) {
13281328
// Set some configuration variables picked up by build scripts and
13291329
// the compiler alike
@@ -1379,18 +1379,24 @@ pub fn rustc_cargo_env(
13791379
cargo.rustflag("--cfg=llvm_enzyme");
13801380
}
13811381

1382-
// Note that this is disabled if LLVM itself is disabled or we're in a check
1383-
// build. If we are in a check build we still go ahead here presuming we've
1384-
// detected that LLVM is already built and good to go which helps prevent
1385-
// busting caches (e.g. like #71152).
1382+
// These conditionals represent a tension between three forces:
1383+
// - For non-check builds, we need to define some LLVM-related environment
1384+
// variables, requiring LLVM to have been built.
1385+
// - For check builds, we want to avoid building LLVM if possible.
1386+
// - Check builds and non-check builds should have the same environment if
1387+
// possible, to avoid unnecessary rebuilds due to cache-busting.
1388+
//
1389+
// Therefore we try to avoid building LLVM for check builds, but only if
1390+
// building LLVM would be expensive. If "building" LLVM is cheap
1391+
// (i.e. it's already built or is downloadable), we prefer to maintain a
1392+
// consistent environment between check and non-check builds.
13861393
if builder.config.llvm_enabled(target) {
1387-
let building_is_expensive =
1394+
let building_llvm_is_expensive =
13881395
crate::core::build_steps::llvm::prebuilt_llvm_config(builder, target, false)
13891396
.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 {
1397+
1398+
let skip_llvm = (builder.kind == Kind::Check) && building_llvm_is_expensive;
1399+
if !skip_llvm {
13941400
rustc_llvm_env(builder, cargo, target)
13951401
}
13961402
}
@@ -1407,6 +1413,9 @@ pub fn rustc_cargo_env(
14071413

14081414
/// Pass down configuration from the LLVM build into the build of
14091415
/// rustc_llvm and rustc_codegen_llvm.
1416+
///
1417+
/// Note that this has the side-effect of _building LLVM_, which is sometimes
1418+
/// unwanted (e.g. for check builds).
14101419
fn rustc_llvm_env(builder: &Builder<'_>, cargo: &mut Cargo, target: TargetSelection) {
14111420
if builder.config.is_rust_llvm(target) {
14121421
cargo.env("LLVM_RUSTLLVM", "1");

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

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1298,7 +1298,6 @@ mod snapshot {
12981298
ctx.config("check")
12991299
.path("compiler")
13001300
.render_steps(), @r"
1301-
[build] llvm <host>
13021301
[check] rustc 0 <host> -> rustc 1 <host>
13031302
[check] rustc 0 <host> -> cranelift 1 <host>
13041303
[check] rustc 0 <host> -> gcc 1 <host>
@@ -1312,7 +1311,6 @@ mod snapshot {
13121311
ctx.config("check")
13131312
.path("rustc")
13141313
.render_steps(), @r"
1315-
[build] llvm <host>
13161314
[check] rustc 0 <host> -> rustc 1 <host>
13171315
");
13181316
}
@@ -1332,7 +1330,6 @@ mod snapshot {
13321330
.path("compiler")
13331331
.stage(1)
13341332
.render_steps(), @r"
1335-
[build] llvm <host>
13361333
[check] rustc 0 <host> -> rustc 1 <host>
13371334
[check] rustc 0 <host> -> cranelift 1 <host>
13381335
[check] rustc 0 <host> -> gcc 1 <host>
@@ -1464,7 +1461,6 @@ mod snapshot {
14641461
.paths(&["library", "compiler"])
14651462
.args(&args)
14661463
.render_steps(), @r"
1467-
[build] llvm <host>
14681464
[check] rustc 0 <host> -> rustc 1 <host>
14691465
[check] rustc 0 <host> -> cranelift 1 <host>
14701466
[check] rustc 0 <host> -> gcc 1 <host>
@@ -1478,7 +1474,6 @@ mod snapshot {
14781474
ctx.config("check")
14791475
.path("miri")
14801476
.render_steps(), @r"
1481-
[build] llvm <host>
14821477
[check] rustc 0 <host> -> rustc 1 <host>
14831478
[check] rustc 0 <host> -> Miri 1 <host>
14841479
");
@@ -1499,7 +1494,6 @@ mod snapshot {
14991494
.path("miri")
15001495
.stage(1)
15011496
.render_steps(), @r"
1502-
[build] llvm <host>
15031497
[check] rustc 0 <host> -> rustc 1 <host>
15041498
[check] rustc 0 <host> -> Miri 1 <host>
15051499
");
@@ -1552,7 +1546,6 @@ mod snapshot {
15521546
ctx.config("check")
15531547
.path("rustc_codegen_cranelift")
15541548
.render_steps(), @r"
1555-
[build] llvm <host>
15561549
[check] rustc 0 <host> -> rustc 1 <host>
15571550
[check] rustc 0 <host> -> cranelift 1 <host>
15581551
[check] rustc 0 <host> -> gcc 1 <host>
@@ -1566,7 +1559,6 @@ mod snapshot {
15661559
ctx.config("check")
15671560
.path("rust-analyzer")
15681561
.render_steps(), @r"
1569-
[build] llvm <host>
15701562
[check] rustc 0 <host> -> rustc 1 <host>
15711563
[check] rustc 0 <host> -> rust-analyzer 1 <host>
15721564
");

0 commit comments

Comments
 (0)