Skip to content

Commit

Permalink
Add experimental raw-dylib feature to std
Browse files Browse the repository at this point in the history
For Windows, this allows defining imports without needing the user to have import libraries. It's intended for this to become the default.
  • Loading branch information
ChrisDenton committed Jul 5, 2024
1 parent c452e62 commit 6b7a259
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
4 changes: 4 additions & 0 deletions std/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 13 additions & 0 deletions std/src/sys/pal/windows/c/windows_targets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -17,6 +29,7 @@ pub macro link {
)
}

#[cfg(not(feature = "windows_raw_dylib"))]
#[link(name = "advapi32")]
#[link(name = "ntdll")]
#[link(name = "userenv")]
Expand Down
1 change: 1 addition & 0 deletions sysroot/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]

0 comments on commit 6b7a259

Please sign in to comment.