Skip to content

Commit e70ffed

Browse files
committed
Add feature gate for raw_dylib.
1 parent 4ac4809 commit e70ffed

File tree

11 files changed

+78
-5
lines changed

11 files changed

+78
-5
lines changed

src/librustc/middle/cstore.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@ pub enum NativeLibraryKind {
9696
NativeStaticNobundle,
9797
/// macOS-specific
9898
NativeFramework,
99+
/// windows dynamic library without import library
100+
NativeRawDylib,
99101
/// default way to specify a dynamic library
100102
NativeUnknown,
101103
}

src/librustc_codegen_ssa/back/link.rs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,7 @@ fn link_rlib<'a, B: ArchiveBuilder<'a>>(sess: &'a Session,
323323
NativeLibraryKind::NativeStatic => {}
324324
NativeLibraryKind::NativeStaticNobundle |
325325
NativeLibraryKind::NativeFramework |
326+
NativeLibraryKind::NativeRawDylib |
326327
NativeLibraryKind::NativeUnknown => continue,
327328
}
328329
if let Some(name) = lib.name {
@@ -883,7 +884,8 @@ pub fn print_native_static_libs(sess: &Session, all_native_libs: &[NativeLibrary
883884
Some(format!("-framework {}", name))
884885
},
885886
// These are included, no need to print them
886-
NativeLibraryKind::NativeStatic => None,
887+
NativeLibraryKind::NativeStatic |
888+
NativeLibraryKind::NativeRawDylib => None,
887889
}
888890
})
889891
.collect();
@@ -1293,7 +1295,11 @@ pub fn add_local_native_libraries(cmd: &mut dyn Linker,
12931295
NativeLibraryKind::NativeUnknown => cmd.link_dylib(name),
12941296
NativeLibraryKind::NativeFramework => cmd.link_framework(name),
12951297
NativeLibraryKind::NativeStaticNobundle => cmd.link_staticlib(name),
1296-
NativeLibraryKind::NativeStatic => cmd.link_whole_staticlib(name, &search_path)
1298+
NativeLibraryKind::NativeStatic => cmd.link_whole_staticlib(name, &search_path),
1299+
NativeLibraryKind::NativeRawDylib => {
1300+
// FIXME(#58713): Proper handling for raw dylibs.
1301+
bug!("raw_dylib feature not yet implemented");
1302+
},
12971303
}
12981304
}
12991305
}
@@ -1678,7 +1684,11 @@ pub fn add_upstream_native_libraries(
16781684
// ignore statically included native libraries here as we've
16791685
// already included them when we included the rust library
16801686
// previously
1681-
NativeLibraryKind::NativeStatic => {}
1687+
NativeLibraryKind::NativeStatic => {},
1688+
NativeLibraryKind::NativeRawDylib => {
1689+
// FIXME(#58713): Proper handling for raw dylibs.
1690+
bug!("raw_dylib feature not yet implemented");
1691+
},
16821692
}
16831693
}
16841694
}

