Fix/no std feature (currently wasm compatible; groundwork for no_std) #25
+105
−21
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The Problem
Issue #24 reports that
crc-fastcannot compile forwasm32-unknown-unknowntargets becauserandandregexare runtime dependencies, even though they're only used in CLI binaries and tests.This prevents:
The Solution
Move
randandregexto[dev-dependencies]and gate all CLI binaries behind aclifeature flag. This separates the library from the tools, allowing the library to compile for wasm32 and preparing for future no_std support.Changes
1. Cargo.toml
randandregexfrom[dependencies]to[dev-dependencies]default = ["std"]- Maintains backward compatibilitystd = []- Gates std-dependent functionalitycli = ["std"]- Gates all binary toolsalloc = []- Existing feature, preserved[[bin]]sections andrequired-features = ["cli"]required-features = ["cli"]2. src/bin/checksum.rs
randdependency completely3. src/lib.rs
#![cfg_attr(not(feature = "std"), no_std)]header for future compatibilitystd::fs::File,std::io::{Read, Write}Writetrait impl with#[cfg(feature = "std")]checksum_file,checksum_file_with_params) with#[cfg(feature = "std")]4. tests/checksum_integration_tests.rs
#![cfg(feature = "cli")]to gate entire test file--features cliflag5. .github/workflows/tests.yml
cargo check→cargo check --all-featurescargo clippy→cargo clippy --all-features--features cli --bin <name>cargo test --features cliPlanned version bump
MINOR]Links
Notes
Validation Performed
All changes tested successfully:
CI Status: All test jobs pass except macos-13 (deprecated runner)
Impact
For library users: Zero breaking changes. Default behavior identical to v1.6.0.
For CLI users: Must now use --features cli:
cargo install crc-fast --features clicargo run --features cli --bin checksumFor wasm/no_std users: Library now compiles for
wasm32-unknown-unknownand is ready for future no_std support... which I'll gladly work on in my free time this week.Future Work
This PR lays the groundwork for full no_std support (would require replacing HashMap (hashbrown?), RwLock, and other std-only types), but doesn't implement it to keep changes focused and reviewable.