1
- use std:: env;
2
1
use std:: fs;
3
2
use std:: path:: { Path , PathBuf } ;
4
3
use std:: process:: { self , Command } ;
@@ -22,25 +21,21 @@ pub(crate) fn build_sysroot(
22
21
fs:: create_dir_all ( target_dir. join ( "lib" ) ) . unwrap ( ) ;
23
22
24
23
// Copy the backend
25
- for file in [ "cg_clif" , "cg_clif_build_sysroot" ] {
26
- try_hard_link (
27
- cg_clif_build_dir. join ( get_file_name ( file, "bin" ) ) ,
28
- target_dir. join ( "bin" ) . join ( get_file_name ( file, "bin" ) ) ,
29
- ) ;
30
- }
31
-
32
24
let cg_clif_dylib = get_file_name ( "rustc_codegen_cranelift" , "dylib" ) ;
25
+ let cg_clif_dylib_path = target_dir
26
+ . join ( if cfg ! ( windows) {
27
+ // Windows doesn't have rpath support, so the cg_clif dylib needs to be next to the
28
+ // binaries.
29
+ "bin"
30
+ } else {
31
+ "lib"
32
+ } )
33
+ . join ( & cg_clif_dylib) ;
34
+ try_hard_link ( cg_clif_build_dir. join ( cg_clif_dylib) , & cg_clif_dylib_path) ;
35
+
33
36
try_hard_link (
34
- cg_clif_build_dir. join ( & cg_clif_dylib) ,
35
- target_dir
36
- . join ( if cfg ! ( windows) {
37
- // Windows doesn't have rpath support, so the cg_clif dylib needs to be next to the
38
- // binaries.
39
- "bin"
40
- } else {
41
- "lib"
42
- } )
43
- . join ( cg_clif_dylib) ,
37
+ cg_clif_build_dir. join ( get_file_name ( "cg_clif" , "bin" ) ) ,
38
+ target_dir. join ( "bin" ) . join ( get_file_name ( "cg_clif" , "bin" ) ) ,
44
39
) ;
45
40
46
41
// Build and copy cargo wrapper
@@ -117,7 +112,13 @@ pub(crate) fn build_sysroot(
117
112
}
118
113
}
119
114
SysrootKind :: Clif => {
120
- build_clif_sysroot_for_triple ( channel, target_dir, host_triple, None ) ;
115
+ build_clif_sysroot_for_triple (
116
+ channel,
117
+ target_dir,
118
+ host_triple,
119
+ & cg_clif_dylib_path,
120
+ None ,
121
+ ) ;
121
122
122
123
if host_triple != target_triple {
123
124
// When cross-compiling it is often necessary to manually pick the right linker
@@ -126,7 +127,13 @@ pub(crate) fn build_sysroot(
126
127
} else {
127
128
None
128
129
} ;
129
- build_clif_sysroot_for_triple ( channel, target_dir, target_triple, linker) ;
130
+ build_clif_sysroot_for_triple (
131
+ channel,
132
+ target_dir,
133
+ target_triple,
134
+ & cg_clif_dylib_path,
135
+ linker,
136
+ ) ;
130
137
}
131
138
132
139
// Copy std for the host to the lib dir. This is necessary for the jit mode to find
@@ -145,6 +152,7 @@ fn build_clif_sysroot_for_triple(
145
152
channel : & str ,
146
153
target_dir : & Path ,
147
154
triple : & str ,
155
+ cg_clif_dylib_path : & Path ,
148
156
linker : Option < & str > ,
149
157
) {
150
158
match fs:: read_to_string ( Path :: new ( "build_sysroot" ) . join ( "rustc_version" ) ) {
@@ -178,7 +186,8 @@ fn build_clif_sysroot_for_triple(
178
186
// Build sysroot
179
187
let mut build_cmd = Command :: new ( "cargo" ) ;
180
188
build_cmd. arg ( "build" ) . arg ( "--target" ) . arg ( triple) . current_dir ( "build_sysroot" ) ;
181
- let mut rustflags = "--clif -Zforce-unstable-if-unmarked" . to_string ( ) ;
189
+ let mut rustflags = "-Zforce-unstable-if-unmarked -Cpanic=abort" . to_string ( ) ;
190
+ rustflags. push_str ( & format ! ( " -Zcodegen-backend={}" , cg_clif_dylib_path. to_str( ) . unwrap( ) ) ) ;
182
191
if channel == "release" {
183
192
build_cmd. arg ( "--release" ) ;
184
193
rustflags. push_str ( " -Zmir-opt-level=3" ) ;
@@ -188,10 +197,6 @@ fn build_clif_sysroot_for_triple(
188
197
write ! ( rustflags, " -Clinker={}" , linker) . unwrap ( ) ;
189
198
}
190
199
build_cmd. env ( "RUSTFLAGS" , rustflags) ;
191
- build_cmd. env (
192
- "RUSTC" ,
193
- env:: current_dir ( ) . unwrap ( ) . join ( target_dir) . join ( "bin" ) . join ( "cg_clif_build_sysroot" ) ,
194
- ) ;
195
200
build_cmd. env ( "__CARGO_DEFAULT_LIB_METADATA" , "cg_clif" ) ;
196
201
spawn_and_wait ( build_cmd) ;
197
202
0 commit comments