diff --git a/crates/libs/link/src/lib.rs b/crates/libs/link/src/lib.rs index 05f802a543..dbecf9f3b5 100644 --- a/crates/libs/link/src/lib.rs +++ b/crates/libs/link/src/lib.rs @@ -20,8 +20,7 @@ macro_rules! link { macro_rules! link { ($library:literal $abi:literal $($link_name:literal)? fn $($function:tt)*) => ( #[link(name = $library, kind = "raw-dylib", modifiers = "+verbatim")] - // TODO: remove hardcoded "C" before next major update - https://github.com/microsoft/windows-rs/pull/3669 - extern "C" { + extern $abi { $(#[link_name=$link_name])? pub fn $($function)*; } diff --git a/crates/tests/libs/link/tests/link.rs b/crates/tests/libs/link/tests/link.rs index e5e3a8ec6f..a228cdb0d3 100644 --- a/crates/tests/libs/link/tests/link.rs +++ b/crates/tests/libs/link/tests/link.rs @@ -30,3 +30,17 @@ fn cdecl() { assert_eq!(LdapMapErrorToWin32(LDAP_BUSY), ERROR_BUSY); } } + +// Test for https://github.com/microsoft/windows-rs/pull/3669#issuecomment-3097317771 +#[test] +fn fn_ptr() { + windows_link::link!("kernel32.dll" "system" fn GetTickCount() -> u32); + + type GetTickCountType = unsafe extern "system" fn() -> u32; + + static GET_TICK_COUNT: GetTickCountType = GetTickCount; + + unsafe { + GET_TICK_COUNT(); + } +} diff --git a/crates/tests/misc/calling_convention/tests/ptr.rs b/crates/tests/misc/calling_convention/tests/ptr.rs deleted file mode 100644 index 52bf1138ce..0000000000 --- a/crates/tests/misc/calling_convention/tests/ptr.rs +++ /dev/null @@ -1,20 +0,0 @@ -// This is a test specifically for the breaking change discussed in https://github.com/microsoft/windows-rs/pull/3669 -// and https://github.com/microsoft/windows-rs/issues/3626 where a function pointer is stored. All of this can be -// removed if the hardcoding of "C" is removed in a future breaking change. - -windows_link::link!("kernel32.dll" "system" fn GetTickCount() -> u32); - -#[cfg(target_arch = "x86")] -type GetTickCountType = unsafe extern "system" fn() -> u32; - -#[cfg(not(target_arch = "x86"))] -type GetTickCountType = unsafe extern "C" fn() -> u32; - -static GET_TICK_COUNT: GetTickCountType = GetTickCount; - -#[test] -fn store_ptr() { - unsafe { - GET_TICK_COUNT(); - } -}