1
Fork 0

Rollup merge of #134950 - Zalathar:tool-check-step, r=jieyouxu

bootstrap: Overhaul and simplify the `tool_check_step!` macro

Main changes:

- Pull most of `run` out of the macro and into a regular helper function
- Reduce the number of redundant/unnecessary macro arguments
- Switch to struct-like syntax so that optional arguments are clearer, and so that rustfmt is happy

~~The one “functional” change is that the `-check.stamp` files now get their name from the final path segment, instead of the struct name; in practice this means that they now contain more hyphens in some cases. As far as I'm aware, the exact filename doesn't matter so this should be fine.~~ (that change has been removed from this PR)
This commit is contained in:
Stuart Cook 2025-01-01 16:35:31 +11:00 committed by GitHub
commit cf7d7f5096
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -401,12 +401,13 @@ impl Step for RustAnalyzer {
macro_rules! tool_check_step { macro_rules! tool_check_step {
( (
$name:ident, $name:ident {
$display_name:literal, // The part of this path after the final '/' is also used as a display name.
$path:literal, path: $path:literal
$($alias:literal, )* $(, alt_path: $alt_path:literal )*
$source_type:path $(, default: $default:literal )?
$(, $default:literal )? $( , )?
}
) => { ) => {
#[derive(Debug, Clone, PartialEq, Eq, Hash)] #[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct $name { pub struct $name {
@ -416,11 +417,11 @@ macro_rules! tool_check_step {
impl Step for $name { impl Step for $name {
type Output = (); type Output = ();
const ONLY_HOSTS: bool = true; const ONLY_HOSTS: bool = true;
/// don't ever check out-of-tree tools by default, they'll fail when toolstate is broken /// Most of the tool-checks using this macro are run by default.
const DEFAULT: bool = matches!($source_type, SourceType::InTree) $( && $default )?; const DEFAULT: bool = true $( && $default )?;
fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> { fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
run.paths(&[ $path, $($alias),* ]) run.paths(&[ $path, $( $alt_path ),* ])
} }
fn make_run(run: RunConfig<'_>) { fn make_run(run: RunConfig<'_>) {
@ -428,8 +429,22 @@ macro_rules! tool_check_step {
} }
fn run(self, builder: &Builder<'_>) { fn run(self, builder: &Builder<'_>) {
let Self { target } = self;
run_tool_check_step(builder, target, stringify!($name), $path);
}
}
}
}
/// Used by the implementation of `Step::run` in `tool_check_step!`.
fn run_tool_check_step(
builder: &Builder<'_>,
target: TargetSelection,
step_type_name: &str,
path: &str,
) {
let display_name = path.rsplit('/').next().unwrap();
let compiler = builder.compiler(builder.top_stage, builder.config.build); let compiler = builder.compiler(builder.top_stage, builder.config.build);
let target = self.target;
builder.ensure(Rustc::new(target, builder)); builder.ensure(Rustc::new(target, builder));
@ -439,8 +454,12 @@ macro_rules! tool_check_step {
Mode::ToolRustc, Mode::ToolRustc,
target, target,
builder.kind, builder.kind,
$path, path,
$source_type, // Currently, all of the tools that use this macro/function are in-tree.
// If support for out-of-tree tools is re-added in the future, those
// steps should probably be marked non-default so that the default
// checks aren't affected by toolstate being broken.
SourceType::InTree,
&[], &[],
); );
@ -450,60 +469,31 @@ macro_rules! tool_check_step {
cargo.arg("--all-targets"); cargo.arg("--all-targets");
} }
let _guard = builder.msg_check(&format!("{} artifacts", $display_name), target); let stamp = builder
run_cargo(
builder,
cargo,
builder.config.free_args.clone(),
&stamp(builder, compiler, target),
vec![],
true,
false,
);
/// Cargo's output path in a given stage, compiled by a particular
/// compiler for the specified target.
fn stamp(
builder: &Builder<'_>,
compiler: Compiler,
target: TargetSelection,
) -> PathBuf {
builder
.cargo_out(compiler, Mode::ToolRustc, target) .cargo_out(compiler, Mode::ToolRustc, target)
.join(format!(".{}-check.stamp", stringify!($name).to_lowercase())) .join(format!(".{}-check.stamp", step_type_name.to_lowercase()));
}
} let _guard = builder.msg_check(format!("{display_name} artifacts"), target);
} run_cargo(builder, cargo, builder.config.free_args.clone(), &stamp, vec![], true, false);
};
} }
tool_check_step!(Rustdoc, "rustdoc", "src/tools/rustdoc", "src/librustdoc", SourceType::InTree); tool_check_step!(Rustdoc { path: "src/tools/rustdoc", alt_path: "src/librustdoc" });
// Clippy, miri and Rustfmt are hybrids. They are external tools, but use a git subtree instead // Clippy, miri and Rustfmt are hybrids. They are external tools, but use a git subtree instead
// of a submodule. Since the SourceType only drives the deny-warnings // of a submodule. Since the SourceType only drives the deny-warnings
// behavior, treat it as in-tree so that any new warnings in clippy will be // behavior, treat it as in-tree so that any new warnings in clippy will be
// rejected. // rejected.
tool_check_step!(Clippy, "clippy", "src/tools/clippy", SourceType::InTree); tool_check_step!(Clippy { path: "src/tools/clippy" });
tool_check_step!(Miri, "miri", "src/tools/miri", SourceType::InTree); tool_check_step!(Miri { path: "src/tools/miri" });
tool_check_step!(CargoMiri, "cargo-miri", "src/tools/miri/cargo-miri", SourceType::InTree); tool_check_step!(CargoMiri { path: "src/tools/miri/cargo-miri" });
tool_check_step!(Rls, "rls", "src/tools/rls", SourceType::InTree); tool_check_step!(Rls { path: "src/tools/rls" });
tool_check_step!(Rustfmt, "rustfmt", "src/tools/rustfmt", SourceType::InTree); tool_check_step!(Rustfmt { path: "src/tools/rustfmt" });
tool_check_step!( tool_check_step!(MiroptTestTools { path: "src/tools/miropt-test-tools" });
MiroptTestTools, tool_check_step!(TestFloatParse { path: "src/etc/test-float-parse" });
"miropt-test-tools",
"src/tools/miropt-test-tools",
SourceType::InTree
);
tool_check_step!(
TestFloatParse,
"test-float-parse",
"src/etc/test-float-parse",
SourceType::InTree
);
tool_check_step!(Bootstrap, "bootstrap", "src/bootstrap", SourceType::InTree, false); tool_check_step!(Bootstrap { path: "src/bootstrap", default: false });
// Compiletest is implicitly "checked" when it gets built in order to run tests, // Compiletest is implicitly "checked" when it gets built in order to run tests,
// so this is mainly for people working on compiletest to run locally. // so this is mainly for people working on compiletest to run locally.
tool_check_step!(Compiletest, "compiletest", "src/tools/compiletest", SourceType::InTree, false); tool_check_step!(Compiletest { path: "src/tools/compiletest", default: false });
/// Cargo's output path for the standard library in a given stage, compiled /// Cargo's output path for the standard library in a given stage, compiled
/// by a particular compiler for the specified target. /// by a particular compiler for the specified target.