Repository navigation
rust: Port libobs/util/platform-cocoa.m to obs-util - #746
Merged
Merged
Conversation
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
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
enabled auto-merge
October 14, 2026 17:23
Member
|
I saw you pushed |
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.
Refs #744
What and why
libobs/util/platform-cocoa.mmoves intoobs-util. The 26 exports stay the same.ENABLE_RUST_LIBOBSdrops 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
622112cdc. On macOS all 16 Tier 1 tests panic withnot 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.97896aa13. Tier 1 is 16/16. Tier 3 parity is 8/8. Mutation: joining a path with+failedconfig_and_program_paths_match. The slash is restored.f0c73f29dquiets clippy (max_size < cap, and the dstr helpers are macOS-only).2d47693ebpackstask_basic_info_64to match the SDK (#pragma pack(4), size 40,user_timeat 20).PerformanceToken::from_rawis unsafe.82e503be7drops the staleos_gettime_nsentry 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 209withENABLE_RUST_LIBOBSOFF and ON.test_platform_cocoapassed both (the Linux binary is the Apple-only no-op). ExportsIDENTICAL (1766 symbols).== ported objects checked with ENABLE_RUST_LIBOBS=ON: 41.Host is macOS 27.0.1, arm64, rustc 1.98.1.
test_platform_cocoais 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/varpwsh path, and a few host compiles. No local-gate stamp. PR CI runs the Linux jobs.Checklist
master(or the description starts with a Stacked: note)-W..., ratchets): built with theci-fulllabel, or with scripting ON and cross-checked with clang and MSVC