@@ -56,28 +56,6 @@ pub(crate) fn build_sysroot(
56
56
spawn_and_wait ( build_cargo_wrapper_cmd) ;
57
57
}
58
58
59
- if target_triple. ends_with ( "windows-gnu" ) {
60
- eprintln ! ( "[BUILD] rtstartup for {target_triple}" ) ;
61
-
62
- let rtstartup_src = SYSROOT_SRC . to_path ( dirs) . join ( "library" ) . join ( "rtstartup" ) ;
63
- let mut target_libs = SysrootTarget { triple : target_triple. clone ( ) , libs : vec ! [ ] } ;
64
-
65
- for file in [ "rsbegin" , "rsend" ] {
66
- let obj = RelPath :: BUILD . to_path ( dirs) . join ( format ! ( "{file}.o" ) ) ;
67
- let mut build_rtstartup_cmd = Command :: new ( & bootstrap_host_compiler. rustc ) ;
68
- build_rtstartup_cmd
69
- . arg ( "--target" )
70
- . arg ( & target_triple)
71
- . arg ( "--emit=obj" )
72
- . arg ( "-o" )
73
- . arg ( & obj)
74
- . arg ( rtstartup_src. join ( format ! ( "{file}.rs" ) ) ) ;
75
- spawn_and_wait ( build_rtstartup_cmd) ;
76
- target_libs. libs . push ( obj) ;
77
- }
78
-
79
- target_libs. install_into_sysroot ( & DIST_DIR . to_path ( dirs) )
80
- }
81
59
match sysroot_kind {
82
60
SysrootKind :: None => { } // Nothing to do
83
61
SysrootKind :: Llvm => {
@@ -190,6 +168,7 @@ pub(crate) static SYSROOT_RUSTC_VERSION: RelPath = BUILD_SYSROOT.join("rustc_ver
190
168
pub ( crate ) static SYSROOT_SRC : RelPath = BUILD_SYSROOT . join ( "sysroot_src" ) ;
191
169
pub ( crate ) static STANDARD_LIBRARY : CargoProject =
192
170
CargoProject :: new ( & BUILD_SYSROOT , "build_sysroot" ) ;
171
+ pub ( crate ) static RTSTARTUP_SYSROOT : RelPath = RelPath :: BUILD . join ( "rtstartup" ) ;
193
172
194
173
#[ must_use]
195
174
fn build_clif_sysroot_for_triple (
@@ -216,6 +195,35 @@ fn build_clif_sysroot_for_triple(
216
195
}
217
196
}
218
197
198
+ let mut target_libs = SysrootTarget { triple : compiler. triple . clone ( ) , libs : vec ! [ ] } ;
199
+
200
+ if compiler. triple . ends_with ( "windows-gnu" ) {
201
+ eprintln ! ( "[BUILD] rtstartup for {}" , compiler. triple) ;
202
+
203
+ RTSTARTUP_SYSROOT . ensure_fresh ( dirs) ;
204
+
205
+ let rtstartup_src = SYSROOT_SRC . to_path ( dirs) . join ( "library" ) . join ( "rtstartup" ) ;
206
+ let mut rtstartup_target_libs =
207
+ SysrootTarget { triple : compiler. triple . clone ( ) , libs : vec ! [ ] } ;
208
+
209
+ for file in [ "rsbegin" , "rsend" ] {
210
+ let obj = RTSTARTUP_SYSROOT . to_path ( dirs) . join ( format ! ( "{file}.o" ) ) ;
211
+ let mut build_rtstartup_cmd = Command :: new ( & compiler. rustc ) ;
212
+ build_rtstartup_cmd
213
+ . arg ( "--target" )
214
+ . arg ( & compiler. triple )
215
+ . arg ( "--emit=obj" )
216
+ . arg ( "-o" )
217
+ . arg ( & obj)
218
+ . arg ( rtstartup_src. join ( format ! ( "{file}.rs" ) ) ) ;
219
+ spawn_and_wait ( build_rtstartup_cmd) ;
220
+ rtstartup_target_libs. libs . push ( obj. clone ( ) ) ;
221
+ target_libs. libs . push ( obj) ;
222
+ }
223
+
224
+ rtstartup_target_libs. install_into_sysroot ( & RTSTARTUP_SYSROOT . to_path ( dirs) ) ;
225
+ }
226
+
219
227
let build_dir = STANDARD_LIBRARY . target_dir ( dirs) . join ( & compiler. triple ) . join ( channel) ;
220
228
221
229
if !super :: config:: get_bool ( "keep_sysroot" ) {
@@ -230,7 +238,8 @@ fn build_clif_sysroot_for_triple(
230
238
let mut rustflags = " -Zforce-unstable-if-unmarked -Cpanic=abort" . to_string ( ) ;
231
239
rustflags. push_str ( & format ! ( " -Zcodegen-backend={}" , cg_clif_dylib_path. to_str( ) . unwrap( ) ) ) ;
232
240
// Necessary for MinGW to find rsbegin.o and rsend.o
233
- rustflags. push_str ( & format ! ( " --sysroot={}" , DIST_DIR . to_path( dirs) . to_str( ) . unwrap( ) ) ) ;
241
+ rustflags
242
+ . push_str ( & format ! ( " --sysroot={}" , RTSTARTUP_SYSROOT . to_path( dirs) . to_str( ) . unwrap( ) ) ) ;
234
243
if channel == "release" {
235
244
rustflags. push_str ( " -Zmir-opt-level=3" ) ;
236
245
}
@@ -242,8 +251,6 @@ fn build_clif_sysroot_for_triple(
242
251
build_cmd. env ( "__CARGO_DEFAULT_LIB_METADATA" , "cg_clif" ) ;
243
252
spawn_and_wait ( build_cmd) ;
244
253
245
- let mut target_libs = SysrootTarget { triple : compiler. triple , libs : vec ! [ ] } ;
246
-
247
254
for entry in fs:: read_dir ( build_dir. join ( "deps" ) ) . unwrap ( ) {
248
255
let entry = entry. unwrap ( ) ;
249
256
if let Some ( ext) = entry. path ( ) . extension ( ) {
0 commit comments