Skip to content

Commit 1117bc1

Browse files
committed
only stabilize -Clink-self-contained=-linker on x64 linux
Some combinations of opt-ins and other flags need more work to be stabilized, so we can only stabilize the opt-outs.
1 parent ef99848 commit 1117bc1

14 files changed

+45
-46
lines changed

compiler/rustc_session/src/config.rs

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -375,28 +375,22 @@ impl LinkSelfContained {
375375
return Ok(());
376376
}
377377

378-
// `-C link-self-contained=[-+]linker` is only stable on x64 linux.
379-
let check_linker = |components: LinkSelfContainedComponents, polarity: &str| {
380-
let has_linker = components.is_linker_enabled();
381-
if has_linker && target_tuple.tuple() != "x86_64-unknown-linux-gnu" {
382-
return Err(format!(
383-
"`-C link-self-contained={polarity}linker` is unstable on the `{target_tuple}` \
378+
// `-C link-self-contained=-linker` is only stable on x64 linux.
379+
let has_minus_linker = self.disabled_components.is_linker_enabled();
380+
if has_minus_linker && target_tuple.tuple() != "x86_64-unknown-linux-gnu" {
381+
return Err(format!(
382+
"`-C link-self-contained=-linker` is unstable on the `{target_tuple}` \
384383
target. The `-Z unstable-options` flag must also be passed to use it on this target",
385-
));
386-
}
387-
Ok(())
388-
};
389-
check_linker(self.enabled_components, "+")?;
390-
check_linker(self.disabled_components, "-")?;
384+
));
385+
}
391386

392-
// Since only the linker component is stable, any other component used is unstable, and
393-
// that's an error.
394-
let unstable_enabled = self.enabled_components - LinkSelfContainedComponents::LINKER;
387+
// Any `+linker` or other component used is unstable, and that's an error.
388+
let unstable_enabled = self.enabled_components;
395389
let unstable_disabled = self.disabled_components - LinkSelfContainedComponents::LINKER;
396390
if !unstable_enabled.union(unstable_disabled).is_empty() {
397391
return Err(String::from(
398-
"only `-C link-self-contained` values `y`/`yes`/`on`/`n`/`no`/`off`/`-linker`\
399-
/`+linker` are stable, the `-Z unstable-options` flag must also be passed to use \
392+
"only `-C link-self-contained` values `y`/`yes`/`on`/`n`/`no`/`off`/`-linker` \
393+
are stable, the `-Z unstable-options` flag must also be passed to use \
400394
the unstable values",
401395
));
402396
}

tests/run-make/rust-lld/rmake.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ fn main() {
1414
rustc()
1515
.arg("-Clinker-features=+lld")
1616
.arg("-Clink-self-contained=+linker")
17-
.arg("-Zunstable-options") // needed for targets other than `x86_64-unknown-linux-gnu`
17+
.arg("-Zunstable-options") // the opt-ins are unstable
1818
.input("main.rs"),
1919
);
2020

tests/ui/linking/link-self-contained-linker-disallowed-target.positive.stderr

Lines changed: 0 additions & 2 deletions
This file was deleted.

tests/ui/linking/link-self-contained-linker-disallowed-target.rs

