implement opt out -Clink-self-contained=-linker
record both enabled and disabled components so that they can be merged with the ones that the target spec will define
This commit is contained in:
parent
2ce46f8e8c
commit
5b9aa26401
@ -2978,8 +2978,9 @@ fn add_lld_args(cmd: &mut dyn Linker, sess: &Session, flavor: LinkerFlavor) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 1. Implement the "self-contained" part of this feature by adding rustc distribution
|
// 1. Implement the "self-contained" part of this feature by adding rustc distribution
|
||||||
// directories to the tool's search path.
|
// directories to the tool's search path:
|
||||||
if sess.opts.cg.link_self_contained.linker() {
|
// - if the self-contained linker is enabled on the CLI.
|
||||||
|
if sess.opts.cg.link_self_contained.is_linker_enabled() {
|
||||||
for path in sess.get_tools_search_paths(false) {
|
for path in sess.get_tools_search_paths(false) {
|
||||||
cmd.arg({
|
cmd.arg({
|
||||||
let mut arg = OsString::from("-B");
|
let mut arg = OsString::from("-B");
|
||||||
@ -2990,7 +2991,7 @@ fn add_lld_args(cmd: &mut dyn Linker, sess: &Session, flavor: LinkerFlavor) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 2. Implement the "linker flavor" part of this feature by asking `cc` to use some kind of
|
// 2. Implement the "linker flavor" part of this feature by asking `cc` to use some kind of
|
||||||
// `lld` as the linker.
|
// `lld` as the linker.
|
||||||
cmd.arg("-fuse-ld=lld");
|
cmd.arg("-fuse-ld=lld");
|
||||||
|
|
||||||
if !flavor.is_gnu() {
|
if !flavor.is_gnu() {
|
||||||
|
@ -233,8 +233,13 @@ pub struct LinkSelfContained {
|
|||||||
/// Used for compatibility with the existing opt-in and target inference.
|
/// Used for compatibility with the existing opt-in and target inference.
|
||||||
pub explicitly_set: Option<bool>,
|
pub explicitly_set: Option<bool>,
|
||||||
|
|
||||||
/// The components that are enabled.
|
/// The components that are enabled on the CLI, using the `+component` syntax or one of the
|
||||||
components: LinkSelfContainedComponents,
|
/// `true` shorcuts.
|
||||||
|
enabled_components: LinkSelfContainedComponents,
|
||||||
|
|
||||||
|
/// The components that are disabled on the CLI, using the `-component` syntax or one of the
|
||||||
|
/// `false` shortcuts.
|
||||||
|
disabled_components: LinkSelfContainedComponents,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl LinkSelfContained {
|
impl LinkSelfContained {
|
||||||
@ -247,11 +252,13 @@ impl LinkSelfContained {
|
|||||||
// `explicitly_set` state.
|
// `explicitly_set` state.
|
||||||
if let Some(component_to_enable) = component.strip_prefix('+') {
|
if let Some(component_to_enable) = component.strip_prefix('+') {
|
||||||
self.explicitly_set = None;
|
self.explicitly_set = None;
|
||||||
self.components.insert(LinkSelfContainedComponents::from_str(component_to_enable)?);
|
self.enabled_components
|
||||||
|
.insert(LinkSelfContainedComponents::from_str(component_to_enable)?);
|
||||||
Some(())
|
Some(())
|
||||||
} else if let Some(component_to_disable) = component.strip_prefix('-') {
|
} else if let Some(component_to_disable) = component.strip_prefix('-') {
|
||||||
self.explicitly_set = None;
|
self.explicitly_set = None;
|
||||||
self.components.remove(LinkSelfContainedComponents::from_str(component_to_disable)?);
|
self.disabled_components
|
||||||
|
.insert(LinkSelfContainedComponents::from_str(component_to_disable)?);
|
||||||
Some(())
|
Some(())
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
@ -262,11 +269,14 @@ impl LinkSelfContained {
|
|||||||
/// purposes.
|
/// purposes.
|
||||||
pub(crate) fn set_all_explicitly(&mut self, enabled: bool) {
|
pub(crate) fn set_all_explicitly(&mut self, enabled: bool) {
|
||||||
self.explicitly_set = Some(enabled);
|
self.explicitly_set = Some(enabled);
|
||||||
self.components = if enabled {
|
|
||||||
LinkSelfContainedComponents::all()
|
if enabled {
|
||||||
|
self.enabled_components = LinkSelfContainedComponents::all();
|
||||||
|
self.disabled_components = LinkSelfContainedComponents::empty();
|
||||||
} else {
|
} else {
|
||||||
LinkSelfContainedComponents::empty()
|
self.enabled_components = LinkSelfContainedComponents::empty();
|
||||||
};
|
self.disabled_components = LinkSelfContainedComponents::all();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Helper creating a fully enabled `LinkSelfContained` instance. Used in tests.
|
/// Helper creating a fully enabled `LinkSelfContained` instance. Used in tests.
|
||||||
@ -280,13 +290,21 @@ impl LinkSelfContained {
|
|||||||
/// components was set individually. This would also require the `-Zunstable-options` flag, to
|
/// components was set individually. This would also require the `-Zunstable-options` flag, to
|
||||||
/// be allowed.
|
/// be allowed.
|
||||||
fn are_unstable_variants_set(&self) -> bool {
|
fn are_unstable_variants_set(&self) -> bool {
|
||||||
let any_component_set = !self.components.is_empty();
|
let any_component_set =
|
||||||
|
!self.enabled_components.is_empty() || !self.disabled_components.is_empty();
|
||||||
self.explicitly_set.is_none() && any_component_set
|
self.explicitly_set.is_none() && any_component_set
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns whether the self-contained linker component is enabled.
|
/// Returns whether the self-contained linker component was enabled on the CLI, using the
|
||||||
pub fn linker(&self) -> bool {
|
/// `-C link-self-contained=+linker` syntax, or one of the `true` shorcuts.
|
||||||
self.components.contains(LinkSelfContainedComponents::LINKER)
|
pub fn is_linker_enabled(&self) -> bool {
|
||||||
|
self.enabled_components.contains(LinkSelfContainedComponents::LINKER)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Returns whether the self-contained linker component was disabled on the CLI, using the
|
||||||
|
/// `-C link-self-contained=-linker` syntax, or one of the `false` shorcuts.
|
||||||
|
pub fn is_linker_disabled(&self) -> bool {
|
||||||
|
self.disabled_components.contains(LinkSelfContainedComponents::LINKER)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user