From 54c8dfb100f5a63e68c28d0255f260f10e0726d1 Mon Sep 17 00:00:00 2001 From: Ben Kimock Date: Thu, 3 Oct 2024 23:53:37 -0400 Subject: [PATCH] Add linkage attributes to extern "C" blocks --- build.rs | 4 ++-- src/ffi_avx2.rs | 4 ++++ src/ffi_avx512.rs | 4 ++++ src/ffi_neon.rs | 1 + src/ffi_sse2.rs | 4 ++++ src/ffi_sse41.rs | 4 ++++ 6 files changed, 19 insertions(+), 2 deletions(-) diff --git a/build.rs b/build.rs index af5805d9c..0cf34449b 100644 --- a/build.rs +++ b/build.rs @@ -230,6 +230,7 @@ fn build_avx512_assembly() { } fn build_neon_c_intrinsics() { + println!("cargo:rustc-cfg=blake3_neon_ffi"); let mut build = new_build(); // Note that blake3_neon.c normally depends on the blake3_portable.c // for the single-instance compression function, but we expose @@ -254,7 +255,7 @@ fn main() -> Result<(), Box> { "blake3_avx2_ffi", "blake3_avx2_rust", "blake3_avx512_ffi", - "blake3_neon", + "blake3_neon_ffi", ]; for cfg_name in all_cfgs { // TODO: Switch this whole file to the new :: syntax when our MSRV reaches 1.77. @@ -296,7 +297,6 @@ fn main() -> Result<(), Box> { if (is_arm() && is_neon()) || (!is_no_neon() && !is_pure() && is_aarch64() && is_little_endian()) { - println!("cargo:rustc-cfg=blake3_neon"); build_neon_c_intrinsics(); } diff --git a/src/ffi_avx2.rs b/src/ffi_avx2.rs index 33961e9d4..0fc466487 100644 --- a/src/ffi_avx2.rs +++ b/src/ffi_avx2.rs @@ -33,6 +33,10 @@ pub unsafe fn hash_many( } pub mod ffi { + #[cfg_attr( + blake3_avx2_ffi, + link(name = "blake3_sse2_sse41_avx2_assembly", kind = "static") + )] extern "C" { pub fn blake3_hash_many_avx2( inputs: *const *const u8, diff --git a/src/ffi_avx512.rs b/src/ffi_avx512.rs index 884f48135..4c08b72ee 100644 --- a/src/ffi_avx512.rs +++ b/src/ffi_avx512.rs @@ -61,6 +61,10 @@ pub unsafe fn hash_many( } pub mod ffi { + #[cfg_attr( + blake3_avx512_ffi, + link(name = "blake3_avx512_assembly", kind = "static") + )] extern "C" { pub fn blake3_compress_in_place_avx512( cv: *mut u32, diff --git a/src/ffi_neon.rs b/src/ffi_neon.rs index 54d07a4de..b8493dae0 100644 --- a/src/ffi_neon.rs +++ b/src/ffi_neon.rs @@ -53,6 +53,7 @@ pub extern "C" fn blake3_compress_in_place_portable( } pub mod ffi { + #[cfg_attr(blake3_neon_ffi, link(name = "blake3_neon", kind = "static"))] extern "C" { pub fn blake3_hash_many_neon( inputs: *const *const u8, diff --git a/src/ffi_sse2.rs b/src/ffi_sse2.rs index 1c5da81f9..353bac0ae 100644 --- a/src/ffi_sse2.rs +++ b/src/ffi_sse2.rs @@ -61,6 +61,10 @@ pub unsafe fn hash_many( } pub mod ffi { + #[cfg_attr( + blake3_sse2_ffi, + link(name = "blake3_sse2_sse41_avx2_assembly", kind = "static") + )] extern "C" { pub fn blake3_compress_in_place_sse2( cv: *mut u32, diff --git a/src/ffi_sse41.rs b/src/ffi_sse41.rs index 62989c5ec..ff7b62c6e 100644 --- a/src/ffi_sse41.rs +++ b/src/ffi_sse41.rs @@ -61,6 +61,10 @@ pub unsafe fn hash_many( } pub mod ffi { + #[cfg_attr( + blake3_sse41_ffi, + link(name = "blake3_sse2_sse41_avx2_assembly", kind = "static") + )] extern "C" { pub fn blake3_compress_in_place_sse41( cv: *mut u32,