Skip to content

Commit 2b1e6d2

Browse files
committed
crc-fast-rust: testing the no_std fix against CI; really gating spin dep in no_std builds
1 parent 30e84d7 commit 2b1e6d2

File tree

4 files changed

+22
-5
lines changed

4 files changed

+22
-5
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@
55
.DS_Store
66
.git
77
.vscode
8+
walkthrough.md

Cargo.toml

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,22 @@ rustversion = "1.0"
3535
indexmap = { version = ">=2.11.0, <2.12.0", optional = true }
3636

3737
# no_std support
38-
# spin is always required for no_std builds (feature detection synchronization)
39-
spin = { version = "0.10.0", default-features = false, features = ["once", "rwlock", "mutex", "spin_mutex"] }
38+
# spin is optional - only needed on architectures with SIMD (for feature detection)
39+
# or when cache feature is enabled
40+
spin = { version = "0.10.0", default-features = false, features = ["once", "rwlock", "mutex", "spin_mutex"], optional = true }
4041
# hashbrown is only needed when caching is enabled in no_std
4142
hashbrown = { version = "0.16.0", optional = true }
4243

44+
# Target-specific dependencies: spin is needed for feature detection on SIMD-capable architectures
45+
[target.'cfg(target_arch = "aarch64")'.dependencies]
46+
spin = { version = "0.10.0", default-features = false, features = ["once", "rwlock", "mutex", "spin_mutex"] }
47+
48+
[target.'cfg(target_arch = "x86")'.dependencies]
49+
spin = { version = "0.10.0", default-features = false, features = ["once", "rwlock", "mutex", "spin_mutex"] }
50+
51+
[target.'cfg(target_arch = "x86_64")'.dependencies]
52+
spin = { version = "0.10.0", default-features = false, features = ["once", "rwlock", "mutex", "spin_mutex"] }
53+
4354
[dev-dependencies]
4455
criterion = "0.7"
4556
cbindgen = "0.29"
@@ -84,7 +95,7 @@ ffi = [] # C/C++ compatible dynamic/static library, planned to become optional i
8495

8596
# optional features
8697
cli = ["std"] # command line interface binaries (checksum, arch-check, get-custom-params)
87-
cache = ["alloc", "hashbrown"] # no_std caching requires alloc + hashbrown HashMap
98+
cache = ["alloc", "hashbrown", "spin"] # no_std caching requires alloc + hashbrown HashMap + spin for synchronization
8899

89100
# the features below are deprecated, aren't in use, and will be removed in the next MAJOR version (v2)
90101
vpclmulqdq = [] # deprecated, VPCLMULQDQ stabilized in Rust 1.89.0

src/arch/x86_64/avx512_vpclmulqdq.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ impl Simd512 {
6666
))
6767
}
6868

69+
#[cfg(feature = "std")]
6970
#[inline]
7071
#[target_feature(enable = "avx512f")]
7172
unsafe fn extract_u64s(&self) -> [u64; 8] {
@@ -93,6 +94,7 @@ impl Simd512 {
9394
Self(_mm512_xor_si512(self.0, other.0))
9495
}
9596

97+
#[cfg(feature = "std")]
9698
#[inline]
9799
#[target_feature(enable = "avx512f")]
98100
#[allow(unused)]
@@ -382,7 +384,7 @@ unsafe fn reflect_bytes512(reflector: &Reflector512, data: Simd512) -> Simd512 {
382384
// pre-compute the reverse indices for 512-bit shuffling
383385
#[rustversion::since(1.89)]
384386
static REVERSE_INDICES_512: __m512i =
385-
unsafe { std::mem::transmute([7u64, 6u64, 5u64, 4u64, 3u64, 2u64, 1u64, 0u64]) };
387+
unsafe { core::mem::transmute([7u64, 6u64, 5u64, 4u64, 3u64, 2u64, 1u64, 0u64]) };
386388

387389
// Implement a 512-bit byte shuffle function
388390
#[rustversion::since(1.89)]

src/crc32/mod.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,8 @@
55
pub mod algorithm;
66
pub mod consts;
77

8-
#[cfg(any(target_arch = "x86", target_arch = "x86_64", target_arch = "aarch64"))]
8+
#[cfg(all(
9+
feature = "std",
10+
any(target_arch = "x86", target_arch = "x86_64", target_arch = "aarch64")
11+
))]
912
pub(crate) mod fusion;

0 commit comments

Comments
 (0)