@@ -468,23 +468,74 @@ impl fmt::Display for LinkOutputKind {
468468
469469pub type LinkArgs = BTreeMap < LinkerFlavor , Vec < StaticCow < str > > > ;
470470
471- #[ derive( Clone , Copy , Hash , Debug , PartialEq , Eq ) ]
471+ /// Which kind of debuginfo does the target use?
472+ ///
473+ /// Useful in determining whether a target supports Split DWARF (a target with
474+ /// `DebuginfoKind::Dwarf` and supporting `SplitDebuginfo::Unpacked` for example).
475+ #[ derive( Clone , Copy , Debug , Default , Eq , Hash , PartialEq ) ]
476+ pub enum DebuginfoKind {
477+ /// DWARF debuginfo (such as that used on `x86_64_unknown_linux_gnu`).
478+ #[ default]
479+ Dwarf ,
480+ /// DWARF debuginfo in dSYM files (such as on Apple platforms).
481+ DwarfDsym ,
482+ /// Program database files (such as on Windows).
483+ Pdb ,
484+ }
485+
486+ impl DebuginfoKind {
487+ fn as_str ( & self ) -> & ' static str {
488+ match self {
489+ DebuginfoKind :: Dwarf => "dwarf" ,
490+ DebuginfoKind :: DwarfDsym => "dwarf-dsym" ,
491+ DebuginfoKind :: Pdb => "pdb" ,
492+ }
493+ }
494+ }
495+
496+ impl FromStr for DebuginfoKind {
497+ type Err = ( ) ;
498+
499+ fn from_str ( s : & str ) -> Result < Self , ( ) > {
500+ Ok ( match s {
501+ "dwarf" => DebuginfoKind :: Dwarf ,
502+ "dwarf-dsym" => DebuginfoKind :: DwarfDsym ,
503+ "pdb" => DebuginfoKind :: Pdb ,
504+ _ => return Err ( ( ) ) ,
505+ } )
506+ }
507+ }
508+
509+ impl ToJson for DebuginfoKind {
510+ fn to_json ( & self ) -> Json {
511+ self . as_str ( ) . to_json ( )
512+ }
513+ }
514+
515+ impl fmt:: Display for DebuginfoKind {
516+ fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
517+ f. write_str ( self . as_str ( ) )
518+ }
519+ }
520+
521+ #[ derive( Clone , Copy , Debug , Default , Eq , Hash , PartialEq ) ]
472522pub enum SplitDebuginfo {
473523 /// Split debug-information is disabled, meaning that on supported platforms
474524 /// you can find all debug information in the executable itself. This is
475525 /// only supported for ELF effectively.
476526 ///
477527 /// * Windows - not supported
478528 /// * macOS - don't run `dsymutil`
479- /// * ELF - `.dwarf_*` sections
529+ /// * ELF - `.debug_*` sections
530+ #[ default]
480531 Off ,
481532
482533 /// Split debug-information can be found in a "packed" location separate
483534 /// from the final artifact. This is supported on all platforms.
484535 ///
485536 /// * Windows - `*.pdb`
486537 /// * macOS - `*.dSYM` (run `dsymutil`)
487- /// * ELF - `*.dwp` (run `rust-llvm-dwp `)
538+ /// * ELF - `*.dwp` (run `thorin `)
488539 Packed ,
489540
490541 /// Split debug-information can be found in individual object files on the
@@ -509,7 +560,7 @@ impl SplitDebuginfo {
509560impl FromStr for SplitDebuginfo {
510561 type Err = ( ) ;
511562
512- fn from_str ( s : & str ) -> Result < SplitDebuginfo , ( ) > {
563+ fn from_str ( s : & str ) -> Result < Self , ( ) > {
513564 Ok ( match s {
514565 "off" => SplitDebuginfo :: Off ,
515566 "unpacked" => SplitDebuginfo :: Unpacked ,
@@ -1435,9 +1486,13 @@ pub struct TargetOptions {
14351486 /// thumb and arm interworking.
14361487 pub has_thumb_interworking : bool ,
14371488
1489+ /// Which kind of debuginfo is used by this target?
1490+ pub debuginfo_kind : DebuginfoKind ,
14381491 /// How to handle split debug information, if at all. Specifying `None` has
14391492 /// target-specific meaning.
14401493 pub split_debuginfo : SplitDebuginfo ,
1494+ /// Which kinds of split debuginfo are supported by the target?
1495+ pub supported_split_debuginfo : StaticCow < [ SplitDebuginfo ] > ,
14411496
14421497 /// The sanitizers supported by this target
14431498 ///
@@ -1595,7 +1650,10 @@ impl Default for TargetOptions {
15951650 use_ctors_section : false ,
15961651 eh_frame_header : true ,
15971652 has_thumb_interworking : false ,
1598- split_debuginfo : SplitDebuginfo :: Off ,
1653+ debuginfo_kind : Default :: default ( ) ,
1654+ split_debuginfo : Default :: default ( ) ,
1655+ // `Off` is supported by default, but targets can remove this manually, e.g. Windows.
1656+ supported_split_debuginfo : Cow :: Borrowed ( & [ SplitDebuginfo :: Off ] ) ,
15991657 supported_sanitizers : SanitizerSet :: empty ( ) ,
16001658 default_adjusted_cabi : None ,
16011659 c_enum_min_bits : 32 ,
@@ -1868,6 +1926,19 @@ impl Target {
18681926 Some ( Ok ( ( ) ) )
18691927 } ) ) . unwrap_or( Ok ( ( ) ) )
18701928 } ) ;
1929+ ( $key_name: ident, DebuginfoKind ) => ( {
1930+ let name = ( stringify!( $key_name) ) . replace( "_" , "-" ) ;
1931+ obj. remove( & name) . and_then( |o| o. as_str( ) . and_then( |s| {
1932+ match s. parse:: <DebuginfoKind >( ) {
1933+ Ok ( level) => base. $key_name = level,
1934+ _ => return Some ( Err (
1935+ format!( "'{s}' is not a valid value for debuginfo-kind. Use 'dwarf', \
1936+ 'dwarf-dsym' or 'pdb'.")
1937+ ) ) ,
1938+ }
1939+ Some ( Ok ( ( ) ) )
1940+ } ) ) . unwrap_or( Ok ( ( ) ) )
1941+ } ) ;
18711942 ( $key_name: ident, SplitDebuginfo ) => ( {
18721943 let name = ( stringify!( $key_name) ) . replace( "_" , "-" ) ;
18731944 obj. remove( & name) . and_then( |o| o. as_str( ) . and_then( |s| {
@@ -1904,6 +1975,25 @@ impl Target {
19041975 }
19051976 }
19061977 } ) ;
1978+ ( $key_name: ident, falliable_list) => ( {
1979+ let name = ( stringify!( $key_name) ) . replace( "_" , "-" ) ;
1980+ obj. remove( & name) . and_then( |j| {
1981+ if let Some ( v) = j. as_array( ) {
1982+ match v. iter( ) . map( |a| FromStr :: from_str( a. as_str( ) . unwrap( ) ) ) . collect( ) {
1983+ Ok ( l) => { base. $key_name = l } ,
1984+ // FIXME: `falliable_list` can't re-use the `key!` macro for list
1985+ // elements and the error messages from that macro, so it has a bad
1986+ // generic message instead
1987+ Err ( _) => return Some ( Err (
1988+ format!( "`{:?}` is not a valid value for `{}`" , j, name)
1989+ ) ) ,
1990+ }
1991+ } else {
1992+ incorrect_type. push( name)
1993+ }
1994+ Some ( Ok ( ( ) ) )
1995+ } ) . unwrap_or( Ok ( ( ) ) )
1996+ } ) ;
19071997 ( $key_name: ident, optional) => ( {
19081998 let name = ( stringify!( $key_name) ) . replace( "_" , "-" ) ;
19091999 if let Some ( o) = obj. remove( & name) {
@@ -2190,7 +2280,9 @@ impl Target {
21902280 key ! ( use_ctors_section, bool ) ;
21912281 key ! ( eh_frame_header, bool ) ;
21922282 key ! ( has_thumb_interworking, bool ) ;
2283+ key ! ( debuginfo_kind, DebuginfoKind ) ?;
21932284 key ! ( split_debuginfo, SplitDebuginfo ) ?;
2285+ key ! ( supported_split_debuginfo, falliable_list) ?;
21942286 key ! ( supported_sanitizers, SanitizerSet ) ?;
21952287 key ! ( default_adjusted_cabi, Option <Abi >) ?;
21962288 key ! ( c_enum_min_bits, u64 ) ;
@@ -2434,7 +2526,9 @@ impl ToJson for Target {
24342526 target_option_val ! ( use_ctors_section) ;
24352527 target_option_val ! ( eh_frame_header) ;
24362528 target_option_val ! ( has_thumb_interworking) ;
2529+ target_option_val ! ( debuginfo_kind) ;
24372530 target_option_val ! ( split_debuginfo) ;
2531+ target_option_val ! ( supported_split_debuginfo) ;
24382532 target_option_val ! ( supported_sanitizers) ;
24392533 target_option_val ! ( c_enum_min_bits) ;
24402534 target_option_val ! ( generate_arange_section) ;
0 commit comments