@@ -11,6 +11,7 @@ use crate::util::{add_dylib_path, PathBufExt};
11
11
use lazycell:: LazyCell ;
12
12
use std:: collections:: HashSet ;
13
13
use test:: { ColorConfig , OutputFormat } ;
14
+ use serde:: de:: { Deserialize , Deserializer , Error as _} ;
14
15
15
16
macro_rules! string_enum {
16
17
( $( #[ $meta: meta] ) * $vis: vis enum $name: ident { $( $variant: ident => $repr: expr, ) * } ) => {
@@ -114,8 +115,10 @@ string_enum! {
114
115
}
115
116
}
116
117
117
- #[ derive( Clone , Copy , Debug , PartialEq ) ]
118
+ #[ derive( Clone , Copy , Debug , PartialEq , Default , serde:: Deserialize ) ]
119
+ #[ serde( rename_all = "kebab-case" ) ]
118
120
pub enum PanicStrategy {
121
+ #[ default]
119
122
Unwind ,
120
123
Abort ,
121
124
}
@@ -450,72 +453,43 @@ impl TargetCfgs {
450
453
}
451
454
}
452
455
453
- #[ derive( Clone , Debug ) ]
456
+ #[ derive( Clone , Debug , serde:: Deserialize ) ]
457
+ #[ serde( rename_all = "kebab-case" ) ]
454
458
pub struct TargetCfg {
455
459
pub ( crate ) arch : String ,
460
+ #[ serde( default ) ]
456
461
pub ( crate ) os : String ,
462
+ #[ serde( default ) ]
457
463
pub ( crate ) env : String ,
464
+ #[ serde( default ) ]
458
465
pub ( crate ) abi : String ,
466
+ #[ serde( rename = "target-family" , default ) ]
459
467
pub ( crate ) families : Vec < String > ,
468
+ #[ serde( rename = "target-pointer-width" , deserialize_with = "serde_parse_u32" ) ]
460
469
pub ( crate ) pointer_width : u32 ,
470
+ #[ serde( rename = "target-endian" , default ) ]
461
471
endian : Endian ,
472
+ #[ serde( rename = "panic-strategy" , default ) ]
462
473
panic : PanicStrategy ,
463
474
}
464
475
465
- #[ derive( Eq , PartialEq , Clone , Debug ) ]
476
+ #[ derive( Eq , PartialEq , Clone , Debug , Default , serde:: Deserialize ) ]
477
+ #[ serde( rename_all = "kebab-case" ) ]
466
478
pub enum Endian {
479
+ #[ default]
467
480
Little ,
468
481
Big ,
469
482
}
470
483
471
484
impl TargetCfg {
472
485
fn new ( config : & Config , target : & str ) -> TargetCfg {
473
- let print_cfg = rustc_output ( config, & [ "--print=cfg" , "--target" , target] ) ;
474
- let mut arch = None ;
475
- let mut os = None ;
476
- let mut env = None ;
477
- let mut abi = None ;
478
- let mut families = Vec :: new ( ) ;
479
- let mut pointer_width = None ;
480
- let mut endian = None ;
481
- let mut panic = None ;
482
- for line in print_cfg. lines ( ) {
483
- if let Some ( ( name, value) ) = line. split_once ( '=' ) {
484
- let value = value. trim_matches ( '"' ) ;
485
- match name {
486
- "target_arch" => arch = Some ( value) ,
487
- "target_os" => os = Some ( value) ,
488
- "target_env" => env = Some ( value) ,
489
- "target_abi" => abi = Some ( value) ,
490
- "target_family" => families. push ( value. to_string ( ) ) ,
491
- "target_pointer_width" => pointer_width = Some ( value. parse ( ) . unwrap ( ) ) ,
492
- "target_endian" => {
493
- endian = Some ( match value {
494
- "little" => Endian :: Little ,
495
- "big" => Endian :: Big ,
496
- s => panic ! ( "unexpected {s}" ) ,
497
- } )
498
- }
499
- "panic" => {
500
- panic = match value {
501
- "abort" => Some ( PanicStrategy :: Abort ) ,
502
- "unwind" => Some ( PanicStrategy :: Unwind ) ,
503
- s => panic ! ( "unexpected {s}" ) ,
504
- }
505
- }
506
- _ => { }
507
- }
508
- }
509
- }
510
- TargetCfg {
511
- arch : arch. unwrap ( ) . to_string ( ) ,
512
- os : os. unwrap ( ) . to_string ( ) ,
513
- env : env. unwrap ( ) . to_string ( ) ,
514
- abi : abi. unwrap ( ) . to_string ( ) ,
515
- families,
516
- pointer_width : pointer_width. unwrap ( ) ,
517
- endian : endian. unwrap ( ) ,
518
- panic : panic. unwrap ( ) ,
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}" ) ,
519
493
}
520
494
}
521
495
}
@@ -524,6 +498,7 @@ fn rustc_output(config: &Config, args: &[&str]) -> String {
524
498
let mut command = Command :: new ( & config. rustc_path ) ;
525
499
add_dylib_path ( & mut command, iter:: once ( & config. compile_lib_path ) ) ;
526
500
command. args ( & config. target_rustcflags ) . args ( args) ;
501
+ command. env ( "RUSTC_BOOTSTRAP" , "1" ) ;
527
502
528
503
let output = match command. output ( ) {
529
504
Ok ( output) => output,
@@ -539,6 +514,11 @@ fn rustc_output(config: &Config, args: &[&str]) -> String {
539
514
String :: from_utf8 ( output. stdout ) . unwrap ( )
540
515
}
541
516
517
+ fn serde_parse_u32 < ' de , D : Deserializer < ' de > > ( deserializer : D ) -> Result < u32 , D :: Error > {
518
+ let string = String :: deserialize ( deserializer) ?;
519
+ string. parse ( ) . map_err ( D :: Error :: custom)
520
+ }
521
+
542
522
#[ derive( Debug , Clone ) ]
543
523
pub struct TestPaths {
544
524
pub file : PathBuf , // e.g., compile-test/foo/bar/baz.rs
0 commit comments