Skip to content

Commit a702d4c

Browse files
committed
Fixup codegen checking
1 parent a18d5a4 commit a702d4c

File tree

2 files changed

+44
-9
lines changed

2 files changed

+44
-9
lines changed

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

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ fn default_compiler_for_checking_rustc(builder: &Builder<'_>) -> Compiler {
144144
}
145145

146146
/// Checks rustc using `build_compiler` and copies the built
147-
/// .rmeta files into the sysroot of `build_copoiler`.
147+
/// .rmeta files into the sysroot of `build_compiler`.
148148
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
149149
pub struct Rustc {
150150
/// Compiler that will check this rustc.
@@ -249,8 +249,19 @@ impl Step for Rustc {
249249
}
250250
}
251251

252+
/// Prepares a build compiler sysroot that will check a `Mode::ToolRustc` tool.
253+
/// Also checks rustc using this compiler, to prepare .rmetas that the tool will link to.
254+
fn prepare_compiler_for_tool_rustc(builder: &Builder<'_>, target: TargetSelection) -> Compiler {
255+
// When we check tool stage N, we check it with compiler stage N-1
256+
let build_compiler = builder.compiler(builder.top_stage - 1, builder.config.host_target);
257+
builder.ensure(Rustc::new(builder, build_compiler, target));
258+
build_compiler
259+
}
260+
261+
/// Checks a single codegen backend.
252262
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
253263
pub struct CodegenBackend {
264+
pub build_compiler: Compiler,
254265
pub target: TargetSelection,
255266
pub backend: &'static str,
256267
}
@@ -265,8 +276,10 @@ impl Step for CodegenBackend {
265276
}
266277

267278
fn make_run(run: RunConfig<'_>) {
279+
// FIXME: only check the backend(s) that were actually selected in run.paths
280+
let build_compiler = prepare_compiler_for_tool_rustc(run.builder, run.target);
268281
for &backend in &["cranelift", "gcc"] {
269-
run.builder.ensure(CodegenBackend { target: run.target, backend });
282+
run.builder.ensure(CodegenBackend { build_compiler, target: run.target, backend });
270283
}
271284
}
272285

@@ -277,15 +290,13 @@ impl Step for CodegenBackend {
277290
return;
278291
}
279292

280-
let compiler = builder.compiler(builder.top_stage, builder.config.host_target);
293+
let build_compiler = self.build_compiler;
281294
let target = self.target;
282295
let backend = self.backend;
283296

284-
builder.ensure(Rustc::new(target, builder));
285-
286297
let mut cargo = builder::Cargo::new(
287298
builder,
288-
compiler,
299+
build_compiler,
289300
Mode::Codegen,
290301
SourceType::InTree,
291302
target,
@@ -295,15 +306,19 @@ impl Step for CodegenBackend {
295306
cargo
296307
.arg("--manifest-path")
297308
.arg(builder.src.join(format!("compiler/rustc_codegen_{backend}/Cargo.toml")));
298-
rustc_cargo_env(builder, &mut cargo, target, compiler.stage);
309+
rustc_cargo_env(builder, &mut cargo, target, build_compiler.stage);
299310

300-
let _guard = builder.msg_check(backend, target, None);
311+
let _guard = builder.msg_check(&format!("rustc_codegen_{backend}"), target, None);
301312

302-
let stamp = build_stamp::codegen_backend_stamp(builder, compiler, target, backend)
313+
let stamp = build_stamp::codegen_backend_stamp(builder, build_compiler, target, backend)
303314
.with_prefix("check");
304315

305316
run_cargo(builder, cargo, builder.config.free_args.clone(), &stamp, vec![], true, false);
306317
}
318+
319+
fn metadata(&self) -> Option<StepMetadata> {
320+
Some(StepMetadata::check(self.backend, self.target).built_by(self.build_compiler))
321+
}
307322
}
308323

309324
#[derive(Debug, Clone, PartialEq, Eq, Hash)]

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1242,6 +1242,8 @@ mod snapshot {
12421242
.render_steps(), @r"
12431243
[build] llvm <host>
12441244
[check] rustc 0 <host> -> rustc 1 <host>
1245+
[check] rustc 0 <host> -> cranelift 1 <host>
1246+
[check] rustc 0 <host> -> gcc 1 <host>
12451247
");
12461248

12471249
insta::assert_snapshot!(
@@ -1270,6 +1272,8 @@ mod snapshot {
12701272
.render_steps(), @r"
12711273
[build] llvm <host>
12721274
[check] rustc 0 <host> -> rustc 1 <host>
1275+
[check] rustc 0 <host> -> cranelift 1 <host>
1276+
[check] rustc 0 <host> -> gcc 1 <host>
12731277
");
12741278
}
12751279

@@ -1285,6 +1289,8 @@ mod snapshot {
12851289
[build] rustc 0 <host> -> rustc 1 <host>
12861290
[build] rustc 1 <host> -> std 1 <host>
12871291
[check] rustc 1 <host> -> rustc 2 <host>
1292+
[check] rustc 1 <host> -> cranelift 2 <host>
1293+
[check] rustc 1 <host> -> gcc 2 <host>
12881294
");
12891295
}
12901296

@@ -1415,6 +1421,20 @@ mod snapshot {
14151421
");
14161422
}
14171423

1424+
#[test]
1425+
fn check_codegen() {
1426+
let ctx = TestCtx::new();
1427+
insta::assert_snapshot!(
1428+
ctx.config("check")
1429+
.path("rustc_codegen_cranelift")
1430+
.render_steps(), @r"
1431+
[build] llvm <host>
1432+
[check] rustc 0 <host> -> rustc 1 <host>
1433+
[check] rustc 0 <host> -> cranelift 1 <host>
1434+
[check] rustc 0 <host> -> gcc 1 <host>
1435+
");
1436+
}
1437+
14181438
#[test]
14191439
fn test_exclude() {
14201440
let ctx = TestCtx::new();

0 commit comments

Comments
 (0)