Lines changed: 0 additions & 16 deletions
This file was deleted.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Check that only `-C link-self-contained=-linker` is stable on x64 linux. Any other value or
2+
// target, needs `-Z unstable-options`.
3+
4+
// ignore-tidy-linelength
5+
6+
//@ revisions: unstable_target_positive unstable_target_negative unstable_positive
7+
//@ [unstable_target_negative] compile-flags: --target=x86_64-unknown-linux-musl -C link-self-contained=-linker --crate-type=rlib
8+
//@ [unstable_target_negative] needs-llvm-components: x86
9+
//@ [unstable_target_positive] compile-flags: --target=x86_64-unknown-linux-musl -C link-self-contained=+linker --crate-type=rlib
10+
//@ [unstable_target_positive] needs-llvm-components: x86
11+
//@ [unstable_positive] compile-flags: --target=x86_64-unknown-linux-gnu -C link-self-contained=+linker --crate-type=rlib
12+
//@ [unstable_positive] needs-llvm-components: x86
13+
14+
#![feature(no_core)]
15+
#![no_core]
16+
17+
//[unstable_target_negative]~? ERROR `-C link-self-contained=-linker` is unstable on the `x86_64-unknown-linux-musl` target
18+
//[unstable_target_positive]~? ERROR only `-C link-self-contained` values `y`/`yes`/`on`/`n`/`no`/`off`/`-linker` are stable
19+
//[unstable_positive]~? ERROR only `-C link-self-contained` values `y`/`yes`/`on`/`n`/`no`/`off`/`-linker` are stable
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
error: only `-C link-self-contained` values `y`/`yes`/`on`/`n`/`no`/`off`/`-linker` are stable, the `-Z unstable-options` flag must also be passed to use the unstable values
2+
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
error: only `-C link-self-contained` values `y`/`yes`/`on`/`n`/`no`/`off`/`-linker` are stable, the `-Z unstable-options` flag must also be passed to use the unstable values
2+
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
error: only `-C link-self-contained` values `y`/`yes`/`on`/`n`/`no`/`off`/`-linker`/`+linker` are stable, the `-Z unstable-options` flag must also be passed to use the unstable values
1+
error: only `-C link-self-contained` values `y`/`yes`/`on`/`n`/`no`/`off`/`-linker` are stable, the `-Z unstable-options` flag must also be passed to use the unstable values
22

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
error: only `-C link-self-contained` values `y`/`yes`/`on`/`n`/`no`/`off`/`-linker`/`+linker` are stable, the `-Z unstable-options` flag must also be passed to use the unstable values
1+
error: only `-C link-self-contained` values `y`/`yes`/`on`/`n`/`no`/`off`/`-linker` are stable, the `-Z unstable-options` flag must also be passed to use the unstable values
22

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
error: only `-C link-self-contained` values `y`/`yes`/`on`/`n`/`no`/`off`/`-linker`/`+linker` are stable, the `-Z unstable-options` flag must also be passed to use the unstable values
1+
error: only `-C link-self-contained` values `y`/`yes`/`on`/`n`/`no`/`off`/`-linker` are stable, the `-Z unstable-options` flag must also be passed to use the unstable values
22

tests/ui/linking/link-self-contained-unstable.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010

1111
fn main() {}
1212

13-
//[crto]~? ERROR only `-C link-self-contained` values `y`/`yes`/`on`/`n`/`no`/`off`/`-linker`/`+linker` are stable
14-
//[libc]~? ERROR only `-C link-self-contained` values `y`/`yes`/`on`/`n`/`no`/`off`/`-linker`/`+linker` are stable
15-
//[unwind]~? ERROR only `-C link-self-contained` values `y`/`yes`/`on`/`n`/`no`/`off`/`-linker`/`+linker` are stable
16-
//[sanitizers]~? ERROR only `-C link-self-contained` values `y`/`yes`/`on`/`n`/`no`/`off`/`-linker`/`+linker` are stable
17-
//[mingw]~? ERROR only `-C link-self-contained` values `y`/`yes`/`on`/`n`/`no`/`off`/`-linker`/`+linker` are stable
13+
//[crto]~? ERROR only `-C link-self-contained` values `y`/`yes`/`on`/`n`/`no`/`off`/`-linker` are stable
14+
//[libc]~? ERROR only `-C link-self-contained` values `y`/`yes`/`on`/`n`/`no`/`off`/`-linker` are stable
15+
//[unwind]~? ERROR only `-C link-self-contained` values `y`/`yes`/`on`/`n`/`no`/`off`/`-linker` are stable
16+
//[sanitizers]~? ERROR only `-C link-self-contained` values `y`/`yes`/`on`/`n`/`no`/`off`/`-linker` are stable
17+
//[mingw]~? ERROR only `-C link-self-contained` values `y`/`yes`/`on`/`n`/`no`/`off`/`-linker` are stable
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
error: only `-C link-self-contained` values `y`/`yes`/`on`/`n`/`no`/`off`/`-linker`/`+linker` are stable, the `-Z unstable-options` flag must also be passed to use the unstable values
1+
error: only `-C link-self-contained` values `y`/`yes`/`on`/`n`/`no`/`off`/`-linker` are stable, the `-Z unstable-options` flag must also be passed to use the unstable values
22

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
error: only `-C link-self-contained` values `y`/`yes`/`on`/`n`/`no`/`off`/`-linker`/`+linker` are stable, the `-Z unstable-options` flag must also be passed to use the unstable values
1+
error: only `-C link-self-contained` values `y`/`yes`/`on`/`n`/`no`/`off`/`-linker` are stable, the `-Z unstable-options` flag must also be passed to use the unstable values
22

0 commit comments

Comments
 (0)