Auto merge of #135014 - Zalathar:tool-build-step, r=jieyouxu
bootstrap: Overhaul and simplify the `tool_extended!` macro Similar to #134950, but for the macro that declares build steps for some tools. The main changes are: - Removing some functionality that isn't needed by any of the tools currently using the macro - Moving some code out of the macro and into ordinary helper functions - Switching to one macro invocation per tool, and struct-like syntax so that rustfmt will format them There should be no functional change.
This commit is contained in:
commit
1b2745d72a
4 changed files with 136 additions and 114 deletions
|
@ -1152,7 +1152,7 @@ impl Step for Rls {
|
||||||
let compiler = self.compiler;
|
let compiler = self.compiler;
|
||||||
let target = self.target;
|
let target = self.target;
|
||||||
|
|
||||||
let rls = builder.ensure(tool::Rls { compiler, target, extra_features: Vec::new() });
|
let rls = builder.ensure(tool::Rls { compiler, target });
|
||||||
|
|
||||||
let mut tarball = Tarball::new(builder, "rls", &target.triple);
|
let mut tarball = Tarball::new(builder, "rls", &target.triple);
|
||||||
tarball.set_overlay(OverlayKind::Rls);
|
tarball.set_overlay(OverlayKind::Rls);
|
||||||
|
@ -1239,9 +1239,8 @@ impl Step for Clippy {
|
||||||
// Prepare the image directory
|
// Prepare the image directory
|
||||||
// We expect clippy to build, because we've exited this step above if tool
|
// We expect clippy to build, because we've exited this step above if tool
|
||||||
// state for clippy isn't testing.
|
// state for clippy isn't testing.
|
||||||
let clippy = builder.ensure(tool::Clippy { compiler, target, extra_features: Vec::new() });
|
let clippy = builder.ensure(tool::Clippy { compiler, target });
|
||||||
let cargoclippy =
|
let cargoclippy = builder.ensure(tool::CargoClippy { compiler, target });
|
||||||
builder.ensure(tool::CargoClippy { compiler, target, extra_features: Vec::new() });
|
|
||||||
|
|
||||||
let mut tarball = Tarball::new(builder, "clippy", &target.triple);
|
let mut tarball = Tarball::new(builder, "clippy", &target.triple);
|
||||||
tarball.set_overlay(OverlayKind::Clippy);
|
tarball.set_overlay(OverlayKind::Clippy);
|
||||||
|
@ -1290,9 +1289,8 @@ impl Step for Miri {
|
||||||
let compiler = self.compiler;
|
let compiler = self.compiler;
|
||||||
let target = self.target;
|
let target = self.target;
|
||||||
|
|
||||||
let miri = builder.ensure(tool::Miri { compiler, target, extra_features: Vec::new() });
|
let miri = builder.ensure(tool::Miri { compiler, target });
|
||||||
let cargomiri =
|
let cargomiri = builder.ensure(tool::CargoMiri { compiler, target });
|
||||||
builder.ensure(tool::CargoMiri { compiler, target, extra_features: Vec::new() });
|
|
||||||
|
|
||||||
let mut tarball = Tarball::new(builder, "miri", &target.triple);
|
let mut tarball = Tarball::new(builder, "miri", &target.triple);
|
||||||
tarball.set_overlay(OverlayKind::Miri);
|
tarball.set_overlay(OverlayKind::Miri);
|
||||||
|
@ -1423,10 +1421,8 @@ impl Step for Rustfmt {
|
||||||
let compiler = self.compiler;
|
let compiler = self.compiler;
|
||||||
let target = self.target;
|
let target = self.target;
|
||||||
|
|
||||||
let rustfmt =
|
let rustfmt = builder.ensure(tool::Rustfmt { compiler, target });
|
||||||
builder.ensure(tool::Rustfmt { compiler, target, extra_features: Vec::new() });
|
let cargofmt = builder.ensure(tool::Cargofmt { compiler, target });
|
||||||
let cargofmt =
|
|
||||||
builder.ensure(tool::Cargofmt { compiler, target, extra_features: Vec::new() });
|
|
||||||
let mut tarball = Tarball::new(builder, "rustfmt", &target.triple);
|
let mut tarball = Tarball::new(builder, "rustfmt", &target.triple);
|
||||||
tarball.set_overlay(OverlayKind::Rustfmt);
|
tarball.set_overlay(OverlayKind::Rustfmt);
|
||||||
tarball.is_preview(true);
|
tarball.is_preview(true);
|
||||||
|
|
|
@ -409,7 +409,7 @@ impl Step for Rustfmt {
|
||||||
let host = self.host;
|
let host = self.host;
|
||||||
let compiler = builder.compiler(stage, host);
|
let compiler = builder.compiler(stage, host);
|
||||||
|
|
||||||
builder.ensure(tool::Rustfmt { compiler, target: self.host, extra_features: Vec::new() });
|
builder.ensure(tool::Rustfmt { compiler, target: self.host });
|
||||||
|
|
||||||
let mut cargo = tool::prepare_tool_cargo(
|
let mut cargo = tool::prepare_tool_cargo(
|
||||||
builder,
|
builder,
|
||||||
|
@ -511,17 +511,9 @@ impl Step for Miri {
|
||||||
let host_compiler = builder.compiler(stage - 1, host);
|
let host_compiler = builder.compiler(stage - 1, host);
|
||||||
|
|
||||||
// Build our tools.
|
// Build our tools.
|
||||||
let miri = builder.ensure(tool::Miri {
|
let miri = builder.ensure(tool::Miri { compiler: host_compiler, target: host });
|
||||||
compiler: host_compiler,
|
|
||||||
target: host,
|
|
||||||
extra_features: Vec::new(),
|
|
||||||
});
|
|
||||||
// the ui tests also assume cargo-miri has been built
|
// the ui tests also assume cargo-miri has been built
|
||||||
builder.ensure(tool::CargoMiri {
|
builder.ensure(tool::CargoMiri { compiler: host_compiler, target: host });
|
||||||
compiler: host_compiler,
|
|
||||||
target: host,
|
|
||||||
extra_features: Vec::new(),
|
|
||||||
});
|
|
||||||
|
|
||||||
// We also need sysroots, for Miri and for the host (the latter for build scripts).
|
// We also need sysroots, for Miri and for the host (the latter for build scripts).
|
||||||
// This is for the tests so everything is done with the target compiler.
|
// This is for the tests so everything is done with the target compiler.
|
||||||
|
@ -740,7 +732,7 @@ impl Step for Clippy {
|
||||||
let host = self.host;
|
let host = self.host;
|
||||||
let compiler = builder.compiler(stage, host);
|
let compiler = builder.compiler(stage, host);
|
||||||
|
|
||||||
builder.ensure(tool::Clippy { compiler, target: self.host, extra_features: Vec::new() });
|
builder.ensure(tool::Clippy { compiler, target: self.host });
|
||||||
let mut cargo = tool::prepare_tool_cargo(
|
let mut cargo = tool::prepare_tool_cargo(
|
||||||
builder,
|
builder,
|
||||||
compiler,
|
compiler,
|
||||||
|
|
|
@ -1007,43 +1007,32 @@ impl Step for LibcxxVersionTool {
|
||||||
}
|
}
|
||||||
|
|
||||||
macro_rules! tool_extended {
|
macro_rules! tool_extended {
|
||||||
(($sel:ident, $builder:ident),
|
(
|
||||||
$($name:ident,
|
$name:ident {
|
||||||
$path:expr,
|
path: $path:expr,
|
||||||
$tool_name:expr,
|
tool_name: $tool_name:expr,
|
||||||
stable = $stable:expr
|
stable: $stable:expr
|
||||||
$(,tool_std = $tool_std:literal)?
|
$( , add_bins_to_sysroot: $add_bins_to_sysroot:expr )?
|
||||||
$(,allow_features = $allow_features:expr)?
|
$( , )?
|
||||||
$(,add_bins_to_sysroot = $add_bins_to_sysroot:expr)?
|
}
|
||||||
;)+) => {
|
) => {
|
||||||
$(
|
#[derive(Debug, Clone, Hash, PartialEq, Eq)]
|
||||||
#[derive(Debug, Clone, Hash, PartialEq, Eq)]
|
|
||||||
pub struct $name {
|
pub struct $name {
|
||||||
pub compiler: Compiler,
|
pub compiler: Compiler,
|
||||||
pub target: TargetSelection,
|
pub target: TargetSelection,
|
||||||
pub extra_features: Vec<String>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Step for $name {
|
impl Step for $name {
|
||||||
type Output = PathBuf;
|
type Output = PathBuf;
|
||||||
const DEFAULT: bool = true; // Overwritten below
|
const DEFAULT: bool = true; // Overridden by `should_run_tool_build_step`
|
||||||
const ONLY_HOSTS: bool = true;
|
const ONLY_HOSTS: bool = true;
|
||||||
|
|
||||||
fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
|
fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
|
||||||
let builder = run.builder;
|
should_run_tool_build_step(
|
||||||
run.path($path).default_condition(
|
run,
|
||||||
builder.config.extended
|
$tool_name,
|
||||||
&& builder.config.tools.as_ref().map_or(
|
$path,
|
||||||
// By default, on nightly/dev enable all tools, else only
|
$stable,
|
||||||
// build stable tools.
|
|
||||||
$stable || builder.build.unstable_features(),
|
|
||||||
// If `tools` is set, search list for this tool.
|
|
||||||
|tools| {
|
|
||||||
tools.iter().any(|tool| match tool.as_ref() {
|
|
||||||
"clippy" => $tool_name == "clippy-driver",
|
|
||||||
x => $tool_name == x,
|
|
||||||
})
|
|
||||||
}),
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1051,58 +1040,117 @@ macro_rules! tool_extended {
|
||||||
run.builder.ensure($name {
|
run.builder.ensure($name {
|
||||||
compiler: run.builder.compiler(run.builder.top_stage, run.builder.config.build),
|
compiler: run.builder.compiler(run.builder.top_stage, run.builder.config.build),
|
||||||
target: run.target,
|
target: run.target,
|
||||||
extra_features: Vec::new(),
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(unused_mut)]
|
fn run(self, builder: &Builder<'_>) -> PathBuf {
|
||||||
fn run(mut $sel, $builder: &Builder<'_>) -> PathBuf {
|
let Self { compiler, target } = self;
|
||||||
let tool = $builder.ensure(ToolBuild {
|
run_tool_build_step(
|
||||||
compiler: $sel.compiler,
|
builder,
|
||||||
target: $sel.target,
|
compiler,
|
||||||
tool: $tool_name,
|
target,
|
||||||
mode: if false $(|| $tool_std)? { Mode::ToolStd } else { Mode::ToolRustc },
|
$tool_name,
|
||||||
path: $path,
|
$path,
|
||||||
extra_features: $sel.extra_features,
|
None $( .or(Some(&$add_bins_to_sysroot)) )?,
|
||||||
source_type: SourceType::InTree,
|
)
|
||||||
allow_features: concat!($($allow_features)*),
|
|
||||||
cargo_args: vec![]
|
|
||||||
});
|
|
||||||
|
|
||||||
if (false $(|| !$add_bins_to_sysroot.is_empty())?) && $sel.compiler.stage > 0 {
|
|
||||||
let bindir = $builder.sysroot($sel.compiler).join("bin");
|
|
||||||
t!(fs::create_dir_all(&bindir));
|
|
||||||
|
|
||||||
#[allow(unused_variables)]
|
|
||||||
let tools_out = $builder
|
|
||||||
.cargo_out($sel.compiler, Mode::ToolRustc, $sel.target);
|
|
||||||
|
|
||||||
$(for add_bin in $add_bins_to_sysroot {
|
|
||||||
let bin_source = tools_out.join(exe(add_bin, $sel.target));
|
|
||||||
let bin_destination = bindir.join(exe(add_bin, $sel.compiler.host));
|
|
||||||
$builder.copy_link(&bin_source, &bin_destination);
|
|
||||||
})?
|
|
||||||
|
|
||||||
let tool = bindir.join(exe($tool_name, $sel.compiler.host));
|
|
||||||
tool
|
|
||||||
} else {
|
|
||||||
tool
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
)+
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
tool_extended!((self, builder),
|
fn should_run_tool_build_step<'a>(
|
||||||
Cargofmt, "src/tools/rustfmt", "cargo-fmt", stable=true;
|
run: ShouldRun<'a>,
|
||||||
CargoClippy, "src/tools/clippy", "cargo-clippy", stable=true;
|
tool_name: &'static str,
|
||||||
Clippy, "src/tools/clippy", "clippy-driver", stable=true, add_bins_to_sysroot = ["clippy-driver", "cargo-clippy"];
|
path: &'static str,
|
||||||
Miri, "src/tools/miri", "miri", stable=false, add_bins_to_sysroot = ["miri"];
|
stable: bool,
|
||||||
CargoMiri, "src/tools/miri/cargo-miri", "cargo-miri", stable=false, add_bins_to_sysroot = ["cargo-miri"];
|
) -> ShouldRun<'a> {
|
||||||
Rls, "src/tools/rls", "rls", stable=true;
|
let builder = run.builder;
|
||||||
Rustfmt, "src/tools/rustfmt", "rustfmt", stable=true, add_bins_to_sysroot = ["rustfmt", "cargo-fmt"];
|
run.path(path).default_condition(
|
||||||
);
|
builder.config.extended
|
||||||
|
&& builder.config.tools.as_ref().map_or(
|
||||||
|
// By default, on nightly/dev enable all tools, else only
|
||||||
|
// build stable tools.
|
||||||
|
stable || builder.build.unstable_features(),
|
||||||
|
// If `tools` is set, search list for this tool.
|
||||||
|
|tools| {
|
||||||
|
tools.iter().any(|tool| match tool.as_ref() {
|
||||||
|
"clippy" => tool_name == "clippy-driver",
|
||||||
|
x => tool_name == x,
|
||||||
|
})
|
||||||
|
},
|
||||||
|
),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn run_tool_build_step(
|
||||||
|
builder: &Builder<'_>,
|
||||||
|
compiler: Compiler,
|
||||||
|
target: TargetSelection,
|
||||||
|
tool_name: &'static str,
|
||||||
|
path: &'static str,
|
||||||
|
add_bins_to_sysroot: Option<&[&str]>,
|
||||||
|
) -> PathBuf {
|
||||||
|
let tool = builder.ensure(ToolBuild {
|
||||||
|
compiler,
|
||||||
|
target,
|
||||||
|
tool: tool_name,
|
||||||
|
mode: Mode::ToolRustc,
|
||||||
|
path,
|
||||||
|
extra_features: vec![],
|
||||||
|
source_type: SourceType::InTree,
|
||||||
|
allow_features: "",
|
||||||
|
cargo_args: vec![],
|
||||||
|
});
|
||||||
|
|
||||||
|
// FIXME: This should just be an if-let-chain, but those are unstable.
|
||||||
|
if let Some(add_bins_to_sysroot) =
|
||||||
|
add_bins_to_sysroot.filter(|bins| !bins.is_empty() && compiler.stage > 0)
|
||||||
|
{
|
||||||
|
let bindir = builder.sysroot(compiler).join("bin");
|
||||||
|
t!(fs::create_dir_all(&bindir));
|
||||||
|
|
||||||
|
let tools_out = builder.cargo_out(compiler, Mode::ToolRustc, target);
|
||||||
|
|
||||||
|
for add_bin in add_bins_to_sysroot {
|
||||||
|
let bin_source = tools_out.join(exe(add_bin, target));
|
||||||
|
let bin_destination = bindir.join(exe(add_bin, compiler.host));
|
||||||
|
builder.copy_link(&bin_source, &bin_destination);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Return a path into the bin dir.
|
||||||
|
bindir.join(exe(tool_name, compiler.host))
|
||||||
|
} else {
|
||||||
|
tool
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
tool_extended!(Cargofmt { path: "src/tools/rustfmt", tool_name: "cargo-fmt", stable: true });
|
||||||
|
tool_extended!(CargoClippy { path: "src/tools/clippy", tool_name: "cargo-clippy", stable: true });
|
||||||
|
tool_extended!(Clippy {
|
||||||
|
path: "src/tools/clippy",
|
||||||
|
tool_name: "clippy-driver",
|
||||||
|
stable: true,
|
||||||
|
add_bins_to_sysroot: ["clippy-driver", "cargo-clippy"]
|
||||||
|
});
|
||||||
|
tool_extended!(Miri {
|
||||||
|
path: "src/tools/miri",
|
||||||
|
tool_name: "miri",
|
||||||
|
stable: false,
|
||||||
|
add_bins_to_sysroot: ["miri"]
|
||||||
|
});
|
||||||
|
tool_extended!(CargoMiri {
|
||||||
|
path: "src/tools/miri/cargo-miri",
|
||||||
|
tool_name: "cargo-miri",
|
||||||
|
stable: false,
|
||||||
|
add_bins_to_sysroot: ["cargo-miri"]
|
||||||
|
});
|
||||||
|
tool_extended!(Rls { path: "src/tools/rls", tool_name: "rls", stable: true });
|
||||||
|
tool_extended!(Rustfmt {
|
||||||
|
path: "src/tools/rustfmt",
|
||||||
|
tool_name: "rustfmt",
|
||||||
|
stable: true,
|
||||||
|
add_bins_to_sysroot: ["rustfmt", "cargo-fmt"]
|
||||||
|
});
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||||
pub struct TestFloatParse {
|
pub struct TestFloatParse {
|
||||||
|
|
|
@ -1343,16 +1343,9 @@ impl<'a> Builder<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
let build_compiler = self.compiler(run_compiler.stage - 1, self.build.build);
|
let build_compiler = self.compiler(run_compiler.stage - 1, self.build.build);
|
||||||
self.ensure(tool::Clippy {
|
self.ensure(tool::Clippy { compiler: build_compiler, target: self.build.build });
|
||||||
compiler: build_compiler,
|
let cargo_clippy =
|
||||||
target: self.build.build,
|
self.ensure(tool::CargoClippy { compiler: build_compiler, target: self.build.build });
|
||||||
extra_features: vec![],
|
|
||||||
});
|
|
||||||
let cargo_clippy = self.ensure(tool::CargoClippy {
|
|
||||||
compiler: build_compiler,
|
|
||||||
target: self.build.build,
|
|
||||||
extra_features: vec![],
|
|
||||||
});
|
|
||||||
let mut dylib_path = helpers::dylib_path();
|
let mut dylib_path = helpers::dylib_path();
|
||||||
dylib_path.insert(0, self.sysroot(run_compiler).join("lib"));
|
dylib_path.insert(0, self.sysroot(run_compiler).join("lib"));
|
||||||
|
|
||||||
|
@ -1367,16 +1360,9 @@ impl<'a> Builder<'a> {
|
||||||
let build_compiler = self.compiler(run_compiler.stage - 1, self.build.build);
|
let build_compiler = self.compiler(run_compiler.stage - 1, self.build.build);
|
||||||
|
|
||||||
// Prepare the tools
|
// Prepare the tools
|
||||||
let miri = self.ensure(tool::Miri {
|
let miri = self.ensure(tool::Miri { compiler: build_compiler, target: self.build.build });
|
||||||
compiler: build_compiler,
|
let cargo_miri =
|
||||||
target: self.build.build,
|
self.ensure(tool::CargoMiri { compiler: build_compiler, target: self.build.build });
|
||||||
extra_features: Vec::new(),
|
|
||||||
});
|
|
||||||
let cargo_miri = self.ensure(tool::CargoMiri {
|
|
||||||
compiler: build_compiler,
|
|
||||||
target: self.build.build,
|
|
||||||
extra_features: Vec::new(),
|
|
||||||
});
|
|
||||||
// Invoke cargo-miri, make sure it can find miri and cargo.
|
// Invoke cargo-miri, make sure it can find miri and cargo.
|
||||||
let mut cmd = command(cargo_miri);
|
let mut cmd = command(cargo_miri);
|
||||||
cmd.env("MIRI", &miri);
|
cmd.env("MIRI", &miri);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue