@@ -30,10 +30,6 @@ pub struct Std {
30
30
31
31
impl Std {
32
32
const CRATE_OR_DEPS : & [ & str ] = & [ "sysroot" , "coretests" , "alloctests" ] ;
33
-
34
- pub fn new ( build_compiler : Compiler , target : TargetSelection ) -> Self {
35
- Self { build_compiler, target, crates : vec ! [ ] }
36
- }
37
33
}
38
34
39
35
impl Step for Std {
@@ -168,12 +164,8 @@ pub struct Rustc {
168
164
}
169
165
170
166
impl Rustc {
171
- pub fn new ( builder : & Builder < ' _ > , build_compiler : Compiler , target : TargetSelection ) -> Self {
172
- let crates = builder
173
- . in_tree_crates ( "rustc-main" , Some ( target) )
174
- . into_iter ( )
175
- . map ( |krate| krate. name . to_string ( ) )
176
- . collect ( ) ;
167
+ pub fn new ( builder : & Builder < ' _ > , target : TargetSelection , crates : Vec < String > ) -> Self {
168
+ let build_compiler = prepare_compiler_for_check ( builder, target, Mode :: Rustc ) ;
177
169
Self { build_compiler, target, crates }
178
170
}
179
171
}
@@ -189,11 +181,7 @@ impl Step for Rustc {
189
181
190
182
fn make_run ( run : RunConfig < ' _ > ) {
191
183
let crates = run. make_run_crates ( Alias :: Compiler ) ;
192
- run. builder . ensure ( Rustc {
193
- target : run. target ,
194
- build_compiler : prepare_compiler_for_check ( run. builder , run. target , Mode :: Rustc ) ,
195
- crates,
196
- } ) ;
184
+ run. builder . ensure ( Rustc :: new ( run. builder , run. target , crates) ) ;
197
185
}
198
186
199
187
/// Check the compiler.
@@ -207,15 +195,6 @@ impl Step for Rustc {
207
195
let build_compiler = self . build_compiler ;
208
196
let target = self . target ;
209
197
210
- // Build host std for compiling build scripts
211
- builder. std ( build_compiler, build_compiler. host ) ;
212
-
213
- // Build target std so that the checked rustc can link to it during the check
214
- // FIXME: maybe we can a way to only do a check of std here?
215
- // But for that we would have to copy the stdlib rmetas to the sysroot of the build
216
- // compiler, which conflicts with std rlibs, if we also build std.
217
- builder. std ( build_compiler, target) ;
218
-
219
198
let mut cargo = builder:: Cargo :: new (
220
199
builder,
221
200
build_compiler,
@@ -253,12 +232,18 @@ impl Step for Rustc {
253
232
}
254
233
255
234
fn metadata ( & self ) -> Option < StepMetadata > {
256
- Some ( StepMetadata :: check ( "rustc" , self . target ) . built_by ( self . build_compiler ) )
235
+ let metadata = StepMetadata :: check ( "rustc" , self . target ) . built_by ( self . build_compiler ) ;
236
+ let metadata = if self . crates . is_empty ( ) {
237
+ metadata
238
+ } else {
239
+ metadata. with_metadata ( format ! ( "({} crates)" , self . crates. len( ) ) )
240
+ } ;
241
+ Some ( metadata)
257
242
}
258
243
}
259
244
260
245
/// Prepares a compiler that will check something with the given `mode`.
261
- fn prepare_compiler_for_check (
246
+ pub fn prepare_compiler_for_check (
262
247
builder : & Builder < ' _ > ,
263
248
target : TargetSelection ,
264
249
mode : Mode ,
@@ -289,11 +274,13 @@ fn prepare_compiler_for_check(
289
274
build_compiler
290
275
}
291
276
Mode :: ToolRustc | Mode :: Codegen => {
292
- // FIXME: this is a hack, see description of Mode::Rustc below
293
- let stage = if host == target { builder. top_stage - 1 } else { builder. top_stage } ;
294
- // When checking tool stage N, we check it with compiler stage N-1
295
- let build_compiler = builder. compiler ( stage, host) ;
296
- builder. ensure ( Rustc :: new ( builder, build_compiler, target) ) ;
277
+ // Check Rustc to produce the required rmeta artifacts for rustc_private, and then
278
+ // return the build compiler that was used to check rustc.
279
+ // We do not need to check examples/tests/etc. of Rustc for rustc_private, so we pass
280
+ // an empty set of crates, which will avoid using `cargo -p`.
281
+ let check = Rustc :: new ( builder, target, vec ! [ ] ) ;
282
+ let build_compiler = check. build_compiler ;
283
+ builder. ensure ( check) ;
297
284
build_compiler
298
285
}
299
286
Mode :: Rustc => {
@@ -305,7 +292,18 @@ fn prepare_compiler_for_check(
305
292
// FIXME: remove this and either fix cross-compilation check on stage 2 (which has a
306
293
// myriad of other problems) or disable cross-checking on stage 1.
307
294
let stage = if host == target { builder. top_stage - 1 } else { builder. top_stage } ;
308
- builder. compiler ( stage, host)
295
+ let build_compiler = builder. compiler ( stage, host) ;
296
+
297
+ // Build host std for compiling build scripts
298
+ builder. std ( build_compiler, build_compiler. host ) ;
299
+
300
+ // Build target std so that the checked rustc can link to it during the check
301
+ // FIXME: maybe we can a way to only do a check of std here?
302
+ // But for that we would have to copy the stdlib rmetas to the sysroot of the build
303
+ // compiler, which conflicts with std rlibs, if we also build std.
304
+ builder. std ( build_compiler, target) ;
305
+
306
+ build_compiler
309
307
}
310
308
Mode :: Std => {
311
309
// When checking std stage N, we want to do it with the stage N compiler
0 commit comments