Skip to content

Commit 38dca73

Browse files
committed
require -Zunstable-options to use new link-self-contained values and
linker flavors - only the stable values for `-Clink-self-contained` can be used on stable until we have more feedback on the interface - `-Zunstable-options` is required to use unstable linker flavors
1 parent 051e94d commit 38dca73

File tree

2 files changed

+53
-10
lines changed

2 files changed

+53
-10
lines changed

compiler/rustc_session/src/config.rs

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use crate::{EarlyErrorHandler, Session};
1111
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
1212
use rustc_data_structures::stable_hasher::{StableOrd, ToStableHashKey};
1313
use rustc_target::abi::Align;
14-
use rustc_target::spec::{LinkerFlavorCli, PanicStrategy, SanitizerSet, SplitDebuginfo};
14+
use rustc_target::spec::{PanicStrategy, SanitizerSet, SplitDebuginfo};
1515
use rustc_target::spec::{Target, TargetTriple, TargetWarnings, TARGETS};
1616

1717
use crate::parse::{CrateCheckConfig, CrateConfig};
@@ -308,6 +308,14 @@ impl LinkSelfContained {
308308
on
309309
}
310310

311+
/// To help checking CLI usage while some of the values are unstable: returns whether one of the
312+
/// components was set individually. This would also require the `-Zunstable-options` flag, to
313+
/// be allowed.
314+
fn are_unstable_variants_set(&self) -> bool {
315+
let any_component_set = !self.components.is_empty();
316+
self.explicitly_set.is_none() && any_component_set
317+
}
318+
311319
/// Returns whether the self-contained linker component is enabled.
312320
pub fn linker(&self) -> bool {
313321
self.components.contains(LinkSelfContainedComponents::LINKER)
@@ -2648,16 +2656,28 @@ pub fn build_session_options(
26482656
}
26492657
}
26502658

2651-
if let Some(flavor) = cg.linker_flavor {
2652-
if matches!(flavor, LinkerFlavorCli::BpfLinker | LinkerFlavorCli::PtxLinker)
2653-
&& !nightly_options::is_unstable_enabled(matches)
2654-
{
2655-
let msg = format!(
2656-
"linker flavor `{}` is unstable, `-Z unstable-options` \
2657-
flag must also be passed to explicitly use it",
2658-
flavor.desc()
2659+
// For testing purposes, until we have more feedback about these options: ensure `-Z
2660+
// unstable-options` is required when using the unstable `-C link-self-contained` options, like
2661+
// `-C link-self-contained=+linker`, and when using the unstable `-C linker-flavor` options, like
2662+
// `-C linker-flavor=gnu-lld-cc`.
2663+
if !nightly_options::is_unstable_enabled(matches) {
2664+
let uses_unstable_self_contained_option =
2665+
cg.link_self_contained.are_unstable_variants_set();
2666+
if uses_unstable_self_contained_option {
2667+
handler.early_error(
2668+
"only `-C link-self-contained` values `y`/`yes`/`on`/`n`/`no`/`off` are stable, \
2669+
the `-Z unstable-options` flag must also be passed to use the unstable values",
26592670
);
2660-
handler.early_error(msg);
2671+
}
2672+
2673+
if let Some(flavor) = cg.linker_flavor {
2674+
if flavor.is_unstable() {
2675+
handler.early_error(format!(
2676+
"the linker flavor `{}` is unstable, the `-Z unstable-options` \
2677+
flag must also be passed to use the unstable values",
2678+
flavor.desc()
2679+
));
2680+
}
26612681
}
26622682
}
26632683

compiler/rustc_target/src/spec/mod.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,29 @@ pub enum LinkerFlavorCli {
181181
PtxLinker,
182182
}
183183

184+
impl LinkerFlavorCli {
185+
/// Returns whether this `-C linker-flavor` option is one of the unstable values.
186+
pub fn is_unstable(&self) -> bool {
187+
match self {
188+
LinkerFlavorCli::Gnu(..)
189+
| LinkerFlavorCli::Darwin(..)
190+
| LinkerFlavorCli::WasmLld(..)
191+
| LinkerFlavorCli::Unix(..)
192+
| LinkerFlavorCli::Msvc(Lld::Yes)
193+
| LinkerFlavorCli::EmCc
194+
| LinkerFlavorCli::Bpf
195+
| LinkerFlavorCli::Ptx
196+
| LinkerFlavorCli::BpfLinker
197+
| LinkerFlavorCli::PtxLinker => true,
198+
LinkerFlavorCli::Gcc
199+
| LinkerFlavorCli::Ld
200+
| LinkerFlavorCli::Lld(..)
201+
| LinkerFlavorCli::Msvc(Lld::No)
202+
| LinkerFlavorCli::Em => false,
203+
}
204+
}
205+
}
206+
184207
#[derive(Clone, Copy, Debug, Eq, Ord, PartialEq, PartialOrd)]
185208
pub enum LldFlavor {
186209
Wasm,

0 commit comments

Comments
 (0)