@@ -473,11 +473,29 @@ impl Step for Rustc {
473
473
) ;
474
474
}
475
475
}
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
+
480
+ maybe_install_wasm_component_ld (
481
+ builder,
482
+ builder_compiler,
483
+ compiler. host ,
484
+ & dst_dir,
485
+ true ,
486
+ ) ;
487
+
488
+ let self_contained_bin_dir = dst_dir. join ( "self-contained" ) ;
489
+ t ! ( fs:: create_dir_all( & self_contained_bin_dir) ) ;
490
+ maybe_install_llvm_bitcode_linker (
491
+ builder,
492
+ builder_compiler,
493
+ compiler. host ,
494
+ & self_contained_bin_dir,
495
+ true ,
496
+ ) ;
497
+
498
+ maybe_install_llvm_tools ( builder, compiler. host , & dst_dir, true ) ;
481
499
482
500
// Man pages
483
501
t ! ( fs:: create_dir_all( image. join( "share/man/man1" ) ) ) ;
@@ -2086,6 +2104,85 @@ pub fn maybe_install_llvm_runtime(builder: &Builder<'_>, target: TargetSelection
2086
2104
}
2087
2105
}
2088
2106
2107
+ /// Maybe add LLVM tools to the rustc sysroot.
2108
+ pub fn maybe_install_llvm_tools (
2109
+ builder : & Builder < ' _ > ,
2110
+ target : TargetSelection ,
2111
+ dst_dir : & Path ,
2112
+ dereference_symlinks : bool ,
2113
+ ) {
2114
+ if builder. config . llvm_enabled ( target) {
2115
+ let llvm:: LlvmResult { llvm_config, .. } = builder. ensure ( llvm:: Llvm { target } ) ;
2116
+ if !builder. config . dry_run ( ) && builder. config . llvm_tools_enabled {
2117
+ let llvm_bin_dir =
2118
+ command ( llvm_config) . arg ( "--bindir" ) . run_capture_stdout ( builder) . stdout ( ) ;
2119
+ let llvm_bin_dir = Path :: new ( llvm_bin_dir. trim ( ) ) ;
2120
+
2121
+ // Since we've already built the LLVM tools, install them to the sysroot.
2122
+ // This is the equivalent of installing the `llvm-tools-preview` component via
2123
+ // rustup, and lets developers use a locally built toolchain to
2124
+ // build projects that expect llvm tools to be present in the sysroot
2125
+ // (e.g. the `bootimage` crate).
2126
+ for tool in LLVM_TOOLS {
2127
+ let tool_exe = exe ( tool, target) ;
2128
+ let src_path = llvm_bin_dir. join ( & tool_exe) ;
2129
+ // When using `download-ci-llvm`, some of the tools
2130
+ // may not exist, so skip trying to copy them.
2131
+ if src_path. exists ( ) {
2132
+ builder. copy_link_internal (
2133
+ & src_path,
2134
+ & dst_dir. join ( & tool_exe) ,
2135
+ dereference_symlinks,
2136
+ ) ;
2137
+ }
2138
+ }
2139
+ }
2140
+ }
2141
+ }
2142
+
2143
+ /// Maybe add `llvm-bitcode-linker` to the rustc sysroot.
2144
+ pub fn maybe_install_llvm_bitcode_linker (
2145
+ builder : & Builder < ' _ > ,
2146
+ builder_compiler : Compiler ,
2147
+ target : TargetSelection ,
2148
+ dst_dir : & Path ,
2149
+ dereference_symlinks : bool ,
2150
+ ) {
2151
+ if builder. config . llvm_bitcode_linker_enabled {
2152
+ let llvm_bitcode_linker_exe = builder. ensure ( tool:: LlvmBitcodeLinker {
2153
+ compiler : builder_compiler,
2154
+ target,
2155
+ extra_features : vec ! [ ] ,
2156
+ } ) ;
2157
+
2158
+ builder. copy_link_internal (
2159
+ & llvm_bitcode_linker_exe,
2160
+ & dst_dir. join ( llvm_bitcode_linker_exe. file_name ( ) . unwrap ( ) ) ,
2161
+ dereference_symlinks,
2162
+ ) ;
2163
+ }
2164
+ }
2165
+
2166
+ /// Maybe add `wasm-component-ld` to the rustc sysroot.
2167
+ pub fn maybe_install_wasm_component_ld (
2168
+ builder : & Builder < ' _ > ,
2169
+ builder_compiler : Compiler ,
2170
+ target : TargetSelection ,
2171
+ dst_dir : & Path ,
2172
+ dereference_symlinks : bool ,
2173
+ ) {
2174
+ if builder. tool_enabled ( "wasm-component-ld" ) {
2175
+ let wasm_component_ld_exe =
2176
+ builder. ensure ( tool:: WasmComponentLd { compiler : builder_compiler, target } ) ;
2177
+
2178
+ builder. copy_link_internal (
2179
+ & wasm_component_ld_exe,
2180
+ & dst_dir. join ( wasm_component_ld_exe. file_name ( ) . unwrap ( ) ) ,
2181
+ dereference_symlinks,
2182
+ ) ;
2183
+ }
2184
+ }
2185
+
2089
2186
#[ derive( Clone , Debug , Eq , Hash , PartialEq ) ]
2090
2187
pub struct LlvmTools {
2091
2188
pub target : TargetSelection ,
0 commit comments