Skip to content

Commit c57e8eb

Browse files
committed
Add feature gate for raw_dylib.
1 parent 64c0969 commit c57e8eb

File tree

11 files changed

+78
-5
lines changed

11 files changed

+78
-5
lines changed

src/librustc/middle/cstore.rs

+2
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

+13-3
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,7 @@ fn link_rlib<'a, B: ArchiveBuilder<'a>>(sess: &'a Session,
314314
NativeLibraryKind::NativeStatic => {}
315315
NativeLibraryKind::NativeStaticNobundle |
316316
NativeLibraryKind::NativeFramework |
317+
NativeLibraryKind::NativeRawDylib |
317318
NativeLibraryKind::NativeUnknown => continue,
318319
}
319320
if let Some(name) = lib.name {
@@ -874,7 +875,8 @@ pub fn print_native_static_libs(sess: &Session, all_native_libs: &[NativeLibrary
874875
Some(format!("-framework {}", name))
875876
},
876877
// These are included, no need to print them
877-
NativeLibraryKind::NativeStatic => None,
878+
NativeLibraryKind::NativeStatic |
879+
NativeLibraryKind::NativeRawDylib => None,
878880
}
879881
})
880882
.collect();
@@ -1284,7 +1286,11 @@ pub fn add_local_native_libraries(cmd: &mut dyn Linker,
12841286
NativeLibraryKind::NativeUnknown => cmd.link_dylib(name),
12851287
NativeLibraryKind::NativeFramework => cmd.link_framework(name),
12861288
NativeLibraryKind::NativeStaticNobundle => cmd.link_staticlib(name),
1287-
NativeLibraryKind::NativeStatic => cmd.link_whole_staticlib(name, &search_path)
1289+
NativeLibraryKind::NativeStatic => cmd.link_whole_staticlib(name, &search_path),
1290+
NativeLibraryKind::NativeRawDylib => {
1291+
// FIXME(#58713): Proper handling for raw dylibs.
1292+
bug!("raw_dylib feature not yet implemented");
1293+
},
12881294
}
12891295
}
12901296
}
@@ -1661,7 +1667,11 @@ pub fn add_upstream_native_libraries(cmd: &mut dyn Linker,
16611667
// ignore statically included native libraries here as we've
16621668
// already included them when we included the rust library
16631669
// previously
1664-
NativeLibraryKind::NativeStatic => {}
1670+
NativeLibraryKind::NativeStatic => {},
1671+
NativeLibraryKind::NativeRawDylib => {
1672+
// FIXME(#58713): Proper handling for raw dylibs.
1673+
bug!("raw_dylib feature not yet implemented");
1674+
},
16651675
}
16661676
}
16671677
}

src/librustc_metadata/cstore_impl.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,11 @@ pub fn provide(providers: &mut Providers<'_>) {
248248
// resolve! Does this work? Unsure! That's what the issue is about
249249
*providers = Providers {
250250
is_dllimport_foreign_item: |tcx, id| {
251-
tcx.native_library_kind(id) == Some(NativeLibraryKind::NativeUnknown)
251+
match tcx.native_library_kind(id) {
252+
Some(NativeLibraryKind::NativeUnknown) |
253+
Some(NativeLibraryKind::NativeRawDylib) => true,
254+
_ => false,
255+
}
252256
},
253257
is_statically_included_foreign_item: |tcx, id| {
254258
match tcx.native_library_kind(id) {

src/librustc_metadata/native_libs.rs

+9
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

+3
Original file line numberDiff line numberDiff line change
@@ -525,6 +525,9 @@ declare_features! (
525525
/// Allows the use of or-patterns (e.g., `0 | 1`).
526526
(active, or_patterns, "1.38.0", Some(54883), None),
527527

528+
// Allows the use of raw-dylibs (RFC 2627).
529+
(active, raw_dylib, "1.39.0", Some(58713), None),
530+
528531
// -------------------------------------------------------------------------
529532
// feature-group-end: actual feature gates
530533
// -------------------------------------------------------------------------

src/libsyntax/feature_gate/builtin_attrs.rs

+7-1
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
ungated!(plugin_registrar, Normal, template!(Word)),
282288
gated!(

src/libsyntax_pos/symbol.rs

+2
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,
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() {}
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`.
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() {}
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)