@@ -428,7 +428,6 @@ impl TargetCfgs {
428
428
) )
429
429
. unwrap ( ) ;
430
430
431
- let mut current = None ;
432
431
let mut all_targets = HashSet :: new ( ) ;
433
432
let mut all_archs = HashSet :: new ( ) ;
434
433
let mut all_oses = HashSet :: new ( ) ;
@@ -449,14 +448,11 @@ impl TargetCfgs {
449
448
}
450
449
all_pointer_widths. insert ( format ! ( "{}bit" , cfg. pointer_width) ) ;
451
450
452
- if target == config. target {
453
- current = Some ( cfg) ;
454
- }
455
451
all_targets. insert ( target. into ( ) ) ;
456
452
}
457
453
458
454
Self {
459
- current : current . expect ( "current target not found" ) ,
455
+ current : Self :: get_current_target_config ( config ) ,
460
456
all_targets,
461
457
all_archs,
462
458
all_oses,
@@ -467,6 +463,89 @@ impl TargetCfgs {
467
463
all_pointer_widths,
468
464
}
469
465
}
466
+
467
+ fn get_current_target_config ( config : & Config ) -> TargetCfg {
468
+ let mut arch = None ;
469
+ let mut os = None ;
470
+ let mut env = None ;
471
+ let mut abi = None ;
472
+ let mut families = Vec :: new ( ) ;
473
+ let mut pointer_width = None ;
474
+ let mut endian = None ;
475
+ let mut panic = None ;
476
+
477
+ for config in
478
+ rustc_output ( config, & [ "--print=cfg" , "--target" , & config. target ] ) . trim ( ) . lines ( )
479
+ {
480
+ let ( name, value) = config
481
+ . split_once ( "=\" " )
482
+ . map ( |( name, value) | {
483
+ (
484
+ name,
485
+ Some (
486
+ value
487
+ . strip_suffix ( "\" " )
488
+ . expect ( "key-value pair should be properly quoted" ) ,
489
+ ) ,
490
+ )
491
+ } )
492
+ . unwrap_or_else ( || ( config, None ) ) ;
493
+
494
+ match name {
495
+ "target_arch" => {
496
+ arch = Some ( value. expect ( "target_arch should be a key-value pair" ) . to_string ( ) ) ;
497
+ }
498
+ "target_os" => {
499
+ os = Some ( value. expect ( "target_os sould be a key-value pair" ) . to_string ( ) ) ;
500
+ }
501
+ "target_env" => {
502
+ env = Some ( value. expect ( "target_env should be a key-value pair" ) . to_string ( ) ) ;
503
+ }
504
+ "target_abi" => {
505
+ abi = Some ( value. expect ( "target_abi should be a key-value pair" ) . to_string ( ) ) ;
506
+ }
507
+ "target_family" => {
508
+ families
509
+ . push ( value. expect ( "target_family should be a key-value pair" ) . to_string ( ) ) ;
510
+ }
511
+ "target_pointer_width" => {
512
+ pointer_width = Some (
513
+ value
514
+ . expect ( "target_pointer_width should be a key-value pair" )
515
+ . parse :: < u32 > ( )
516
+ . expect ( "target_pointer_width should be a valid u32" ) ,
517
+ ) ;
518
+ }
519
+ "target_endian" => {
520
+ endian = Some ( match value. expect ( "target_endian should be a key-value pair" ) {
521
+ "big" => Endian :: Big ,
522
+ "little" => Endian :: Little ,
523
+ _ => panic ! ( "target_endian should be either 'big' or 'little'" ) ,
524
+ } ) ;
525
+ }
526
+ "panic" => {
527
+ panic = Some ( match value. expect ( "panic should be a key-value pair" ) {
528
+ "abort" => PanicStrategy :: Abort ,
529
+ "unwind" => PanicStrategy :: Unwind ,
530
+ _ => panic ! ( "panic should be either 'abort' or 'unwind'" ) ,
531
+ } ) ;
532
+ }
533
+ _ => ( ) ,
534
+ }
535
+ }
536
+
537
+ TargetCfg {
538
+ arch : arch. expect ( "target configuration should specify target_arch" ) ,
539
+ os : os. expect ( "target configuration should specify target_os" ) ,
540
+ env : env. expect ( "target configuration should specify target_env" ) ,
541
+ abi : abi. expect ( "target configuration should specify target_abi" ) ,
542
+ families,
543
+ pointer_width : pointer_width
544
+ . expect ( "target configuration should specify target_pointer_width" ) ,
545
+ endian : endian. expect ( "target configuration should specify target_endian" ) ,
546
+ panic : panic. expect ( "target configuration should specify panic" ) ,
547
+ }
548
+ }
470
549
}
471
550
472
551
#[ derive( Clone , Debug , serde:: Deserialize ) ]
0 commit comments