@@ -77,6 +77,14 @@ impl Step for Std {
77
77
target,
78
78
} ) ;
79
79
println ! ( "Uplifting stage1 std ({} -> {})" , from. host, target) ;
80
+
81
+ // Even if we're not building std this stage, the new sysroot must
82
+ // still contain the musl startup objects.
83
+ if target. contains ( "musl" ) && !target. contains ( "mips" ) {
84
+ let libdir = builder. sysroot_libdir ( compiler, target) ;
85
+ copy_musl_third_party_objects ( build, target, & libdir) ;
86
+ }
87
+
80
88
builder. ensure ( StdLink {
81
89
compiler : from,
82
90
target_compiler : compiler,
@@ -89,6 +97,11 @@ impl Step for Std {
89
97
println ! ( "Building stage{} std artifacts ({} -> {})" , compiler. stage,
90
98
& compiler. host, target) ;
91
99
100
+ if target. contains ( "musl" ) && !target. contains ( "mips" ) {
101
+ let libdir = builder. sysroot_libdir ( compiler, target) ;
102
+ copy_musl_third_party_objects ( build, target, & libdir) ;
103
+ }
104
+
92
105
let out_dir = build. cargo_out ( compiler, Mode :: Libstd , target) ;
93
106
build. clear_if_dirty ( & out_dir, & builder. rustc ( compiler) ) ;
94
107
let mut cargo = builder. cargo ( compiler, Mode :: Libstd , target, "build" ) ;
@@ -105,6 +118,20 @@ impl Step for Std {
105
118
}
106
119
}
107
120
121
+ /// Copies the crt(1,i,n).o startup objects
122
+ ///
123
+ /// Since musl supports fully static linking, we can cross link for it even
124
+ /// with a glibc-targeting toolchain, given we have the appropriate startup
125
+ /// files. As those shipped with glibc won't work, copy the ones provided by
126
+ /// musl so we have them on linux-gnu hosts.
127
+ fn copy_musl_third_party_objects ( build : & Build ,
128
+ target : Interned < String > ,
129
+ into : & Path ) {
130
+ for & obj in & [ "crt1.o" , "crti.o" , "crtn.o" ] {
131
+ copy ( & build. musl_root ( target) . unwrap ( ) . join ( "lib" ) . join ( obj) , & into. join ( obj) ) ;
132
+ }
133
+ }
134
+
108
135
/// Configure cargo to compile the standard library, adding appropriate env vars
109
136
/// and such.
110
137
pub fn std_cargo ( build : & Build ,
@@ -189,10 +216,6 @@ impl Step for StdLink {
189
216
let libdir = builder. sysroot_libdir ( target_compiler, target) ;
190
217
add_to_sysroot ( & libdir, & libstd_stamp ( build, compiler, target) ) ;
191
218
192
- if target. contains ( "musl" ) && !target. contains ( "mips" ) {
193
- copy_musl_third_party_objects ( build, target, & libdir) ;
194
- }
195
-
196
219
if build. config . sanitizers && compiler. stage != 0 && target == "x86_64-apple-darwin" {
197
220
// The sanitizers are only built in stage1 or above, so the dylibs will
198
221
// be missing in stage0 and causes panic. See the `std()` function above
@@ -208,15 +231,6 @@ impl Step for StdLink {
208
231
}
209
232
}
210
233
211
- /// Copies the crt(1,i,n).o startup objects
212
- ///
213
- /// Only required for musl targets that statically link to libc
214
- fn copy_musl_third_party_objects ( build : & Build , target : Interned < String > , into : & Path ) {
215
- for & obj in & [ "crt1.o" , "crti.o" , "crtn.o" ] {
216
- copy ( & build. musl_root ( target) . unwrap ( ) . join ( "lib" ) . join ( obj) , & into. join ( obj) ) ;
217
- }
218
- }
219
-
220
234
fn copy_apple_sanitizer_dylibs ( native_dir : & Path , platform : & str , into : & Path ) {
221
235
for & sanitizer in & [ "asan" , "tsan" ] {
222
236
let filename = format ! ( "libclang_rt.{}_{}_dynamic.dylib" , sanitizer, platform) ;
0 commit comments