Factor out NativeLibKind::Dylib from NativeLibKind::Unspecified

This commit is contained in:
Vadim Petrochenkov 2020-05-18 01:37:24 +03:00
parent ee7a35ab95
commit 529d488f1a
6 changed files with 17 additions and 9 deletions

View File

@ -330,6 +330,7 @@ fn link_rlib<'a, B: ArchiveBuilder<'a>>(
match lib.kind {
NativeLibKind::StaticBundle => {}
NativeLibKind::StaticNoBundle
| NativeLibKind::Dylib
| NativeLibKind::Framework
| NativeLibKind::RawDylib
| NativeLibKind::Unspecified => continue,
@ -866,7 +867,9 @@ fn print_native_static_libs(sess: &Session, all_native_libs: &[NativeLib]) {
.filter_map(|lib| {
let name = lib.name?;
match lib.kind {
NativeLibKind::StaticNoBundle | NativeLibKind::Unspecified => {
NativeLibKind::StaticNoBundle
| NativeLibKind::Dylib
| NativeLibKind::Unspecified => {
if sess.target.target.options.is_like_msvc {
Some(format!("{}.lib", name))
} else {
@ -1648,7 +1651,7 @@ fn add_local_native_libraries(
None => continue,
};
match lib.kind {
NativeLibKind::Unspecified => cmd.link_dylib(name),
NativeLibKind::Dylib | NativeLibKind::Unspecified => cmd.link_dylib(name),
NativeLibKind::Framework => cmd.link_framework(name),
NativeLibKind::StaticNoBundle => cmd.link_staticlib(name),
NativeLibKind::StaticBundle => cmd.link_whole_staticlib(name, &search_path),
@ -1984,7 +1987,7 @@ fn add_upstream_native_libraries(
continue;
}
match lib.kind {
NativeLibKind::Unspecified => cmd.link_dylib(name),
NativeLibKind::Dylib | NativeLibKind::Unspecified => cmd.link_dylib(name),
NativeLibKind::Framework => cmd.link_framework(name),
NativeLibKind::StaticNoBundle => {
// Link "static-nobundle" native libs only if the crate they originate from

View File

@ -896,7 +896,7 @@ pub fn provide_both(providers: &mut Providers<'_>) {
.native_libraries(krate)
.iter()
.filter(|lib| {
if lib.kind != NativeLibKind::Unspecified {
if !matches!(lib.kind, NativeLibKind::Dylib | NativeLibKind::Unspecified) {
return false;
}
let cfg = match lib.cfg {

View File

@ -67,7 +67,7 @@ impl ItemLikeVisitor<'tcx> for Collector<'tcx> {
lib.kind = match &*kind.as_str() {
"static" => NativeLibKind::StaticBundle,
"static-nobundle" => NativeLibKind::StaticNoBundle,
"dylib" => NativeLibKind::Unspecified,
"dylib" => NativeLibKind::Dylib,
"framework" => NativeLibKind::Framework,
"raw-dylib" => NativeLibKind::RawDylib,
k => {

View File

@ -247,7 +247,9 @@ pub fn provide(providers: &mut Providers<'_>) {
// resolve! Does this work? Unsure! That's what the issue is about
*providers = Providers {
is_dllimport_foreign_item: |tcx, id| match tcx.native_library_kind(id) {
Some(NativeLibKind::Unspecified | NativeLibKind::RawDylib) => true,
Some(NativeLibKind::Dylib | NativeLibKind::RawDylib | NativeLibKind::Unspecified) => {
true
}
_ => false,
},
is_statically_included_foreign_item: |tcx, id| match tcx.native_library_kind(id) {

View File

@ -1463,7 +1463,7 @@ fn parse_libs(
let kind = parts.next().unwrap();
let (name, kind) = match (parts.next(), kind) {
(None, name) => (name, None),
(Some(name), "dylib") => (name, Some(NativeLibKind::Unspecified)),
(Some(name), "dylib") => (name, Some(NativeLibKind::Dylib)),
(Some(name), "framework") => (name, Some(NativeLibKind::Framework)),
(Some(name), "static") => (name, Some(NativeLibKind::StaticBundle)),
(Some(name), "static-nobundle") => (name, Some(NativeLibKind::StaticNoBundle)),

View File

@ -18,11 +18,14 @@ pub enum NativeLibKind {
/// Static library (e.g. `libfoo.a` on Linux or `foo.lib` on Windows/MSVC) included
/// when linking a final binary, but also included when archiving an rlib.
StaticBundle,
/// Windows dynamic library (`foo.dll`) without a corresponding import library.
/// Dynamic library (e.g. `libfoo.so` on Linux)
/// or an import library corresponding to a dynamic library (e.g. `foo.lib` on Windows/MSVC).
Dylib,
/// Dynamic library (e.g. `foo.dll` on Windows) without a corresponding import library.
RawDylib,
/// A macOS-specific kind of dynamic libraries.
Framework,
/// The library kind wasn't specified, dynamic linking is currently preferred.
/// The library kind wasn't specified, `Dylib` is currently used as a default.
Unspecified,
}