@@ -3,7 +3,9 @@ use std::path::Path;
33use std:: process:: { self , Command } ;
44
55use super :: path:: { Dirs , RelPath } ;
6- use super :: rustc_info:: { get_file_name, get_rustc_version, get_wrapper_file_name} ;
6+ use super :: rustc_info:: {
7+ get_file_name, get_rustc_version, get_toolchain_name, get_wrapper_file_name,
8+ } ;
79use super :: utils:: { spawn_and_wait, try_hard_link, CargoProject , Compiler } ;
810use super :: SysrootKind ;
911
@@ -17,15 +19,17 @@ pub(crate) fn build_sysroot(
1719 channel : & str ,
1820 sysroot_kind : SysrootKind ,
1921 cg_clif_dylib_src : & Path ,
20- host_compiler : & Compiler ,
21- target_triple : & str ,
22- ) {
22+ bootstrap_host_compiler : & Compiler ,
23+ target_triple : String ,
24+ ) -> Compiler {
2325 eprintln ! ( "[BUILD] sysroot {:?}" , sysroot_kind) ;
2426
2527 DIST_DIR . ensure_fresh ( dirs) ;
2628 BIN_DIR . ensure_exists ( dirs) ;
2729 LIB_DIR . ensure_exists ( dirs) ;
2830
31+ let is_native = bootstrap_host_compiler. triple == target_triple;
32+
2933 // Copy the backend
3034 let cg_clif_dylib_path = if cfg ! ( windows) {
3135 // Windows doesn't have rpath support, so the cg_clif dylib needs to be next to the
@@ -42,32 +46,34 @@ pub(crate) fn build_sysroot(
4246 for wrapper in [ "rustc-clif" , "rustdoc-clif" , "cargo-clif" ] {
4347 let wrapper_name = get_wrapper_file_name ( wrapper, "bin" ) ;
4448
45- let mut build_cargo_wrapper_cmd = Command :: new ( " rustc" ) ;
49+ let mut build_cargo_wrapper_cmd = Command :: new ( & bootstrap_host_compiler . rustc ) ;
4650 build_cargo_wrapper_cmd
51+ . env ( "TOOLCHAIN_NAME" , get_toolchain_name ( ) )
4752 . arg ( RelPath :: SCRIPTS . to_path ( dirs) . join ( & format ! ( "{wrapper}.rs" ) ) )
4853 . arg ( "-o" )
4954 . arg ( DIST_DIR . to_path ( dirs) . join ( wrapper_name) )
5055 . arg ( "-g" ) ;
5156 spawn_and_wait ( build_cargo_wrapper_cmd) ;
5257 }
5358
54- let default_sysroot = super :: rustc_info:: get_default_sysroot ( ) ;
59+ let default_sysroot = super :: rustc_info:: get_default_sysroot ( & bootstrap_host_compiler . rustc ) ;
5560
56- let host_rustlib_lib = RUSTLIB_DIR . to_path ( dirs) . join ( & host_compiler. triple ) . join ( "lib" ) ;
57- let target_rustlib_lib = RUSTLIB_DIR . to_path ( dirs) . join ( target_triple) . join ( "lib" ) ;
61+ let host_rustlib_lib =
62+ RUSTLIB_DIR . to_path ( dirs) . join ( & bootstrap_host_compiler. triple ) . join ( "lib" ) ;
63+ let target_rustlib_lib = RUSTLIB_DIR . to_path ( dirs) . join ( & target_triple) . join ( "lib" ) ;
5864 fs:: create_dir_all ( & host_rustlib_lib) . unwrap ( ) ;
5965 fs:: create_dir_all ( & target_rustlib_lib) . unwrap ( ) ;
6066
6167 if target_triple == "x86_64-pc-windows-gnu" {
62- if !default_sysroot. join ( "lib" ) . join ( "rustlib" ) . join ( target_triple) . join ( "lib" ) . exists ( ) {
68+ if !default_sysroot. join ( "lib" ) . join ( "rustlib" ) . join ( & target_triple) . join ( "lib" ) . exists ( ) {
6369 eprintln ! (
6470 "The x86_64-pc-windows-gnu target needs to be installed first before it is possible \
6571 to compile a sysroot for it.",
6672 ) ;
6773 process:: exit ( 1 ) ;
6874 }
6975 for file in fs:: read_dir (
70- default_sysroot. join ( "lib" ) . join ( "rustlib" ) . join ( target_triple) . join ( "lib" ) ,
76+ default_sysroot. join ( "lib" ) . join ( "rustlib" ) . join ( & target_triple) . join ( "lib" ) ,
7177 )
7278 . unwrap ( )
7379 {
@@ -83,7 +89,11 @@ pub(crate) fn build_sysroot(
8389 SysrootKind :: None => { } // Nothing to do
8490 SysrootKind :: Llvm => {
8591 for file in fs:: read_dir (
86- default_sysroot. join ( "lib" ) . join ( "rustlib" ) . join ( & host_compiler. triple ) . join ( "lib" ) ,
92+ default_sysroot
93+ . join ( "lib" )
94+ . join ( "rustlib" )
95+ . join ( & bootstrap_host_compiler. triple )
96+ . join ( "lib" ) ,
8797 )
8898 . unwrap ( )
8999 {
@@ -103,9 +113,9 @@ pub(crate) fn build_sysroot(
103113 try_hard_link ( & file, host_rustlib_lib. join ( file. file_name ( ) . unwrap ( ) ) ) ;
104114 }
105115
106- if target_triple != host_compiler . triple {
116+ if !is_native {
107117 for file in fs:: read_dir (
108- default_sysroot. join ( "lib" ) . join ( "rustlib" ) . join ( target_triple) . join ( "lib" ) ,
118+ default_sysroot. join ( "lib" ) . join ( "rustlib" ) . join ( & target_triple) . join ( "lib" ) ,
109119 )
110120 . unwrap ( )
111121 {
@@ -118,19 +128,19 @@ pub(crate) fn build_sysroot(
118128 build_clif_sysroot_for_triple (
119129 dirs,
120130 channel,
121- host_compiler . clone ( ) ,
131+ bootstrap_host_compiler . clone ( ) ,
122132 & cg_clif_dylib_path,
123133 ) ;
124134
125- if host_compiler . triple != target_triple {
135+ if !is_native {
126136 build_clif_sysroot_for_triple (
127137 dirs,
128138 channel,
129139 {
130- let mut target_compiler = host_compiler . clone ( ) ;
131- target_compiler . triple = target_triple. to_owned ( ) ;
132- target_compiler . set_cross_linker_and_runner ( ) ;
133- target_compiler
140+ let mut bootstrap_target_compiler = bootstrap_host_compiler . clone ( ) ;
141+ bootstrap_target_compiler . triple = target_triple. clone ( ) ;
142+ bootstrap_target_compiler . set_cross_linker_and_runner ( ) ;
143+ bootstrap_target_compiler
134144 } ,
135145 & cg_clif_dylib_path,
136146 ) ;
@@ -147,6 +157,12 @@ pub(crate) fn build_sysroot(
147157 }
148158 }
149159 }
160+
161+ let mut target_compiler = Compiler :: clif_with_triple ( & dirs, target_triple) ;
162+ if !is_native {
163+ target_compiler. set_cross_linker_and_runner ( ) ;
164+ }
165+ target_compiler
150166}
151167
152168pub ( crate ) static ORIG_BUILD_SYSROOT : RelPath = RelPath :: SOURCE . join ( "build_sysroot" ) ;
@@ -169,7 +185,7 @@ fn build_clif_sysroot_for_triple(
169185 process:: exit ( 1 ) ;
170186 }
171187 Ok ( source_version) => {
172- let rustc_version = get_rustc_version ( ) ;
188+ let rustc_version = get_rustc_version ( & compiler . rustc ) ;
173189 if source_version != rustc_version {
174190 eprintln ! ( "The patched sysroot source is outdated" ) ;
175191 eprintln ! ( "Source version: {}" , source_version. trim( ) ) ;
0 commit comments