Skip to content

Commit 46851d3

Browse files
committed
Make WasmComponentLd a ToolTarget tool
This avoid needless rebuilds when the tool can be simply compiled by the stage0 compiler.
1 parent 1239b99 commit 46851d3

File tree

4 files changed

+64
-11
lines changed

4 files changed

+64
-11
lines changed

src/bootstrap/src/core/build_steps/compile.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2282,15 +2282,13 @@ impl Step for Assemble {
22822282
}
22832283

22842284
// In addition to `rust-lld` also install `wasm-component-ld` when
2285-
// LLD is enabled. This is a relatively small binary that primarily
2286-
// delegates to the `rust-lld` binary for linking and then runs
2287-
// logic to create the final binary. This is used by the
2288-
// `wasm32-wasip2` target of Rust.
2285+
// is enabled. This is used by the `wasm32-wasip2` target of Rust.
22892286
if builder.tool_enabled("wasm-component-ld") {
2290-
let wasm_component = builder.ensure(crate::core::build_steps::tool::WasmComponentLd {
2291-
compiler: build_compiler,
2292-
target: target_compiler.host,
2293-
});
2287+
let wasm_component =
2288+
builder.ensure(crate::core::build_steps::tool::WasmComponentLd::for_target(
2289+
builder,
2290+
target_compiler.host,
2291+
));
22942292
builder.copy_link(
22952293
&wasm_component.tool_path,
22962294
&libdir_bin.join(wasm_component.tool_path.file_name().unwrap()),

src/bootstrap/src/core/build_steps/tool.rs

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,6 @@ bootstrap_tool!(
534534
// rustdoc-gui-test has a crate dependency on compiletest, so it needs the same unstable features.
535535
RustdocGUITest, "src/tools/rustdoc-gui-test", "rustdoc-gui-test", is_unstable_tool = true, allow_features = COMPILETEST_ALLOW_FEATURES;
536536
CoverageDump, "src/tools/coverage-dump", "coverage-dump";
537-
WasmComponentLd, "src/tools/wasm-component-ld", "wasm-component-ld", is_unstable_tool = true, allow_features = "min_specialization";
538537
UnicodeTableGenerator, "src/tools/unicode-table-generator", "unicode-table-generator";
539538
FeaturesStatusDump, "src/tools/features-status-dump", "features-status-dump";
540539
OptimizedDist, "src/tools/opt-dist", "opt-dist", submodules = &["src/tools/rustc-perf"];
@@ -929,6 +928,63 @@ impl Step for LldWrapper {
929928
}
930929
}
931930

931+
#[derive(Debug, Clone, Hash, PartialEq, Eq)]
932+
pub struct WasmComponentLd {
933+
build_compiler: Compiler,
934+
target: TargetSelection,
935+
}
936+
937+
impl WasmComponentLd {
938+
pub fn for_target(builder: &Builder<'_>, target: TargetSelection) -> Self {
939+
Self { build_compiler: get_tool_target_compiler(builder, target), target }
940+
}
941+
}
942+
943+
impl Step for WasmComponentLd {
944+
type Output = ToolBuildResult;
945+
946+
const ONLY_HOSTS: bool = true;
947+
948+
fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
949+
run.path("src/tools/wasm-component-ld")
950+
}
951+
952+
fn make_run(run: RunConfig<'_>) {
953+
run.builder.ensure(WasmComponentLd {
954+
build_compiler: get_tool_target_compiler(run.builder, run.target),
955+
target: run.target,
956+
});
957+
}
958+
959+
#[cfg_attr(
960+
feature = "tracing",
961+
instrument(
962+
level = "debug",
963+
name = "WasmComponentLd::run",
964+
skip_all,
965+
fields(build_compiler = ?self.build_compiler),
966+
),
967+
)]
968+
fn run(self, builder: &Builder<'_>) -> ToolBuildResult {
969+
builder.ensure(ToolBuild {
970+
build_compiler: self.build_compiler,
971+
target: self.target,
972+
tool: "wasm-component-ld",
973+
mode: Mode::ToolTarget,
974+
path: "src/tools/wasm-component-ld",
975+
source_type: SourceType::InTree,
976+
extra_features: vec![],
977+
allow_features: "min-specialization",
978+
cargo_args: vec![],
979+
artifact_kind: ToolArtifactKind::Binary,
980+
})
981+
}
982+
983+
fn metadata(&self) -> Option<StepMetadata> {
984+
Some(StepMetadata::build("WasmComponentLd", self.target).built_by(self.build_compiler))
985+
}
986+
}
987+
932988
#[derive(Debug, Clone, Hash, PartialEq, Eq)]
933989
pub struct RustAnalyzer {
934990
pub compiler: Compiler,

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -980,6 +980,7 @@ impl<'a> Builder<'a> {
980980
tool::CoverageDump,
981981
tool::LlvmBitcodeLinker,
982982
tool::RustcPerf,
983+
tool::WasmComponentLd
983984
),
984985
Kind::Clippy => describe!(
985986
clippy::Std,

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1021,7 +1021,6 @@ mod snapshot {
10211021
[build] rustc 0 <host> -> WasmComponentLd 1 <host>
10221022
[build] rustc 1 <host> -> std 1 <host>
10231023
[build] rustc 1 <host> -> rustc 2 <host>
1024-
[build] rustc 1 <host> -> WasmComponentLd 2 <host>
10251024
[build] rustdoc 1 <host>
10261025
[doc] std 2 <host>
10271026
[build] rustc 2 <host> -> std 2 <host>
@@ -1205,7 +1204,6 @@ mod snapshot {
12051204
[build] rustc 0 <host> -> WasmComponentLd 1 <host>
12061205
[build] rustc 1 <host> -> std 1 <host>
12071206
[build] rustc 1 <host> -> rustc 2 <host>
1208-
[build] rustc 1 <host> -> WasmComponentLd 2 <host>
12091207
[build] rustdoc 1 <host>
12101208
[doc] std 2 <target1>
12111209
[build] rustc 2 <host> -> std 2 <host>

0 commit comments

Comments
 (0)