Skip to content

rust: Port libobs/util/platform-cocoa.m to obs-util - #746

Merged
zackees merged 9 commits into
obs-rust:masterfrom
nathan-v:port/platform-cocoa
Oct 14, 2026
Merged

zackees merged 9 commits into
obs-rust:masterfrom
nathan-v:port/platform-cocoa

Conversation

@nathan-v

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

Copy link
Copy Markdown
Contributor

Refs #744

What and why

libobs/util/platform-cocoa.m moves into obs-util. The 26 exports stay the same. ENABLE_RUST_LIBOBS drops the Objective-C file on macOS. Linux and FreeBSD still get the overlapping symbols from the nix shims. Windows keeps its own inhibit exports.

RED → GREEN

  • RED commit: 622112cdc. On macOS all 16 Tier 1 tests panic with not yet implemented: platform-cocoa: format_path_omits_the_slash_for_an_empty_name, format_path_ptr_always_appends_a_slash, cpu_percent_matches_the_query_formula, inhibit_create_uses_a_null_cstring_only_for_a_null_reason, free_disk_cast_wraps_a_negative_free_space, test_config_path_application_support, test_program_data_path, test_executable_path_ptr, test_gettime_ns_monotonic, test_core_counts_stable, test_sys_memory, test_emulation_status, test_cpu_usage_null_query, test_high_performance_null_end, test_inhibit_null, test_free_space_null.
  • GREEN: 97896aa13. Tier 1 is 16/16. Tier 3 parity is 8/8. Mutation: joining a path with + failed config_and_program_paths_match. The slash is restored.
  • f0c73f29d quiets clippy (max_size < cap, and the dstr helpers are macOS-only).
  • 2d47693eb packs task_basic_info_64 to match the SDK (#pragma pack(4), size 40, user_time at 20). PerformanceToken::from_raw is unsafe.
  • 82e503be7 drops the stale os_gettime_ns entry from the oracle stand-in list. The weak stub remains.

Linux Tier 2 (rust/tools/linux-validate/run.sh): 100% tests passed, 0 tests failed out of 209 with ENABLE_RUST_LIBOBS OFF and ON. test_platform_cocoa passed both (the Linux binary is the Apple-only no-op). Exports IDENTICAL (1766 symbols). == ported objects checked with ENABLE_RUST_LIBOBS=ON: 41.

Host is macOS 27.0.1, arm64, rustc 1.98.1. test_platform_cocoa is 12/12 against C libobs and 12/12 against the Rust libobs. Homebrew cmocka will not load in an Xcode-linked ctest binary (Team ID), so those two runs used an ad-hoc signed copy. The full ctest suite was not run here.

./lint: clang-format and gersemi passed. rustfmt, clippy -D warnings, and the repo Dylints passed after that. The lint self-test still fails on this Mac for soldr's Windows GNU target, the /private/var pwsh path, and a few host compiles. No local-gate stamp. PR CI runs the Linux jobs.

Checklist

  • Base is master (or the description starts with a Stacked: note)
  • I claimed the issue, or no one else has an open PR for it
  • Characterization test (if the unit had none), then RED, then GREEN commits
  • (Optional) Local gate passed and the pushed head is stamped; otherwise PR CI runs the full suite
  • Warning or flag changes (-W..., ratchets): built with the ci-full label, or with scripting ON and cross-checked with clang and MSVC
  • Intentional differences from C listed in the parity test header and rust/README.md (ports)

cmocka test for libobs/util/platform-cocoa.m. test_platform.c
does not call this file and is left alone. Off Apple the binary
is a no-op so the aggregate still builds.

Pins config and program-data paths (Application Support, the
pointer form's trailing slash), the executable path, a monotonic
clock, core counts, system and process memory, emulation status,
cpu usage, the high-performance token, sleep inhibit, free space,
and the cfstr copy helpers.

os_inhibit_sleep_create's condition is inverted, and the cfstr
slow path sets dstr len to the encoding maximum. Both are
characterized, not endorsed. A null inhibit reason faults in
CFStringCreateWithCString on current macOS, so the test passes
a non-null reason.

Refs obs-rust#744
Tier 1 tests for libobs/util/platform-cocoa.m against todo!()
stubs of the safe API. On macOS all 16 panic with
"not yet implemented: platform-cocoa":

format_path_omits_the_slash_for_an_empty_name,
format_path_ptr_always_appends_a_slash,
cpu_percent_matches_the_query_formula,
inhibit_create_uses_a_null_cstring_only_for_a_null_reason,
free_disk_cast_wraps_a_negative_free_space,
test_config_path_application_support, test_program_data_path,
test_executable_path_ptr, test_gettime_ns_monotonic,
test_core_counts_stable, test_sys_memory, test_emulation_status,
test_cpu_usage_null_query, test_high_performance_null_end,
test_inhibit_null, test_free_space_null.

No shims, no oracle, and no ENABLE_RUST_LIBOBS guard in this
commit.

Refs obs-rust#744
Safe core in platform::unix::cocoa, C shims for the 26 exports,
and Tier 3 parity against the original file. ENABLE_RUST_LIBOBS
drops util/platform-cocoa.m on macOS.

The nix posix oracle no longer defines os_gettime_ns on Apple.
The cocoa oracle owns that symbol. The cargo-test stub stays a
weak zero, with a prototype, so a missing shim still links.

Intentional differences: Box instead of bmalloc for the cpu and
inhibit objects; a mutex on the core-count and total-memory
caches; a null os_get_proc_memory_usage returns false; a null
cfstr_copy_dstr dstr pointer returns false; the cfstr slow path
zeros the gap past the first NUL; cfstr_copy_cstr's slow path is
sized to the C string; a non-null inhibit reason is
CFStringCreateWithCString of an empty string; a null UTF8String
becomes an empty base path.

A null inhibit reason still goes to CFStringCreateWithCString
with a null cstring. That faults on current macOS, in C and
here, so the tests pass a non-null reason.

Mutation: joining a path with '+' failed
config_and_program_paths_match. The slash is restored.

Refs obs-rust#744
dstr_resize's extra byte was written as `max_size + 1 <= cap`.
Clippy wants `max_size < cap`, which is the same check.

read_model and write_model are only called from the macOS Cocoa
shims. On Linux they were unused, and clippy -D warnings fails
the rust-test lane for that.

Refs obs-rust#744
task_basic_info_64 is pack(4) in the SDK. Size 40, align 4,
user_time at 20. A natural repr(C) is 48 bytes and reads
that field at 24, so CPU usage added the wrong bytes. The
kernel count is 10 natural_t words. A unit test pins the
measured size, alignment, and offsets.

PerformanceToken::from_raw is unsafe. It takes ownership of
a retained activity, and end_high_performance releases it.

Refs obs-rust#744
The weak os_gettime_ns in test_stubs.c is no longer a scanned
definition, so DIFFERENT's entry fails
test_different_entries_are_still_standins. The Cocoa and nix
shims own the symbol. The stub stays weak and returns 0 when
nothing else provides it.

Refs obs-rust#744
soldr's Apple cross compiler targets macOS 10.12 and appends
that -mmacosx-version-min after the builder flags. The file
uses NSURL keys from 10.13, so -Werror fails the cross check.
The project target is 13.0. Silence that one warning.

Refs obs-rust#744
@zackees zackees added the ci-full Run every CI job on this PR, including the release-gating OBS app builds and Flatpak label Oct 14, 2026
The non-Apple stub used true without stdbool.h. MSVC C
rejects that. assert_true(1) is the same check.

Refs obs-rust#744
get_time_info multiplies seconds by 1000000 in int, then
stores the wrapped value in an int64. Past 2147 CPU seconds
the wide multiply stays smooth and the percent diverges.
3000 seconds plus 5 microseconds is -1294967291, matching clang.

Refs obs-rust#744
@zackees
zackees enabled auto-merge October 14, 2026 17:23
@zackees

zackees commented Oct 14, 2026

Copy link
Copy Markdown
Member

I saw you pushed 984208e56 (Quiet Cocoa availability) while I was preparing the same fix for the x86_64-apple-darwin cross lint, so I dropped mine and didn't push. #746 is queued in the merge queue; it lands when CI Gate ✅ passes on its merge result.

@zackees
zackees added this pull request to the merge queue Oct 14, 2026
Merged via the queue into obs-rust:master with commit 3463a9f Oct 14, 2026
25 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci-full Run every CI job on this PR, including the release-gating OBS app builds and Flatpak

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants