Skip to content

Commit 41279ef

Browse files
committed
Merge branch 'main' of github.com:loadingalias/crc-fast-rust into add-no_std-and-wasm
2 parents a6d21b4 + 95d4f58 commit 41279ef

37 files changed

+1634
-292
lines changed

.github/workflows/tests.yml

Lines changed: 82 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jobs:
2323
with:
2424
toolchain: ${{ matrix.rust-toolchain }}
2525
components: rustfmt, clippy
26-
cache-key: ${{ matrix.os }}-${{ matrix.rust-toolchain }}
26+
cache-key: ${{ matrix.os }}-${{ matrix.rust-toolchain }}-v2
2727
- name: Check
2828
run: cargo check --all-features
2929
- name: Architecture check
@@ -54,7 +54,7 @@ jobs:
5454
with:
5555
toolchain: ${{ matrix.rust-toolchain }}
5656
components: rustfmt, clippy
57-
cache-key: ${{ matrix.os }}-${{ matrix.rust-toolchain }}
57+
cache-key: ${{ matrix.os }}-${{ matrix.rust-toolchain }}-v2
5858
- name: Check
5959
run: cargo check --all-features
6060
- name: Architecture check
@@ -146,4 +146,83 @@ jobs:
146146
run: cargo miri nextest run --all-features -j${{ steps.cores.outputs.count }}
147147
- name: Run Miri tests (serial)
148148
if: steps.cores.outputs.use_nextest == 'false'
149-
run: cargo miri test --all-features
149+
run: cargo miri test --all-features
150+
151+
test-no-std:
152+
name: Test no_std
153+
runs-on: ubuntu-latest
154+
strategy:
155+
matrix:
156+
target:
157+
- thumbv7em-none-eabihf # ARM Cortex-M4F/M7F
158+
- thumbv8m.main-none-eabihf # ARM Cortex-M33/M35P
159+
- riscv32imac-unknown-none-elf # RISC-V 32-bit
160+
rust-toolchain:
161+
- "1.81" # minimum for this crate
162+
- "stable"
163+
- "nightly"
164+
steps:
165+
- uses: actions/checkout@v4 # not pinning to commit hash since this is a GitHub action, which we trust
166+
- uses: actions-rust-lang/setup-rust-toolchain@9d7e65c320fdb52dcd45ffaa68deb6c02c8754d9 # v1.12.0
167+
with:
168+
toolchain: ${{ matrix.rust-toolchain }}
169+
target: ${{ matrix.target }}
170+
components: rustfmt, clippy
171+
cache-key: ${{ matrix.target }}-${{ matrix.rust-toolchain }}-v2
172+
- name: Check no_std (no features)
173+
run: cargo check --target ${{ matrix.target }} --no-default-features --features panic-handler --lib
174+
- name: Check no_std with alloc
175+
run: cargo check --target ${{ matrix.target }} --no-default-features --features alloc,panic-handler --lib
176+
- name: Check no_std with cache
177+
run: cargo check --target ${{ matrix.target }} --no-default-features --features cache,panic-handler --lib
178+
- name: Run no_std tests (on host with std test harness)
179+
run: cargo test --test no_std_tests
180+
181+
test-wasm:
182+
name: Test WASM
183+
runs-on: ubuntu-latest
184+
strategy:
185+
matrix:
186+
include:
187+
# WASM 1.0/2.0 (32-bit) - all toolchains
188+
- target: wasm32-unknown-unknown
189+
rust-toolchain: "1.81"
190+
- target: wasm32-unknown-unknown
191+
rust-toolchain: "stable"
192+
- target: wasm32-unknown-unknown
193+
rust-toolchain: "nightly"
194+
# WASI preview 1 (32-bit) - all toolchains
195+
- target: wasm32-wasip1
196+
rust-toolchain: "1.81"
197+
- target: wasm32-wasip1
198+
rust-toolchain: "stable"
199+
- target: wasm32-wasip1
200+
rust-toolchain: "nightly"
201+
# WASI preview 2 (32-bit) - nightly only (experimental)
202+
- target: wasm32-wasip2
203+
rust-toolchain: "nightly"
204+
# Note: wasm64-unknown-unknown removed - not consistently available in nightly
205+
steps:
206+
- uses: actions/checkout@v4 # not pinning to commit hash since this is a GitHub action, which we trust
207+
- uses: actions-rust-lang/setup-rust-toolchain@9d7e65c320fdb52dcd45ffaa68deb6c02c8754d9 # v1.12.0
208+
with:
209+
toolchain: ${{ matrix.rust-toolchain }}
210+
target: ${{ matrix.target }}
211+
components: rustfmt, clippy
212+
cache-key: ${{ matrix.target }}-${{ matrix.rust-toolchain }}-v2
213+
- name: Check WASM (no features)
214+
run: cargo check --target ${{ matrix.target }} --no-default-features --features panic-handler --lib
215+
- name: Check WASM with alloc
216+
run: cargo check --target ${{ matrix.target }} --no-default-features --features alloc,panic-handler --lib
217+
- name: Check WASM with cache
218+
run: cargo check --target ${{ matrix.target }} --no-default-features --features cache,panic-handler --lib
219+
- name: Build WASM release
220+
run: cargo build --target ${{ matrix.target }} --no-default-features --features alloc,panic-handler --lib --release
221+
- name: Run WASM tests (on host with std test harness)
222+
run: cargo test --test wasm_tests
223+
- if: ${{ matrix.target == 'wasm32-unknown-unknown' && matrix.rust-toolchain == 'stable' }}
224+
name: Install wasm-pack
225+
run: curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
226+
- if: ${{ matrix.target == 'wasm32-unknown-unknown' && matrix.rust-toolchain == 'stable' }}
227+
name: Build WASM package with wasm-pack
228+
run: wasm-pack build --target web --no-default-features --features alloc,panic-handler

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@
44
.idea
55
.DS_Store
66
.git
7-
.vscode
7+
.vscode

