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