Skip to content

Commit e6af292

Browse files
committedMar 6, 2025
Auto merge of rust-lang#138039 - onur-ozkan:handle-forced-compiler-on-tools, r=jieyouxu
handle forced compiler and revert rust-lang#137476 Fixes rust-lang#138004 I would appreciate it if we could measure CI pipelines with the current changes to see if this reduces recent CI overhead. cc `@rust-lang/infra` try-job: dist-powerpc64le-linux
2 parents 30f168e + 64dd484 commit e6af292

File tree

5 files changed

+145
-86
lines changed

5 files changed

+145
-86
lines changed
 

‎src/bootstrap/src/core/build_steps/dist.rs

+47-12
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,11 @@ impl Step for Rustc {
421421

422422
if let Some(ra_proc_macro_srv) = builder.ensure_if_default(
423423
tool::RustAnalyzerProcMacroSrv {
424-
compiler: builder.compiler(compiler.stage, builder.config.build),
424+
compiler: builder.compiler_for(
425+
compiler.stage,
426+
builder.config.build,
427+
compiler.host,
428+
),
425429
target: compiler.host,
426430
},
427431
builder.kind,
@@ -771,7 +775,11 @@ impl Step for Analysis {
771775
// Find the actual compiler (handling the full bootstrap option) which
772776
// produced the save-analysis data because that data isn't copied
773777
// through the sysroot uplifting.
774-
compiler: run.builder.compiler(run.builder.top_stage, run.builder.config.build),
778+
compiler: run.builder.compiler_for(
779+
run.builder.top_stage,
780+
run.builder.config.build,
781+
run.target,
782+
),
775783
target: run.target,
776784
});
777785
}
@@ -1116,7 +1124,11 @@ impl Step for Cargo {
11161124

11171125
fn make_run(run: RunConfig<'_>) {
11181126
run.builder.ensure(Cargo {
1119-
compiler: run.builder.compiler(run.builder.top_stage, run.builder.config.build),
1127+
compiler: run.builder.compiler_for(
1128+
run.builder.top_stage,
1129+
run.builder.config.build,
1130+
run.target,
1131+
),
11201132
target: run.target,
11211133
});
11221134
}
@@ -1161,7 +1173,11 @@ impl Step for Rls {
11611173

11621174
fn make_run(run: RunConfig<'_>) {
11631175
run.builder.ensure(Rls {
1164-
compiler: run.builder.compiler(run.builder.top_stage, run.builder.config.build),
1176+
compiler: run.builder.compiler_for(
1177+
run.builder.top_stage,
1178+
run.builder.config.build,
1179+
run.target,
1180+
),
11651181
target: run.target,
11661182
});
11671183
}
@@ -1199,7 +1215,11 @@ impl Step for RustAnalyzer {
11991215

12001216
fn make_run(run: RunConfig<'_>) {
12011217
run.builder.ensure(RustAnalyzer {
1202-
compiler: run.builder.compiler(run.builder.top_stage, run.builder.config.build),
1218+
compiler: run.builder.compiler_for(
1219+
run.builder.top_stage,
1220+
run.builder.config.build,
1221+
run.target,
1222+
),
12031223
target: run.target,
12041224
});
12051225
}
@@ -1237,7 +1257,11 @@ impl Step for Clippy {
12371257

12381258
fn make_run(run: RunConfig<'_>) {
12391259
run.builder.ensure(Clippy {
1240-
compiler: run.builder.compiler(run.builder.top_stage, run.builder.config.build),
1260+
compiler: run.builder.compiler_for(
1261+
run.builder.top_stage,
1262+
run.builder.config.build,
1263+
run.target,
1264+
),
12411265
target: run.target,
12421266
});
12431267
}
@@ -1280,7 +1304,11 @@ impl Step for Miri {
12801304

12811305
fn make_run(run: RunConfig<'_>) {
12821306
run.builder.ensure(Miri {
1283-
compiler: run.builder.compiler(run.builder.top_stage, run.builder.config.build),
1307+
compiler: run.builder.compiler_for(
1308+
run.builder.top_stage,
1309+
run.builder.config.build,
1310+
run.target,
1311+
),
12841312
target: run.target,
12851313
});
12861314
}
@@ -1414,7 +1442,11 @@ impl Step for Rustfmt {
14141442

14151443
fn make_run(run: RunConfig<'_>) {
14161444
run.builder.ensure(Rustfmt {
1417-
compiler: run.builder.compiler(run.builder.top_stage, run.builder.config.build),
1445+
compiler: run.builder.compiler_for(
1446+
run.builder.top_stage,
1447+
run.builder.config.build,
1448+
run.target,
1449+
),
14181450
target: run.target,
14191451
});
14201452
}
@@ -1464,7 +1496,7 @@ impl Step for Extended {
14641496
fn run(self, builder: &Builder<'_>) {
14651497
let target = self.target;
14661498
let stage = self.stage;
1467-
let compiler = builder.compiler(self.stage, self.host);
1499+
let compiler = builder.compiler_for(self.stage, self.host, self.target);
14681500

14691501
builder.info(&format!("Dist extended stage{} ({})", compiler.stage, target));
14701502

@@ -2112,8 +2144,7 @@ pub fn maybe_install_llvm_target(builder: &Builder<'_>, target: TargetSelection,
21122144
),
21132145
)]
21142146
pub fn maybe_install_llvm_runtime(builder: &Builder<'_>, target: TargetSelection, sysroot: &Path) {
2115-
let dst_libdir =
2116-
sysroot.join(builder.sysroot_libdir_relative(Compiler { stage: 1, host: target }));
2147+
let dst_libdir = sysroot.join(builder.sysroot_libdir_relative(Compiler::new(1, target)));
21172148
// We do not need to copy LLVM files into the sysroot if it is not
21182149
// dynamically linked; it is already included into librustc_llvm
21192150
// statically.
@@ -2228,7 +2259,11 @@ impl Step for LlvmBitcodeLinker {
22282259

22292260
fn make_run(run: RunConfig<'_>) {
22302261
run.builder.ensure(LlvmBitcodeLinker {
2231-
compiler: run.builder.compiler(run.builder.top_stage, run.builder.config.build),
2262+
compiler: run.builder.compiler_for(
2263+
run.builder.top_stage,
2264+
run.builder.config.build,
2265+
run.target,
2266+
),
22322267
target: run.target,
22332268
});
22342269
}

‎src/bootstrap/src/core/build_steps/tool.rs

+2
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,8 @@ pub(crate) fn get_tool_rustc_compiler(
322322
if builder.download_rustc() && target_compiler.stage == 1 {
323323
// We already have the stage 1 compiler, we don't need to cut the stage.
324324
builder.compiler(target_compiler.stage, builder.config.build)
325+
} else if target_compiler.is_forced_compiler() {
326+
target_compiler
325327
} else {
326328
// Similar to `compile::Assemble`, build with the previous stage's compiler. Otherwise
327329
// we'd have stageN/bin/rustc and stageN/bin/$rustc_tool be effectively different stage

‎src/bootstrap/src/core/builder/mod.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -1235,7 +1235,7 @@ impl<'a> Builder<'a> {
12351235
),
12361236
)]
12371237
pub fn compiler(&self, stage: u32, host: TargetSelection) -> Compiler {
1238-
self.ensure(compile::Assemble { target_compiler: Compiler { stage, host } })
1238+
self.ensure(compile::Assemble { target_compiler: Compiler::new(stage, host) })
12391239
}
12401240

12411241
/// Similar to `compiler`, except handles the full-bootstrap option to
@@ -1273,7 +1273,7 @@ impl<'a> Builder<'a> {
12731273
target: TargetSelection,
12741274
) -> Compiler {
12751275
#![allow(clippy::let_and_return)]
1276-
let resolved_compiler = if self.build.force_use_stage2(stage) {
1276+
let mut resolved_compiler = if self.build.force_use_stage2(stage) {
12771277
trace!(target: "COMPILER_FOR", ?stage, "force_use_stage2");
12781278
self.compiler(2, self.config.build)
12791279
} else if self.build.force_use_stage1(stage, target) {
@@ -1283,6 +1283,11 @@ impl<'a> Builder<'a> {
12831283
trace!(target: "COMPILER_FOR", ?stage, ?host, "no force, fallback to `compiler()`");
12841284
self.compiler(stage, host)
12851285
};
1286+
1287+
if stage != resolved_compiler.stage {
1288+
resolved_compiler.forced_compiler(true);
1289+
}
1290+
12861291
trace!(target: "COMPILER_FOR", ?resolved_compiler);
12871292
resolved_compiler
12881293
}

0 commit comments

Comments
 (0)