From d598c43f4b8f6e0d504b201c3f2f11ef188e8611 Mon Sep 17 00:00:00 2001 From: Kenny Kerr Date: Thu, 22 Feb 2024 08:40:21 -0600 Subject: [PATCH] doc --- crates/libs/targets/src/lib.rs | 8 ++++---- crates/tests/targets/tests/link.rs | 11 +++++++++++ 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/crates/libs/targets/src/lib.rs b/crates/libs/targets/src/lib.rs index 976b09020d..3b8919043c 100644 --- a/crates/libs/targets/src/lib.rs +++ b/crates/libs/targets/src/lib.rs @@ -8,7 +8,7 @@ Learn more about Rust for Windows here: ( + ($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])? @@ -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])? @@ -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])? @@ -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)*; } diff --git a/crates/tests/targets/tests/link.rs b/crates/tests/targets/tests/link.rs index 8ce6839680..f306992a66 100644 --- a/crates/tests/targets/tests/link.rs +++ b/crates/tests/targets/tests/link.rs @@ -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);