Skip to content

Commit 697bce8

Browse files
committed
Use the given ABI in link!
1 parent 068989a commit 697bce8

File tree

2 files changed

+33
-18
lines changed

2 files changed

+33
-18
lines changed

crates/libs/link/src/lib.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
#[cfg(all(windows, target_arch = "x86"))]
66
#[macro_export]
77
macro_rules! link {
8+
// Avoid future-compat lint if bindings are still using the old "cdecl" form of the bindings.
9+
($library:literal "cdecl" $($link_name:literal)? fn $($function:tt)*) => (
10+
$crate::link!($library "C" $($link_name)? fn $($function)*);
11+
);
812
($library:literal $abi:literal $($link_name:literal)? fn $($function:tt)*) => (
913
#[link(name = $library, kind = "raw-dylib", modifiers = "+verbatim", import_name_type = "undecorated")]
1014
extern $abi {
@@ -18,9 +22,13 @@ macro_rules! link {
1822
#[cfg(all(windows, not(target_arch = "x86")))]
1923
#[macro_export]
2024
macro_rules! link {
25+
// Avoid future-compat lint if bindings are still using the old "cdecl" form of the bindings.
26+
($library:literal "cdecl" $($link_name:literal)? fn $($function:tt)*) => (
27+
$crate::link!($library "C" $($link_name)? fn $($function)*);
28+
);
2129
($library:literal $abi:literal $($link_name:literal)? fn $($function:tt)*) => (
2230
#[link(name = $library, kind = "raw-dylib", modifiers = "+verbatim")]
23-
extern "C" {
31+
extern $abi {
2432
$(#[link_name=$link_name])?
2533
pub fn $($function)*;
2634
}
@@ -31,8 +39,12 @@ macro_rules! link {
3139
#[cfg(not(windows))]
3240
#[macro_export]
3341
macro_rules! link {
42+
// Avoid future-compat lint if bindings are still using the old "cdecl" form of the bindings.
43+
($library:literal "cdecl" $($link_name:literal)? fn $($function:tt)*) => (
44+
$crate::link!($library "C" $($link_name)? fn $($function)*);
45+
);
3446
($library:literal $abi:literal $($link_name:literal)? fn $($function:tt)*) => (
35-
extern "C" {
47+
extern $abi {
3648
pub fn $($function)*;
3749
}
3850
)

crates/libs/targets/src/lib.rs

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
#[cfg(all(windows_raw_dylib, target_arch = "x86"))]
66
#[macro_export]
77
macro_rules! link {
8+
// Avoid future-compat lint if bindings are still using the old "cdecl" form of the bindings.
9+
($library:literal "cdecl" $($link_name:literal)? fn $($function:tt)*) => (
10+
$crate::link!($library "C" $($link_name)? fn $($function)*);
11+
);
812
($library:literal $abi:literal $($link_name:literal)? fn $($function:tt)*) => (
913
#[link(name = $library, kind = "raw-dylib", modifiers = "+verbatim", import_name_type = "undecorated")]
1014
extern $abi {
@@ -18,21 +22,12 @@ macro_rules! link {
1822
#[cfg(all(windows_raw_dylib, not(target_arch = "x86")))]
1923
#[macro_export]
2024
macro_rules! link {
25+
// Avoid future-compat lint if bindings are still using the old "cdecl" form of the bindings.
26+
($library:literal "cdecl" $($link_name:literal)? fn $($function:tt)*) => (
27+
$crate::link!($library "C" $($link_name)? fn $($function)*);
28+
);
2129
($library:literal $abi:literal $($link_name:literal)? fn $($function:tt)*) => (
2230
#[link(name = $library, kind = "raw-dylib", modifiers = "+verbatim")]
23-
extern "C" {
24-
$(#[link_name=$link_name])?
25-
pub fn $($function)*;
26-
}
27-
)
28-
}
29-
30-
/// Defines an external function to import.
31-
#[cfg(all(windows, not(windows_raw_dylib), target_arch = "x86"))]
32-
#[macro_export]
33-
macro_rules! link {
34-
($library:literal $abi:literal $($link_name:literal)? fn $($function:tt)*) => (
35-
#[link(name = "windows.0.53.0")]
3631
extern $abi {
3732
$(#[link_name=$link_name])?
3833
pub fn $($function)*;
@@ -41,12 +36,16 @@ macro_rules! link {
4136
}
4237

4338
/// Defines an external function to import.
44-
#[cfg(all(windows, not(windows_raw_dylib), not(target_arch = "x86")))]
39+
#[cfg(all(windows, not(windows_raw_dylib)))]
4540
#[macro_export]
4641
macro_rules! link {
42+
// Avoid future-compat lint if bindings are still using the old "cdecl" form of the bindings.
43+
($library:literal "cdecl" $($link_name:literal)? fn $($function:tt)*) => (
44+
$crate::link!($library "C" $($link_name)? fn $($function)*);
45+
);
4746
($library:literal $abi:literal $($link_name:literal)? fn $($function:tt)*) => (
4847
#[link(name = "windows.0.53.0")]
49-
extern "C" {
48+
extern $abi {
5049
$(#[link_name=$link_name])?
5150
pub fn $($function)*;
5251
}
@@ -57,8 +56,12 @@ macro_rules! link {
5756
#[cfg(all(not(windows), not(windows_raw_dylib)))]
5857
#[macro_export]
5958
macro_rules! link {
59+
// Avoid future-compat lint if bindings are still using the old "cdecl" form of the bindings.
60+
($library:literal "cdecl" $($link_name:literal)? fn $($function:tt)*) => (
61+
$crate::link!($library "C" $($link_name)? fn $($function)*);
62+
);
6063
($library:literal $abi:literal $($link_name:literal)? fn $($function:tt)*) => (
61-
extern "C" {
64+
extern $abi {
6265
pub fn $($function)*;
6366
}
6467
)

0 commit comments

Comments
 (0)