@@ -74,6 +74,7 @@ impl Step for Std {
74
74
// Even if we're not building std this stage, the new sysroot must
75
75
// still contain the third party objects needed by various targets.
76
76
copy_third_party_objects ( builder, & compiler, target) ;
77
+ copy_self_contained_objects ( builder, & compiler, target) ;
77
78
78
79
builder. ensure ( StdLink {
79
80
compiler : compiler_to_use,
@@ -84,6 +85,7 @@ impl Step for Std {
84
85
}
85
86
86
87
target_deps. extend ( copy_third_party_objects ( builder, & compiler, target) . into_iter ( ) ) ;
88
+ target_deps. extend ( copy_self_contained_objects ( builder, & compiler, target) ) ;
87
89
88
90
let mut cargo = builder. cargo ( compiler, Mode :: Std , target, "build" ) ;
89
91
std_cargo ( builder, target, compiler. stage , & mut cargo) ;
@@ -109,39 +111,28 @@ impl Step for Std {
109
111
}
110
112
}
111
113
114
+ fn copy_and_stamp (
115
+ builder : & Builder < ' _ > ,
116
+ libdir : & Path ,
117
+ sourcedir : & Path ,
118
+ name : & str ,
119
+ target_deps : & mut Vec < PathBuf > ,
120
+ ) {
121
+ let target = libdir. join ( name) ;
122
+ builder. copy ( & sourcedir. join ( name) , & target) ;
123
+
124
+ target_deps. push ( ( target, dependency_type) ) ;
125
+ }
126
+
112
127
/// Copies third party objects needed by various targets.
113
128
fn copy_third_party_objects (
114
129
builder : & Builder < ' _ > ,
115
130
compiler : & Compiler ,
116
131
target : Interned < String > ,
117
132
) -> Vec < PathBuf > {
118
133
let libdir = builder. sysroot_libdir ( * compiler, target) ;
119
-
120
134
let mut target_deps = vec ! [ ] ;
121
135
122
- let mut copy_and_stamp = |sourcedir : & Path , name : & str | {
123
- let target = libdir. join ( name) ;
124
- builder. copy ( & sourcedir. join ( name) , & target) ;
125
- target_deps. push ( target) ;
126
- } ;
127
-
128
- // Copies the CRT objects.
129
- //
130
- // rustc historically provides a more self-contained installation for musl targets
131
- // not requiring the presence of a native musl toolchain. For example, it can fall back
132
- // to using gcc from a glibc-targeting toolchain for linking.
133
- // To do that we have to distribute musl startup objects as a part of Rust toolchain
134
- // and link with them manually in the self-contained mode.
135
- if target. contains ( "musl" ) {
136
- let srcdir = builder. musl_root ( target) . unwrap ( ) . join ( "lib" ) ;
137
- for & obj in & [ "crt1.o" , "Scrt1.o" , "rcrt1.o" , "crti.o" , "crtn.o" ] {
138
- copy_and_stamp ( & srcdir, obj) ;
139
- }
140
- } else if target. ends_with ( "-wasi" ) {
141
- let srcdir = builder. wasi_root ( target) . unwrap ( ) . join ( "lib/wasm32-wasi" ) ;
142
- copy_and_stamp ( & srcdir, "crt1.o" ) ;
143
- }
144
-
145
136
// Copies libunwind.a compiled to be linked with x86_64-fortanix-unknown-sgx.
146
137
//
147
138
// This target needs to be linked to Fortanix's port of llvm's libunwind.
@@ -151,7 +142,13 @@ fn copy_third_party_objects(
151
142
let src_path_env = "X86_FORTANIX_SGX_LIBS" ;
152
143
let src =
153
144
env:: var ( src_path_env) . unwrap_or_else ( |_| panic ! ( "{} not found in env" , src_path_env) ) ;
154
- copy_and_stamp ( Path :: new ( & src) , "libunwind.a" ) ;
145
+ copy_and_stamp (
146
+ builder,
147
+ & * libdir,
148
+ Path :: new ( & src) ,
149
+ "libunwind.a" ,
150
+ & mut target_deps,
151
+ ) ;
155
152
}
156
153
157
154
if builder. config . sanitizers && compiler. stage != 0 {
@@ -163,6 +160,47 @@ fn copy_third_party_objects(
163
160
target_deps
164
161
}
165
162
163
+ /// Copies third party objects needed by various targets for self-contained linkage.
164
+ fn copy_self_contained_objects (
165
+ builder : & Builder < ' _ > ,
166
+ compiler : & Compiler ,
167
+ target : Interned < String > ,
168
+ ) -> Vec < PathBuf > {
169
+ let libdir = builder. sysroot_libdir ( * compiler, target) ;
170
+ let mut target_deps = vec ! [ ] ;
171
+
172
+ // Copies the CRT objects.
173
+ //
174
+ // rustc historically provides a more self-contained installation for musl targets
175
+ // not requiring the presence of a native musl toolchain. For example, it can fall back
176
+ // to using gcc from a glibc-targeting toolchain for linking.
177
+ // To do that we have to distribute musl startup objects as a part of Rust toolchain
178
+ // and link with them manually in the self-contained mode.
179
+ if target. contains ( "musl" ) {
180
+ let srcdir = builder. musl_root ( target) . unwrap ( ) . join ( "lib" ) ;
181
+ for & obj in & [ "crt1.o" , "Scrt1.o" , "rcrt1.o" , "crti.o" , "crtn.o" ] {
182
+ copy_and_stamp (
183
+ builder,
184
+ & libdir_self_contained,
185
+ & srcdir,
186
+ obj,
187
+ & mut target_deps,
188
+ ) ;
189
+ }
190
+ } else if target. ends_with ( "-wasi" ) {
191
+ let srcdir = builder. wasi_root ( target) . unwrap ( ) . join ( "lib/wasm32-wasi" ) ;
192
+ copy_and_stamp (
193
+ builder,
194
+ & libdir_self_contained,
195
+ & srcdir,
196
+ "crt1.o" ,
197
+ & mut target_deps,
198
+ ) ;
199
+ }
200
+
201
+ target_deps
202
+ }
203
+
166
204
/// Configure cargo to compile the standard library, adding appropriate env vars
167
205
/// and such.
168
206
pub fn std_cargo ( builder : & Builder < ' _ > , target : Interned < String > , stage : u32 , cargo : & mut Cargo ) {
0 commit comments