Skip to content

Commit

Permalink
Add linkage attributes to extern "C" blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
saethlin committed Oct 4, 2024
1 parent 27cbd6b commit 54c8dfb
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 2 deletions.
4 changes: 2 additions & 2 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -254,7 +255,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
"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.
Expand Down Expand Up @@ -296,7 +297,6 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
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();
}

Expand Down
4 changes: 4 additions & 0 deletions src/ffi_avx2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ pub unsafe fn hash_many<const N: usize>(
}

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,
Expand Down
4 changes: 4 additions & 0 deletions src/ffi_avx512.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ pub unsafe fn hash_many<const N: usize>(
}

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,
Expand Down
1 change: 1 addition & 0 deletions src/ffi_neon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 4 additions & 0 deletions src/ffi_sse2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ pub unsafe fn hash_many<const N: usize>(
}

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,
Expand Down
4 changes: 4 additions & 0 deletions src/ffi_sse41.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ pub unsafe fn hash_many<const N: usize>(
}

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,
Expand Down

0 comments on commit 54c8dfb

Please sign in to comment.