Derive the Rust static-library configuration from the effective C HUF decoder flags and place each mode in its own Cargo target directory. This prevents a forced X1/X2 C build from silently reusing the default Rust archive. The test and program makefiles now also build and link an i686 Rust archive for their 32-bit targets, including zstd32. zstd-small retains its existing default configuration while preserving an explicitly requested HUF mode. Test Plan: - cargo clippy; cargo clippy --benches; cargo clippy --tests - cargo +nightly fmt, then repeat the Clippy checks - cargo test --all-targets for default, forced X1, and forced X2 modes - cargo build --release --target i686-unknown-linux-gnu for each mode - make -n checks for default, forced, direct -D, and 32-bit test/CLI targets Refs: rust/README.md
Rust rewrite
This directory contains the in-progress Rust replacement for the zstd library and command-line program. During the migration, the crate is built as a static library and linked into the original C test programs. Production C translation units become declaration-only shims as their implementations move to Rust; the original C tests remain unchanged and provide compatibility coverage.
Component map
The crate is organized from low-level representation helpers toward the public zstd ABI:
- Common primitives
mem,bits,bitstream, andcpuimplement byte-order, bitstream, and target-feature operations used by the codecs.errors,debug,xxhash, andzstd_commonprovide common exported ABI functions and state.commoncontains shared frame constants and internal data types.
- Entropy coding
entropy_commonreads FSE normalized counts and Huffman statistics.fse_decompressbuilds FSE decoding tables and decodes FSE streams.fse_compressnormalizes counts, writes FSE headers, builds compression tables, and encodes FSE streams.
- Compression primitives
histcounts byte frequencies for FSE and Huffman compression.
- Runtime support
threadingprovides platform pthread wrappers required by zstd headers.poolimplements the bounded worker pool used by multithreaded compression.
The remaining block compression, general decompression, dictionary, legacy, and CLI translation units are still C. They must move before the rewrite is complete. Keeping that boundary explicit prevents a passing hybrid build from being mistaken for the final all-Rust result.
Compatibility boundary
The public ABI continues to come from the existing headers under lib/.
Exported Rust functions therefore use C layout and calling conventions. A C
source file whose implementation has moved to Rust remains in the original
makefile source list as a small shim so header configuration and platform
preprocessor behavior stay available during the transition.
The test and program makefiles select an archive directory for the active C configuration: default, forced HUF X1/X2, and the matching Rust target for 32-bit C binaries. They rebuild the selected archive and relink the executable when a Rust source changes, so original C tests do not accidentally use a stale or configuration-incompatible implementation.
Validation
Run focused Rust checks from this directory:
cargo fmt --check
cargo clippy --all-targets -- -D warnings
cargo test --all-targets
cargo build --release
Then run original compatibility tests from the repository root, starting with the narrow target for the component being migrated. For example:
make -C tests fuzzer
./tests/fuzzer -i1 --no-big-tests
Broader tests/Makefile targets remain the authoritative integration gates as
more of the library and CLI are rewritten.