Add experimental raw-dylib feature to std

For Windows, this allows defining imports without needing the user to have import libraries. It's intended for this to become the default.
This commit is contained in:
Chris Denton 2024-07-05 14:04:26 +00:00
parent a5dc082d6f
commit e136f08a6f
No known key found for this signature in database
GPG Key ID: 713472F2F45627DE
3 changed files with 18 additions and 0 deletions

View File

@ -87,6 +87,10 @@ std_detect_file_io = ["std_detect/std_detect_file_io"]
std_detect_dlsym_getauxval = ["std_detect/std_detect_dlsym_getauxval"]
std_detect_env_override = ["std_detect/std_detect_env_override"]
# Enable using raw-dylib for Windows imports.
# This will eventually be the default.
windows_raw_dylib = []
[package.metadata.fortanix-sgx]
# Maximum possible number of threads when testing
threads = 125

View File

@ -3,6 +3,18 @@
//! This is a simple wrapper around an `extern` block with a `#[link]` attribute.
//! It's very roughly equivalent to the windows-targets crate.
#[cfg(feature = "windows_raw_dylib")]
pub macro link {
($library:literal $abi:literal $($link_name:literal)? $(#[$doc:meta])? fn $($function:tt)*) => (
#[cfg_attr(not(target_arch = "x86"), link(name = $library, kind = "raw-dylib", modifiers = "+verbatim"))]
#[cfg_attr(target_arch = "x86", link(name = $library, kind = "raw-dylib", modifiers = "+verbatim", import_name_type = "undecorated"))]
extern $abi {
$(#[link_name=$link_name])?
pub fn $($function)*;
}
)
}
#[cfg(not(feature = "windows_raw_dylib"))]
pub macro link {
($library:literal $abi:literal $($link_name:literal)? $(#[$doc:meta])? fn $($function:tt)*) => (
// Note: the windows-targets crate uses a pre-built Windows.lib import library which we don't
@ -17,6 +29,7 @@
)
}
#[cfg(not(feature = "windows_raw_dylib"))]
#[link(name = "advapi32")]
#[link(name = "ntdll")]
#[link(name = "userenv")]

View File

@ -27,3 +27,4 @@ profiler = ["std/profiler"]
std_detect_file_io = ["std/std_detect_file_io"]
std_detect_dlsym_getauxval = ["std/std_detect_dlsym_getauxval"]
std_detect_env_override = ["std/std_detect_env_override"]
windows_raw_dylib = ["std/windows_raw_dylib"]