From a930388e4531c4260e6b27de62ea15a11bee6928 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Wed, 17 Jul 2024 07:46:09 -0700 Subject: [PATCH] Conditionally build `wasm-component-ld` when `lld` is enabled This commit updates the support for the `wasm-component-ld` tool from #126967 to conditionally build it when LLD is enabled rather than unconditionally building it when LLD is enabled. This support is disabled by default and can be enabled by one of two means: * the `extended` field in `config.toml` which dist builders use to build a complete set of tools for each host platform. * a `"wasm-component-ld"` entry in the `tools` section of `config.toml`. Neither of these are enabled by default meaning that most local builds will likely not have this new tool built. Dist builders should still, however, build the tool. --- config.example.toml | 1 + src/bootstrap/src/core/build_steps/compile.rs | 20 ++++++++++--------- src/bootstrap/src/core/sanity.rs | 6 ++++++ src/bootstrap/src/lib.rs | 13 ++++++++++++ 4 files changed, 31 insertions(+), 9 deletions(-) diff --git a/config.example.toml b/config.example.toml index a2c2fa1c2bd58..26687bcfb370f 100644 --- a/config.example.toml +++ b/config.example.toml @@ -333,6 +333,7 @@ # "rust-analyzer-proc-macro-srv", # "analysis", # "src", +# "wasm-component-ld", #] # Verbosity level: 0 == not verbose, 1 == verbose, 2 == very verbose, 3 == print environment variables on each rustc invocation diff --git a/src/bootstrap/src/core/build_steps/compile.rs b/src/bootstrap/src/core/build_steps/compile.rs index d4dd3e546ec44..88be685a8e2cf 100644 --- a/src/bootstrap/src/core/build_steps/compile.rs +++ b/src/bootstrap/src/core/build_steps/compile.rs @@ -1826,15 +1826,17 @@ impl Step for Assemble { // delegates to the `rust-lld` binary for linking and then runs // logic to create the final binary. This is used by the // `wasm32-wasip2` target of Rust. - let wasm_component_ld_exe = - builder.ensure(crate::core::build_steps::tool::WasmComponentLd { - compiler: build_compiler, - target: target_compiler.host, - }); - builder.copy_link( - &wasm_component_ld_exe, - &libdir_bin.join(wasm_component_ld_exe.file_name().unwrap()), - ); + if builder.build_wasm_component_ld() { + let wasm_component_ld_exe = + builder.ensure(crate::core::build_steps::tool::WasmComponentLd { + compiler: build_compiler, + target: target_compiler.host, + }); + builder.copy_link( + &wasm_component_ld_exe, + &libdir_bin.join(wasm_component_ld_exe.file_name().unwrap()), + ); + } } if builder.config.llvm_enabled(target_compiler.host) { diff --git a/src/bootstrap/src/core/sanity.rs b/src/bootstrap/src/core/sanity.rs index 2be819d52ea1a..c85db4dcf01db 100644 --- a/src/bootstrap/src/core/sanity.rs +++ b/src/bootstrap/src/core/sanity.rs @@ -375,4 +375,10 @@ $ pacman -R cmake && pacman -S mingw-w64-x86_64-cmake if let Some(ref s) = build.config.ccache { cmd_finder.must_have(s); } + + // Verify that if the `wasm-component-ld` tool is requested to be built that + // it's dependency, lld, is also being built. + if build.build_wasm_component_ld() && !build.config.lld_enabled { + panic!("when wasm-component-ld is requested to be built LLD must be enabled as well"); + } } diff --git a/src/bootstrap/src/lib.rs b/src/bootstrap/src/lib.rs index db1fa05a82cb6..e42ac92058141 100644 --- a/src/bootstrap/src/lib.rs +++ b/src/bootstrap/src/lib.rs @@ -1413,6 +1413,19 @@ Executed at: {executed_at}"#, None } + /// Returns whether it's requested that `wasm-component-ld` is built as part + /// of the sysroot. This is done either with the `extended` key in + /// `config.toml` or with the `tools` set. + fn build_wasm_component_ld(&self) -> bool { + if self.config.extended { + return true; + } + match &self.config.tools { + Some(set) => set.contains("wasm-component-ld"), + None => false, + } + } + /// Returns the root of the "rootfs" image that this target will be using, /// if one was configured. ///