@@ -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" ) ) ) ;
@@ -2095,6 +2113,85 @@ pub fn maybe_install_llvm_runtime(builder: &Builder<'_>, target: TargetSelection
2095
2113
}
2096
2114
}
2097
2115
2116
+ /// Maybe add LLVM tools to the rustc sysroot.
2117
+ pub fn maybe_install_llvm_tools (
2118
+ builder : & Builder < ' _ > ,
2119
+ target : TargetSelection ,
2120
+ dst_dir : & Path ,
2121
+ dereference_symlinks : bool ,
2122
+ ) {
2123
+ if builder. config . llvm_enabled ( target) {
2124
+ let llvm:: LlvmResult { llvm_config, .. } = builder. ensure ( llvm:: Llvm { target } ) ;
2125
+ if !builder. config . dry_run ( ) && builder. config . llvm_tools_enabled {
2126
+ let llvm_bin_dir =
2127
+ command ( llvm_config) . arg ( "--bindir" ) . run_capture_stdout ( builder) . stdout ( ) ;
2128
+ let llvm_bin_dir = Path :: new ( llvm_bin_dir. trim ( ) ) ;
2129
+
2130
+ // Since we've already built the LLVM tools, install them to the sysroot.
2131
+ // This is the equivalent of installing the `llvm-tools-preview` component via
2132
+ // rustup, and lets developers use a locally built toolchain to
2133
+ // build projects that expect llvm tools to be present in the sysroot
2134
+ // (e.g. the `bootimage` crate).
2135
+ for tool in LLVM_TOOLS {
2136
+ let tool_exe = exe ( tool, target) ;
2137
+ let src_path = llvm_bin_dir. join ( & tool_exe) ;
2138
+ // When using `download-ci-llvm`, some of the tools
2139
+ // may not exist, so skip trying to copy them.
2140
+ if src_path. exists ( ) {
2141
+ builder. copy_link_internal (
2142
+ & src_path,
2143
+ & dst_dir. join ( & tool_exe) ,
2144
+ dereference_symlinks,
2145
+ ) ;
2146
+ }
2147
+ }
2148
+ }
2149
+ }
2150
+ }
2151
+
2152
+ /// Maybe add `llvm-bitcode-linker` to the rustc sysroot.
2153
+ pub fn maybe_install_llvm_bitcode_linker (
2154
+ builder : & Builder < ' _ > ,
2155
+ builder_compiler : Compiler ,
2156
+ target : TargetSelection ,
2157
+ dst_dir : & Path ,
2158
+ dereference_symlinks : bool ,
2159
+ ) {
2160
+ if builder. config . llvm_bitcode_linker_enabled {
2161
+ let llvm_bitcode_linker_exe = builder. ensure ( tool:: LlvmBitcodeLinker {
2162
+ compiler : builder_compiler,
2163
+ target,
2164
+ extra_features : vec ! [ ] ,
2165
+ } ) ;
2166
+
2167
+ builder. copy_link_internal (
2168
+ & llvm_bitcode_linker_exe,
2169
+ & dst_dir. join ( llvm_bitcode_linker_exe. file_name ( ) . unwrap ( ) ) ,
2170
+ dereference_symlinks,
2171
+ ) ;
2172
+ }
2173
+ }
2174
+
2175
+ /// Maybe add `wasm-component-ld` to the rustc sysroot.
2176
+ pub fn maybe_install_wasm_component_ld (
2177
+ builder : & Builder < ' _ > ,
2178
+ builder_compiler : Compiler ,
2179
+ target : TargetSelection ,
2180
+ dst_dir : & Path ,
2181
+ dereference_symlinks : bool ,
2182
+ ) {
2183
+ if builder. tool_enabled ( "wasm-component-ld" ) {
2184
+ let wasm_component_ld_exe =
2185
+ builder. ensure ( tool:: WasmComponentLd { compiler : builder_compiler, target } ) ;
2186
+
2187
+ builder. copy_link_internal (
2188
+ & wasm_component_ld_exe,
2189
+ & dst_dir. join ( wasm_component_ld_exe. file_name ( ) . unwrap ( ) ) ,
2190
+ dereference_symlinks,
2191
+ ) ;
2192
+ }
2193
+ }
2194
+
2098
2195
#[ derive( Clone , Debug , Eq , Hash , PartialEq ) ]
2099
2196
pub struct LlvmTools {
2100
2197
pub target : TargetSelection ,
0 commit comments