@@ -9,9 +9,9 @@ use std::str::FromStr;
99
1010use crate :: util:: { add_dylib_path, PathBufExt } ;
1111use lazycell:: LazyCell ;
12- use std:: collections:: HashSet ;
13- use test:: { ColorConfig , OutputFormat } ;
1412use serde:: de:: { Deserialize , Deserializer , Error as _} ;
13+ use std:: collections:: { HashMap , HashSet } ;
14+ use test:: { ColorConfig , OutputFormat } ;
1515
1616macro_rules! string_enum {
1717 ( $( #[ $meta: meta] ) * $vis: vis enum $name: ident { $( $variant: ident => $repr: expr, ) * } ) => {
@@ -410,8 +410,17 @@ pub struct TargetCfgs {
410410
411411impl TargetCfgs {
412412 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+ } ;
415424
416425 let mut current = None ;
417426 let mut all_targets = HashSet :: new ( ) ;
@@ -422,9 +431,7 @@ impl TargetCfgs {
422431 let mut all_families = HashSet :: new ( ) ;
423432 let mut all_pointer_widths = HashSet :: new ( ) ;
424433
425- for target in targets. trim ( ) . lines ( ) {
426- let cfg = TargetCfg :: new ( config, target) ;
427-
434+ for ( target, cfg) in targets. into_iter ( ) {
428435 all_archs. insert ( cfg. arch . clone ( ) ) ;
429436 all_oses. insert ( cfg. os . clone ( ) ) ;
430437 all_envs. insert ( cfg. env . clone ( ) ) ;
@@ -451,6 +458,25 @@ impl TargetCfgs {
451458 all_pointer_widths,
452459 }
453460 }
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+ }
454480}
455481
456482#[ derive( Clone , Debug , serde:: Deserialize ) ]
@@ -481,19 +507,6 @@ pub enum Endian {
481507 Big ,
482508}
483509
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-
497510fn rustc_output ( config : & Config , args : & [ & str ] ) -> String {
498511 let mut command = Command :: new ( & config. rustc_path ) ;
499512 add_dylib_path ( & mut command, iter:: once ( & config. compile_lib_path ) ) ;
0 commit comments