Skip to content

Commit c878869

Browse files
committed
fix: use cfg to allow certain archs certain convs
(fixes unsupported_fn_ptr_calling_conventions) rust-lang/rust#130260
1 parent 0a8b18e commit c878869

File tree

1 file changed

+23
-6
lines changed

1 file changed

+23
-6
lines changed

src/function.rs

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -148,15 +148,32 @@ macro_rules! impl_fn {
148148
};
149149

150150
(@impl_all ($($nm:ident : $ty:ident),*)) => {
151-
impl_fn!(@impl_u_and_s ($($nm : $ty),*) ("Rust") fn($($ty),*) -> Ret);
152-
impl_fn!(@impl_u_and_s ($($nm : $ty),*) ("cdecl") fn($($ty),*) -> Ret);
153-
impl_fn!(@impl_u_and_s ($($nm : $ty),*) ("stdcall") fn($($ty),*) -> Ret);
154-
impl_fn!(@impl_u_and_s ($($nm : $ty),*) ("fastcall") fn($($ty),*) -> Ret);
151+
// Universal conventions
152+
{
153+
impl_fn!(@impl_u_and_s ($($nm : $ty),*) ("Rust") fn($($ty),*) -> Ret);
154+
impl_fn!(@impl_u_and_s ($($nm : $ty),*) ("C") fn($($ty),*) -> Ret);
155+
impl_fn!(@impl_u_and_s ($($nm : $ty),*) ("system") fn($($ty),*) -> Ret);
156+
}
157+
158+
// x86-specific conventions
159+
#[cfg(target_arch = "x86")]
160+
{
161+
impl_fn!(@impl_u_and_s ($($nm : $ty),*) ("cdecl") fn($($ty),*) -> Ret);
162+
impl_fn!(@impl_u_and_s ($($nm : $ty),*) ("stdcall") fn($($ty),*) -> Ret);
163+
impl_fn!(@impl_u_and_s ($($nm : $ty),*) ("fastcall") fn($($ty),*) -> Ret);
164+
}
165+
166+
// x86_64 Windows
167+
#[cfg(all(target_arch = "x86_64", target_os = "windows"))]
155168
impl_fn!(@impl_u_and_s ($($nm : $ty),*) ("win64") fn($($ty),*) -> Ret);
169+
170+
// x86_64 System V (Linux/macOS)
171+
#[cfg(all(target_arch = "x86_64", not(target_os = "windows")))]
156172
impl_fn!(@impl_u_and_s ($($nm : $ty),*) ("sysv64") fn($($ty),*) -> Ret);
173+
174+
// ARM conventions
175+
#[cfg(any(target_arch = "arm", target_arch = "aarch64"))]
157176
impl_fn!(@impl_u_and_s ($($nm : $ty),*) ("aapcs") fn($($ty),*) -> Ret);
158-
impl_fn!(@impl_u_and_s ($($nm : $ty),*) ("C") fn($($ty),*) -> Ret);
159-
impl_fn!(@impl_u_and_s ($($nm : $ty),*) ("system") fn($($ty),*) -> Ret);
160177
};
161178

162179
(@impl_u_and_s ($($nm:ident : $ty:ident),*) ($call_conv:expr) fn($($param_ty:ident),*) -> $ret:ty) => {

0 commit comments

Comments
 (0)