@@ -38,7 +38,7 @@ use crate::abi::call::Conv;
38
38
use crate :: abi:: { Endian , Integer , Size , TargetDataLayout , TargetDataLayoutErrors } ;
39
39
use crate :: json:: { Json , ToJson } ;
40
40
use crate :: spec:: abi:: { lookup as lookup_abi, Abi } ;
41
- use crate :: spec:: crt_objects:: { CrtObjects , LinkSelfContainedDefault } ;
41
+ use crate :: spec:: crt_objects:: CrtObjects ;
42
42
use rustc_data_structures:: stable_hasher:: { HashStable , StableHasher } ;
43
43
use rustc_fs_util:: try_canonicalize;
44
44
use rustc_serialize:: { Decodable , Decoder , Encodable , Encoder } ;
@@ -542,7 +542,7 @@ impl ToJson for LinkerFlavorCli {
542
542
/// - explicitly enabling some of the self-contained linking components, e.g. the linker component
543
543
/// to use `rust-lld`
544
544
#[ derive( Clone , Copy , PartialEq , Debug ) ]
545
- pub enum LinkSelfContained {
545
+ pub enum LinkSelfContainedDefault {
546
546
/// The target spec explicitly enables self-contained linking.
547
547
True ,
548
548
@@ -560,10 +560,25 @@ pub enum LinkSelfContained {
560
560
WithComponents ( LinkSelfContainedComponents ) ,
561
561
}
562
562
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 {
564
579
fn to_json ( & self ) -> Json {
565
580
match * self {
566
- LinkSelfContained :: WithComponents ( components) => {
581
+ LinkSelfContainedDefault :: WithComponents ( components) => {
567
582
// Serialize the components in a json object's `components` field, to prepare for a
568
583
// future where `crt-objects-fallback` is removed from the json specs and
569
584
// incorporated as a field here.
@@ -572,29 +587,31 @@ impl ToJson for LinkSelfContained {
572
587
map. to_json ( )
573
588
}
574
589
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 ( ) ,
580
595
}
581
596
}
582
597
}
583
598
584
- impl LinkSelfContained {
599
+ impl LinkSelfContainedDefault {
585
600
/// Returns whether the target spec has self-contained linking explicitly disabled. Used to emit
586
601
/// errors if the user then enables it on the CLI.
587
602
pub fn is_disabled ( self ) -> bool {
588
- self == LinkSelfContained :: False
603
+ self == LinkSelfContainedDefault :: False
589
604
}
590
605
591
606
/// Returns whether the target spec explictly requests self-contained linking, i.e. not via
592
607
/// inference.
593
608
pub fn is_linker_enabled ( self ) -> bool {
594
609
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
+ }
598
615
_ => false ,
599
616
}
600
617
}
@@ -604,23 +621,12 @@ impl LinkSelfContained {
604
621
/// - the other variants as a backwards-compatible `crt-objects-fallback` string
605
622
fn json_key ( self ) -> & ' static str {
606
623
match self {
607
- LinkSelfContained :: WithComponents ( _) => "link-self-contained" ,
624
+ LinkSelfContainedDefault :: WithComponents ( _) => "link-self-contained" ,
608
625
_ => "crt-objects-fallback" ,
609
626
}
610
627
}
611
628
}
612
629
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
-
624
630
bitflags:: bitflags! {
625
631
#[ derive( Default ) ]
626
632
/// The `-C link-self-contained` components that can individually be enabled or disabled.
@@ -1888,7 +1894,7 @@ pub struct TargetOptions {
1888
1894
pub post_link_objects_self_contained : CrtObjects ,
1889
1895
/// Behavior for the self-contained linking mode: inferred for some targets, or explicitly
1890
1896
/// enabled (in bulk, or with individual components).
1891
- pub link_self_contained : LinkSelfContained ,
1897
+ pub link_self_contained : LinkSelfContainedDefault ,
1892
1898
1893
1899
/// Linker arguments that are passed *before* any user-defined libraries.
1894
1900
pub pre_link_args : LinkArgs ,
@@ -2363,7 +2369,7 @@ impl Default for TargetOptions {
2363
2369
post_link_objects : Default :: default ( ) ,
2364
2370
pre_link_objects_self_contained : Default :: default ( ) ,
2365
2371
post_link_objects_self_contained : Default :: default ( ) ,
2366
- link_self_contained : LinkSelfContained :: False ,
2372
+ link_self_contained : LinkSelfContainedDefault :: False ,
2367
2373
pre_link_args : LinkArgs :: new ( ) ,
2368
2374
pre_link_args_json : LinkArgsCli :: new ( ) ,
2369
2375
late_link_args : LinkArgs :: new ( ) ,
@@ -2844,7 +2850,7 @@ impl Target {
2844
2850
}
2845
2851
Ok :: <( ) , String >( ( ) )
2846
2852
} ) ;
2847
- ( $key_name: ident, LinkSelfContained ) => ( {
2853
+ ( $key_name: ident, link_self_contained_components ) => ( {
2848
2854
// Skeleton of what needs to be parsed:
2849
2855
//
2850
2856
// ```
@@ -2873,18 +2879,18 @@ impl Target {
2873
2879
_ => return Err ( format!( "not a string: {:?}" , s) ) ,
2874
2880
} ;
2875
2881
}
2876
- base. $key_name = LinkSelfContained :: WithComponents ( components) ;
2882
+ base. $key_name = LinkSelfContainedDefault :: WithComponents ( components) ;
2877
2883
} else {
2878
2884
incorrect_type. push( name)
2879
2885
}
2880
2886
}
2881
2887
Ok :: <( ) , String >( ( ) )
2882
2888
} ) ;
2883
- ( $key_name: ident = $json_name: expr, LinkSelfContainedDefault ) => ( {
2889
+ ( $key_name: ident = $json_name: expr, link_self_contained_backwards_compatible ) => ( {
2884
2890
let name = $json_name;
2885
2891
obj. remove( name) . and_then( |o| o. as_str( ) . and_then( |s| {
2886
2892
match s. parse:: <LinkSelfContainedDefault >( ) {
2887
- Ok ( lsc_default) => base. $key_name = lsc_default. into ( ) ,
2893
+ Ok ( lsc_default) => base. $key_name = lsc_default,
2888
2894
_ => return Some ( Err ( format!( "'{}' is not a valid `-Clink-self-contained` default. \
2889
2895
Use 'false', 'true', 'musl' or 'mingw'", s) ) ) ,
2890
2896
}
@@ -3034,9 +3040,12 @@ impl Target {
3034
3040
key ! ( pre_link_objects_self_contained = "pre-link-objects-fallback" , link_objects) ;
3035
3041
key ! ( post_link_objects_self_contained = "post-link-objects-fallback" , link_objects) ;
3036
3042
// 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
+ ) ?;
3038
3047
// Deserializes the components variant of `-Clink-self-contained`
3039
- key ! ( link_self_contained, LinkSelfContained ) ?;
3048
+ key ! ( link_self_contained, link_self_contained_components ) ?;
3040
3049
key ! ( pre_link_args_json = "pre-link-args" , link_args) ;
3041
3050
key ! ( late_link_args_json = "late-link-args" , link_args) ;
3042
3051
key ! ( late_link_args_dynamic_json = "late-link-args-dynamic" , link_args) ;
0 commit comments