Skip to content
Merged
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
77 changes: 50 additions & 27 deletions src/bootstrap/src/core/build_steps/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,23 @@ use crate::core::config::TargetSelection;
use crate::utils::build_stamp::{self, BuildStamp};
use crate::{CodegenBackendKind, Compiler, Mode, Subcommand, t};

/// Allows individual check-step instances to keep track of whether they
/// represent `cargo check` or `cargo fix`, independently of [`Builder::kind`].
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
enum CheckKind {
Check,
Fix,
}

impl CheckKind {
fn to_kind(self) -> Kind {
match self {
CheckKind::Check => Kind::Check,
CheckKind::Fix => Kind::Fix,
}
}
}

#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct Std {
/// Compiler that will check this std.
Expand Down Expand Up @@ -225,11 +242,7 @@ impl Step for PrepareRustcRmetaSysroot {

fn run(self, builder: &Builder<'_>) -> Self::Output {
// Check rustc
let stamp = builder.ensure(Rustc::from_build_compiler(
self.build_compiler.clone(),
self.target,
vec![],
));
let stamp = Rustc::check_rustc_for_preparing_sysroot(builder, &self);

let build_compiler = self.build_compiler.build_compiler();

Expand Down Expand Up @@ -284,9 +297,12 @@ impl Step for PrepareStdRmetaSysroot {
/// Checks rustc using `build_compiler`.
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct Rustc {
check_kind: CheckKind,

/// Compiler that will check this rustc.
pub build_compiler: CompilerForCheck,
pub target: TargetSelection,
build_compiler: CompilerForCheck,
target: TargetSelection,

/// Whether to build only a subset of crates.
///
/// This shouldn't be used from other steps; see the comment on [`compile::Rustc`].
Expand All @@ -296,17 +312,17 @@ pub struct Rustc {
}

impl Rustc {
pub fn new(builder: &Builder<'_>, target: TargetSelection, crates: Vec<String>) -> Self {
let build_compiler = prepare_compiler_for_check(builder, target, Mode::Rustc);
Self::from_build_compiler(build_compiler, target, crates)
}

fn from_build_compiler(
build_compiler: CompilerForCheck,
target: TargetSelection,
crates: Vec<String>,
) -> Self {
Self { build_compiler, target, crates }
fn check_rustc_for_preparing_sysroot(
builder: &Builder<'_>,
prepare: &PrepareRustcRmetaSysroot,
) -> BuildStamp {
builder.ensure(Rustc {
// We specifically want `cargo check`, not the current bootstrap subcommand.
check_kind: CheckKind::Check,
build_compiler: prepare.build_compiler.clone(),
target: prepare.target,
crates: vec![],
})
}
}

Expand All @@ -323,8 +339,17 @@ impl CommandLineStep for Rustc {
}

fn make_run(run: RunConfig<'_>) {
let check_kind = match run.builder.kind {
Kind::Check => CheckKind::Check,
Kind::Fix => CheckKind::Fix,
kind => panic!("unexpected kind for `check::Rustc`: {kind:?}"),
};

let target = run.target;
let build_compiler = prepare_compiler_for_check(run.builder, target, Mode::Rustc);
let crates = run.make_run_crates(Alias::Compiler);
run.builder.ensure(Rustc::new(run.builder, run.target, crates));

run.builder.ensure(Rustc { check_kind, build_compiler, target, crates });
}

/// Check the compiler.
Expand All @@ -344,7 +369,7 @@ impl CommandLineStep for Rustc {
Mode::Rustc,
SourceType::InTree,
target,
Kind::Check,
self.check_kind.to_kind(),
);

rustc_cargo(builder, &mut cargo, target, &build_compiler, &self.crates);
Expand All @@ -358,7 +383,7 @@ impl CommandLineStep for Rustc {
}

let _guard = builder.msg(
Kind::Check,
self.check_kind.to_kind(),
format_args!("compiler artifacts{}", crate_description(&self.crates)),
Mode::Rustc,
self.build_compiler.build_compiler(),
Expand All @@ -381,13 +406,11 @@ impl CommandLineStep for Rustc {
}

fn metadata(&self) -> Option<StepMetadata> {
let metadata = StepMetadata::check("rustc", self.target)
let mut metadata = StepMetadata::new("rustc", self.target, self.check_kind.to_kind())
.built_by(self.build_compiler.build_compiler());
let metadata = if self.crates.is_empty() {
metadata
} else {
metadata.with_metadata(format!("({} crates)", self.crates.len()))
};
if !self.crates.is_empty() {
metadata = metadata.with_metadata(format!("({} crates)", self.crates.len()));
}
Some(metadata)
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/bootstrap/src/core/builder/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ impl StepMetadata {
Self::new(name, target, Kind::Run)
}

fn new(name: &str, target: TargetSelection, kind: Kind) -> Self {
pub fn new(name: &str, target: TargetSelection, kind: Kind) -> Self {
Self { name: name.to_string(), kind, target, built_by: None, stage: None, metadata: None }
}

Expand Down
9 changes: 9 additions & 0 deletions src/bootstrap/src/core/builder/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3086,6 +3086,15 @@ mod snapshot {
[run] rustc 0 <host> -> miri 1 <target1>
");
}

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

struct ExecutedSteps {
Expand Down
Loading