unify LinkSelfContained and LinkSelfContainedDefault
Removes the backwards-compatible `LinkSelfContainedDefault`, by incorporating the remaining specifics into `LinkSelfContained`. Then renames the modern options to keep the old name.
This commit is contained in:
@@ -38,7 +38,7 @@ use crate::abi::call::Conv;
|
||||
use crate::abi::{Endian, Integer, Size, TargetDataLayout, TargetDataLayoutErrors};
|
||||
use crate::json::{Json, ToJson};
|
||||
use crate::spec::abi::{lookup as lookup_abi, Abi};
|
||||
use crate::spec::crt_objects::{CrtObjects, LinkSelfContainedDefault};
|
||||
use crate::spec::crt_objects::CrtObjects;
|
||||
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
|
||||
use rustc_fs_util::try_canonicalize;
|
||||
use rustc_serialize::{Decodable, Decoder, Encodable, Encoder};
|
||||
@@ -542,7 +542,7 @@ impl ToJson for LinkerFlavorCli {
|
||||
/// - explicitly enabling some of the self-contained linking components, e.g. the linker component
|
||||
/// to use `rust-lld`
|
||||
#[derive(Clone, Copy, PartialEq, Debug)]
|
||||
pub enum LinkSelfContained {
|
||||
pub enum LinkSelfContainedDefault {
|
||||
/// The target spec explicitly enables self-contained linking.
|
||||
True,
|
||||
|
||||
@@ -560,10 +560,25 @@ pub enum LinkSelfContained {
|
||||
WithComponents(LinkSelfContainedComponents),
|
||||
}
|
||||
|
||||
impl ToJson for LinkSelfContained {
|
||||
/// Parses a backwards-compatible `-Clink-self-contained` option string, without components.
|
||||
impl FromStr for LinkSelfContainedDefault {
|
||||
type Err = ();
|
||||
|
||||
fn from_str(s: &str) -> Result<LinkSelfContainedDefault, ()> {
|
||||
Ok(match s {
|
||||
"false" => LinkSelfContainedDefault::False,
|
||||
"true" | "wasm" => LinkSelfContainedDefault::True,
|
||||
"musl" => LinkSelfContainedDefault::InferredForMusl,
|
||||
"mingw" => LinkSelfContainedDefault::InferredForMingw,
|
||||
_ => return Err(()),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl ToJson for LinkSelfContainedDefault {
|
||||
fn to_json(&self) -> Json {
|
||||
match *self {
|
||||
LinkSelfContained::WithComponents(components) => {
|
||||
LinkSelfContainedDefault::WithComponents(components) => {
|
||||
// Serialize the components in a json object's `components` field, to prepare for a
|
||||
// future where `crt-objects-fallback` is removed from the json specs and
|
||||
// incorporated as a field here.
|
||||
@@ -572,29 +587,31 @@ impl ToJson for LinkSelfContained {
|
||||
map.to_json()
|
||||
}
|
||||
|
||||
// Stable values backwards-compatible with `LinkSelfContainedDefault`
|
||||
LinkSelfContained::True => "true".to_json(),
|
||||
LinkSelfContained::False => "false".to_json(),
|
||||
LinkSelfContained::InferredForMusl => "musl".to_json(),
|
||||
LinkSelfContained::InferredForMingw => "mingw".to_json(),
|
||||
// Stable backwards-compatible values
|
||||
LinkSelfContainedDefault::True => "true".to_json(),
|
||||
LinkSelfContainedDefault::False => "false".to_json(),
|
||||
LinkSelfContainedDefault::InferredForMusl => "musl".to_json(),
|
||||
LinkSelfContainedDefault::InferredForMingw => "mingw".to_json(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl LinkSelfContained {
|
||||
impl LinkSelfContainedDefault {
|
||||
/// Returns whether the target spec has self-contained linking explicitly disabled. Used to emit
|
||||
/// errors if the user then enables it on the CLI.
|
||||
pub fn is_disabled(self) -> bool {
|
||||
self == LinkSelfContained::False
|
||||
self == LinkSelfContainedDefault::False
|
||||
}
|
||||
|
||||
/// Returns whether the target spec explictly requests self-contained linking, i.e. not via
|
||||
/// inference.
|
||||
pub fn is_linker_enabled(self) -> bool {
|
||||
match self {
|
||||
LinkSelfContained::True => true,
|
||||
LinkSelfContained::False => false,
|
||||
LinkSelfContained::WithComponents(c) => c.contains(LinkSelfContainedComponents::LINKER),
|
||||
LinkSelfContainedDefault::True => true,
|
||||
LinkSelfContainedDefault::False => false,
|
||||
LinkSelfContainedDefault::WithComponents(c) => {
|
||||
c.contains(LinkSelfContainedComponents::LINKER)
|
||||
}
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
@@ -604,23 +621,12 @@ impl LinkSelfContained {
|
||||
/// - the other variants as a backwards-compatible `crt-objects-fallback` string
|
||||
fn json_key(self) -> &'static str {
|
||||
match self {
|
||||
LinkSelfContained::WithComponents(_) => "link-self-contained",
|
||||
LinkSelfContainedDefault::WithComponents(_) => "link-self-contained",
|
||||
_ => "crt-objects-fallback",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<LinkSelfContainedDefault> for LinkSelfContained {
|
||||
fn from(value: LinkSelfContainedDefault) -> Self {
|
||||
match value {
|
||||
LinkSelfContainedDefault::True => LinkSelfContained::True,
|
||||
LinkSelfContainedDefault::False => LinkSelfContained::False,
|
||||
LinkSelfContainedDefault::Musl => LinkSelfContained::InferredForMusl,
|
||||
LinkSelfContainedDefault::Mingw => LinkSelfContained::InferredForMingw,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bitflags::bitflags! {
|
||||
#[derive(Default)]
|
||||
/// The `-C link-self-contained` components that can individually be enabled or disabled.
|
||||
@@ -1888,7 +1894,7 @@ pub struct TargetOptions {
|
||||
pub post_link_objects_self_contained: CrtObjects,
|
||||
/// Behavior for the self-contained linking mode: inferred for some targets, or explicitly
|
||||
/// enabled (in bulk, or with individual components).
|
||||
pub link_self_contained: LinkSelfContained,
|
||||
pub link_self_contained: LinkSelfContainedDefault,
|
||||
|
||||
/// Linker arguments that are passed *before* any user-defined libraries.
|
||||
pub pre_link_args: LinkArgs,
|
||||
@@ -2363,7 +2369,7 @@ impl Default for TargetOptions {
|
||||
post_link_objects: Default::default(),
|
||||
pre_link_objects_self_contained: Default::default(),
|
||||
post_link_objects_self_contained: Default::default(),
|
||||
link_self_contained: LinkSelfContained::False,
|
||||
link_self_contained: LinkSelfContainedDefault::False,
|
||||
pre_link_args: LinkArgs::new(),
|
||||
pre_link_args_json: LinkArgsCli::new(),
|
||||
late_link_args: LinkArgs::new(),
|
||||
@@ -2844,7 +2850,7 @@ impl Target {
|
||||
}
|
||||
Ok::<(), String>(())
|
||||
} );
|
||||
($key_name:ident, LinkSelfContained) => ( {
|
||||
($key_name:ident, link_self_contained_components) => ( {
|
||||
// Skeleton of what needs to be parsed:
|
||||
//
|
||||
// ```
|
||||
@@ -2873,18 +2879,18 @@ impl Target {
|
||||
_ => return Err(format!("not a string: {:?}", s)),
|
||||
};
|
||||
}
|
||||
base.$key_name = LinkSelfContained::WithComponents(components);
|
||||
base.$key_name = LinkSelfContainedDefault::WithComponents(components);
|
||||
} else {
|
||||
incorrect_type.push(name)
|
||||
}
|
||||
}
|
||||
Ok::<(), String>(())
|
||||
} );
|
||||
($key_name:ident = $json_name:expr, LinkSelfContainedDefault) => ( {
|
||||
($key_name:ident = $json_name:expr, link_self_contained_backwards_compatible) => ( {
|
||||
let name = $json_name;
|
||||
obj.remove(name).and_then(|o| o.as_str().and_then(|s| {
|
||||
match s.parse::<LinkSelfContainedDefault>() {
|
||||
Ok(lsc_default) => base.$key_name = lsc_default.into(),
|
||||
Ok(lsc_default) => base.$key_name = lsc_default,
|
||||
_ => return Some(Err(format!("'{}' is not a valid `-Clink-self-contained` default. \
|
||||
Use 'false', 'true', 'musl' or 'mingw'", s))),
|
||||
}
|
||||
@@ -3034,9 +3040,12 @@ impl Target {
|
||||
key!(pre_link_objects_self_contained = "pre-link-objects-fallback", link_objects);
|
||||
key!(post_link_objects_self_contained = "post-link-objects-fallback", link_objects);
|
||||
// Deserializes the backwards-compatible variants of `-Clink-self-contained`
|
||||
key!(link_self_contained = "crt-objects-fallback", LinkSelfContainedDefault)?;
|
||||
key!(
|
||||
link_self_contained = "crt-objects-fallback",
|
||||
link_self_contained_backwards_compatible
|
||||
)?;
|
||||
// Deserializes the components variant of `-Clink-self-contained`
|
||||
key!(link_self_contained, LinkSelfContained)?;
|
||||
key!(link_self_contained, link_self_contained_components)?;
|
||||
key!(pre_link_args_json = "pre-link-args", link_args);
|
||||
key!(late_link_args_json = "late-link-args", link_args);
|
||||
key!(late_link_args_dynamic_json = "late-link-args-dynamic", link_args);
|
||||
|
||||
Reference in New Issue
Block a user