Skip to content

Commit d048925

Browse files
authored
Unrolled build for rust-lang#130034
Rollup merge of rust-lang#130034 - alexcrichton:fix-some-wasm-component-ld-comments, r=onur-ozkan Fix enabling wasm-component-ld to match other tools It was [pointed out recently][comment] that enabling `wasm-component-ld` as a host tool is different from other host tools. This commit refactors the logic to match by deduplicating selection of when to build other tools and then using the same logic for `wasm-component-ld`. While here I also fixed a typo pointed out in rust-lang#126967 (review) [comment]: rust-lang#127866 (comment)
2 parents 263a3ae + c15469a commit d048925

File tree

5 files changed

+19
-44
lines changed

5 files changed

+19
-44
lines changed

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -1912,7 +1912,7 @@ impl Step for Assemble {
19121912
// delegates to the `rust-lld` binary for linking and then runs
19131913
// logic to create the final binary. This is used by the
19141914
// `wasm32-wasip2` target of Rust.
1915-
if builder.build_wasm_component_ld() {
1915+
if builder.tool_enabled("wasm-component-ld") {
19161916
let wasm_component_ld_exe =
19171917
builder.ensure(crate::core::build_steps::tool::WasmComponentLd {
19181918
compiler: build_compiler,

src/bootstrap/src/core/build_steps/dist.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,7 @@ impl Step for Rustc {
473473
);
474474
}
475475
}
476-
if builder.build_wasm_component_ld() {
476+
if builder.tool_enabled("wasm-component-ld") {
477477
let src_dir = builder.sysroot_libdir(compiler, host).parent().unwrap().join("bin");
478478
let ld = exe("wasm-component-ld", compiler.host);
479479
builder.copy_link(&src_dir.join(&ld), &dst_dir.join(&ld));

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

+6-32
Original file line numberDiff line numberDiff line change
@@ -693,14 +693,7 @@ impl Step for Cargo {
693693

694694
fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
695695
let builder = run.builder;
696-
run.path("src/tools/cargo").default_condition(
697-
builder.config.extended
698-
&& builder.config.tools.as_ref().map_or(
699-
true,
700-
// If `tools` is set, search list for this tool.
701-
|tools| tools.iter().any(|tool| tool == "cargo"),
702-
),
703-
)
696+
run.path("src/tools/cargo").default_condition(builder.tool_enabled("cargo"))
704697
}
705698

706699
fn make_run(run: RunConfig<'_>) {
@@ -772,14 +765,7 @@ impl Step for RustAnalyzer {
772765

773766
fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
774767
let builder = run.builder;
775-
run.path("src/tools/rust-analyzer").default_condition(
776-
builder.config.extended
777-
&& builder
778-
.config
779-
.tools
780-
.as_ref()
781-
.map_or(true, |tools| tools.iter().any(|tool| tool == "rust-analyzer")),
782-
)
768+
run.path("src/tools/rust-analyzer").default_condition(builder.tool_enabled("rust-analyzer"))
783769
}
784770

785771
fn make_run(run: RunConfig<'_>) {
@@ -821,12 +807,8 @@ impl Step for RustAnalyzerProcMacroSrv {
821807
run.path("src/tools/rust-analyzer")
822808
.path("src/tools/rust-analyzer/crates/proc-macro-srv-cli")
823809
.default_condition(
824-
builder.config.extended
825-
&& builder.config.tools.as_ref().map_or(true, |tools| {
826-
tools.iter().any(|tool| {
827-
tool == "rust-analyzer" || tool == "rust-analyzer-proc-macro-srv"
828-
})
829-
}),
810+
builder.tool_enabled("rust-analyzer")
811+
|| builder.tool_enabled("rust-analyzer-proc-macro-srv"),
830812
)
831813
}
832814

@@ -874,16 +856,8 @@ impl Step for LlvmBitcodeLinker {
874856

875857
fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
876858
let builder = run.builder;
877-
run.path("src/tools/llvm-bitcode-linker").default_condition(
878-
builder.config.extended
879-
&& builder
880-
.config
881-
.tools
882-
.as_ref()
883-
.map_or(builder.build.unstable_features(), |tools| {
884-
tools.iter().any(|tool| tool == "llvm-bitcode-linker")
885-
}),
886-
)
859+
run.path("src/tools/llvm-bitcode-linker")
860+
.default_condition(builder.tool_enabled("llvm-bitcode-linker"))
887861
}
888862

889863
fn make_run(run: RunConfig<'_>) {

src/bootstrap/src/lib.rs

+9-8
Original file line numberDiff line numberDiff line change
@@ -1407,16 +1407,17 @@ Executed at: {executed_at}"#,
14071407
None
14081408
}
14091409

1410-
/// Returns whether it's requested that `wasm-component-ld` is built as part
1411-
/// of the sysroot. This is done either with the `extended` key in
1412-
/// `config.toml` or with the `tools` set.
1413-
fn build_wasm_component_ld(&self) -> bool {
1414-
if self.config.extended {
1415-
return true;
1410+
/// Returns whether the specified tool is configured as part of this build.
1411+
///
1412+
/// This requires that both the `extended` key is set and the `tools` key is
1413+
/// either unset or specifically contains the specified tool.
1414+
fn tool_enabled(&self, tool: &str) -> bool {
1415+
if !self.config.extended {
1416+
return false;
14161417
}
14171418
match &self.config.tools {
1418-
Some(set) => set.contains("wasm-component-ld"),
1419-
None => false,
1419+
Some(set) => set.contains(tool),
1420+
None => true,
14201421
}
14211422
}
14221423

src/tools/wasm-component-ld/README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# `wasm-component-ld`
22

3-
This wrapper is a wrapper around the [`wasm-component-ld`] crates.io crate. That
4-
crate. That crate is itself a thin wrapper around two pieces:
3+
This wrapper is a wrapper around the [`wasm-component-ld`] crates.io crate.
4+
That crate is itself a thin wrapper around two pieces:
55

66
* `wasm-ld` - the LLVM-based linker distributed as part of LLD and packaged in
77
Rust as `rust-lld`.

0 commit comments

Comments
 (0)