@@ -2,7 +2,7 @@ use std::fs;
22use std:: path:: Path ;
33use std:: process:: { self , Command } ;
44
5- use super :: path:: RelPath ;
5+ use super :: path:: { Dirs , RelPath } ;
66use super :: rustc_info:: { get_file_name, get_rustc_version, get_wrapper_file_name} ;
77use super :: utils:: { spawn_and_wait, try_hard_link, CargoProject , Compiler } ;
88use super :: SysrootKind ;
@@ -13,6 +13,7 @@ static LIB_DIR: RelPath = RelPath::DIST.join("lib");
1313static RUSTLIB_DIR : RelPath = LIB_DIR . join ( "rustlib" ) ;
1414
1515pub ( crate ) fn build_sysroot (
16+ dirs : & Dirs ,
1617 channel : & str ,
1718 sysroot_kind : SysrootKind ,
1819 cg_clif_dylib_src : & Path ,
@@ -21,9 +22,9 @@ pub(crate) fn build_sysroot(
2122) {
2223 eprintln ! ( "[BUILD] sysroot {:?}" , sysroot_kind) ;
2324
24- DIST_DIR . ensure_fresh ( ) ;
25- BIN_DIR . ensure_exists ( ) ;
26- LIB_DIR . ensure_exists ( ) ;
25+ DIST_DIR . ensure_fresh ( dirs ) ;
26+ BIN_DIR . ensure_exists ( dirs ) ;
27+ LIB_DIR . ensure_exists ( dirs ) ;
2728
2829 // Copy the backend
2930 let cg_clif_dylib_path = if cfg ! ( windows) {
@@ -33,7 +34,7 @@ pub(crate) fn build_sysroot(
3334 } else {
3435 LIB_DIR
3536 }
36- . to_path ( )
37+ . to_path ( dirs )
3738 . join ( get_file_name ( "rustc_codegen_cranelift" , "dylib" ) ) ;
3839 try_hard_link ( cg_clif_dylib_src, & cg_clif_dylib_path) ;
3940
@@ -43,17 +44,17 @@ pub(crate) fn build_sysroot(
4344
4445 let mut build_cargo_wrapper_cmd = Command :: new ( "rustc" ) ;
4546 build_cargo_wrapper_cmd
46- . arg ( RelPath :: SCRIPTS . to_path ( ) . join ( & format ! ( "{wrapper}.rs" ) ) )
47+ . arg ( RelPath :: SCRIPTS . to_path ( dirs ) . join ( & format ! ( "{wrapper}.rs" ) ) )
4748 . arg ( "-o" )
48- . arg ( DIST_DIR . to_path ( ) . join ( wrapper_name) )
49+ . arg ( DIST_DIR . to_path ( dirs ) . join ( wrapper_name) )
4950 . arg ( "-g" ) ;
5051 spawn_and_wait ( build_cargo_wrapper_cmd) ;
5152 }
5253
5354 let default_sysroot = super :: rustc_info:: get_default_sysroot ( ) ;
5455
55- let host_rustlib_lib = RUSTLIB_DIR . to_path ( ) . join ( host_triple) . join ( "lib" ) ;
56- let target_rustlib_lib = RUSTLIB_DIR . to_path ( ) . join ( target_triple) . join ( "lib" ) ;
56+ let host_rustlib_lib = RUSTLIB_DIR . to_path ( dirs ) . join ( host_triple) . join ( "lib" ) ;
57+ let target_rustlib_lib = RUSTLIB_DIR . to_path ( dirs ) . join ( target_triple) . join ( "lib" ) ;
5758 fs:: create_dir_all ( & host_rustlib_lib) . unwrap ( ) ;
5859 fs:: create_dir_all ( & target_rustlib_lib) . unwrap ( ) ;
5960
@@ -114,7 +115,7 @@ pub(crate) fn build_sysroot(
114115 }
115116 }
116117 SysrootKind :: Clif => {
117- build_clif_sysroot_for_triple ( channel, host_triple, & cg_clif_dylib_path, None ) ;
118+ build_clif_sysroot_for_triple ( dirs , channel, host_triple, & cg_clif_dylib_path, None ) ;
118119
119120 if host_triple != target_triple {
120121 // When cross-compiling it is often necessary to manually pick the right linker
@@ -123,7 +124,13 @@ pub(crate) fn build_sysroot(
123124 } else {
124125 None
125126 } ;
126- build_clif_sysroot_for_triple ( channel, target_triple, & cg_clif_dylib_path, linker) ;
127+ build_clif_sysroot_for_triple (
128+ dirs,
129+ channel,
130+ target_triple,
131+ & cg_clif_dylib_path,
132+ linker,
133+ ) ;
127134 }
128135
129136 // Copy std for the host to the lib dir. This is necessary for the jit mode to find
@@ -132,7 +139,7 @@ pub(crate) fn build_sysroot(
132139 let file = file. unwrap ( ) . path ( ) ;
133140 let filename = file. file_name ( ) . unwrap ( ) . to_str ( ) . unwrap ( ) ;
134141 if filename. contains ( "std-" ) && !filename. contains ( ".rlib" ) {
135- try_hard_link ( & file, LIB_DIR . to_path ( ) . join ( file. file_name ( ) . unwrap ( ) ) ) ;
142+ try_hard_link ( & file, LIB_DIR . to_path ( dirs ) . join ( file. file_name ( ) . unwrap ( ) ) ) ;
136143 }
137144 }
138145 }
@@ -145,12 +152,13 @@ pub(crate) static SYSROOT_SRC: RelPath = RelPath::BUILD_SYSROOT.join("sysroot_sr
145152static STANDARD_LIBRARY : CargoProject = CargoProject :: new ( & RelPath :: BUILD_SYSROOT , "build_sysroot" ) ;
146153
147154fn build_clif_sysroot_for_triple (
155+ dirs : & Dirs ,
148156 channel : & str ,
149157 triple : & str ,
150158 cg_clif_dylib_path : & Path ,
151159 linker : Option < & str > ,
152160) {
153- match fs:: read_to_string ( SYSROOT_RUSTC_VERSION . to_path ( ) ) {
161+ match fs:: read_to_string ( SYSROOT_RUSTC_VERSION . to_path ( dirs ) ) {
154162 Err ( e) => {
155163 eprintln ! ( "Failed to get rustc version for patched sysroot source: {}" , e) ;
156164 eprintln ! ( "Hint: Try `./y.rs prepare` to patch the sysroot source" ) ;
@@ -168,7 +176,7 @@ fn build_clif_sysroot_for_triple(
168176 }
169177 }
170178
171- let build_dir = STANDARD_LIBRARY . target_dir ( ) . join ( triple) . join ( channel) ;
179+ let build_dir = STANDARD_LIBRARY . target_dir ( dirs ) . join ( triple) . join ( channel) ;
172180
173181 if !super :: config:: get_bool ( "keep_sysroot" ) {
174182 // Cleanup the deps dir, but keep build scripts and the incremental cache for faster
@@ -181,7 +189,7 @@ fn build_clif_sysroot_for_triple(
181189 // Build sysroot
182190 let mut rustflags = "-Zforce-unstable-if-unmarked -Cpanic=abort" . to_string ( ) ;
183191 rustflags. push_str ( & format ! ( " -Zcodegen-backend={}" , cg_clif_dylib_path. to_str( ) . unwrap( ) ) ) ;
184- rustflags. push_str ( & format ! ( " --sysroot={}" , DIST_DIR . to_path( ) . to_str( ) . unwrap( ) ) ) ;
192+ rustflags. push_str ( & format ! ( " --sysroot={}" , DIST_DIR . to_path( dirs ) . to_str( ) . unwrap( ) ) ) ;
185193 if channel == "release" {
186194 rustflags. push_str ( " -Zmir-opt-level=3" ) ;
187195 }
@@ -191,7 +199,7 @@ fn build_clif_sysroot_for_triple(
191199 }
192200 let mut compiler = Compiler :: with_triple ( triple. to_owned ( ) ) ;
193201 compiler. rustflags = rustflags;
194- let mut build_cmd = STANDARD_LIBRARY . build ( & compiler) ;
202+ let mut build_cmd = STANDARD_LIBRARY . build ( & compiler, dirs ) ;
195203 if channel == "release" {
196204 build_cmd. arg ( "--release" ) ;
197205 }
@@ -210,7 +218,7 @@ fn build_clif_sysroot_for_triple(
210218 } ;
211219 try_hard_link (
212220 entry. path ( ) ,
213- RUSTLIB_DIR . to_path ( ) . join ( triple) . join ( "lib" ) . join ( entry. file_name ( ) ) ,
221+ RUSTLIB_DIR . to_path ( dirs ) . join ( triple) . join ( "lib" ) . join ( entry. file_name ( ) ) ,
214222 ) ;
215223 }
216224}
0 commit comments