Skip to content

Commit ad5eca6

Browse files
committed
Fixup codegen checking
1 parent 6fc6753 commit ad5eca6

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
@@ -146,7 +146,7 @@ fn default_compiler_for_checking_rustc(builder: &Builder<'_>) -> Compiler {
146146
}
147147

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

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

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

@@ -279,15 +292,13 @@ impl Step for CodegenBackend {
279292
return;
280293
}
281294

282-
let compiler = builder.compiler(builder.top_stage, builder.config.host_target);
295+
let build_compiler = self.build_compiler;
283296
let target = self.target;
284297
let backend = self.backend;
285298

286-
builder.ensure(Rustc::new(target, builder));
287-
288299
let mut cargo = builder::Cargo::new(
289300
builder,
290-
compiler,
301+
build_compiler,
291302
Mode::Codegen,
292303
SourceType::InTree,
293304
target,
@@ -297,15 +308,19 @@ impl Step for CodegenBackend {
297308
cargo
298309
.arg("--manifest-path")
299310
.arg(builder.src.join(format!("compiler/rustc_codegen_{backend}/Cargo.toml")));
300-
rustc_cargo_env(builder, &mut cargo, target, compiler.stage);
311+
rustc_cargo_env(builder, &mut cargo, target, build_compiler.stage);
301312

302-
let _guard = builder.msg_check(backend, target, None);
313+
let _guard = builder.msg_check(&format!("rustc_codegen_{backend}"), target, None);
303314

304-
let stamp = build_stamp::codegen_backend_stamp(builder, compiler, target, backend)
315+
let stamp = build_stamp::codegen_backend_stamp(builder, build_compiler, target, backend)
305316
.with_prefix("check");
306317

307318
run_cargo(builder, cargo, builder.config.free_args.clone(), &stamp, vec![], true, false);
308319
}
320+
321+
fn metadata(&self) -> Option<StepMetadata> {
322+
Some(StepMetadata::check(self.backend, self.target).built_by(self.build_compiler))
323+
}
309324
}
310325

311326
#[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)