@@ -1760,6 +1760,49 @@ impl Step for Assemble {
1760
1760
return target_compiler;
1761
1761
}
1762
1762
1763
+ // We prepend this bin directory to the user PATH when linking Rust binaries. To
1764
+ // avoid shadowing the system LLD we rename the LLD we provide to `rust-lld`.
1765
+ let libdir = builder. sysroot_libdir ( target_compiler, target_compiler. host ) ;
1766
+ let libdir_bin = libdir. parent ( ) . unwrap ( ) . join ( "bin" ) ;
1767
+ t ! ( fs:: create_dir_all( & libdir_bin) ) ;
1768
+
1769
+ if builder. config . llvm_enabled ( target_compiler. host ) {
1770
+ let llvm:: LlvmResult { llvm_config, .. } =
1771
+ builder. ensure ( llvm:: Llvm { target : target_compiler. host } ) ;
1772
+ if !builder. config . dry_run ( ) && builder. config . llvm_tools_enabled {
1773
+ let llvm_bin_dir =
1774
+ command ( llvm_config) . arg ( "--bindir" ) . run_capture_stdout ( builder) . stdout ( ) ;
1775
+ let llvm_bin_dir = Path :: new ( llvm_bin_dir. trim ( ) ) ;
1776
+
1777
+ // Since we've already built the LLVM tools, install them to the sysroot.
1778
+ // This is the equivalent of installing the `llvm-tools-preview` component via
1779
+ // rustup, and lets developers use a locally built toolchain to
1780
+ // build projects that expect llvm tools to be present in the sysroot
1781
+ // (e.g. the `bootimage` crate).
1782
+ for tool in LLVM_TOOLS {
1783
+ let tool_exe = exe ( tool, target_compiler. host ) ;
1784
+ let src_path = llvm_bin_dir. join ( & tool_exe) ;
1785
+ // When using `download-ci-llvm`, some of the tools
1786
+ // may not exist, so skip trying to copy them.
1787
+ if src_path. exists ( ) {
1788
+ builder. copy_link ( & src_path, & libdir_bin. join ( & tool_exe) ) ;
1789
+ }
1790
+ }
1791
+ }
1792
+ }
1793
+
1794
+ let maybe_install_llvm_bitcode_linker = |compiler| {
1795
+ if builder. config . llvm_bitcode_linker_enabled {
1796
+ let src_path = builder. ensure ( crate :: core:: build_steps:: tool:: LlvmBitcodeLinker {
1797
+ compiler,
1798
+ target : target_compiler. host ,
1799
+ extra_features : vec ! [ ] ,
1800
+ } ) ;
1801
+ let tool_exe = exe ( "llvm-bitcode-linker" , target_compiler. host ) ;
1802
+ builder. copy_link ( & src_path, & libdir_bin. join ( tool_exe) ) ;
1803
+ }
1804
+ } ;
1805
+
1763
1806
// If we're downloading a compiler from CI, we can use the same compiler for all stages other than 0.
1764
1807
if builder. download_rustc ( ) {
1765
1808
builder. ensure ( Std :: new ( target_compiler, target_compiler. host ) ) ;
@@ -1772,6 +1815,9 @@ impl Step for Assemble {
1772
1815
if target_compiler. stage == builder. top_stage {
1773
1816
builder. info ( & format ! ( "Creating a sysroot for stage{stage} compiler (use `rustup toolchain link 'name' build/host/stage{stage}`)" , stage=target_compiler. stage) ) ;
1774
1817
}
1818
+
1819
+ maybe_install_llvm_bitcode_linker ( target_compiler) ;
1820
+
1775
1821
return target_compiler;
1776
1822
}
1777
1823
@@ -1880,11 +1926,6 @@ impl Step for Assemble {
1880
1926
1881
1927
copy_codegen_backends_to_sysroot ( builder, build_compiler, target_compiler) ;
1882
1928
1883
- // We prepend this bin directory to the user PATH when linking Rust binaries. To
1884
- // avoid shadowing the system LLD we rename the LLD we provide to `rust-lld`.
1885
- let libdir = builder. sysroot_libdir ( target_compiler, target_compiler. host ) ;
1886
- let libdir_bin = libdir. parent ( ) . unwrap ( ) . join ( "bin" ) ;
1887
- t ! ( fs:: create_dir_all( & libdir_bin) ) ;
1888
1929
if let Some ( lld_install) = lld_install {
1889
1930
let src_exe = exe ( "lld" , target_compiler. host ) ;
1890
1931
let dst_exe = exe ( "rust-lld" , target_compiler. host ) ;
@@ -1920,40 +1961,7 @@ impl Step for Assemble {
1920
1961
) ;
1921
1962
}
1922
1963
1923
- if builder. config . llvm_enabled ( target_compiler. host ) {
1924
- let llvm:: LlvmResult { llvm_config, .. } =
1925
- builder. ensure ( llvm:: Llvm { target : target_compiler. host } ) ;
1926
- if !builder. config . dry_run ( ) && builder. config . llvm_tools_enabled {
1927
- let llvm_bin_dir =
1928
- command ( llvm_config) . arg ( "--bindir" ) . run_capture_stdout ( builder) . stdout ( ) ;
1929
- let llvm_bin_dir = Path :: new ( llvm_bin_dir. trim ( ) ) ;
1930
-
1931
- // Since we've already built the LLVM tools, install them to the sysroot.
1932
- // This is the equivalent of installing the `llvm-tools-preview` component via
1933
- // rustup, and lets developers use a locally built toolchain to
1934
- // build projects that expect llvm tools to be present in the sysroot
1935
- // (e.g. the `bootimage` crate).
1936
- for tool in LLVM_TOOLS {
1937
- let tool_exe = exe ( tool, target_compiler. host ) ;
1938
- let src_path = llvm_bin_dir. join ( & tool_exe) ;
1939
- // When using `download-ci-llvm`, some of the tools
1940
- // may not exist, so skip trying to copy them.
1941
- if src_path. exists ( ) {
1942
- builder. copy_link ( & src_path, & libdir_bin. join ( & tool_exe) ) ;
1943
- }
1944
- }
1945
- }
1946
- }
1947
-
1948
- if builder. config . llvm_bitcode_linker_enabled {
1949
- let src_path = builder. ensure ( crate :: core:: build_steps:: tool:: LlvmBitcodeLinker {
1950
- compiler : build_compiler,
1951
- target : target_compiler. host ,
1952
- extra_features : vec ! [ ] ,
1953
- } ) ;
1954
- let tool_exe = exe ( "llvm-bitcode-linker" , target_compiler. host ) ;
1955
- builder. copy_link ( & src_path, & libdir_bin. join ( tool_exe) ) ;
1956
- }
1964
+ maybe_install_llvm_bitcode_linker ( build_compiler) ;
1957
1965
1958
1966
// Ensure that `libLLVM.so` ends up in the newly build compiler directory,
1959
1967
// so that it can be found when the newly built `rustc` is run.
0 commit comments