Skip to content

Commit

Permalink
Fix for windows-targets::link doc compatibility (#2868)
Browse files Browse the repository at this point in the history
  • Loading branch information
kennykerr authored Feb 22, 2024
1 parent 0494b02 commit 428a7ca
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
2 changes: 1 addition & 1 deletion crates/libs/targets/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

[package]
name = "windows-targets"
version = "0.52.1"
version = "0.52.2"
authors = ["Microsoft"]
edition = "2021"
rust-version = "1.60"
Expand Down
8 changes: 4 additions & 4 deletions crates/libs/targets/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Learn more about Rust for Windows here: <https://github.com/microsoft/windows-rs
#[cfg(all(windows_raw_dylib, target_arch = "x86"))]
#[macro_export]
macro_rules! link {
($library:literal $abi:literal $($link_name:literal)? fn $($function:tt)*) => (
($library:literal $abi:literal $($link_name:literal)? $(#[$doc:meta])? fn $($function:tt)*) => (
#[link(name = $library, kind = "raw-dylib", modifiers = "+verbatim", import_name_type = "undecorated")]
extern $abi {
$(#[link_name=$link_name])?
Expand All @@ -21,7 +21,7 @@ macro_rules! link {
#[cfg(all(windows_raw_dylib, not(target_arch = "x86")))]
#[macro_export]
macro_rules! link {
($library:literal $abi:literal $($link_name:literal)? fn $($function:tt)*) => (
($library:literal $abi:literal $($link_name:literal)? $(#[$doc:meta])? fn $($function:tt)*) => (
#[link(name = $library, kind = "raw-dylib", modifiers = "+verbatim")]
extern "C" {
$(#[link_name=$link_name])?
Expand All @@ -34,7 +34,7 @@ macro_rules! link {
#[cfg(all(windows, not(windows_raw_dylib)))]
#[macro_export]
macro_rules! link {
($library:literal $abi:literal $($link_name:literal)? fn $($function:tt)*) => (
($library:literal $abi:literal $($link_name:literal)? $(#[$doc:meta])? fn $($function:tt)*) => (
#[link(name = "windows.0.52.1")]
extern $abi {
$(#[link_name=$link_name])?
Expand All @@ -47,7 +47,7 @@ macro_rules! link {
#[cfg(all(not(windows), not(windows_raw_dylib)))]
#[macro_export]
macro_rules! link {
($library:literal $abi:literal $($link_name:literal)? fn $($function:tt)*) => (
($library:literal $abi:literal $($link_name:literal)? $(#[$doc:meta])? fn $($function:tt)*) => (
extern $abi {
pub fn $($function)*;
}
Expand Down
11 changes: 11 additions & 0 deletions crates/tests/targets/tests/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,17 @@ fn link_name() {
}
}

#[test]
fn doc() {
windows_targets::link!("kernel32.dll" "system" "SetLastError" #[doc = "SetLastError"] fn SetLastError(code: u32) -> ());
windows_targets::link!("kernel32.dll" "system" #[doc = "GetLastError"] fn GetLastError() -> u32);

unsafe {
SetLastError(1234);
assert_eq!(GetLastError(), 1234);
}
}

#[test]
fn cdecl() {
windows_targets::link!("wldap32.dll" "cdecl" fn LdapMapErrorToWin32(code : i32) -> u32);
Expand Down

0 comments on commit 428a7ca

Please sign in to comment.