Skip to content

Commit a1096f6

Browse files
committed
Add linkage attributes to extern "C" blocks
1 parent 5c8b350 commit a1096f6

File tree

8 files changed

+37
-12
lines changed

8 files changed

+37
-12
lines changed

build.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@ fn build_avx512_c_intrinsics() {
193193
// This is required on 32-bit x86 targets, since the assembly
194194
// implementation doesn't support those.
195195
println!("cargo:rustc-cfg=blake3_avx512_ffi");
196+
println!("cargo:rustc-cfg=blake3_avx512_ffi_intrinsics");
196197
let mut build = new_build();
197198
build.file("c/blake3_avx512.c");
198199
if is_windows_msvc() {
@@ -213,6 +214,7 @@ fn build_avx512_assembly() {
213214
// only supports x86_64.
214215
assert!(is_x86_64());
215216
println!("cargo:rustc-cfg=blake3_avx512_ffi");
217+
println!("cargo:rustc-cfg=blake3_avx512_ffi_assembly");
216218
let mut build = new_build();
217219
if is_windows_msvc() {
218220
build.file("c/blake3_avx512_x86-64_windows_msvc.asm");
@@ -234,6 +236,7 @@ fn build_avx512_assembly() {
234236
}
235237

236238
fn build_neon_c_intrinsics() {
239+
println!("cargo:rustc-cfg=blake3_neon_ffi");
237240
let mut build = new_build();
238241
// Note that blake3_neon.c normally depends on the blake3_portable.c
239242
// for the single-instance compression function, but we expose
@@ -258,7 +261,9 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
258261
"blake3_avx2_ffi",
259262
"blake3_avx2_rust",
260263
"blake3_avx512_ffi",
261-
"blake3_neon",
264+
"blake3_avx512_ffi_assembly",
265+
"blake3_avx512_ffi_intrinsics",
266+
"blake3_neon_ffi",
262267
];
263268
for cfg_name in all_cfgs {
264269
// TODO: Switch this whole file to the new :: syntax when our MSRV reaches 1.77.
@@ -300,7 +305,6 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
300305
if (is_arm() && is_neon())
301306
|| (!is_no_neon() && !is_pure() && is_aarch64() && is_little_endian())
302307
{
303-
println!("cargo:rustc-cfg=blake3_neon");
304308
build_neon_c_intrinsics();
305309
}
306310

src/ffi_avx2.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ pub unsafe fn hash_many<const N: usize>(
3333
}
3434

3535
pub mod ffi {
36+
#[cfg_attr(
37+
blake3_avx2_ffi,
38+
link(name = "blake3_sse2_sse41_avx2_assembly", kind = "static")
39+
)]
3640
extern "C" {
3741
pub fn blake3_hash_many_avx2(
3842
inputs: *const *const u8,

src/ffi_avx512.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,14 @@ pub unsafe fn xof_many(
8383
}
8484

8585
pub mod ffi {
86+
#[cfg_attr(
87+
blake3_avx512_ffi_assembly,
88+
link(name = "blake3_avx512_assembly", kind = "static")
89+
)]
90+
#[cfg_attr(
91+
blake3_avx512_ffi_intrinsics,
92+
link(name = "blake3_avx512_intrinsics", kind = "static")
93+
)]
8694
extern "C" {
8795
pub fn blake3_compress_in_place_avx512(
8896
cv: *mut u32,

src/ffi_neon.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ pub extern "C" fn blake3_compress_in_place_portable(
5353
}
5454

5555
pub mod ffi {
56+
#[cfg_attr(blake3_neon_ffi, link(name = "blake3_neon", kind = "static"))]
5657
extern "C" {
5758
pub fn blake3_hash_many_neon(
5859
inputs: *const *const u8,

src/ffi_sse2.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ pub unsafe fn hash_many<const N: usize>(
6161
}
6262

6363
pub mod ffi {
64+
#[cfg_attr(
65+
blake3_sse2_ffi,
66+
link(name = "blake3_sse2_sse41_avx2_assembly", kind = "static")
67+
)]
6468
extern "C" {
6569
pub fn blake3_compress_in_place_sse2(
6670
cv: *mut u32,

src/ffi_sse41.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ pub unsafe fn hash_many<const N: usize>(
6161
}
6262

6363
pub mod ffi {
64+
#[cfg_attr(
65+
blake3_sse41_ffi,
66+
link(name = "blake3_sse2_sse41_avx2_assembly", kind = "static")
67+
)]
6468
extern "C" {
6569
pub fn blake3_compress_in_place_sse41(
6670
cv: *mut u32,

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ mod avx2;
110110
#[cfg(blake3_avx512_ffi)]
111111
#[path = "ffi_avx512.rs"]
112112
mod avx512;
113-
#[cfg(blake3_neon)]
113+
#[cfg(blake3_neon_ffi)]
114114
#[path = "ffi_neon.rs"]
115115
mod neon;
116116
mod portable;

src/platform.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ cfg_if::cfg_if! {
1010
pub const MAX_SIMD_DEGREE: usize = 8;
1111
}
1212
}
13-
} else if #[cfg(blake3_neon)] {
13+
} else if #[cfg(blake3_neon_ffi)] {
1414
pub const MAX_SIMD_DEGREE: usize = 4;
1515
} else {
1616
pub const MAX_SIMD_DEGREE: usize = 1;
@@ -30,7 +30,7 @@ cfg_if::cfg_if! {
3030
pub const MAX_SIMD_DEGREE_OR_2: usize = 8;
3131
}
3232
}
33-
} else if #[cfg(blake3_neon)] {
33+
} else if #[cfg(blake3_neon_ffi)] {
3434
pub const MAX_SIMD_DEGREE_OR_2: usize = 4;
3535
} else {
3636
pub const MAX_SIMD_DEGREE_OR_2: usize = 2;
@@ -49,7 +49,7 @@ pub enum Platform {
4949
#[cfg(blake3_avx512_ffi)]
5050
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
5151
AVX512,
52-
#[cfg(blake3_neon)]
52+
#[cfg(blake3_neon_ffi)]
5353
NEON,
5454
}
5555

@@ -81,7 +81,7 @@ impl Platform {
8181
}
8282
// We don't use dynamic feature detection for NEON. If the "neon"
8383
// feature is on, NEON is assumed to be supported.
84-
#[cfg(blake3_neon)]
84+
#[cfg(blake3_neon_ffi)]
8585
{
8686
return Platform::NEON;
8787
}
@@ -100,7 +100,7 @@ impl Platform {
100100
#[cfg(blake3_avx512_ffi)]
101101
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
102102
Platform::AVX512 => 16,
103-
#[cfg(blake3_neon)]
103+
#[cfg(blake3_neon_ffi)]
104104
Platform::NEON => 4,
105105
};
106106
debug_assert!(degree <= MAX_SIMD_DEGREE);
@@ -134,7 +134,7 @@ impl Platform {
134134
crate::avx512::compress_in_place(cv, block, block_len, counter, flags)
135135
},
136136
// No NEON compress_in_place() implementation yet.
137-
#[cfg(blake3_neon)]
137+
#[cfg(blake3_neon_ffi)]
138138
Platform::NEON => portable::compress_in_place(cv, block, block_len, counter, flags),
139139
}
140140
}
@@ -166,7 +166,7 @@ impl Platform {
166166
crate::avx512::compress_xof(cv, block, block_len, counter, flags)
167167
},
168168
// No NEON compress_xof() implementation yet.
169-
#[cfg(blake3_neon)]
169+
#[cfg(blake3_neon_ffi)]
170170
Platform::NEON => portable::compress_xof(cv, block, block_len, counter, flags),
171171
}
172172
}
@@ -261,7 +261,7 @@ impl Platform {
261261
)
262262
},
263263
// Assumed to be safe if the "neon" feature is on.
264-
#[cfg(blake3_neon)]
264+
#[cfg(blake3_neon_ffi)]
265265
Platform::NEON => unsafe {
266266
crate::neon::hash_many(
267267
inputs,
@@ -355,7 +355,7 @@ impl Platform {
355355
}
356356
}
357357

358-
#[cfg(blake3_neon)]
358+
#[cfg(blake3_neon_ffi)]
359359
pub fn neon() -> Option<Self> {
360360
// Assumed to be safe if the "neon" feature is on.
361361
Some(Self::NEON)

0 commit comments

Comments
 (0)