Cargo.lock

Lines changed: 95 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,26 @@ bench = true
2323

2424
[dependencies]
2525
crc = "3"
26-
digest = { version = "0.10", features = ["alloc"] }
26+
digest = { version = "0.10", optional = true, default-features = false, features = ["alloc"] }
2727

2828
# will be removed once Rust 1.89 is the minimum supported version
2929
rustversion = "1.0"
3030

3131
# constrain indexmap (transitive) to a version compatible with Rust 1.81.0
3232
indexmap = { version = ">=2.11.0, <2.12.0", optional = true }
3333

34+
# no_std support
35+
# spin is always required for no_std builds (feature detection synchronization)
36+
spin = { version = "0.10.0", default-features = false, features = ["once", "rwlock", "mutex", "spin_mutex"] }
37+
# hashbrown is only needed when caching is enabled in no_std
38+
hashbrown = { version = "0.16.0", optional = true }
39+
3440
[dev-dependencies]
3541
criterion = "0.7"
3642
cbindgen = "0.29"
3743
rand = "0.9"
3844
regex = "1.12"
45+
wasm-bindgen-test = "0.3"
3946

4047
# lto=true has a big improvement in performance
4148
[profile.release]
@@ -62,12 +69,16 @@ required-features = ["cli"]
6269
[[bench]]
6370
name = "benchmark"
6471
harness = false
72+
required-features = ["std"]
6573

6674
[features]
67-
default = ["std"]
68-
std = []
75+
default = ["std", "panic-handler"]
76+
std = ["alloc"] # std implies alloc is available
6977
cli = ["std"]
70-
alloc = []
78+
alloc = ["digest"] # marker feature for heap allocation support
79+
cache = ["alloc", "hashbrown"] # caching requires alloc + hashbrown HashMap
80+
ffi = ["std"]
81+
panic-handler = [] # Provides panic handler for no_std library checks (disable in binaries)
7182

7283
# the features below are deprecated, aren't in use, and will be removed in the next MAJOR version (v2)
7384
vpclmulqdq = [] # deprecated, VPCLMULQDQ stabilized in Rust 1.89.0
@@ -87,4 +98,4 @@ rustdoc-args = ["--cfg", "docsrs"]
8798
[[test]]
8899
name = "checksum_integration_tests"
89100
path = "tests/checksum_integration_tests.rs"
90-
required-features = ["cli"]
101+
required-features = ["cli"]

0 commit comments

Comments
 (0)