Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 6b7a259

Browse files
committedJul 5, 2024
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.
1 parent c452e62 commit 6b7a259

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed
 

‎std/Cargo.toml

+4
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,10 @@ std_detect_file_io = ["std_detect/std_detect_file_io"]
8787
std_detect_dlsym_getauxval = ["std_detect/std_detect_dlsym_getauxval"]
8888
std_detect_env_override = ["std_detect/std_detect_env_override"]
8989

90+
# Enable using raw-dylib for Windows imports.
91+
# This will eventually be the default.
92+
windows_raw_dylib = []
93+
9094
[package.metadata.fortanix-sgx]
9195
# Maximum possible number of threads when testing
9296
threads = 125

‎std/src/sys/pal/windows/c/windows_targets.rs

+13
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,18 @@
33
//! This is a simple wrapper around an `extern` block with a `#[link]` attribute.
44
//! It's very roughly equivalent to the windows-targets crate.
55
6+
#[cfg(feature = "windows_raw_dylib")]
7+
pub macro link {
8+
($library:literal $abi:literal $($link_name:literal)? $(#[$doc:meta])? fn $($function:tt)*) => (
9+
#[cfg_attr(not(target_arch = "x86"), link(name = $library, kind = "raw-dylib", modifiers = "+verbatim"))]
10+
#[cfg_attr(target_arch = "x86", link(name = $library, kind = "raw-dylib", modifiers = "+verbatim", import_name_type = "undecorated"))]
11+
extern $abi {
12+
$(#[link_name=$link_name])?
13+
pub fn $($function)*;
14+
}
15+
)
16+
}
17+
#[cfg(not(feature = "windows_raw_dylib"))]
618
pub macro link {
719
($library:literal $abi:literal $($link_name:literal)? $(#[$doc:meta])? fn $($function:tt)*) => (
820
// Note: the windows-targets crate uses a pre-built Windows.lib import library which we don't
@@ -17,6 +29,7 @@ pub macro link {
1729
)
1830
}
1931

32+
#[cfg(not(feature = "windows_raw_dylib"))]
2033
#[link(name = "advapi32")]
2134
#[link(name = "ntdll")]
2235
#[link(name = "userenv")]

‎sysroot/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,4 @@ profiler = ["std/profiler"]
2727
std_detect_file_io = ["std/std_detect_file_io"]
2828
std_detect_dlsym_getauxval = ["std/std_detect_dlsym_getauxval"]
2929
std_detect_env_override = ["std/std_detect_env_override"]
30+
windows_raw_dylib = ["std/windows_raw_dylib"]

0 commit comments

Comments
 (0)
Failed to load comments.