Skip to content

Commit 7b52ad0

Browse files
committedAug 9, 2021
Auto merge of #87619 - 12101111:fix-native_link_modifiers_bundle, r=petrochenkov
Fix feature gate checking of static-nobundle and native_link_modifiers Feature native_link_modifiers_bundle don't need feature static-nobundle to work. Also check the feature gates when using native_link_modifiers from command line options. Current nighly compiler don't check those feature gate. ``` > touch lib.rs > rustc +nightly lib.rs -L /usr/lib -l static:+bundle=dl --crate-type=rlib > rustc +nightly lib.rs -L /usr/lib -l dylib:+as-needed=dl --crate-type=dylib -Ctarget-feature=-crt-static > rustc +nightly lib.rs -L /usr/lib -l static:-bundle=dl --crate-type=rlib error[E0658]: kind="static-nobundle" is unstable | = note: see issue #37403 <#37403> for more information = help: add `#![feature(static_nobundle)]` to the crate attributes to enable error: aborting due to previous error For more information about this error, try `rustc --explain E0658`. ``` First found this in #85600 (comment)
2 parents d3928b1 + d935a14 commit 7b52ad0

8 files changed

+75
-43
lines changed
 

‎compiler/rustc_metadata/src/native_libs.rs

+9-11
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,15 @@ impl ItemLikeVisitor<'tcx> for Collector<'tcx> {
7777
modifier `-bundle` with library kind `static`",
7878
)
7979
.emit();
80+
if !self.tcx.features().static_nobundle {
81+
feature_err(
82+
&self.tcx.sess.parse_sess,
83+
sym::static_nobundle,
84+
item.span(),
85+
"kind=\"static-nobundle\" is unstable",
86+
)
87+
.emit();
88+
}
8089
NativeLibKind::Static { bundle: Some(false), whole_archive: None }
8190
}
8291
"dylib" => NativeLibKind::Dylib { as_needed: None },
@@ -252,17 +261,6 @@ impl Collector<'tcx> {
252261
)
253262
.emit();
254263
}
255-
if matches!(lib.kind, NativeLibKind::Static { bundle: Some(false), .. })
256-
&& !self.tcx.features().static_nobundle
257-
{
258-
feature_err(
259-
&self.tcx.sess.parse_sess,
260-
sym::static_nobundle,
261-
span.unwrap_or(rustc_span::DUMMY_SP),
262-
"kind=\"static-nobundle\" is unstable",
263-
)
264-
.emit();
265-
}
266264
// this just unwraps lib.name; we already established that it isn't empty above.
267265
if let (NativeLibKind::RawDylib, Some(lib_name)) = (lib.kind, lib.name) {
268266
let span = match span {

‎compiler/rustc_session/src/config.rs

+48-19
Original file line numberDiff line numberDiff line change
@@ -1609,8 +1609,20 @@ fn select_debuginfo(
16091609
}
16101610
}
16111611

1612-
fn parse_native_lib_kind(kind: &str, error_format: ErrorOutputType) -> NativeLibKind {
1613-
match kind {
1612+
fn parse_native_lib_kind(
1613+
matches: &getopts::Matches,
1614+
kind: &str,
1615+
error_format: ErrorOutputType,
1616+
) -> (NativeLibKind, Option<bool>) {
1617+
let is_nightly = nightly_options::match_is_nightly_build(matches);
1618+
let enable_unstable = nightly_options::is_unstable_enabled(matches);
1619+
1620+
let (kind, modifiers) = match kind.split_once(':') {
1621+
None => (kind, None),
1622+
Some((kind, modifiers)) => (kind, Some(modifiers)),
1623+
};
1624+
1625+
let kind = match kind {
16141626
"dylib" => NativeLibKind::Dylib { as_needed: None },
16151627
"framework" => NativeLibKind::Framework { as_needed: None },
16161628
"static" => NativeLibKind::Static { bundle: None, whole_archive: None },
@@ -1620,17 +1632,49 @@ fn parse_native_lib_kind(kind: &str, error_format: ErrorOutputType) -> NativeLib
16201632
"library kind `static-nobundle` has been superseded by specifying \
16211633
`-bundle` on library kind `static`. Try `static:-bundle`",
16221634
);
1635+
if modifiers.is_some() {
1636+
early_error(
1637+
error_format,
1638+
"linking modifier can't be used with library kind `static-nobundle`",
1639+
)
1640+
}
1641+
if !is_nightly {
1642+
early_error(
1643+
error_format,
1644+
"library kind `static-nobundle` are currently unstable and only accepted on \
1645+
the nightly compiler",
1646+
);
1647+
}
16231648
NativeLibKind::Static { bundle: Some(false), whole_archive: None }
16241649
}
16251650
s => early_error(
16261651
error_format,
16271652
&format!("unknown library kind `{}`, expected one of dylib, framework, or static", s),
16281653
),
1654+
};
1655+
match modifiers {
1656+
None => (kind, None),
1657+
Some(modifiers) => {
1658+
if !is_nightly {
1659+
early_error(
1660+
error_format,
1661+
"linking modifiers are currently unstable and only accepted on \
1662+
the nightly compiler",
1663+
);
1664+
}
1665+
if !enable_unstable {
1666+
early_error(
1667+
error_format,
1668+
"linking modifiers are currently unstable, \
1669+
the `-Z unstable-options` flag must also be passed to use it",
1670+
)
1671+
}
1672+
parse_native_lib_modifiers(kind, modifiers, error_format)
1673+
}
16291674
}
16301675
}
16311676

16321677
fn parse_native_lib_modifiers(
1633-
is_nightly: bool,
16341678
mut kind: NativeLibKind,
16351679
modifiers: &str,
16361680
error_format: ErrorOutputType,
@@ -1646,14 +1690,6 @@ fn parse_native_lib_modifiers(
16461690
),
16471691
};
16481692

1649-
if !is_nightly {
1650-
early_error(
1651-
error_format,
1652-
"linking modifiers are currently unstable and only accepted on \
1653-
the nightly compiler",
1654-
);
1655-
}
1656-
16571693
match (modifier, &mut kind) {
16581694
("bundle", NativeLibKind::Static { bundle, .. }) => {
16591695
*bundle = Some(value);
@@ -1700,7 +1736,6 @@ fn parse_native_lib_modifiers(
17001736
}
17011737

17021738
fn parse_libs(matches: &getopts::Matches, error_format: ErrorOutputType) -> Vec<NativeLib> {
1703-
let is_nightly = nightly_options::match_is_nightly_build(matches);
17041739
matches
17051740
.opt_strs("l")
17061741
.into_iter()
@@ -1714,13 +1749,7 @@ fn parse_libs(matches: &getopts::Matches, error_format: ErrorOutputType) -> Vec<
17141749
let (name, kind, verbatim) = match s.split_once('=') {
17151750
None => (s, NativeLibKind::Unspecified, None),
17161751
Some((kind, name)) => {
1717-
let (kind, verbatim) = match kind.split_once(':') {
1718-
None => (parse_native_lib_kind(kind, error_format), None),
1719-
Some((kind, modifiers)) => {
1720-
let kind = parse_native_lib_kind(kind, error_format);
1721-
parse_native_lib_modifiers(is_nightly, kind, modifiers, error_format)
1722-
}
1723-
};
1752+
let (kind, verbatim) = parse_native_lib_kind(matches, kind, error_format);
17241753
(name.to_string(), kind, verbatim)
17251754
}
17261755
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// Test native_link_modifiers_bundle don't need static-nobundle
2+
// check-pass
3+
4+
#![feature(native_link_modifiers)]
5+
#![feature(native_link_modifiers_bundle)]
6+
7+
#[link(name = "foo", kind = "static", modifiers = "-bundle")]
8+
extern "C" {}
9+
10+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// compile-flags: -l static:-bundle=nonexistent
2+
3+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
error: linking modifiers are currently unstable, the `-Z unstable-options` flag must also be passed to use it
2+
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
//~ ERROR kind="static-nobundle" is unstable
2-
// Test the behavior of rustc when non-existent library is statically linked
3-
1+
// check-pass
42
// compile-flags: -l static-nobundle=nonexistent
53

64
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,2 @@
11
warning: library kind `static-nobundle` has been superseded by specifying `-bundle` on library kind `static`. Try `static:-bundle`
22

3-
error[E0658]: kind="static-nobundle" is unstable
4-
|
5-
= note: see issue #37403 <https://github.com/rust-lang/rust/issues/37403> for more information
6-
= help: add `#![feature(static_nobundle)]` to the crate attributes to enable
7-
8-
error: aborting due to previous error
9-
10-
For more information about this error, try `rustc --explain E0658`.

‎src/test/ui/feature-gates/feature-gate-static-nobundle.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ LL | #[link(name = "foo", kind = "static-nobundle")]
55
| ^^^^^^^^^^^^^^^^^^^^^^^^
66

77
error[E0658]: kind="static-nobundle" is unstable
8-
--> $DIR/feature-gate-static-nobundle.rs:1:1
8+
--> $DIR/feature-gate-static-nobundle.rs:1:22
99
|
1010
LL | #[link(name = "foo", kind = "static-nobundle")]
11-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
11+
| ^^^^^^^^^^^^^^^^^^^^^^^^
1212
|
1313
= note: see issue #37403 <https://github.com/rust-lang/rust/issues/37403> for more information
1414
= help: add `#![feature(static_nobundle)]` to the crate attributes to enable

0 commit comments

Comments
 (0)