@@ -18,14 +18,16 @@ pub(crate) fn build_sysroot(
1818 sysroot_kind : SysrootKind ,
1919 cg_clif_dylib_src : & Path ,
2020 bootstrap_host_compiler : & Compiler ,
21- target_triple : & str ,
22- ) {
21+ target_triple : String ,
22+ ) -> Compiler {
2323 eprintln ! ( "[BUILD] sysroot {:?}" , sysroot_kind) ;
2424
2525 DIST_DIR . ensure_fresh ( dirs) ;
2626 BIN_DIR . ensure_exists ( dirs) ;
2727 LIB_DIR . ensure_exists ( dirs) ;
2828
29+ let is_native = bootstrap_host_compiler. triple == target_triple;
30+
2931 // Copy the backend
3032 let cg_clif_dylib_path = if cfg ! ( windows) {
3133 // Windows doesn't have rpath support, so the cg_clif dylib needs to be next to the
@@ -55,20 +57,20 @@ pub(crate) fn build_sysroot(
5557
5658 let host_rustlib_lib =
5759 RUSTLIB_DIR . to_path ( dirs) . join ( & bootstrap_host_compiler. triple ) . join ( "lib" ) ;
58- let target_rustlib_lib = RUSTLIB_DIR . to_path ( dirs) . join ( target_triple) . join ( "lib" ) ;
60+ let target_rustlib_lib = RUSTLIB_DIR . to_path ( dirs) . join ( & target_triple) . join ( "lib" ) ;
5961 fs:: create_dir_all ( & host_rustlib_lib) . unwrap ( ) ;
6062 fs:: create_dir_all ( & target_rustlib_lib) . unwrap ( ) ;
6163
6264 if target_triple == "x86_64-pc-windows-gnu" {
63- if !default_sysroot. join ( "lib" ) . join ( "rustlib" ) . join ( target_triple) . join ( "lib" ) . exists ( ) {
65+ if !default_sysroot. join ( "lib" ) . join ( "rustlib" ) . join ( & target_triple) . join ( "lib" ) . exists ( ) {
6466 eprintln ! (
6567 "The x86_64-pc-windows-gnu target needs to be installed first before it is possible \
6668 to compile a sysroot for it.",
6769 ) ;
6870 process:: exit ( 1 ) ;
6971 }
7072 for file in fs:: read_dir (
71- default_sysroot. join ( "lib" ) . join ( "rustlib" ) . join ( target_triple) . join ( "lib" ) ,
73+ default_sysroot. join ( "lib" ) . join ( "rustlib" ) . join ( & target_triple) . join ( "lib" ) ,
7274 )
7375 . unwrap ( )
7476 {
@@ -108,9 +110,9 @@ pub(crate) fn build_sysroot(
108110 try_hard_link ( & file, host_rustlib_lib. join ( file. file_name ( ) . unwrap ( ) ) ) ;
109111 }
110112
111- if target_triple != bootstrap_host_compiler . triple {
113+ if !is_native {
112114 for file in fs:: read_dir (
113- default_sysroot. join ( "lib" ) . join ( "rustlib" ) . join ( target_triple) . join ( "lib" ) ,
115+ default_sysroot. join ( "lib" ) . join ( "rustlib" ) . join ( & target_triple) . join ( "lib" ) ,
114116 )
115117 . unwrap ( )
116118 {
@@ -127,13 +129,13 @@ pub(crate) fn build_sysroot(
127129 & cg_clif_dylib_path,
128130 ) ;
129131
130- if bootstrap_host_compiler . triple != target_triple {
132+ if !is_native {
131133 build_clif_sysroot_for_triple (
132134 dirs,
133135 channel,
134136 {
135137 let mut bootstrap_target_compiler = bootstrap_host_compiler. clone ( ) ;
136- bootstrap_target_compiler. triple = target_triple. to_owned ( ) ;
138+ bootstrap_target_compiler. triple = target_triple. clone ( ) ;
137139 bootstrap_target_compiler. set_cross_linker_and_runner ( ) ;
138140 bootstrap_target_compiler
139141 } ,
@@ -152,6 +154,12 @@ pub(crate) fn build_sysroot(
152154 }
153155 }
154156 }
157+
158+ let mut target_compiler = Compiler :: clif_with_triple ( & dirs, target_triple) ;
159+ if !is_native {
160+ target_compiler. set_cross_linker_and_runner ( ) ;
161+ }
162+ target_compiler
155163}
156164
157165pub ( crate ) static ORIG_BUILD_SYSROOT : RelPath = RelPath :: SOURCE . join ( "build_sysroot" ) ;
0 commit comments