Skip to content

feat(libobs): port buffered-file-serializer to Rust - #76

Merged
zackees merged 2 commits into
obs-rust:masterfrom
nathan-v:rust/buffered-file-serializer-port
Oct 10, 2026
Merged

zackees merged 2 commits into
obs-rust:masterfrom
nathan-v:rust/buffered-file-serializer-port

Conversation

@nathan-v

@nathan-v nathan-v commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

Description

Ports libobs/util/buffered-file-serializer.c to Rust. A background thread queues a seek offset and a length ahead of each piece, then writes the file in chunk_size chunks. Chunks under 64 KiB stay off disk until free, a discontinuous seek, or the next piece would pass chunk_size. SERIALIZE_SEEK_END subtracts from the virtual write position. A flushed chunk uses File::write, so those bytes can show up before close. C's fwrite can keep them in the stdio buffer until fclose. Close flushes. This does not fsync.

file-serializer.c stays C. test/cmocka/test_file_serializer.c is unchanged. With ENABLE_RUST_LIBOBS=ON the buffered cases run against the Rust shim.

Unknown seek codes leave the position alone. The C switch has no default.

A null path returns false and leaves the serializer untouched, matching C. A null serializer pointer to buffered_file_serializer_free returns. C would crash. A null data pointer with a non-zero size returns 0. Debug and error blog lines are not emitted. The C oracle still prints Final buffer capacity from its writer thread during Tier 3. libtest does not capture that thread, so those lines show up in the test log.

Motivation and Context

Issue #44 still has the buffered file serializer open. This is that file only. The three functions in buffered-file-serializer.h are unchanged. It does not close #44. file-serializer.c is PR #66, and config-file, platform, threading, pipe, task, and profiler are still open.

Refs #44

How Has This Been Tested?

macOS 27.0.1 (26A434), Apple Silicon (arm64), rustc 1.97.1 (8bab26f4f 2026-07-14).

  • ./lint: clang-format, gersemi, rustfmt, clippy -D warnings. Pass.
  • soldr cargo test -p obs-util --test buffered_file_serializer -- --test-threads=1: 6 passed. These mirror the cmocka buffered cases on the safe core.
  • soldr cargo test -p obs-util --test buffered_file_serializer_parity -- --test-threads=1: 13 passed, including proptest against the original C file compiled as an oracle.
  • Mutation check: SERIALIZE_SEEK_END was changed to add. test_buffered_seek_overwrite failed (left: 26, right: 16, from 21+5 against 21-5). Reverted, and that test passed again.
  • Linux Tier 2 in Docker on ubuntu:26.04 arm64: 29/29 cmocka tests passed with ENABLE_RUST_LIBOBS OFF and ON, including test_file_serializer. libobs exports were identical (1752 symbols). buffered-file-serializer.c.o is not in the ON build graph.

Windows was not run here.

Types of changes

  • New feature (non-breaking change which adds functionality)
  • Documentation (a change to documentation pages)

Checklist:

  • I have read the contributing document.
  • My code has been run through clang-format.
  • My code follows the project's style guidelines
  • My code is not on the master branch.
  • My code has been tested.
  • All commit messages are properly formatted and commits squashed where appropriate.
  • I have included updates to all appropriate documentation.

@zackees
zackees force-pushed the rust/buffered-file-serializer-port branch from 215b8e7 to f7b48fd Compare October 10, 2026 16:46
@zackees

zackees commented Oct 10, 2026

Copy link
Copy Markdown
Member