src/librustc_metadata/cstore_impl.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,11 @@ pub fn provide(providers: &mut Providers<'_>) {
270270
// resolve! Does this work? Unsure! That's what the issue is about
271271
*providers = Providers {
272272
is_dllimport_foreign_item: |tcx, id| {
273-
tcx.native_library_kind(id) == Some(NativeLibraryKind::NativeUnknown)
273+
match tcx.native_library_kind(id) {
274+
Some(NativeLibraryKind::NativeUnknown) |
275+
Some(NativeLibraryKind::NativeRawDylib) => true,
276+
_ => false,
277+
}
274278
},
275279
is_statically_included_foreign_item: |tcx, id| {
276280
match tcx.native_library_kind(id) {

src/librustc_metadata/native_libs.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ impl ItemLikeVisitor<'tcx> for Collector<'tcx> {
7373
"static-nobundle" => cstore::NativeStaticNobundle,
7474
"dylib" => cstore::NativeUnknown,
7575
"framework" => cstore::NativeFramework,
76+
"raw-dylib" => cstore::NativeRawDylib,
7677
k => {
7778
struct_span_err!(self.tcx.sess, item.span(), E0458,
7879
"unknown kind: `{}`", k)
@@ -169,6 +170,14 @@ impl Collector<'tcx> {
169170
GateIssue::Language,
170171
"kind=\"static-nobundle\" is unstable");
171172
}
173+
if lib.kind == cstore::NativeRawDylib &&
174+
!self.tcx.features().raw_dylib {
175+
feature_gate::emit_feature_err(&self.tcx.sess.parse_sess,
176+
sym::raw_dylib,
177+
span.unwrap_or_else(|| syntax_pos::DUMMY_SP),
178+
GateIssue::Language,
179+
"kind=\"raw-dylib\" is feature gated");
180+
}
172181
self.libs.push(lib);
173182
}
174183

src/libsyntax/feature_gate/active.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -522,6 +522,9 @@ declare_features! (
522522
/// Allows the definition of `const extern fn` and `const unsafe extern fn`.
523523
(active, const_extern_fn, "1.40.0", Some(64926), None),
524524

525+
// Allows the use of raw-dylibs (RFC 2627).
526+
(active, raw_dylib, "1.39.0", Some(58713), None),
527+
525528
// -------------------------------------------------------------------------
526529
// feature-group-end: actual feature gates
527530
// -------------------------------------------------------------------------

src/libsyntax/feature_gate/builtin_attrs.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,13 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
276276
"the `link_args` attribute is experimental and not portable across platforms, \
277277
it is recommended to use `#[link(name = \"foo\")] instead",
278278
),
279-
279+
gated!(
280+
link_ordinal,
281+
Whitelisted,
282+
template!(List: "ordinal"),
283+
raw_dylib,
284+
experimental!(link_ordinal)
285+
),
280286
// Plugins:
281287
(
282288
sym::plugin_registrar, Normal, template!(Word),

src/libsyntax_pos/symbol.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,7 @@ symbols! {
389389
link_cfg,
390390
link_llvm_intrinsics,
391391
link_name,
392+
link_ordinal,
392393
link_section,
393394
LintPass,
394395
lint_reasons,
@@ -531,6 +532,7 @@ symbols! {
531532
RangeInclusive,
532533
RangeTo,
533534
RangeToInclusive,
535+
raw_dylib,
534536
raw_identifiers,
535537
Ready,
536538
reason,
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#[link(name="foo")]
2+
extern {
3+
#[link_ordinal(42)]
4+
//~^ ERROR: the `#[link_ordinal]` attribute is an experimental feature
5+
fn foo();
6+
}
7+
8+
fn main() {}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
error[E0658]: the `#[link_ordinal]` attribute is an experimental feature
2+
--> $DIR/feature-gate-raw-dylib-2.rs:3:1
3+
|
4+
LL | #[link_ordinal(42)]
5+
| ^^^^^^^^^^^^^^^^^^^
6+
|
7+
= note: for more information, see https://github.com/rust-lang/rust/issues/58713
8+
= help: add `#![feature(raw_dylib)]` to the crate attributes to enable
9+
10+
error: aborting due to previous error
11+
12+
For more information about this error, try `rustc --explain E0658`.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#[link(name="foo", kind="raw-dylib")]
2+
//~^ ERROR: kind="raw-dylib" is feature gated
3+
extern {}
4+
5+
fn main() {}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
error[E0658]: kind="raw-dylib" is feature gated
2+
--> $DIR/feature-gate-raw-dylib.rs:1:1
3+
|
4+
LL | #[link(name="foo", kind="raw-dylib")]
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6+
|
7+
= note: for more information, see https://github.com/rust-lang/rust/issues/58713
8+
= help: add `#![feature(raw_dylib)]` to the crate attributes to enable
9+
10+
error: aborting due to previous error
11+
12+
For more information about this error, try `rustc --explain E0658`.

0 commit comments

Comments
 (0)