support link modifier as-needed for raw-dylib-elf

This commit is contained in:
usamoi
2025-08-26 16:24:29 +08:00
parent 839222065a
commit 21dd997aec
8 changed files with 82 additions and 31 deletions

View File

@@ -309,7 +309,10 @@ pub enum NativeLibKind {
},
/// Dynamic library (e.g. `foo.dll` on Windows) without a corresponding import library.
/// On Linux, it refers to a generated shared library stub.
RawDylib,
RawDylib {
/// Whether the dynamic library will be linked only if it satisfies some undefined symbols
as_needed: Option<bool>,
},
/// A macOS-specific kind of dynamic libraries.
Framework {
/// Whether the framework will be linked only if it satisfies some undefined symbols
@@ -332,11 +335,10 @@ impl NativeLibKind {
NativeLibKind::Static { bundle, whole_archive } => {
bundle.is_some() || whole_archive.is_some()
}
NativeLibKind::Dylib { as_needed } | NativeLibKind::Framework { as_needed } => {
as_needed.is_some()
}
NativeLibKind::RawDylib
| NativeLibKind::Unspecified
NativeLibKind::Dylib { as_needed }
| NativeLibKind::Framework { as_needed }
| NativeLibKind::RawDylib { as_needed } => as_needed.is_some(),
NativeLibKind::Unspecified
| NativeLibKind::LinkArg
| NativeLibKind::WasmImportModule => false,
}
@@ -349,7 +351,9 @@ impl NativeLibKind {
pub fn is_dllimport(&self) -> bool {
matches!(
self,
NativeLibKind::Dylib { .. } | NativeLibKind::RawDylib | NativeLibKind::Unspecified
NativeLibKind::Dylib { .. }
| NativeLibKind::RawDylib { .. }
| NativeLibKind::Unspecified
)
}
}