Repository navigation
feat(rust): port libobs/util/bitstream to Rust (four-tier tested) - #3
Merged
Merged
Conversation
Defines the four mandatory test tiers for porting libobs internals to Rust while keeping the public C API/ABI and obs-websocket protocol compatible. AGENTS.md/CLAUDE.md point every agent at the policy. The root .gitignore allowlist gains the agent files and the Rust workspace paths. Refs #1
Adds the Cargo workspace (rust-toolchain.toml, rust/obs-util, rust/obs-c-oracle placeholder, rust/libobs-rust staticlib) and the Tier 1 tests from docs/rust-port/testing-policy.md. All tests fail against the stubbed safe core. Refs #1
- obs-util::ffi::bitstream: #[repr(C)] bitstream_reader matching the header and #[no_mangle] shims; the core is generic over position so the C ABI keeps the uint8_t pos wrap without duplicating logic. - obs-c-oracle: original bitstream.c compiled with oracle_ symbols. - Tier 2 layout test and Tier 3 proptest parity test (buffers up to 1024 bytes, wrap past byte 255). Mutation check: breaking the u8 wrap fails both parity tests. Refs #1
- libobs/cmake/rust.cmake: Corrosion v0.5.2 imports rust/libobs-rust and whole-archive links it; util/bitstream.c is dropped when ON. - rust-exports.map hides Rust internals so libobs exports the same 1752 symbols ON and OFF. - ENABLE_UNIT_TESTS now actually adds test/cmocka (it was not wired up). - rust/tools/linux-validate: Docker harness building OFF and ON, running the unchanged cmocka tests and diffing exported symbols. - rust/README.md; testing policy updated with what this port established. Closes #1
Review follow-up: the proptest now also starts from any (pos, subPos), covering the subPos == 0 quirk (a mutation replacing the C bit test is caught only by this case). The null-buf divergence from C (UB there) is documented. Refs #1
This was referenced Oct 10, 2026
This was referenced Oct 25, 2026
6 tasks
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.
Closes #1. Supersedes #2 (this branch contains the policy commit).
First Rust port:
libobs/util/bitstream, done exactly per docs/rust-port/testing-policy.md. The public C API/ABI is unchanged; withENABLE_RUST_LIBOBS=ONthe C source is dropped and Rust provides the symbols.What's here
Cargo.toml,rust-toolchain.toml,rust/README.md.rust/obs-util: safe coreBitstreamReader+ffi::bitstreamshim (#[repr(C)]struct matching the header). The core is generic over position:usizefor the safe API, wrappingu8for the C ABI. So the shim keeps C'suint8_t poswrap without duplicating logic.rust/obs-c-oracle: the originalbitstream.c, unmodified, compiled withoracle_symbols.rust/libobs-rust: the single staticlib linked into libobs (one staticlib only, since each embeds its own std).ENABLE_RUST_LIBOBS(default OFF) via Corrosion v0.5.2 with a whole-archive link.libobs/cmake/rust-exports.maphides Rust internals.ENABLE_UNIT_TESTSnow actually addstest/cmocka(it was not wired up before).rust/tools/linux-validate: a Docker harness for Tier 2.Evidence
RED (commit ad02d8e,
todo!()stubs):GREEN:
soldr cargo test --workspacepasses: Tier 1 has 5 tests, Tier 2 has the layout test, and Tier 3 has 3 parity tests. The parity tests are proptests against the C oracle with buffers up to 1024 bytes, arbitrary startingpos/subPos, and a deterministic run across the 255→0 wrap.clippy -D warnings,fmt --check, gersemi 0.25 and clang-format 22 are all clean.Mutation checks:
u8position saturate instead of wrap fails both wrap-sensitive parity tests.(b & s) == swith!= 0failsmatches_c_oracle_from_any_state.Tier 2 (
rust/tools/linux-validate/run.sh, Ubuntu 26.04, FFmpeg 8): builds libobs, the 4 cmocka tests and the decklink plugin in both configurations.With ON,
util/bitstream.cis not compiled, andtest/cmocka/test_bitstream.candbitstream.hare unmodified.Review: pre-push review found 2 LOW issues, both fixed in the last commit.
Known limits
obs.dllexports) and macOS (symbol hiding) are TODOs for when ON is enabled there.