@@ -2,7 +2,7 @@ use std::fs;
2
2
use std:: path:: Path ;
3
3
use std:: process:: { self , Command } ;
4
4
5
- use super :: path:: RelPath ;
5
+ use super :: path:: { Dirs , RelPath } ;
6
6
use super :: rustc_info:: { get_file_name, get_rustc_version, get_wrapper_file_name} ;
7
7
use super :: utils:: { spawn_and_wait, try_hard_link, CargoProject , Compiler } ;
8
8
use super :: SysrootKind ;
@@ -13,6 +13,7 @@ static LIB_DIR: RelPath = RelPath::DIST.join("lib");
13
13
static RUSTLIB_DIR : RelPath = LIB_DIR . join ( "rustlib" ) ;
14
14
15
15
pub ( crate ) fn build_sysroot (
16
+ dirs : & Dirs ,
16
17
channel : & str ,
17
18
sysroot_kind : SysrootKind ,
18
19
cg_clif_dylib_src : & Path ,
@@ -21,9 +22,9 @@ pub(crate) fn build_sysroot(
21
22
) {
22
23
eprintln ! ( "[BUILD] sysroot {:?}" , sysroot_kind) ;
23
24
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 ) ;
27
28
28
29
// Copy the backend
29
30
let cg_clif_dylib_path = if cfg ! ( windows) {
@@ -33,7 +34,7 @@ pub(crate) fn build_sysroot(
33
34
} else {
34
35
LIB_DIR
35
36
}
36
- . to_path ( )
37
+ . to_path ( dirs )
37
38
. join ( get_file_name ( "rustc_codegen_cranelift" , "dylib" ) ) ;
38
39
try_hard_link ( cg_clif_dylib_src, & cg_clif_dylib_path) ;
39
40
@@ -43,17 +44,17 @@ pub(crate) fn build_sysroot(
43
44
44
45
let mut build_cargo_wrapper_cmd = Command :: new ( "rustc" ) ;
45
46
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" ) ) )
47
48
. arg ( "-o" )
48
- . arg ( DIST_DIR . to_path ( ) . join ( wrapper_name) )
49
+ . arg ( DIST_DIR . to_path ( dirs ) . join ( wrapper_name) )
49
50
. arg ( "-g" ) ;
50
51
spawn_and_wait ( build_cargo_wrapper_cmd) ;
51
52
}
52
53
53
54
let default_sysroot = super :: rustc_info:: get_default_sysroot ( ) ;
54
55
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" ) ;
57
58
fs:: create_dir_all ( & host_rustlib_lib) . unwrap ( ) ;
58
59
fs:: create_dir_all ( & target_rustlib_lib) . unwrap ( ) ;
59
60
@@ -114,7 +115,7 @@ pub(crate) fn build_sysroot(
114
115
}
115
116
}
116
117
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 ) ;
118
119
119
120
if host_triple != target_triple {
120
121
// When cross-compiling it is often necessary to manually pick the right linker
@@ -123,7 +124,13 @@ pub(crate) fn build_sysroot(
123
124
} else {
124
125
None
125
126
} ;
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
+ ) ;
127
134
}
128
135
129
136
// 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(
132
139
let file = file. unwrap ( ) . path ( ) ;
133
140
let filename = file. file_name ( ) . unwrap ( ) . to_str ( ) . unwrap ( ) ;
134
141
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 ( ) ) ) ;
136
143
}
137
144
}
138
145
}
@@ -145,12 +152,13 @@ pub(crate) static SYSROOT_SRC: RelPath = RelPath::BUILD_SYSROOT.join("sysroot_sr
145
152
static STANDARD_LIBRARY : CargoProject = CargoProject :: new ( & RelPath :: BUILD_SYSROOT , "build_sysroot" ) ;
146
153
147
154
fn build_clif_sysroot_for_triple (
155
+ dirs : & Dirs ,
148
156
channel : & str ,
149
157
triple : & str ,
150
158
cg_clif_dylib_path : & Path ,
151
159
linker : Option < & str > ,
152
160
) {
153
- match fs:: read_to_string ( SYSROOT_RUSTC_VERSION . to_path ( ) ) {
161
+ match fs:: read_to_string ( SYSROOT_RUSTC_VERSION . to_path ( dirs ) ) {
154
162
Err ( e) => {
155
163
eprintln ! ( "Failed to get rustc version for patched sysroot source: {}" , e) ;
156
164
eprintln ! ( "Hint: Try `./y.rs prepare` to patch the sysroot source" ) ;
@@ -168,7 +176,7 @@ fn build_clif_sysroot_for_triple(
168
176
}
169
177
}
170
178
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) ;
172
180
173
181
if !super :: config:: get_bool ( "keep_sysroot" ) {
174
182
// Cleanup the deps dir, but keep build scripts and the incremental cache for faster
@@ -181,7 +189,7 @@ fn build_clif_sysroot_for_triple(
181
189
// Build sysroot
182
190
let mut rustflags = "-Zforce-unstable-if-unmarked -Cpanic=abort" . to_string ( ) ;
183
191
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( ) ) ) ;
185
193
if channel == "release" {
186
194
rustflags. push_str ( " -Zmir-opt-level=3" ) ;
187
195
}
@@ -191,7 +199,7 @@ fn build_clif_sysroot_for_triple(
191
199
}
192
200
let mut compiler = Compiler :: with_triple ( triple. to_owned ( ) ) ;
193
201
compiler. rustflags = rustflags;
194
- let mut build_cmd = STANDARD_LIBRARY . build ( & compiler) ;
202
+ let mut build_cmd = STANDARD_LIBRARY . build ( & compiler, dirs ) ;
195
203
if channel == "release" {
196
204
build_cmd. arg ( "--release" ) ;
197
205
}
@@ -210,7 +218,7 @@ fn build_clif_sysroot_for_triple(
210
218
} ;
211
219
try_hard_link (
212
220
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 ( ) ) ,
214
222
) ;
215
223
}
216
224
}
0 commit comments