@@ -2,36 +2,39 @@ use std::fs;
2
2
use std:: path:: Path ;
3
3
use std:: process:: { self , Command } ;
4
4
5
+ use super :: path:: RelPath ;
5
6
use super :: rustc_info:: { get_file_name, get_rustc_version, get_wrapper_file_name} ;
6
7
use super :: utils:: { spawn_and_wait, try_hard_link, CargoProject , Compiler } ;
7
8
use super :: SysrootKind ;
8
9
10
+ static DIST_DIR : RelPath = RelPath :: DIST ;
11
+ static BIN_DIR : RelPath = RelPath :: DIST . join ( "bin" ) ;
12
+ static LIB_DIR : RelPath = RelPath :: DIST . join ( "lib" ) ;
13
+ static RUSTLIB_DIR : RelPath = LIB_DIR . join ( "rustlib" ) ;
14
+
9
15
pub ( crate ) fn build_sysroot (
10
16
channel : & str ,
11
17
sysroot_kind : SysrootKind ,
12
- dist_dir : & Path ,
13
18
cg_clif_dylib_src : & Path ,
14
19
host_triple : & str ,
15
20
target_triple : & str ,
16
21
) {
17
22
eprintln ! ( "[BUILD] sysroot {:?}" , sysroot_kind) ;
18
23
19
- if dist_dir. exists ( ) {
20
- fs:: remove_dir_all ( dist_dir) . unwrap ( ) ;
21
- }
22
- fs:: create_dir_all ( dist_dir. join ( "bin" ) ) . unwrap ( ) ;
23
- fs:: create_dir_all ( dist_dir. join ( "lib" ) ) . unwrap ( ) ;
24
+ DIST_DIR . ensure_fresh ( ) ;
25
+ BIN_DIR . ensure_exists ( ) ;
26
+ LIB_DIR . ensure_exists ( ) ;
24
27
25
28
// Copy the backend
26
- let cg_clif_dylib_path = dist_dir
27
- . join ( if cfg ! ( windows ) {
28
- // Windows doesn't have rpath support, so the cg_clif dylib needs to be next to the
29
- // binaries.
30
- "bin"
31
- } else {
32
- "lib"
33
- } )
34
- . join ( get_file_name ( "rustc_codegen_cranelift" , "dylib" ) ) ;
29
+ let cg_clif_dylib_path = if cfg ! ( windows ) {
30
+ // Windows doesn't have rpath support, so the cg_clif dylib needs to be next to the
31
+ // binaries.
32
+ BIN_DIR
33
+ } else {
34
+ LIB_DIR
35
+ }
36
+ . to_path ( )
37
+ . join ( get_file_name ( "rustc_codegen_cranelift" , "dylib" ) ) ;
35
38
try_hard_link ( cg_clif_dylib_src, & cg_clif_dylib_path) ;
36
39
37
40
// Build and copy rustc and cargo wrappers
@@ -40,18 +43,17 @@ pub(crate) fn build_sysroot(
40
43
41
44
let mut build_cargo_wrapper_cmd = Command :: new ( "rustc" ) ;
42
45
build_cargo_wrapper_cmd
43
- . arg ( Path :: new ( "scripts" ) . join ( format ! ( "{wrapper}.rs" ) ) )
46
+ . arg ( RelPath :: SCRIPTS . to_path ( ) . join ( & format ! ( "{wrapper}.rs" ) ) )
44
47
. arg ( "-o" )
45
- . arg ( dist_dir . join ( wrapper_name) )
48
+ . arg ( DIST_DIR . to_path ( ) . join ( wrapper_name) )
46
49
. arg ( "-g" ) ;
47
50
spawn_and_wait ( build_cargo_wrapper_cmd) ;
48
51
}
49
52
50
53
let default_sysroot = super :: rustc_info:: get_default_sysroot ( ) ;
51
54
52
- let rustlib = dist_dir. join ( "lib" ) . join ( "rustlib" ) ;
53
- let host_rustlib_lib = rustlib. join ( host_triple) . join ( "lib" ) ;
54
- let target_rustlib_lib = rustlib. join ( target_triple) . join ( "lib" ) ;
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" ) ;
55
57
fs:: create_dir_all ( & host_rustlib_lib) . unwrap ( ) ;
56
58
fs:: create_dir_all ( & target_rustlib_lib) . unwrap ( ) ;
57
59
@@ -112,13 +114,7 @@ pub(crate) fn build_sysroot(
112
114
}
113
115
}
114
116
SysrootKind :: Clif => {
115
- build_clif_sysroot_for_triple (
116
- channel,
117
- dist_dir,
118
- host_triple,
119
- & cg_clif_dylib_path,
120
- None ,
121
- ) ;
117
+ build_clif_sysroot_for_triple ( channel, host_triple, & cg_clif_dylib_path, None ) ;
122
118
123
119
if host_triple != target_triple {
124
120
// When cross-compiling it is often necessary to manually pick the right linker
@@ -127,13 +123,7 @@ pub(crate) fn build_sysroot(
127
123
} else {
128
124
None
129
125
} ;
130
- build_clif_sysroot_for_triple (
131
- channel,
132
- dist_dir,
133
- target_triple,
134
- & cg_clif_dylib_path,
135
- linker,
136
- ) ;
126
+ build_clif_sysroot_for_triple ( channel, target_triple, & cg_clif_dylib_path, linker) ;
137
127
}
138
128
139
129
// Copy std for the host to the lib dir. This is necessary for the jit mode to find
@@ -142,23 +132,25 @@ pub(crate) fn build_sysroot(
142
132
let file = file. unwrap ( ) . path ( ) ;
143
133
let filename = file. file_name ( ) . unwrap ( ) . to_str ( ) . unwrap ( ) ;
144
134
if filename. contains ( "std-" ) && !filename. contains ( ".rlib" ) {
145
- try_hard_link ( & file, dist_dir . join ( "lib" ) . join ( file. file_name ( ) . unwrap ( ) ) ) ;
135
+ try_hard_link ( & file, LIB_DIR . to_path ( ) . join ( file. file_name ( ) . unwrap ( ) ) ) ;
146
136
}
147
137
}
148
138
}
149
139
}
150
140
}
151
141
152
- static STANDARD_LIBRARY : CargoProject = CargoProject :: local ( "build_sysroot" , "build_sysroot" ) ;
142
+ // FIXME move to download/ or dist/
143
+ pub ( crate ) static SYSROOT_RUSTC_VERSION : RelPath = RelPath :: BUILD_SYSROOT . join ( "rustc_version" ) ;
144
+ pub ( crate ) static SYSROOT_SRC : RelPath = RelPath :: BUILD_SYSROOT . join ( "sysroot_src" ) ;
145
+ static STANDARD_LIBRARY : CargoProject = CargoProject :: new ( & RelPath :: BUILD_SYSROOT , "build_sysroot" ) ;
153
146
154
147
fn build_clif_sysroot_for_triple (
155
148
channel : & str ,
156
- dist_dir : & Path ,
157
149
triple : & str ,
158
150
cg_clif_dylib_path : & Path ,
159
151
linker : Option < & str > ,
160
152
) {
161
- match fs:: read_to_string ( Path :: new ( "build_sysroot" ) . join ( "rustc_version" ) ) {
153
+ match fs:: read_to_string ( SYSROOT_RUSTC_VERSION . to_path ( ) ) {
162
154
Err ( e) => {
163
155
eprintln ! ( "Failed to get rustc version for patched sysroot source: {}" , e) ;
164
156
eprintln ! ( "Hint: Try `./y.rs prepare` to patch the sysroot source" ) ;
@@ -189,7 +181,7 @@ fn build_clif_sysroot_for_triple(
189
181
// Build sysroot
190
182
let mut rustflags = "-Zforce-unstable-if-unmarked -Cpanic=abort" . to_string ( ) ;
191
183
rustflags. push_str ( & format ! ( " -Zcodegen-backend={}" , cg_clif_dylib_path. to_str( ) . unwrap( ) ) ) ;
192
- rustflags. push_str ( & format ! ( " --sysroot={}" , dist_dir . to_str( ) . unwrap( ) ) ) ;
184
+ rustflags. push_str ( & format ! ( " --sysroot={}" , DIST_DIR . to_path ( ) . to_str( ) . unwrap( ) ) ) ;
193
185
if channel == "release" {
194
186
rustflags. push_str ( " -Zmir-opt-level=3" ) ;
195
187
}
@@ -218,7 +210,7 @@ fn build_clif_sysroot_for_triple(
218
210
} ;
219
211
try_hard_link (
220
212
entry. path ( ) ,
221
- dist_dir . join ( "lib" ) . join ( "rustlib" ) . join ( triple) . join ( "lib" ) . join ( entry. file_name ( ) ) ,
213
+ RUSTLIB_DIR . to_path ( ) . join ( triple) . join ( "lib" ) . join ( entry. file_name ( ) ) ,
222
214
) ;
223
215
}
224
216
}
0 commit comments