Skip to content

Commit c538958

Browse files
committed
Add linkage attributes to extern "C" blocks
1 parent 83a60d9 commit c538958

8 files changed

Lines changed: 37 additions & 12 deletions

File tree

build.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,7 @@ fn build_avx512_c_intrinsics() {
236236
// This is required on 32-bit x86 targets, since the assembly
237237
// implementation doesn't support those.
238238
println!("cargo:rustc-cfg=blake3_avx512_ffi");
239+
println!("cargo:rustc-cfg=blake3_avx512_ffi_intrinsics");
239240
let mut build = new_build();
240241
build.file("c/blake3_avx512.c");
241242
if is_windows_msvc() {
@@ -256,6 +257,7 @@ fn build_avx512_assembly() {
256257
// only supports x86_64.
257258
assert!(is_x86_64());
258259
println!("cargo:rustc-cfg=blake3_avx512_ffi");
260+
println!("cargo:rustc-cfg=blake3_avx512_ffi_assembly");
259261
let mut build = new_build();
260262
let mut is_msvc = false;
261263
if is_windows_target() {
@@ -279,6 +281,7 @@ fn build_avx512_assembly() {
279281
}
280282

281283
fn build_neon_c_intrinsics() {
284+
println!("cargo:rustc-cfg=blake3_neon_ffi");
282285
let mut build = new_build();
283286
// Note that blake3_neon.c normally depends on the blake3_portable.c
284287
// for the single-instance compression function, but we expose
@@ -310,7 +313,9 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
310313
"blake3_avx2_ffi",
311314
"blake3_avx2_rust",
312315
"blake3_avx512_ffi",
313-
"blake3_neon",
316+
"blake3_avx512_ffi_assembly",
317+
"blake3_avx512_ffi_intrinsics",
318+
"blake3_neon_ffi",
314319
"blake3_wasm32_simd",
315320
];
316321
for cfg_name in all_cfgs {
@@ -353,7 +358,6 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
353358
if (is_arm() && is_neon())
354359
|| (!is_no_neon() && !is_pure() && is_aarch64() && is_little_endian())
355360
{
356-
println!("cargo:rustc-cfg=blake3_neon");
357361
build_neon_c_intrinsics();
358362
}
359363

src/ffi_avx2.rs

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

3737
pub mod ffi {
38+
#[cfg_attr(
39+
blake3_avx2_ffi,
40+
link(name = "blake3_sse2_sse41_avx2_assembly", kind = "static")
41+
)]
3842
extern "C" {
3943
pub fn blake3_hash_many_avx2(
4044
inputs: *const *const u8,

src/ffi_avx512.rs

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

9999
pub mod ffi {
100+
#[cfg_attr(
101+
blake3_avx512_ffi_assembly,
102+
link(name = "blake3_avx512_assembly", kind = "static")
103+
)]
104+
#[cfg_attr(
105+
blake3_avx512_ffi_intrinsics,
106+
link(name = "blake3_avx512_intrinsics", kind = "static")
107+
)]
100108
extern "C" {
101109
pub fn blake3_compress_in_place_avx512(
102110
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
@@ -73,6 +73,10 @@ pub unsafe fn hash_many<const N: usize>(
7373
}
7474

7575
pub mod ffi {
76+
#[cfg_attr(
77+
blake3_sse2_ffi,
78+
link(name = "blake3_sse2_sse41_avx2_assembly", kind = "static")
79+
)]
7680
extern "C" {
7781
pub fn blake3_compress_in_place_sse2(
7882
cv: *mut u32,

src/ffi_sse41.rs

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

7575
pub mod ffi {
76+
#[cfg_attr(
77+
blake3_sse41_ffi,
78+
link(name = "blake3_sse2_sse41_avx2_assembly", kind = "static")
79+
)]
7680
extern "C" {
7781
pub fn blake3_compress_in_place_sse41(
7882
cv: *mut u32,

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ mod avx2;
114114
#[cfg(blake3_avx512_ffi)]
115115
#[path = "ffi_avx512.rs"]
116116
mod avx512;
117-
#[cfg(blake3_neon)]
117+
#[cfg(blake3_neon_ffi)]
118118
#[path = "ffi_neon.rs"]
119119
mod neon;
120120
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 if #[cfg(blake3_wasm32_simd)] {
1616
pub const MAX_SIMD_DEGREE: usize = 4;
@@ -32,7 +32,7 @@ cfg_if::cfg_if! {
3232
pub const MAX_SIMD_DEGREE_OR_2: usize = 8;
3333
}
3434
}
35-
} else if #[cfg(blake3_neon)] {
35+
} else if #[cfg(blake3_neon_ffi)] {
3636
pub const MAX_SIMD_DEGREE_OR_2: usize = 4;
3737
} else if #[cfg(blake3_wasm32_simd)] {
3838
pub const MAX_SIMD_DEGREE_OR_2: usize = 4;
@@ -53,7 +53,7 @@ pub enum Platform {
5353
#[cfg(blake3_avx512_ffi)]
5454
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
5555
AVX512,
56-
#[cfg(blake3_neon)]
56+
#[cfg(blake3_neon_ffi)]
5757
NEON,
5858
#[cfg(blake3_wasm32_simd)]
5959
#[allow(non_camel_case_types)]
@@ -88,7 +88,7 @@ impl Platform {
8888
}
8989
// We don't use dynamic feature detection for NEON. If the "neon"
9090
// feature is on, NEON is assumed to be supported.
91-
#[cfg(blake3_neon)]
91+
#[cfg(blake3_neon_ffi)]
9292
{
9393
return Platform::NEON;
9494
}
@@ -111,7 +111,7 @@ impl Platform {
111111
#[cfg(blake3_avx512_ffi)]
112112
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
113113
Platform::AVX512 => 16,
114-
#[cfg(blake3_neon)]
114+
#[cfg(blake3_neon_ffi)]
115115
Platform::NEON => 4,
116116
#[cfg(blake3_wasm32_simd)]
117117
Platform::WASM32_SIMD => 4,
@@ -147,7 +147,7 @@ impl Platform {
147147
crate::avx512::compress_in_place(cv, block, block_len, counter, flags)
148148
},
149149
// No NEON compress_in_place() implementation yet.
150-
#[cfg(blake3_neon)]
150+
#[cfg(blake3_neon_ffi)]
151151
Platform::NEON => portable::compress_in_place(cv, block, block_len, counter, flags),
152152
#[cfg(blake3_wasm32_simd)]
153153
Platform::WASM32_SIMD => {
@@ -183,7 +183,7 @@ impl Platform {
183183
crate::avx512::compress_xof(cv, block, block_len, counter, flags)
184184
},
185185
// No NEON compress_xof() implementation yet.
186-
#[cfg(blake3_neon)]
186+
#[cfg(blake3_neon_ffi)]
187187
Platform::NEON => portable::compress_xof(cv, block, block_len, counter, flags),
188188
#[cfg(blake3_wasm32_simd)]
189189
Platform::WASM32_SIMD => {
@@ -282,7 +282,7 @@ impl Platform {
282282
)
283283
},
284284
// Assumed to be safe if the "neon" feature is on.
285-
#[cfg(blake3_neon)]
285+
#[cfg(blake3_neon_ffi)]
286286
Platform::NEON => unsafe {
287287
crate::neon::hash_many(
288288
inputs,
@@ -390,7 +390,7 @@ impl Platform {
390390
}
391391
}
392392

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

0 commit comments

Comments
 (0)