Skip to content

Split codegen backend check step into two and don't run it with x check compiler #145340

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
109 changes: 86 additions & 23 deletions src/bootstrap/src/core/build_steps/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -314,41 +314,31 @@ pub fn prepare_compiler_for_check(
}
}

/// Checks a single codegen backend.
/// Check the Cranelift codegen backend.
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct CodegenBackend {
pub build_compiler: Compiler,
pub target: TargetSelection,
pub backend: CodegenBackendKind,
pub struct CraneliftCodegenBackend {
build_compiler: Compiler,
target: TargetSelection,
}

impl Step for CodegenBackend {
impl Step for CraneliftCodegenBackend {
type Output = ();

const IS_HOST: bool = true;
const DEFAULT: bool = true;

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

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

fn run(self, builder: &Builder<'_>) {
// FIXME: remove once https://github.com/rust-lang/rust/issues/112393 is resolved
if builder.build.config.vendor && self.backend.is_gcc() {
println!("Skipping checking of `rustc_codegen_gcc` with vendoring enabled.");
return;
}

let build_compiler = self.build_compiler;
let target = self.target;
let backend = self.backend;

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

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

let _guard = builder.msg(
Kind::Check,
backend.crate_name(),
"rustc_codegen_cranelift",
Mode::Codegen,
self.build_compiler,
target,
);

let stamp = build_stamp::codegen_backend_stamp(builder, build_compiler, target, &backend)
.with_prefix("check");
let stamp = build_stamp::codegen_backend_stamp(
builder,
build_compiler,
target,
&CodegenBackendKind::Cranelift,
)
.with_prefix("check");

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

fn metadata(&self) -> Option<StepMetadata> {
Some(
StepMetadata::check(&self.backend.crate_name(), self.target)
StepMetadata::check("rustc_codegen_cranelift", self.target)
.built_by(self.build_compiler),
)
}
}

/// Check the GCC codegen backend.
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct GccCodegenBackend {
build_compiler: Compiler,
target: TargetSelection,
}

impl Step for GccCodegenBackend {
type Output = ();

const IS_HOST: bool = true;
const DEFAULT: bool = true;

fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
run.alias("rustc_codegen_gcc").alias("cg_gcc")
}

fn make_run(run: RunConfig<'_>) {
let build_compiler = prepare_compiler_for_check(run.builder, run.target, Mode::Codegen);
run.builder.ensure(GccCodegenBackend { build_compiler, target: run.target });
}

fn run(self, builder: &Builder<'_>) {
// FIXME: remove once https://github.com/rust-lang/rust/issues/112393 is resolved
if builder.build.config.vendor {
println!("Skipping checking of `rustc_codegen_gcc` with vendoring enabled.");
return;
}

let build_compiler = self.build_compiler;
let target = self.target;

let mut cargo = builder::Cargo::new(
builder,
build_compiler,
Mode::Codegen,
SourceType::InTree,
target,
builder.kind,
);

cargo.arg("--manifest-path").arg(builder.src.join("compiler/rustc_codegen_gcc/Cargo.toml"));
rustc_cargo_env(builder, &mut cargo, target);

let _guard = builder.msg(
Kind::Check,
"rustc_codegen_gcc",
Mode::Codegen,
self.build_compiler,
target,
);

let stamp = build_stamp::codegen_backend_stamp(
builder,
build_compiler,
target,
&CodegenBackendKind::Gcc,
)
.with_prefix("check");

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

fn metadata(&self) -> Option<StepMetadata> {
Some(StepMetadata::check("rustc_codegen_gcc", self.target).built_by(self.build_compiler))
}
}

macro_rules! tool_check_step {
(
$name:ident {
Expand Down
3 changes: 2 additions & 1 deletion src/bootstrap/src/core/builder/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1042,7 +1042,8 @@ impl<'a> Builder<'a> {
Kind::Check | Kind::Fix => describe!(
check::Rustc,
check::Rustdoc,
check::CodegenBackend,
check::CraneliftCodegenBackend,
check::GccCodegenBackend,
check::Clippy,
check::Miri,
check::CargoMiri,
Expand Down
149 changes: 3 additions & 146 deletions src/bootstrap/src/core/builder/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1514,12 +1514,7 @@ mod snapshot {
insta::assert_snapshot!(
ctx.config("check")
.path("compiler")
.render_steps(), @r"
[check] rustc 0 <host> -> rustc 1 <host> (73 crates)
[check] rustc 0 <host> -> rustc 1 <host>
[check] rustc 0 <host> -> rustc_codegen_cranelift 1 <host>
[check] rustc 0 <host> -> rustc_codegen_gcc 1 <host>
");
.render_steps(), @"[check] rustc 0 <host> -> rustc 1 <host> (73 crates)");
}

#[test]
Expand All @@ -1545,12 +1540,7 @@ mod snapshot {
ctx.config("check")
.path("compiler")
.stage(1)
.render_steps(), @r"
[check] rustc 0 <host> -> rustc 1 <host> (73 crates)
[check] rustc 0 <host> -> rustc 1 <host>
[check] rustc 0 <host> -> rustc_codegen_cranelift 1 <host>
[check] rustc 0 <host> -> rustc_codegen_gcc 1 <host>
");
.render_steps(), @"[check] rustc 0 <host> -> rustc 1 <host> (73 crates)");
}

#[test]
Expand All @@ -1565,9 +1555,6 @@ mod snapshot {
[build] rustc 0 <host> -> rustc 1 <host>
[build] rustc 1 <host> -> std 1 <host>
[check] rustc 1 <host> -> rustc 2 <host> (73 crates)
[check] rustc 1 <host> -> rustc 2 <host>
[check] rustc 1 <host> -> rustc_codegen_cranelift 2 <host>
[check] rustc 1 <host> -> rustc_codegen_gcc 2 <host>
");
}

Expand Down Expand Up @@ -1679,12 +1666,7 @@ mod snapshot {
ctx.config("check")
.paths(&["library", "compiler"])
.args(&args)
.render_steps(), @r"
[check] rustc 0 <host> -> rustc 1 <host> (73 crates)
[check] rustc 0 <host> -> rustc 1 <host>
[check] rustc 0 <host> -> rustc_codegen_cranelift 1 <host>
[check] rustc 0 <host> -> rustc_codegen_gcc 1 <host>
");
.render_steps(), @"[check] rustc 0 <host> -> rustc 1 <host> (73 crates)");
}

#[test]
Expand Down Expand Up @@ -1768,7 +1750,6 @@ mod snapshot {
.render_steps(), @r"
[check] rustc 0 <host> -> rustc 1 <host>
[check] rustc 0 <host> -> rustc_codegen_cranelift 1 <host>
[check] rustc 0 <host> -> rustc_codegen_gcc 1 <host>
");
}

Expand Down Expand Up @@ -2068,130 +2049,6 @@ mod snapshot {
[doc] rustc 1 <host> -> reference (book) 2 <host>
");
}

#[test]
fn clippy_ci() {
let ctx = TestCtx::new();
insta::assert_snapshot!(
ctx.config("clippy")
.path("ci")
.stage(2)
.render_steps(), @r"
[build] llvm <host>
[build] rustc 0 <host> -> rustc 1 <host>
[build] rustc 1 <host> -> std 1 <host>
[build] rustc 0 <host> -> clippy-driver 1 <host>
[build] rustc 0 <host> -> cargo-clippy 1 <host>
[clippy] rustc 1 <host> -> bootstrap 2 <host>
[clippy] rustc 1 <host> -> std 1 <host>
[clippy] rustc 1 <host> -> rustc 2 <host>
[check] rustc 1 <host> -> rustc 2 <host>
[clippy] rustc 1 <host> -> rustc_codegen_gcc 2 <host>
");
}

#[test]
fn clippy_compiler_stage1() {
let ctx = TestCtx::new();
insta::assert_snapshot!(
ctx.config("clippy")
.path("compiler")
.render_steps(), @r"
[build] llvm <host>
[clippy] rustc 0 <host> -> rustc 1 <host>
");
}

#[test]
fn clippy_compiler_stage2() {
let ctx = TestCtx::new();
insta::assert_snapshot!(
ctx.config("clippy")
.path("compiler")
.stage(2)
.render_steps(), @r"
[build] llvm <host>
[build] rustc 0 <host> -> rustc 1 <host>
[build] rustc 1 <host> -> std 1 <host>
[build] rustc 0 <host> -> clippy-driver 1 <host>
[build] rustc 0 <host> -> cargo-clippy 1 <host>
[clippy] rustc 1 <host> -> rustc 2 <host>
");
}

#[test]
fn clippy_std_stage1() {
let ctx = TestCtx::new();
insta::assert_snapshot!(
ctx.config("clippy")
.path("std")
.render_steps(), @r"
[build] llvm <host>
[build] rustc 0 <host> -> rustc 1 <host>
[build] rustc 0 <host> -> clippy-driver 1 <host>
[build] rustc 0 <host> -> cargo-clippy 1 <host>
[clippy] rustc 1 <host> -> std 1 <host>
");
}

#[test]
fn clippy_std_stage2() {
let ctx = TestCtx::new();
insta::assert_snapshot!(
ctx.config("clippy")
.path("std")
.stage(2)
.render_steps(), @r"
[build] llvm <host>
[build] rustc 0 <host> -> rustc 1 <host>
[build] rustc 1 <host> -> std 1 <host>
[build] rustc 1 <host> -> rustc 2 <host>
[build] rustc 1 <host> -> clippy-driver 2 <host>
[build] rustc 1 <host> -> cargo-clippy 2 <host>
[clippy] rustc 2 <host> -> std 2 <host>
");
}

#[test]
fn clippy_miri_stage1() {
let ctx = TestCtx::new();
insta::assert_snapshot!(
ctx.config("clippy")
.path("miri")
.stage(1)
.render_steps(), @r"
[build] llvm <host>
[check] rustc 0 <host> -> rustc 1 <host>
[clippy] rustc 0 <host> -> miri 1 <host>
");
}

#[test]
fn clippy_miri_stage2() {
let ctx = TestCtx::new();
insta::assert_snapshot!(
ctx.config("clippy")
.path("miri")
.stage(2)
.render_steps(), @r"
[build] llvm <host>
[build] rustc 0 <host> -> rustc 1 <host>
[build] rustc 1 <host> -> std 1 <host>
[check] rustc 1 <host> -> rustc 2 <host>
[build] rustc 0 <host> -> clippy-driver 1 <host>
[build] rustc 0 <host> -> cargo-clippy 1 <host>
[clippy] rustc 1 <host> -> miri 2 <host>
");
}

#[test]
fn clippy_bootstrap() {
let ctx = TestCtx::new();
insta::assert_snapshot!(
ctx.config("clippy")
.path("bootstrap")
.render_steps(), @"[clippy] rustc 0 <host> -> bootstrap 1 <host>");
}
}

struct ExecutedSteps {
Expand Down
Loading