@@ -9,9 +9,9 @@ use std::str::FromStr;
9
9
10
10
use crate :: util:: { add_dylib_path, PathBufExt } ;
11
11
use lazycell:: LazyCell ;
12
- use std:: collections:: HashSet ;
13
- use test:: { ColorConfig , OutputFormat } ;
14
12
use serde:: de:: { Deserialize , Deserializer , Error as _} ;
13
+ use std:: collections:: { HashMap , HashSet } ;
14
+ use test:: { ColorConfig , OutputFormat } ;
15
15
16
16
macro_rules! string_enum {
17
17
( $( #[ $meta: meta] ) * $vis: vis enum $name: ident { $( $variant: ident => $repr: expr, ) * } ) => {
@@ -410,8 +410,17 @@ pub struct TargetCfgs {
410
410
411
411
impl TargetCfgs {
412
412
fn new ( config : & Config ) -> TargetCfgs {
413
- // Gather list of all targets
414
- let targets = rustc_output ( config, & [ "--print=target-list" ] ) ;
413
+ let targets: HashMap < String , TargetCfg > = if config. stage_id . starts_with ( "stage0-" ) {
414
+ // #[cfg(bootstrap)]
415
+ // Needed only for one cycle, remove during the bootstrap bump.
416
+ Self :: collect_all_slow ( config)
417
+ } else {
418
+ serde_json:: from_str ( & rustc_output (
419
+ config,
420
+ & [ "--print=all-target-specs-json" , "-Zunstable-options" ] ,
421
+ ) )
422
+ . unwrap ( )
423
+ } ;
415
424
416
425
let mut current = None ;
417
426
let mut all_targets = HashSet :: new ( ) ;
@@ -422,9 +431,7 @@ impl TargetCfgs {
422
431
let mut all_families = HashSet :: new ( ) ;
423
432
let mut all_pointer_widths = HashSet :: new ( ) ;
424
433
425
- for target in targets. trim ( ) . lines ( ) {
426
- let cfg = TargetCfg :: new ( config, target) ;
427
-
434
+ for ( target, cfg) in targets. into_iter ( ) {
428
435
all_archs. insert ( cfg. arch . clone ( ) ) ;
429
436
all_oses. insert ( cfg. os . clone ( ) ) ;
430
437
all_envs. insert ( cfg. env . clone ( ) ) ;
@@ -451,6 +458,25 @@ impl TargetCfgs {
451
458
all_pointer_widths,
452
459
}
453
460
}
461
+
462
+ // #[cfg(bootstrap)]
463
+ // Needed only for one cycle, remove during the bootstrap bump.
464
+ fn collect_all_slow ( config : & Config ) -> HashMap < String , TargetCfg > {
465
+ let mut result = HashMap :: new ( ) ;
466
+ for target in rustc_output ( config, & [ "--print=target-list" ] ) . trim ( ) . lines ( ) {
467
+ let json = rustc_output (
468
+ config,
469
+ & [ "--print=target-spec-json" , "-Zunstable-options" , "--target" , target] ,
470
+ ) ;
471
+ match serde_json:: from_str ( & json) {
472
+ Ok ( res) => {
473
+ result. insert ( target. into ( ) , res) ;
474
+ }
475
+ Err ( err) => panic ! ( "failed to parse target spec for {target}: {err}" ) ,
476
+ }
477
+ }
478
+ result
479
+ }
454
480
}
455
481
456
482
#[ derive( Clone , Debug , serde:: Deserialize ) ]
@@ -481,19 +507,6 @@ pub enum Endian {
481
507
Big ,
482
508
}
483
509
484
- impl TargetCfg {
485
- fn new ( config : & Config , target : & str ) -> TargetCfg {
486
- let json = rustc_output (
487
- config,
488
- & [ "--print=target-spec-json" , "-Zunstable-options" , "--target" , target] ,
489
- ) ;
490
- match serde_json:: from_str ( & json) {
491
- Ok ( res) => res,
492
- Err ( err) => panic ! ( "failed to parse target spec for {target}: {err}" ) ,
493
- }
494
- }
495
- }
496
-
497
510
fn rustc_output ( config : & Config , args : & [ & str ] ) -> String {
498
511
let mut command = Command :: new ( & config. rustc_path ) ;
499
512
add_dylib_path ( & mut command, iter:: once ( & config. compile_lib_path ) ) ;
0 commit comments