Skip to content

Commit 0734cbd

Browse files
authored
Rollup merge of rust-lang#145340 - Kobzol:bootstrap-codegen-backend-check-split, r=jieyouxu
Split codegen backend check step into two and don't run it with `x check compiler` This reduces the amount of work that is done during `x check compiler`. We still check both backends during `x check` by defaut, even if they are not in `rust.codegen-backends`, as just checking them shouldn't require expensive preparations, like building GCC. r? `@jieyouxu`
2 parents b474f89 + 2a2903c commit 0734cbd

File tree

3 files changed

+91
-170
lines changed

3 files changed

+91
-170
lines changed

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

Lines changed: 86 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -314,41 +314,31 @@ pub fn prepare_compiler_for_check(
314314
}
315315
}
316316

317-
/// Checks a single codegen backend.
317+
/// Check the Cranelift codegen backend.
318318
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
319-
pub struct CodegenBackend {
320-
pub build_compiler: Compiler,
321-
pub target: TargetSelection,
322-
pub backend: CodegenBackendKind,
319+
pub struct CraneliftCodegenBackend {
320+
build_compiler: Compiler,
321+
target: TargetSelection,
323322
}
324323

325-
impl Step for CodegenBackend {
324+
impl Step for CraneliftCodegenBackend {
326325
type Output = ();
326+
327327
const IS_HOST: bool = true;
328328
const DEFAULT: bool = true;
329329

330330
fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
331-
run.paths(&["compiler/rustc_codegen_cranelift", "compiler/rustc_codegen_gcc"])
331+
run.alias("rustc_codegen_cranelift").alias("cg_clif")
332332
}
333333

334334
fn make_run(run: RunConfig<'_>) {
335-
// FIXME: only check the backend(s) that were actually selected in run.paths
336335
let build_compiler = prepare_compiler_for_check(run.builder, run.target, Mode::Codegen);
337-
for backend in [CodegenBackendKind::Cranelift, CodegenBackendKind::Gcc] {
338-
run.builder.ensure(CodegenBackend { build_compiler, target: run.target, backend });
339-
}
336+
run.builder.ensure(CraneliftCodegenBackend { build_compiler, target: run.target });
340337
}
341338

342339
fn run(self, builder: &Builder<'_>) {
343-
// FIXME: remove once https://github.com/rust-lang/rust/issues/112393 is resolved
344-
if builder.build.config.vendor && self.backend.is_gcc() {
345-
println!("Skipping checking of `rustc_codegen_gcc` with vendoring enabled.");
346-
return;
347-
}
348-
349340
let build_compiler = self.build_compiler;
350341
let target = self.target;
351-
let backend = self.backend;
352342

353343
let mut cargo = builder::Cargo::new(
354344
builder,
@@ -361,31 +351,104 @@ impl Step for CodegenBackend {
361351

362352
cargo
363353
.arg("--manifest-path")
364-
.arg(builder.src.join(format!("compiler/{}/Cargo.toml", backend.crate_name())));
354+
.arg(builder.src.join("compiler/rustc_codegen_cranelift/Cargo.toml"));
365355
rustc_cargo_env(builder, &mut cargo, target);
366356

367357
let _guard = builder.msg(
368358
Kind::Check,
369-
backend.crate_name(),
359+
"rustc_codegen_cranelift",
370360
Mode::Codegen,
371361
self.build_compiler,
372362
target,
373363
);
374364

375-
let stamp = build_stamp::codegen_backend_stamp(builder, build_compiler, target, &backend)
376-
.with_prefix("check");
365+
let stamp = build_stamp::codegen_backend_stamp(
366+
builder,
367+
build_compiler,
368+
target,
369+
&CodegenBackendKind::Cranelift,
370+
)
371+
.with_prefix("check");
377372

378373
run_cargo(builder, cargo, builder.config.free_args.clone(), &stamp, vec![], true, false);
379374
}
380375

381376
fn metadata(&self) -> Option<StepMetadata> {
382377
Some(
383-
StepMetadata::check(&self.backend.crate_name(), self.target)
378+
StepMetadata::check("rustc_codegen_cranelift", self.target)
384379
.built_by(self.build_compiler),
385380
)
386381
}
387382
}
388383

384+
/// Check the GCC codegen backend.
385+
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
386+
pub struct GccCodegenBackend {
387+
build_compiler: Compiler,
388+
target: TargetSelection,
389+
}
390+
391+
impl Step for GccCodegenBackend {
392+
type Output = ();
393+
394+
const IS_HOST: bool = true;
395+
const DEFAULT: bool = true;
396+
397+
fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
398+
run.alias("rustc_codegen_gcc").alias("cg_gcc")
399+
}
400+
401+
fn make_run(run: RunConfig<'_>) {
402+
let build_compiler = prepare_compiler_for_check(run.builder, run.target, Mode::Codegen);
403+
run.builder.ensure(GccCodegenBackend { build_compiler, target: run.target });
404+
}
405+
406+
fn run(self, builder: &Builder<'_>) {
407+
// FIXME: remove once https://github.com/rust-lang/rust/issues/112393 is resolved
408+
if builder.build.config.vendor {
409+
println!("Skipping checking of `rustc_codegen_gcc` with vendoring enabled.");
410+
return;
411+
}
412+
413+
let build_compiler = self.build_compiler;
414+
let target = self.target;
415+
416+
let mut cargo = builder::Cargo::new(
417+
builder,
418+
build_compiler,
419+
Mode::Codegen,
420+
SourceType::InTree,
421+
target,
422+
builder.kind,
423+
);
424+
425+
cargo.arg("--manifest-path").arg(builder.src.join("compiler/rustc_codegen_gcc/Cargo.toml"));
426+
rustc_cargo_env(builder, &mut cargo, target);
427+
428+
let _guard = builder.msg(
429+
Kind::Check,
430+
"rustc_codegen_gcc",
431+
Mode::Codegen,
432+
self.build_compiler,
433+
target,
434+
);
435+
436+
let stamp = build_stamp::codegen_backend_stamp(
437+
builder,
438+
build_compiler,
439+
target,
440+
&CodegenBackendKind::Gcc,
441+
)
442+
.with_prefix("check");
443+
444+
run_cargo(builder, cargo, builder.config.free_args.clone(), &stamp, vec![], true, false);
445+
}
446+
447+
fn metadata(&self) -> Option<StepMetadata> {
448+
Some(StepMetadata::check("rustc_codegen_gcc", self.target).built_by(self.build_compiler))
449+
}
450+
}
451+
389452
macro_rules! tool_check_step {
390453
(
391454
$name:ident {

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1042,7 +1042,8 @@ impl<'a> Builder<'a> {
10421042
Kind::Check | Kind::Fix => describe!(
10431043
check::Rustc,
10441044
check::Rustdoc,
1045-
check::CodegenBackend,
1045+
check::CraneliftCodegenBackend,
1046+
check::GccCodegenBackend,
10461047
check::Clippy,
10471048
check::Miri,
10481049
check::CargoMiri,

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

Lines changed: 3 additions & 146 deletions
Original file line numberDiff line numberDiff line change
@@ -1514,12 +1514,7 @@ mod snapshot {
15141514
insta::assert_snapshot!(
15151515
ctx.config("check")
15161516
.path("compiler")
1517-
.render_steps(), @r"
1518-
[check] rustc 0 <host> -> rustc 1 <host> (73 crates)
1519-
[check] rustc 0 <host> -> rustc 1 <host>
1520-
[check] rustc 0 <host> -> rustc_codegen_cranelift 1 <host>
1521-
[check] rustc 0 <host> -> rustc_codegen_gcc 1 <host>
1522-
");
1517+
.render_steps(), @"[check] rustc 0 <host> -> rustc 1 <host> (73 crates)");
15231518
}
15241519

15251520
#[test]
@@ -1545,12 +1540,7 @@ mod snapshot {
15451540
ctx.config("check")
15461541
.path("compiler")
15471542
.stage(1)
1548-
.render_steps(), @r"
1549-
[check] rustc 0 <host> -> rustc 1 <host> (73 crates)
1550-
[check] rustc 0 <host> -> rustc 1 <host>
1551-
[check] rustc 0 <host> -> rustc_codegen_cranelift 1 <host>
1552-
[check] rustc 0 <host> -> rustc_codegen_gcc 1 <host>
1553-
");
1543+
.render_steps(), @"[check] rustc 0 <host> -> rustc 1 <host> (73 crates)");
15541544
}
15551545

15561546
#[test]
@@ -1565,9 +1555,6 @@ mod snapshot {
15651555
[build] rustc 0 <host> -> rustc 1 <host>
15661556
[build] rustc 1 <host> -> std 1 <host>
15671557
[check] rustc 1 <host> -> rustc 2 <host> (73 crates)
1568-
[check] rustc 1 <host> -> rustc 2 <host>
1569-
[check] rustc 1 <host> -> rustc_codegen_cranelift 2 <host>
1570-
[check] rustc 1 <host> -> rustc_codegen_gcc 2 <host>
15711558
");
15721559
}
15731560

@@ -1679,12 +1666,7 @@ mod snapshot {
16791666
ctx.config("check")
16801667
.paths(&["library", "compiler"])
16811668
.args(&args)
1682-
.render_steps(), @r"
1683-
[check] rustc 0 <host> -> rustc 1 <host> (73 crates)
1684-
[check] rustc 0 <host> -> rustc 1 <host>
1685-
[check] rustc 0 <host> -> rustc_codegen_cranelift 1 <host>
1686-
[check] rustc 0 <host> -> rustc_codegen_gcc 1 <host>
1687-
");
1669+
.render_steps(), @"[check] rustc 0 <host> -> rustc 1 <host> (73 crates)");
16881670
}
16891671

16901672
#[test]
@@ -1768,7 +1750,6 @@ mod snapshot {
17681750
.render_steps(), @r"
17691751
[check] rustc 0 <host> -> rustc 1 <host>
17701752
[check] rustc 0 <host> -> rustc_codegen_cranelift 1 <host>
1771-
[check] rustc 0 <host> -> rustc_codegen_gcc 1 <host>
17721753
");
17731754
}
17741755

@@ -2068,130 +2049,6 @@ mod snapshot {
20682049
[doc] rustc 1 <host> -> reference (book) 2 <host>
20692050
");
20702051
}
2071-
2072-
#[test]
2073-
fn clippy_ci() {
2074-
let ctx = TestCtx::new();
2075-
insta::assert_snapshot!(
2076-
ctx.config("clippy")
2077-
.path("ci")
2078-
.stage(2)
2079-
.render_steps(), @r"
2080-
[build] llvm <host>
2081-
[build] rustc 0 <host> -> rustc 1 <host>
2082-
[build] rustc 1 <host> -> std 1 <host>
2083-
[build] rustc 0 <host> -> clippy-driver 1 <host>
2084-
[build] rustc 0 <host> -> cargo-clippy 1 <host>
2085-
[clippy] rustc 1 <host> -> bootstrap 2 <host>
2086-
[clippy] rustc 1 <host> -> std 1 <host>
2087-
[clippy] rustc 1 <host> -> rustc 2 <host>
2088-
[check] rustc 1 <host> -> rustc 2 <host>
2089-
[clippy] rustc 1 <host> -> rustc_codegen_gcc 2 <host>
2090-
");
2091-
}
2092-
2093-
#[test]
2094-
fn clippy_compiler_stage1() {
2095-
let ctx = TestCtx::new();
2096-
insta::assert_snapshot!(
2097-
ctx.config("clippy")
2098-
.path("compiler")
2099-
.render_steps(), @r"
2100-
[build] llvm <host>
2101-
[clippy] rustc 0 <host> -> rustc 1 <host>
2102-
");
2103-
}
2104-
2105-
#[test]
2106-
fn clippy_compiler_stage2() {
2107-
let ctx = TestCtx::new();
2108-
insta::assert_snapshot!(
2109-
ctx.config("clippy")
2110-
.path("compiler")
2111-
.stage(2)
2112-
.render_steps(), @r"
2113-
[build] llvm <host>
2114-
[build] rustc 0 <host> -> rustc 1 <host>
2115-
[build] rustc 1 <host> -> std 1 <host>
2116-
[build] rustc 0 <host> -> clippy-driver 1 <host>
2117-
[build] rustc 0 <host> -> cargo-clippy 1 <host>
2118-
[clippy] rustc 1 <host> -> rustc 2 <host>
2119-
");
2120-
}
2121-
2122-
#[test]
2123-
fn clippy_std_stage1() {
2124-
let ctx = TestCtx::new();
2125-
insta::assert_snapshot!(
2126-
ctx.config("clippy")
2127-
.path("std")
2128-
.render_steps(), @r"
2129-
[build] llvm <host>
2130-
[build] rustc 0 <host> -> rustc 1 <host>
2131-
[build] rustc 0 <host> -> clippy-driver 1 <host>
2132-
[build] rustc 0 <host> -> cargo-clippy 1 <host>
2133-
[clippy] rustc 1 <host> -> std 1 <host>
2134-
");
2135-
}
2136-
2137-
#[test]
2138-
fn clippy_std_stage2() {
2139-
let ctx = TestCtx::new();
2140-
insta::assert_snapshot!(
2141-
ctx.config("clippy")
2142-
.path("std")
2143-
.stage(2)
2144-
.render_steps(), @r"
2145-
[build] llvm <host>
2146-
[build] rustc 0 <host> -> rustc 1 <host>
2147-
[build] rustc 1 <host> -> std 1 <host>
2148-
[build] rustc 1 <host> -> rustc 2 <host>
2149-
[build] rustc 1 <host> -> clippy-driver 2 <host>
2150-
[build] rustc 1 <host> -> cargo-clippy 2 <host>
2151-
[clippy] rustc 2 <host> -> std 2 <host>
2152-
");
2153-
}
2154-
2155-
#[test]
2156-
fn clippy_miri_stage1() {
2157-
let ctx = TestCtx::new();
2158-
insta::assert_snapshot!(
2159-
ctx.config("clippy")
2160-
.path("miri")
2161-
.stage(1)
2162-
.render_steps(), @r"
2163-
[build] llvm <host>
2164-
[check] rustc 0 <host> -> rustc 1 <host>
2165-
[clippy] rustc 0 <host> -> miri 1 <host>
2166-
");
2167-
}
2168-
2169-
#[test]
2170-
fn clippy_miri_stage2() {
2171-
let ctx = TestCtx::new();
2172-
insta::assert_snapshot!(
2173-
ctx.config("clippy")
2174-
.path("miri")
2175-
.stage(2)
2176-
.render_steps(), @r"
2177-
[build] llvm <host>
2178-
[build] rustc 0 <host> -> rustc 1 <host>
2179-
[build] rustc 1 <host> -> std 1 <host>
2180-
[check] rustc 1 <host> -> rustc 2 <host>
2181-
[build] rustc 0 <host> -> clippy-driver 1 <host>
2182-
[build] rustc 0 <host> -> cargo-clippy 1 <host>
2183-
[clippy] rustc 1 <host> -> miri 2 <host>
2184-
");
2185-
}
2186-
2187-
#[test]
2188-
fn clippy_bootstrap() {
2189-
let ctx = TestCtx::new();
2190-
insta::assert_snapshot!(
2191-
ctx.config("clippy")
2192-
.path("bootstrap")
2193-
.render_steps(), @"[clippy] rustc 0 <host> -> bootstrap 1 <host>");
2194-
}
21952052
}
21962053

21972054
struct ExecutedSteps {

0 commit comments

Comments
 (0)