@@ -38,7 +38,7 @@ use crate::abi::call::Conv;
3838use crate :: abi:: { Endian , Integer , Size , TargetDataLayout , TargetDataLayoutErrors } ;
3939use crate :: json:: { Json , ToJson } ;
4040use crate :: spec:: abi:: { lookup as lookup_abi, Abi } ;
41- use crate :: spec:: crt_objects:: { CrtObjects , LinkSelfContainedDefault } ;
41+ use crate :: spec:: crt_objects:: CrtObjects ;
4242use rustc_data_structures:: stable_hasher:: { HashStable , StableHasher } ;
4343use rustc_fs_util:: try_canonicalize;
4444use rustc_serialize:: { Decodable , Decoder , Encodable , Encoder } ;
@@ -542,7 +542,7 @@ impl ToJson for LinkerFlavorCli {
542542/// - explicitly enabling some of the self-contained linking components, e.g. the linker component
543543/// to use `rust-lld`
544544#[ derive( Clone , Copy , PartialEq , Debug ) ]
545- pub enum LinkSelfContained {
545+ pub enum LinkSelfContainedDefault {
546546 /// The target spec explicitly enables self-contained linking.
547547 True ,
548548
@@ -560,10 +560,25 @@ pub enum LinkSelfContained {
560560 WithComponents ( LinkSelfContainedComponents ) ,
561561}
562562
563- impl ToJson for LinkSelfContained {
563+ /// Parses a backwards-compatible `-Clink-self-contained` option string, without components.
564+ impl FromStr for LinkSelfContainedDefault {
565+ type Err = ( ) ;
566+
567+ fn from_str ( s : & str ) -> Result < LinkSelfContainedDefault , ( ) > {
568+ Ok ( match s {
569+ "false" => LinkSelfContainedDefault :: False ,
570+ "true" | "wasm" => LinkSelfContainedDefault :: True ,
571+ "musl" => LinkSelfContainedDefault :: InferredForMusl ,
572+ "mingw" => LinkSelfContainedDefault :: InferredForMingw ,
573+ _ => return Err ( ( ) ) ,
574+ } )
575+ }
576+ }
577+
578+ impl ToJson for LinkSelfContainedDefault {
564579 fn to_json ( & self ) -> Json {
565580 match * self {
566- LinkSelfContained :: WithComponents ( components) => {
581+ LinkSelfContainedDefault :: WithComponents ( components) => {
567582 // Serialize the components in a json object's `components` field, to prepare for a
568583 // future where `crt-objects-fallback` is removed from the json specs and
569584 // incorporated as a field here.
@@ -572,29 +587,31 @@ impl ToJson for LinkSelfContained {
572587 map. to_json ( )
573588 }
574589
575- // Stable values backwards-compatible with `LinkSelfContainedDefault`
576- LinkSelfContained :: True => "true" . to_json ( ) ,
577- LinkSelfContained :: False => "false" . to_json ( ) ,
578- LinkSelfContained :: InferredForMusl => "musl" . to_json ( ) ,
579- LinkSelfContained :: InferredForMingw => "mingw" . to_json ( ) ,
590+ // Stable backwards-compatible values
591+ LinkSelfContainedDefault :: True => "true" . to_json ( ) ,
592+ LinkSelfContainedDefault :: False => "false" . to_json ( ) ,
593+ LinkSelfContainedDefault :: InferredForMusl => "musl" . to_json ( ) ,
594+ LinkSelfContainedDefault :: InferredForMingw => "mingw" . to_json ( ) ,
580595 }
581596 }
582597}
583598
584- impl LinkSelfContained {
599+ impl LinkSelfContainedDefault {
585600 /// Returns whether the target spec has self-contained linking explicitly disabled. Used to emit
586601 /// errors if the user then enables it on the CLI.
587602 pub fn is_disabled ( self ) -> bool {
588- self == LinkSelfContained :: False
603+ self == LinkSelfContainedDefault :: False
589604 }
590605
591606 /// Returns whether the target spec explictly requests self-contained linking, i.e. not via
592607 /// inference.
593608 pub fn is_linker_enabled ( self ) -> bool {
594609 match self {
595- LinkSelfContained :: True => true ,
596- LinkSelfContained :: False => false ,
597- LinkSelfContained :: WithComponents ( c) => c. contains ( LinkSelfContainedComponents :: LINKER ) ,
610+ LinkSelfContainedDefault :: True => true ,
611+ LinkSelfContainedDefault :: False => false ,
612+ LinkSelfContainedDefault :: WithComponents ( c) => {
613+ c. contains ( LinkSelfContainedComponents :: LINKER )
614+ }
598615 _ => false ,
599616 }
600617 }
@@ -604,23 +621,12 @@ impl LinkSelfContained {
604621 /// - the other variants as a backwards-compatible `crt-objects-fallback` string
605622 fn json_key ( self ) -> & ' static str {
606623 match self {
607- LinkSelfContained :: WithComponents ( _) => "link-self-contained" ,
624+ LinkSelfContainedDefault :: WithComponents ( _) => "link-self-contained" ,
608625 _ => "crt-objects-fallback" ,
609626 }
610627 }
611628}
612629
613- impl From < LinkSelfContainedDefault > for LinkSelfContained {
614- fn from ( value : LinkSelfContainedDefault ) -> Self {
615- match value {
616- LinkSelfContainedDefault :: True => LinkSelfContained :: True ,
617- LinkSelfContainedDefault :: False => LinkSelfContained :: False ,
618- LinkSelfContainedDefault :: Musl => LinkSelfContained :: InferredForMusl ,
619- LinkSelfContainedDefault :: Mingw => LinkSelfContained :: InferredForMingw ,
620- }
621- }
622- }
623-
624630bitflags:: bitflags! {
625631 #[ derive( Default ) ]
626632 /// The `-C link-self-contained` components that can individually be enabled or disabled.
@@ -1888,7 +1894,7 @@ pub struct TargetOptions {
18881894 pub post_link_objects_self_contained : CrtObjects ,
18891895 /// Behavior for the self-contained linking mode: inferred for some targets, or explicitly
18901896 /// enabled (in bulk, or with individual components).
1891- pub link_self_contained : LinkSelfContained ,
1897+ pub link_self_contained : LinkSelfContainedDefault ,
18921898
18931899 /// Linker arguments that are passed *before* any user-defined libraries.
18941900 pub pre_link_args : LinkArgs ,
@@ -2363,7 +2369,7 @@ impl Default for TargetOptions {
23632369 post_link_objects : Default :: default ( ) ,
23642370 pre_link_objects_self_contained : Default :: default ( ) ,
23652371 post_link_objects_self_contained : Default :: default ( ) ,
2366- link_self_contained : LinkSelfContained :: False ,
2372+ link_self_contained : LinkSelfContainedDefault :: False ,
23672373 pre_link_args : LinkArgs :: new ( ) ,
23682374 pre_link_args_json : LinkArgsCli :: new ( ) ,
23692375 late_link_args : LinkArgs :: new ( ) ,
@@ -2844,7 +2850,7 @@ impl Target {
28442850 }
28452851 Ok :: <( ) , String >( ( ) )
28462852 } ) ;
2847- ( $key_name: ident, LinkSelfContained ) => ( {
2853+ ( $key_name: ident, link_self_contained_components ) => ( {
28482854 // Skeleton of what needs to be parsed:
28492855 //
28502856 // ```
@@ -2873,18 +2879,18 @@ impl Target {
28732879 _ => return Err ( format!( "not a string: {:?}" , s) ) ,
28742880 } ;
28752881 }
2876- base. $key_name = LinkSelfContained :: WithComponents ( components) ;
2882+ base. $key_name = LinkSelfContainedDefault :: WithComponents ( components) ;
28772883 } else {
28782884 incorrect_type. push( name)
28792885 }
28802886 }
28812887 Ok :: <( ) , String >( ( ) )
28822888 } ) ;
2883- ( $key_name: ident = $json_name: expr, LinkSelfContainedDefault ) => ( {
2889+ ( $key_name: ident = $json_name: expr, link_self_contained_backwards_compatible ) => ( {
28842890 let name = $json_name;
28852891 obj. remove( name) . and_then( |o| o. as_str( ) . and_then( |s| {
28862892 match s. parse:: <LinkSelfContainedDefault >( ) {
2887- Ok ( lsc_default) => base. $key_name = lsc_default. into ( ) ,
2893+ Ok ( lsc_default) => base. $key_name = lsc_default,
28882894 _ => return Some ( Err ( format!( "'{}' is not a valid `-Clink-self-contained` default. \
28892895 Use 'false', 'true', 'musl' or 'mingw'", s) ) ) ,
28902896 }
@@ -3034,9 +3040,12 @@ impl Target {
30343040 key ! ( pre_link_objects_self_contained = "pre-link-objects-fallback" , link_objects) ;
30353041 key ! ( post_link_objects_self_contained = "post-link-objects-fallback" , link_objects) ;
30363042 // Deserializes the backwards-compatible variants of `-Clink-self-contained`
3037- key ! ( link_self_contained = "crt-objects-fallback" , LinkSelfContainedDefault ) ?;
3043+ key ! (
3044+ link_self_contained = "crt-objects-fallback" ,
3045+ link_self_contained_backwards_compatible
3046+ ) ?;
30383047 // Deserializes the components variant of `-Clink-self-contained`
3039- key ! ( link_self_contained, LinkSelfContained ) ?;
3048+ key ! ( link_self_contained, link_self_contained_components ) ?;
30403049 key ! ( pre_link_args_json = "pre-link-args" , link_args) ;
30413050 key ! ( late_link_args_json = "late-link-args" , link_args) ;
30423051 key ! ( late_link_args_dynamic_json = "late-link-args-dynamic" , link_args) ;
0 commit comments