@@ -100,22 +100,45 @@ impl Step for Std {
100
100
101
101
let out_dir = builder. cargo_out ( compiler, Mode :: Std , target) ;
102
102
builder. clear_if_dirty ( & out_dir, & builder. rustc ( compiler) ) ;
103
- let mut cargo = builder. cargo ( compiler, Mode :: Std , target, "build" ) ;
104
- std_cargo ( builder, & compiler, target, & mut cargo) ;
103
+ let mut core_cargo_invoc = builder. cargo ( compiler, Mode :: Std , target, "build" ) ;
104
+ core_cargo ( builder, & compiler, target, & mut core_cargo_invoc) ;
105
+ let std_cargo_invoc = if builder. no_std ( target) != Some ( true ) {
106
+ let mut std_cargo_invoc = builder. cargo ( compiler, Mode :: Std , target, "build" ) ;
107
+ std_cargo ( builder, & compiler, target, & mut std_cargo_invoc) ;
108
+ Some ( std_cargo_invoc)
109
+ } else {
110
+ None
111
+ } ;
105
112
106
113
let _folder = builder. fold_output ( || format ! ( "stage{}-std" , compiler. stage) ) ;
107
114
builder. info ( & format ! ( "Building stage{} std artifacts ({} -> {})" , compiler. stage,
108
115
& compiler. host, target) ) ;
109
116
run_cargo ( builder,
110
- & mut cargo ,
117
+ & mut core_cargo_invoc ,
111
118
& libstd_stamp ( builder, compiler, target) ,
112
119
false ) ;
113
-
114
- builder. ensure ( StdLink {
120
+ builder. ensure ( CoreLink {
115
121
compiler : builder. compiler ( compiler. stage , builder. config . build ) ,
116
122
target_compiler : compiler,
117
123
target,
118
124
} ) ;
125
+ if let Some ( mut std_cargo_invoc) = std_cargo_invoc {
126
+ run_cargo ( builder,
127
+ & mut std_cargo_invoc,
128
+ & libstd_stamp ( builder, compiler, target) ,
129
+ false ) ;
130
+ builder. ensure ( StdLink {
131
+ compiler : builder. compiler ( compiler. stage , builder. config . build ) ,
132
+ target_compiler : compiler,
133
+ target,
134
+ } ) ;
135
+ }
136
+
137
+ builder. ensure ( tool:: CleanTools {
138
+ compiler,
139
+ target,
140
+ cause : Mode :: Std ,
141
+ } ) ;
119
142
}
120
143
}
121
144
@@ -139,6 +162,23 @@ fn mac_os_deployment_env_var(cargo: &mut Command) {
139
162
}
140
163
}
141
164
165
+ /// Configure cargo to compile a few no_std crates like core,
166
+ /// adding appropriate env vars and such.
167
+ pub fn core_cargo ( builder : & Builder ,
168
+ _compiler : & Compiler ,
169
+ _target : Interned < String > ,
170
+ cargo : & mut Command ) {
171
+ mac_os_deployment_env_var ( cargo) ;
172
+
173
+ // for no-std targets we only compile a few no_std crates
174
+ cargo. arg ( "--features" ) . arg ( "c mem" )
175
+ . args ( & [ "-p" , "alloc" ] )
176
+ . args ( & [ "-p" , "compiler_builtins" ] )
177
+ . args ( & [ "-p" , "std_unicode" ] )
178
+ . arg ( "--manifest-path" )
179
+ . arg ( builder. src . join ( "src/rustc/compiler_builtins_shim/Cargo.toml" ) ) ;
180
+ }
181
+
142
182
/// Configure cargo to compile the standard library, adding appropriate env vars
143
183
/// and such.
144
184
pub fn std_cargo ( builder : & Builder ,
@@ -147,58 +187,85 @@ pub fn std_cargo(builder: &Builder,
147
187
cargo : & mut Command ) {
148
188
mac_os_deployment_env_var ( cargo) ;
149
189
150
- if builder. no_std ( target) == Some ( true ) {
151
- // for no-std targets we only compile a few no_std crates
152
- cargo. arg ( "--features" ) . arg ( "c mem" )
153
- . args ( & [ "-p" , "alloc" ] )
154
- . args ( & [ "-p" , "compiler_builtins" ] )
155
- . args ( & [ "-p" , "std_unicode" ] )
156
- . arg ( "--manifest-path" )
157
- . arg ( builder. src . join ( "src/rustc/compiler_builtins_shim/Cargo.toml" ) ) ;
158
- } else {
159
- let mut features = builder. std_features ( ) ;
160
-
161
- // When doing a local rebuild we tell cargo that we're stage1 rather than
162
- // stage0. This works fine if the local rust and being-built rust have the
163
- // same view of what the default allocator is, but fails otherwise. Since
164
- // we don't have a way to express an allocator preference yet, work
165
- // around the issue in the case of a local rebuild with jemalloc disabled.
166
- if compiler. stage == 0 && builder. local_rebuild && !builder. config . use_jemalloc {
167
- features. push_str ( " force_alloc_system" ) ;
168
- }
190
+ let mut features = builder. std_features ( ) ;
169
191
170
- if compiler. stage != 0 && builder. config . sanitizers {
171
- // This variable is used by the sanitizer runtime crates, e.g.
172
- // rustc_lsan, to build the sanitizer runtime from C code
173
- // When this variable is missing, those crates won't compile the C code,
174
- // so we don't set this variable during stage0 where llvm-config is
175
- // missing
176
- // We also only build the runtimes when --enable-sanitizers (or its
177
- // config.toml equivalent) is used
178
- let llvm_config = builder. ensure ( native:: Llvm {
179
- target : builder. config . build ,
180
- emscripten : false ,
181
- } ) ;
182
- cargo. env ( "LLVM_CONFIG" , llvm_config) ;
183
- }
192
+ // When doing a local rebuild we tell cargo that we're stage1 rather than
193
+ // stage0. This works fine if the local rust and being-built rust have the
194
+ // same view of what the default allocator is, but fails otherwise. Since
195
+ // we don't have a way to express an allocator preference yet, work
196
+ // around the issue in the case of a local rebuild with jemalloc disabled.
197
+ if compiler. stage == 0 && builder. local_rebuild && !builder. config . use_jemalloc {
198
+ features. push_str ( " force_alloc_system" ) ;
199
+ }
184
200
185
- cargo. arg ( "--features" ) . arg ( features)
186
- . arg ( "--manifest-path" )
187
- . arg ( builder. src . join ( "src/libstd/Cargo.toml" ) ) ;
201
+ if compiler. stage != 0 && builder. config . sanitizers {
202
+ // This variable is used by the sanitizer runtime crates, e.g.
203
+ // rustc_lsan, to build the sanitizer runtime from C code
204
+ // When this variable is missing, those crates won't compile the C code,
205
+ // so we don't set this variable during stage0 where llvm-config is
206
+ // missing
207
+ // We also only build the runtimes when --enable-sanitizers (or its
208
+ // config.toml equivalent) is used
209
+ let llvm_config = builder. ensure ( native:: Llvm {
210
+ target : builder. config . build ,
211
+ emscripten : false ,
212
+ } ) ;
213
+ cargo. env ( "LLVM_CONFIG" , llvm_config) ;
214
+ }
188
215
189
- if let Some ( target) = builder. config . target_config . get ( & target) {
190
- if let Some ( ref jemalloc) = target. jemalloc {
191
- cargo. env ( "JEMALLOC_OVERRIDE" , jemalloc) ;
192
- }
216
+ cargo. arg ( "--features" ) . arg ( features)
217
+ . arg ( "--manifest-path" )
218
+ . arg ( builder. src . join ( "src/libstd/Cargo.toml" ) ) ;
219
+
220
+ if let Some ( target) = builder. config . target_config . get ( & target) {
221
+ if let Some ( ref jemalloc) = target. jemalloc {
222
+ cargo. env ( "JEMALLOC_OVERRIDE" , jemalloc) ;
193
223
}
194
- if target . contains ( "musl" ) {
195
- if let Some ( p ) = builder . musl_root ( target ) {
196
- cargo . env ( "MUSL_ROOT" , p ) ;
197
- }
224
+ }
225
+ if target . contains ( "musl" ) {
226
+ if let Some ( p ) = builder . musl_root ( target ) {
227
+ cargo . env ( "MUSL_ROOT" , p ) ;
198
228
}
199
229
}
200
230
}
201
231
232
+ #[ derive( Debug , Copy , Clone , PartialEq , Eq , Hash ) ]
233
+ struct CoreLink {
234
+ pub compiler : Compiler ,
235
+ pub target_compiler : Compiler ,
236
+ pub target : Interned < String > ,
237
+ }
238
+
239
+ impl Step for CoreLink {
240
+ type Output = ( ) ;
241
+
242
+ fn should_run ( run : ShouldRun ) -> ShouldRun {
243
+ run. never ( )
244
+ }
245
+
246
+ /// Link all libcore rlibs/dylibs into the sysroot location.
247
+ ///
248
+ /// Links those artifacts generated by `compiler` to a the `stage` compiler's
249
+ /// sysroot for the specified `host` and `target`.
250
+ ///
251
+ /// Note that this assumes that `compiler` has already generated the
252
+ /// libraries for `target`, and this method will find them in the relevant
253
+ /// output directory.
254
+ fn run ( self , builder : & Builder ) {
255
+ let compiler = self . compiler ;
256
+ let target_compiler = self . target_compiler ;
257
+ let target = self . target ;
258
+ builder. info ( & format ! ( "Copying stage{} core from stage{} ({} -> {} / {})" ,
259
+ target_compiler. stage,
260
+ compiler. stage,
261
+ & compiler. host,
262
+ target_compiler. host,
263
+ target) ) ;
264
+ let libdir = builder. sysroot_libdir ( target_compiler, target) ;
265
+ add_to_sysroot ( builder, & libdir, & libstd_stamp ( builder, compiler, target) ) ;
266
+ }
267
+ }
268
+
202
269
#[ derive( Debug , Copy , Clone , PartialEq , Eq , Hash ) ]
203
270
struct StdLink {
204
271
pub compiler : Compiler ,
@@ -240,12 +307,6 @@ impl Step for StdLink {
240
307
// for reason why the sanitizers are not built in stage0.
241
308
copy_apple_sanitizer_dylibs ( builder, & builder. native_dir ( target) , "osx" , & libdir) ;
242
309
}
243
-
244
- builder. ensure ( tool:: CleanTools {
245
- compiler : target_compiler,
246
- target,
247
- cause : Mode :: Std ,
248
- } ) ;
249
310
}
250
311
}
251
312
@@ -923,6 +984,7 @@ impl Step for Assemble {
923
984
for stage in 0 ..min ( target_compiler. stage , builder. config . keep_stage . unwrap ( ) ) {
924
985
let target_compiler = builder. compiler ( stage, target_compiler. host ) ;
925
986
let target = target_compiler. host ;
987
+ builder. ensure ( CoreLink { compiler, target_compiler, target } ) ;
926
988
builder. ensure ( StdLink { compiler, target_compiler, target } ) ;
927
989
builder. ensure ( TestLink { compiler, target_compiler, target } ) ;
928
990
builder. ensure ( RustcLink { compiler, target_compiler, target } ) ;
0 commit comments