Repository navigation
Remove bitvec runtime dependency (fixes #114) - #117
Merged
Merged
Conversation
bitvec pulls in radium, which fails to compile on targets without AtomicU64 such as the ESP32-S3 (xtensa-esp32s3-none-elf). It was only used by LsbInteger pack/unpack to shift a bit range for non-byte-aligned widths, so replace it with two small MSB0 bit shift helpers. bitvec is kept as a dev-dependency for a differential test against the new helpers. Also adds an integration test for unaligned LSB integers, with golden bytes captured from the previous bitvec implementation. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes #114.
Why
bitvecdepends onradium, which fails to compile on targets withoutAtomicU64, such as the ESP32-S3 (xtensa-esp32s3-none-elf):That blocks downstream crates like
usbd-human-interface-deviceon those chips.packed_structonly usedbitvecinLsbInteger::pack/unpack, to shift a bit range when an LSB-endian integer isn't a whole number of bytes wide (e.g.Integer<u16, Bits<10>>).What changed
LsbInteger::pack/unpacknow use two small private helpers,msb0_shift_rightandmsb0_shift_left, intypes_num.rs. They reproduceBitSlice::<u8, Msb0>::shift_end/shift_starton the[0, len)bit range. They move one bit at a time, which is plenty fast since the arrays are at most 32 bytes (256 withbyte_types_256).bitvecmoved from[dependencies]to[dev-dependencies]ofpacked_struct. The workspace dependency entry is kept for that.PackingError::BitsErroris now unused, but I kept it to avoid a breaking API change.Tests
test_msb0_shift_against_bitvec: compares both helpers against bitvec'sshift_end/shift_startfor everylenand shift amount on 1–8 byte buffers, over fixed and pseudo-random byte patterns.packing_lsb_unaligned.rsintegration test: no existing test exercised this code path, since all currentendian="lsb"tests use whole-byte widths. The new test uses 10-, 12-, 20-, 3- and 27-bit LSB fields. Its expected packed bytes were recorded from the previous bitvec implementation before the swap. It also round-trips 1,000 pseudo-random structs.Verification
cargo test --workspacepasses.cargo clippy -p packed_struct --all-targetsreports no warnings.cargo tree -p packed_struct -e normalno longer listsbitvec/radium.cargo +esp build -p packed_struct --no-default-features --target xtensa-esp32s3-none-elf -Zbuild-std=corefails onmasterwith the error above and succeeds on this branch.riscv32imc-unknown-none-elfandthumbv6m-none-eabibuilt fine even before this change. The failure is specific to Xtensa targets, becauseradium0.7 doesn't know they lack 64-bit atomics.🤖 Generated with Claude Code