@@ -50,7 +50,7 @@ impl Step for Std {
50
50
fn make_run ( run : RunConfig < ' _ > ) {
51
51
let crates = std_crates_for_run_make ( & run) ;
52
52
run. builder . ensure ( Std {
53
- build_compiler : run . builder . compiler ( run. builder . top_stage , run. target ) ,
53
+ build_compiler : prepare_compiler_for_check ( run. builder , run. target , Mode :: Std ) ,
54
54
target : run. target ,
55
55
crates,
56
56
} ) ;
@@ -138,11 +138,6 @@ impl Step for Std {
138
138
}
139
139
}
140
140
141
- fn default_compiler_for_checking_rustc ( builder : & Builder < ' _ > ) -> Compiler {
142
- // When checking the stage N compiler, we want to do it with the stage N-1 compiler,
143
- builder. compiler ( builder. top_stage - 1 , builder. config . host_target )
144
- }
145
-
146
141
/// Checks rustc using `build_compiler` and copies the built
147
142
/// .rmeta files into the sysroot of `build_compiler`.
148
143
#[ derive( Debug , Clone , PartialEq , Eq , Hash ) ]
@@ -182,7 +177,7 @@ impl Step for Rustc {
182
177
let crates = run. make_run_crates ( Alias :: Compiler ) ;
183
178
run. builder . ensure ( Rustc {
184
179
target : run. target ,
185
- build_compiler : default_compiler_for_checking_rustc ( run. builder ) ,
180
+ build_compiler : prepare_compiler_for_check ( run. builder , run . target , Mode :: Rustc ) ,
186
181
crates,
187
182
} ) ;
188
183
}
@@ -193,11 +188,6 @@ impl Step for Rustc {
193
188
/// the `compiler` targeting the `target` architecture. The artifacts
194
189
/// created will also be linked into the sysroot directory.
195
190
fn run ( self , builder : & Builder < ' _ > ) {
196
- if builder. top_stage < 2 && builder. config . host_target != self . target {
197
- eprintln ! ( "Cannot do a cross-compilation check on stage 1, use stage 2" ) ;
198
- exit ! ( 1 ) ;
199
- }
200
-
201
191
let build_compiler = self . build_compiler ;
202
192
let target = self . target ;
203
193
@@ -249,13 +239,45 @@ impl Step for Rustc {
249
239
}
250
240
}
251
241
252
- /// Prepares a build compiler sysroot that will check a `Mode::ToolRustc` tool.
253
- /// Also checks rustc using this compiler, to prepare .rmetas that the tool will link to.
254
- fn prepare_compiler_for_tool_rustc ( builder : & Builder < ' _ > , target : TargetSelection ) -> Compiler {
255
- // When we check tool stage N, we check it with compiler stage N-1
256
- let build_compiler = builder. compiler ( builder. top_stage - 1 , builder. config . host_target ) ;
257
- builder. ensure ( Rustc :: new ( builder, build_compiler, target) ) ;
258
- build_compiler
242
+ /// Prepares a compiler that will check something with the given `mode`.
243
+ fn prepare_compiler_for_check (
244
+ builder : & Builder < ' _ > ,
245
+ target : TargetSelection ,
246
+ mode : Mode ,
247
+ ) -> Compiler {
248
+ let host = builder. host_target ;
249
+ match mode {
250
+ Mode :: ToolBootstrap => builder. compiler ( 0 , host) ,
251
+ Mode :: ToolStd => {
252
+ // A small number of tools rely on in-tree standard
253
+ // library crates (e.g. compiletest needs libtest).
254
+ let build_compiler = builder. compiler ( builder. top_stage , host) ;
255
+ builder. std ( build_compiler, host) ;
256
+ builder. std ( build_compiler, target) ;
257
+ build_compiler
258
+ }
259
+ Mode :: ToolRustc | Mode :: Codegen => {
260
+ // When checking tool stage N, we check it with compiler stage N-1
261
+ let build_compiler = builder. compiler ( builder. top_stage - 1 , host) ;
262
+ builder. ensure ( Rustc :: new ( builder, build_compiler, target) ) ;
263
+ build_compiler
264
+ }
265
+ Mode :: Rustc => {
266
+ if builder. top_stage < 2 && host != target {
267
+ eprintln ! ( "Cannot do a cross-compilation check of rustc on stage 1, use stage 2" ) ;
268
+ exit ! ( 1 ) ;
269
+ }
270
+
271
+ // When checking the stage N compiler, we want to do it with the stage N-1 compiler
272
+ builder. compiler ( builder. top_stage - 1 , host)
273
+ }
274
+ Mode :: Std => {
275
+ // When checking std stage N, we want to do it with the stage N compiler
276
+ // Note: we don't need to build the host stdlib here, because when compiling std, the
277
+ // stage 0 stdlib is used to compile build scripts and proc macros.
278
+ builder. compiler ( builder. top_stage , host)
279
+ }
280
+ }
259
281
}
260
282
261
283
/// Checks a single codegen backend.
@@ -277,7 +299,7 @@ impl Step for CodegenBackend {
277
299
278
300
fn make_run ( run : RunConfig < ' _ > ) {
279
301
// FIXME: only check the backend(s) that were actually selected in run.paths
280
- let build_compiler = prepare_compiler_for_tool_rustc ( run. builder , run. target ) ;
302
+ let build_compiler = prepare_compiler_for_check ( run. builder , run. target , Mode :: Codegen ) ;
281
303
for & backend in & [ "cranelift" , "gcc" ] {
282
304
run. builder . ensure ( CodegenBackend { build_compiler, target : run. target , backend } ) ;
283
305
}
@@ -345,7 +367,7 @@ impl Step for RustAnalyzer {
345
367
}
346
368
347
369
fn make_run ( run : RunConfig < ' _ > ) {
348
- let build_compiler = prepare_compiler_for_tool_rustc ( run. builder , run. target ) ;
370
+ let build_compiler = prepare_compiler_for_check ( run. builder , run. target , Mode :: ToolRustc ) ;
349
371
run. builder . ensure ( RustAnalyzer { build_compiler, target : run. target } ) ;
350
372
}
351
373
@@ -410,19 +432,11 @@ impl Step for Compiletest {
410
432
} else {
411
433
Mode :: ToolStd
412
434
} ;
413
-
414
- let compiler = builder. compiler (
415
- if mode == Mode :: ToolBootstrap { 0 } else { builder. top_stage } ,
416
- builder. config . host_target ,
417
- ) ;
418
-
419
- if mode != Mode :: ToolBootstrap {
420
- builder. std ( compiler, self . target ) ;
421
- }
435
+ let build_compiler = prepare_compiler_for_check ( builder, self . target , mode) ;
422
436
423
437
let mut cargo = prepare_tool_cargo (
424
438
builder,
425
- compiler ,
439
+ build_compiler ,
426
440
mode,
427
441
self . target ,
428
442
builder. kind ,
@@ -435,7 +449,7 @@ impl Step for Compiletest {
435
449
436
450
cargo. arg ( "--all-targets" ) ;
437
451
438
- let stamp = BuildStamp :: new ( & builder. cargo_out ( compiler , mode, self . target ) )
452
+ let stamp = BuildStamp :: new ( & builder. cargo_out ( build_compiler , mode, self . target ) )
439
453
. with_prefix ( "compiletest-check" ) ;
440
454
441
455
let _guard = builder. msg_check ( "compiletest artifacts" , self . target , None ) ;
@@ -475,23 +489,8 @@ macro_rules! tool_check_step {
475
489
}
476
490
477
491
fn make_run( run: RunConfig <' _>) {
478
- let host = run. builder. config. host_target;
479
492
let target = run. target;
480
- let build_compiler = match $mode {
481
- Mode :: ToolBootstrap => run. builder. compiler( 0 , host) ,
482
- Mode :: ToolStd => {
483
- // A small number of tools rely on in-tree standard
484
- // library crates (e.g. compiletest needs libtest).
485
- let build_compiler = run. builder. compiler( run. builder. top_stage, host) ;
486
- run. builder. std( build_compiler, host) ;
487
- run. builder. std( build_compiler, target) ;
488
- build_compiler
489
- }
490
- Mode :: ToolRustc => {
491
- prepare_compiler_for_tool_rustc( run. builder, target)
492
- }
493
- _ => panic!( "unexpected mode for tool check step: {:?}" , $mode) ,
494
- } ;
493
+ let build_compiler = prepare_compiler_for_check( run. builder, target, $mode) ;
495
494
run. builder. ensure( $name { target, build_compiler } ) ;
496
495
}
497
496
0 commit comments