@@ -1323,7 +1323,7 @@ pub fn rustc_cargo_env(
1323
1323
builder : & Builder < ' _ > ,
1324
1324
cargo : & mut Cargo ,
1325
1325
target : TargetSelection ,
1326
- build_stage : u32 ,
1326
+ _build_stage : u32 ,
1327
1327
) {
1328
1328
// Set some configuration variables picked up by build scripts and
1329
1329
// the compiler alike
@@ -1379,18 +1379,24 @@ pub fn rustc_cargo_env(
1379
1379
cargo. rustflag ( "--cfg=llvm_enzyme" ) ;
1380
1380
}
1381
1381
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.
1386
1393
if builder. config . llvm_enabled ( target) {
1387
- let building_is_expensive =
1394
+ let building_llvm_is_expensive =
1388
1395
crate :: core:: build_steps:: llvm:: prebuilt_llvm_config ( builder, target, false )
1389
1396
. 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 {
1394
1400
rustc_llvm_env ( builder, cargo, target)
1395
1401
}
1396
1402
}
@@ -1407,6 +1413,9 @@ pub fn rustc_cargo_env(
1407
1413
1408
1414
/// Pass down configuration from the LLVM build into the build of
1409
1415
/// 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).
1410
1419
fn rustc_llvm_env ( builder : & Builder < ' _ > , cargo : & mut Cargo , target : TargetSelection ) {
1411
1420
if builder. config . is_rust_llvm ( target) {
1412
1421
cargo. env ( "LLVM_RUSTLLVM" , "1" ) ;
0 commit comments