From d72df7f66fa2b7cb473f575488c0cd11e8e1de3c Mon Sep 17 00:00:00 2001 From: Ivan Tadeu Ferreira Antunes Filho Date: Thu, 24 Jul 2025 14:57:11 -0400 Subject: [PATCH] library/windows_targets: Fix macro expansion error in 'link' macro A recent change altered the definition of the link! macro when the windows_raw_dylib feature is enabled, changing its syntax from pub macro {..} to pub macro($tt:tt) {..} in https://github.com/rust-lang/rust/pull/143592 This change introduced a build failure with the error: "macros that expand to items must be delimited with braces or followed by a semicolon". We also modify the non windows_raw_dylib link to make use of the link_dylib macro --- library/windows_targets/src/lib.rs | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/library/windows_targets/src/lib.rs b/library/windows_targets/src/lib.rs index 9e82e6a720006..894d5f4e2b2e2 100644 --- a/library/windows_targets/src/lib.rs +++ b/library/windows_targets/src/lib.rs @@ -33,23 +33,13 @@ pub macro link_dylib { } #[cfg(feature = "windows_raw_dylib")] -pub macro link($($tt:tt)*) { - $crate::link_raw_dylib!($($tt)*) +pub macro link { + ($($tt:tt)*) => ($crate::link_raw_dylib!($($tt)*)) } #[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 - // have in this repo. So instead we always link kernel32.lib and add the rest of the import - // libraries below by using an empty extern block. This works because extern blocks are not - // connected to the library given in the #[link] attribute. - #[link(name = "kernel32")] - unsafe extern $abi { - $(#[link_name=$link_name])? - pub fn $($function)*; - } - ) + ($($tt:tt)*) => ($crate::link_dylib!($($tt)*)) } #[cfg(not(feature = "windows_raw_dylib"))]