Skip to content

Fix linker issues #2 #6

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,4 @@ optimize_crc32_sse_v4s3x3 = []

[lints.rust]
# build-time feature enablement
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(optimized_crc32_iscsi)','cfg(optimized_crc32_iso_hdlc)' ] }
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(optimized_crc32_iscsi)','cfg(optimized_crc32_iso_hdlc)','cfg(rust_implementation_only)'] }
16 changes: 11 additions & 5 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ fn main() {
// Windows doesn't build the C bindings automatically, and since they're auto-generated from
// another project, I'm not inclined to fix it. The Rust implementation is still very fast.
#[cfg(target_os = "windows")]
return;
{
println!("cargo:rustc-cfg=rust_implementation_only");
return;
}

// build hardware optimized version
build_optimized();
Expand All @@ -32,10 +35,11 @@ fn build_optimized() {
}

if "x86_64" == target_arch || "x86" == target_arch {
build_optimized_x86()
return build_optimized_x86()
}

// fall back to Rust implementation
println!("cargo:rustc-cfg=rust_implementation_only");
}

fn build_optimized_target_crc32_iscsi(name: &str, flags: &[String]) {
Expand Down Expand Up @@ -99,11 +103,12 @@ fn build_optimized_aarch64() {
#[allow(unreachable_code)]
#[cfg(all(target_arch = "aarch64", target_feature = "neon"))]
if is_aarch64_feature_detected!("crc") {
build_neon_v12e_v1()
return build_neon_v12e_v1()
}
}

// fall through to internal Rust implementation
println!("cargo:rustc-cfg=rust_implementation_only");
}

fn build_neon_blended() {
Expand Down Expand Up @@ -163,7 +168,7 @@ fn build_optimized_x86() {
let target_arch = env::var("CARGO_CFG_TARGET_ARCH").unwrap();
if "x86" == target_arch {
// this is the only one supported on 32-bit x86 systems
crate::build_sse_v4s3x3()
return crate::build_sse_v4s3x3()
}

#[cfg(any(target_arch = "x86_64", target_arch = "x86"))]
Expand All @@ -184,11 +189,12 @@ fn build_optimized_x86() {

#[cfg(any(target_arch = "x86_64", target_arch = "x86"))]
if is_x86_feature_detected!("sse4.2") && is_x86_feature_detected!("pclmulqdq") {
crate::build_sse_v4s3x3()
return crate::build_sse_v4s3x3()
}
}

// fall through to internal Rust implementation
println!("cargo:rustc-cfg=rust_implementation_only");
}

fn build_avx512_vpclmulqdq_v3x2() {
Expand Down
6 changes: 6 additions & 0 deletions src/bindings/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,13 @@ use crate::structs::CrcParams;
use std::ffi::CStr;
use std::os::raw::c_char;

#[cfg(not(rust_implementation_only))]
mod crc32_iscsi;
#[cfg(not(rust_implementation_only))]
mod crc32_iso_hdlc;

// note that the initial state needs to be reversed
#[cfg(not(rust_implementation_only))]
#[inline(always)]
pub(crate) fn crc32_iso_hdlc(state: u64, data: &[u8], params: CrcParams) -> u64 {
unsafe {
Expand All @@ -29,6 +32,7 @@ pub(crate) fn crc32_iso_hdlc(state: u64, data: &[u8], params: CrcParams) -> u64
}

// note that the initial state needs to be reversed
#[cfg(not(rust_implementation_only))]
#[inline(always)]
pub(crate) fn crc32_iscsi(state: u64, data: &[u8], params: CrcParams) -> u64 {
unsafe {
Expand All @@ -39,11 +43,13 @@ pub(crate) fn crc32_iscsi(state: u64, data: &[u8], params: CrcParams) -> u64 {
}
}

#[cfg(not(rust_implementation_only))]
#[allow(unused)]
pub unsafe fn get_iso_hdlc_target() -> String {
convert_to_string(crc32_iso_hdlc::get_iso_hdlc_target())
}

#[cfg(not(rust_implementation_only))]
#[allow(unused)]
pub unsafe fn get_iscsi_target() -> String {
convert_to_string(crc32_iscsi::get_iscsi_target())
Expand Down