Rebased onto master (now includes file-serializer #66/#71, vec3, obs-nal). CI fixes:

  • Linux oracle: buffered_file_serializer_host.c failed under -std=c11 (fseeko/off_t hidden) and now duplicated master's file_serializer_host.c/platform_conv_host.c symbols, so it is removed and master's host shims are reused.
  • Windows oracle link: pthread_create/join/mutex_* were unresolved (w32-pthreads is header-only for the oracle). Added oracle/pthread_win_shim.c (Win32 threads + CRITICAL_SECTION), MSVC only. build.rs now picks threading-windows/posix from CARGO_CFG_TARGET_OS instead of the host cfg.
  • macOS arm64 failure was a dependency download flake.
    Data-loss review: buffered-file-serializer.c has no safe-save/rename path (it opens the target with "wb" directly), so the libobs: Preserve serialized files when safe saves fail #71 replace-on-failure bug class doesn't apply. On a failed write the port sets output_error and closes the file, same as C.
    RED->GREEN: the RED commit fails Tier 1 with not yet implemented: buffered-file-serializer; the head passes Tier 1/3 and Tier 2 (test_file_serializer, ENABLE_RUST_LIBOBS OFF/ON). The local gate passed and stamped f7b48fd.

@zackees
zackees force-pushed the rust/buffered-file-serializer-port branch 4 times, most recently from 32ac7a8 to 4c41b37 Compare October 10, 2026 18:28
The Tier 1 tests mirror the cmocka buffered cases. create() panics.

Refs obs-rust#44
The writer thread queues a seek offset and a length ahead of each
piece, then flushes in chunk_size pieces. Chunks under 64 KiB stay
off disk until free, a discontinuous seek, or a full chunk.
SERIALIZE_SEEK_END subtracts from the virtual write position. A
flushed chunk uses File::write, so those bytes can show up before
close. C's fwrite can keep them in the stdio buffer until fclose.
Debug and error blog lines are not emitted. A null serializer
pointer to free returns.

Tier 1 mirrors the cmocka buffered cases. Tier 3 compares the C ABI
with the original C file. Mutating SEEK_END to add failed
test_buffered_seek_overwrite (26 vs 16). Reverted.

Refs obs-rust#44

Local-Gate: v1 tree=f18161255304bc9860f6266304613861f5226078 secs=159 lanes=lint:run,rust-test:run,tier2-linux:run
Ci-Attestation: {"at":1791662609,"gate":"rust/all/fmt","host":"linux-x86_64","key":"6531101e87d706de0266006e35454043f0b58f05584d8a4c049bb9e0482f35ef","lane":"lint","parents":["8540716bb2a98272ac434199e9d7cabbd32b3b0a"],"secs":50,"stamp":"84994a845977cab8e9688f8fd89f5e3c","tree":"f18161255304bc9860f6266304613861f5226078","v":1,"via":"run"}
Ci-Attestation: {"at":1791662609,"gate":"rust/x86_64-unknown-linux-gnu/clippy","host":"linux-x86_64","key":"6531101e87d706de0266006e35454043f0b58f05584d8a4c049bb9e0482f35ef","lane":"lint","parents":["8540716bb2a98272ac434199e9d7cabbd32b3b0a"],"secs":50,"stamp":"13157f954682b667c41f1c6eb6002eb4","tree":"f18161255304bc9860f6266304613861f5226078","v":1,"via":"run"}
Ci-Attestation: {"at":1791662609,"gate":"rust/x86_64-unknown-linux-gnu/test","host":"linux-x86_64","key":"9fd9d85849d4e91afee790e4e78644a0db02013dca4a8a14731f15ff023dd9d8","lane":"rust-test","parents":["8540716bb2a98272ac434199e9d7cabbd32b3b0a"],"secs":29,"stamp":"9a8f67e52645ce025d5d7c2745fafab5","tree":"f18161255304bc9860f6266304613861f5226078","v":1,"via":"run"}
Ci-Attestation: {"at":1791662609,"gate":"cpp/linux-x64/tier2","host":"linux-x86_64","key":"8d2e21f6ea634d9c1cbdc6901bb752d3b273022f090bee25e5fee91575715143","lane":"tier2-linux","parents":["8540716bb2a98272ac434199e9d7cabbd32b3b0a"],"secs":81,"stamp":"a1fcce354aae6a44391289d37463694d","tree":"f18161255304bc9860f6266304613861f5226078","v":1,"via":"run"}
@zackees

zackees commented Oct 10, 2026

Copy link
Copy Markdown
Member

Rebased onto master (after #59, #78 and #106), keeping both sides in the oracle build.rs and lib.rs and in validate.sh's must-not-compile list, plus rustfmt of the module lists. RED→GREEN, checked with soldr's cache disabled: buffered_file_serializer fails 6/6 at the RED commit and the full suite passes at head. The local gate passes and is stamped.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Phase 4 remaining ports: serializers, config-file, platform, threading, pipe, task, profiler

2 participants