@@ -473,11 +473,12 @@ impl Step for Rustc {
473473 ) ;
474474 }
475475 }
476- if builder. tool_enabled ( "wasm-component-ld" ) {
477- let src_dir = builder. sysroot_libdir ( compiler, host) . parent ( ) . unwrap ( ) . join ( "bin" ) ;
478- let ld = exe ( "wasm-component-ld" , compiler. host ) ;
479- builder. copy_link ( & src_dir. join ( & ld) , & dst_dir. join ( & ld) ) ;
480- }
476+
477+ let builder_compiler =
478+ builder. compiler_for ( builder. top_stage , builder. config . build , compiler. host ) ;
479+ maybe_install_wasm_component_ld ( builder, builder_compiler, compiler. host , & dst_dir) ;
480+ maybe_install_llvm_bitcode_linker ( builder, builder_compiler, compiler. host , & dst_dir) ;
481+ maybe_install_llvm_tools ( builder, compiler. host , & dst_dir) ;
481482
482483 // Man pages
483484 t ! ( fs:: create_dir_all( image. join( "share/man/man1" ) ) ) ;
@@ -2095,6 +2096,72 @@ pub fn maybe_install_llvm_runtime(builder: &Builder<'_>, target: TargetSelection
20952096 }
20962097}
20972098
2099+ /// Maybe add LLVM tools to the rustc sysroot.
2100+ pub fn maybe_install_llvm_tools ( builder : & Builder < ' _ > , target : TargetSelection , dst_dir : & Path ) {
2101+ if builder. config . llvm_enabled ( target) {
2102+ let llvm:: LlvmResult { llvm_config, .. } = builder. ensure ( llvm:: Llvm { target } ) ;
2103+ if !builder. config . dry_run ( ) && builder. config . llvm_tools_enabled {
2104+ let llvm_bin_dir =
2105+ command ( llvm_config) . arg ( "--bindir" ) . run_capture_stdout ( builder) . stdout ( ) ;
2106+ let llvm_bin_dir = Path :: new ( llvm_bin_dir. trim ( ) ) ;
2107+
2108+ // Since we've already built the LLVM tools, install them to the sysroot.
2109+ // This is the equivalent of installing the `llvm-tools-preview` component via
2110+ // rustup, and lets developers use a locally built toolchain to
2111+ // build projects that expect llvm tools to be present in the sysroot
2112+ // (e.g. the `bootimage` crate).
2113+ for tool in LLVM_TOOLS {
2114+ let tool_exe = exe ( tool, target) ;
2115+ let src_path = llvm_bin_dir. join ( & tool_exe) ;
2116+ // When using `download-ci-llvm`, some of the tools
2117+ // may not exist, so skip trying to copy them.
2118+ if src_path. exists ( ) {
2119+ builder. copy_link ( & src_path, & dst_dir. join ( & tool_exe) ) ;
2120+ }
2121+ }
2122+ }
2123+ }
2124+ }
2125+
2126+ /// Maybe add `llvm-bitcode-linker` to the rustc sysroot.
2127+ pub fn maybe_install_llvm_bitcode_linker (
2128+ builder : & Builder < ' _ > ,
2129+ builder_compiler : Compiler ,
2130+ target : TargetSelection ,
2131+ dst_dir : & Path ,
2132+ ) {
2133+ if builder. config . llvm_bitcode_linker_enabled {
2134+ let llvm_bitcode_linker_exe = builder. ensure ( tool:: LlvmBitcodeLinker {
2135+ compiler : builder_compiler,
2136+ target,
2137+ extra_features : vec ! [ ] ,
2138+ } ) ;
2139+
2140+ builder. copy_link (
2141+ & llvm_bitcode_linker_exe,
2142+ & dst_dir. join ( llvm_bitcode_linker_exe. file_name ( ) . unwrap ( ) ) ,
2143+ ) ;
2144+ }
2145+ }
2146+
2147+ /// Maybe add `wasm-component-ld` to the rustc sysroot.
2148+ pub fn maybe_install_wasm_component_ld (
2149+ builder : & Builder < ' _ > ,
2150+ builder_compiler : Compiler ,
2151+ target : TargetSelection ,
2152+ dst_dir : & Path ,
2153+ ) {
2154+ if builder. tool_enabled ( "wasm-component-ld" ) {
2155+ let wasm_component_ld_exe =
2156+ builder. ensure ( tool:: WasmComponentLd { compiler : builder_compiler, target } ) ;
2157+
2158+ builder. copy_link (
2159+ & wasm_component_ld_exe,
2160+ & dst_dir. join ( wasm_component_ld_exe. file_name ( ) . unwrap ( ) ) ,
2161+ ) ;
2162+ }
2163+ }
2164+
20982165#[ derive( Clone , Debug , Eq , Hash , PartialEq ) ]
20992166pub struct LlvmTools {
21002167 pub target : TargetSelection ,
0 commit comments