@@ -17,7 +17,7 @@ pub(crate) fn build_sysroot(
1717    channel :  & str , 
1818    sysroot_kind :  SysrootKind , 
1919    cg_clif_dylib_src :  & Path , 
20-     host_triple :  & str , 
20+     host_compiler :  & Compiler , 
2121    target_triple :  & str , 
2222)  { 
2323    eprintln ! ( "[BUILD] sysroot {:?}" ,  sysroot_kind) ; 
@@ -53,7 +53,7 @@ pub(crate) fn build_sysroot(
5353
5454    let  default_sysroot = super :: rustc_info:: get_default_sysroot ( ) ; 
5555
56-     let  host_rustlib_lib = RUSTLIB_DIR . to_path ( dirs) . join ( host_triple ) . join ( "lib" ) ; 
56+     let  host_rustlib_lib = RUSTLIB_DIR . to_path ( dirs) . join ( & host_compiler . triple ) . join ( "lib" ) ; 
5757    let  target_rustlib_lib = RUSTLIB_DIR . to_path ( dirs) . join ( target_triple) . join ( "lib" ) ; 
5858    fs:: create_dir_all ( & host_rustlib_lib) . unwrap ( ) ; 
5959    fs:: create_dir_all ( & target_rustlib_lib) . unwrap ( ) ; 
@@ -83,7 +83,7 @@ pub(crate) fn build_sysroot(
8383        SysrootKind :: None  => { }  // Nothing to do 
8484        SysrootKind :: Llvm  => { 
8585            for  file in  fs:: read_dir ( 
86-                 default_sysroot. join ( "lib" ) . join ( "rustlib" ) . join ( host_triple ) . join ( "lib" ) , 
86+                 default_sysroot. join ( "lib" ) . join ( "rustlib" ) . join ( & host_compiler . triple ) . join ( "lib" ) , 
8787            ) 
8888            . unwrap ( ) 
8989            { 
@@ -103,7 +103,7 @@ pub(crate) fn build_sysroot(
103103                try_hard_link ( & file,  host_rustlib_lib. join ( file. file_name ( ) . unwrap ( ) ) ) ; 
104104            } 
105105
106-             if  target_triple != host_triple  { 
106+             if  target_triple != host_compiler . triple  { 
107107                for  file in  fs:: read_dir ( 
108108                    default_sysroot. join ( "lib" ) . join ( "rustlib" ) . join ( target_triple) . join ( "lib" ) , 
109109                ) 
@@ -115,21 +115,24 @@ pub(crate) fn build_sysroot(
115115            } 
116116        } 
117117        SysrootKind :: Clif  => { 
118-             build_clif_sysroot_for_triple ( dirs,  channel,  host_triple,  & cg_clif_dylib_path,  None ) ; 
119- 
120-             if  host_triple != target_triple { 
121-                 // When cross-compiling it is often necessary to manually pick the right linker 
122-                 let  linker = match  target_triple { 
123-                     "aarch64-unknown-linux-gnu"  => Some ( "aarch64-linux-gnu-gcc" ) , 
124-                     "s390x-unknown-linux-gnu"  => Some ( "s390x-linux-gnu-gcc" ) , 
125-                     _ => None , 
126-                 } ; 
118+             build_clif_sysroot_for_triple ( 
119+                 dirs, 
120+                 channel, 
121+                 host_compiler. clone ( ) , 
122+                 & cg_clif_dylib_path, 
123+             ) ; 
124+ 
125+             if  host_compiler. triple  != target_triple { 
127126                build_clif_sysroot_for_triple ( 
128127                    dirs, 
129128                    channel, 
130-                     target_triple, 
129+                     { 
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
134+                     } , 
131135                    & cg_clif_dylib_path, 
132-                     linker, 
133136                ) ; 
134137            } 
135138
@@ -150,14 +153,14 @@ pub(crate) static ORIG_BUILD_SYSROOT: RelPath = RelPath::SOURCE.join("build_sysr
150153pub ( crate )  static  BUILD_SYSROOT :  RelPath  = RelPath :: DOWNLOAD . join ( "sysroot" ) ; 
151154pub ( crate )  static  SYSROOT_RUSTC_VERSION :  RelPath  = BUILD_SYSROOT . join ( "rustc_version" ) ; 
152155pub ( crate )  static  SYSROOT_SRC :  RelPath  = BUILD_SYSROOT . join ( "sysroot_src" ) ; 
153- static  STANDARD_LIBRARY :  CargoProject  = CargoProject :: new ( & BUILD_SYSROOT ,  "build_sysroot" ) ; 
156+ pub ( crate )  static  STANDARD_LIBRARY :  CargoProject  =
157+     CargoProject :: new ( & BUILD_SYSROOT ,  "build_sysroot" ) ; 
154158
155159fn  build_clif_sysroot_for_triple ( 
156160    dirs :  & Dirs , 
157161    channel :  & str , 
158-     triple :   & str , 
162+     mut   compiler :   Compiler , 
159163    cg_clif_dylib_path :  & Path , 
160-     linker :  Option < & str > , 
161164)  { 
162165    match  fs:: read_to_string ( SYSROOT_RUSTC_VERSION . to_path ( dirs) )  { 
163166        Err ( e)  => { 
@@ -177,7 +180,7 @@ fn build_clif_sysroot_for_triple(
177180        } 
178181    } 
179182
180-     let  build_dir = STANDARD_LIBRARY . target_dir ( dirs) . join ( triple) . join ( channel) ; 
183+     let  build_dir = STANDARD_LIBRARY . target_dir ( dirs) . join ( & compiler . triple ) . join ( channel) ; 
181184
182185    if  !super :: config:: get_bool ( "keep_sysroot" )  { 
183186        // Cleanup the deps dir, but keep build scripts and the incremental cache for faster 
@@ -188,18 +191,13 @@ fn build_clif_sysroot_for_triple(
188191    } 
189192
190193    // Build sysroot 
191-     let  mut  rustflags = "-Zforce-unstable-if-unmarked -Cpanic=abort" . to_string ( ) ; 
194+     let  mut  rustflags = "  -Zforce-unstable-if-unmarked -Cpanic=abort" . to_string ( ) ; 
192195    rustflags. push_str ( & format ! ( " -Zcodegen-backend={}" ,  cg_clif_dylib_path. to_str( ) . unwrap( ) ) ) ; 
193196    rustflags. push_str ( & format ! ( " --sysroot={}" ,  DIST_DIR . to_path( dirs) . to_str( ) . unwrap( ) ) ) ; 
194197    if  channel == "release"  { 
195198        rustflags. push_str ( " -Zmir-opt-level=3" ) ; 
196199    } 
197-     if  let  Some ( linker)  = linker { 
198-         use  std:: fmt:: Write ; 
199-         write ! ( rustflags,  " -Clinker={}" ,  linker) . unwrap ( ) ; 
200-     } 
201-     let  mut  compiler = Compiler :: with_triple ( triple. to_owned ( ) ) ; 
202-     compiler. rustflags  = rustflags; 
200+     compiler. rustflags  += & rustflags; 
203201    let  mut  build_cmd = STANDARD_LIBRARY . build ( & compiler,  dirs) ; 
204202    if  channel == "release"  { 
205203        build_cmd. arg ( "--release" ) ; 
@@ -219,7 +217,7 @@ fn build_clif_sysroot_for_triple(
219217        } ; 
220218        try_hard_link ( 
221219            entry. path ( ) , 
222-             RUSTLIB_DIR . to_path ( dirs) . join ( triple) . join ( "lib" ) . join ( entry. file_name ( ) ) , 
220+             RUSTLIB_DIR . to_path ( dirs) . join ( & compiler . triple ) . join ( "lib" ) . join ( entry. file_name ( ) ) , 
223221        ) ; 
224222    } 
225223} 
0 commit comments