Repository navigation
Description
Part of #297. Ports the platform-boundary pattern used by soldr (dylints/ban_platform_cfg_outside_boundary), zccache and fbuild (dylints/enforce_platform_boundary).
Problem
#![deny(unsafe_code)] (#290) and clippy only check code that compiles for the target being linted. Host-cfg'd code in the safe cores, such as obs-util/src/pipe.rs:150 and utf8.rs:13 (both #[cfg(windows)] + allow(unsafe_code)), is never checked by the Linux lint lane. Host selection is spread across about 20 sites in production sources:
| File | Host cfg / native refs |
|---|---|
obs-util/src/pipe.rs (+ pipe/windows.rs) |
7 cfg, std::os::unix, Win32 |
obs-util/src/bmem.rs |
2 (CLong width) |
obs-util/src/config_file.rs |
2 (path bytes, Windows BOM) + std::os::unix |
obs-util/src/file_serializer.rs |
2 (path bytes) + std::os::unix |
obs-util/src/task.rs |
2 (native vs condvar sem) |
obs-util/src/threading.rs |
1 (Sem re-export) |
obs-util/src/utf8.rs (+ utf8/windows.rs) |
1, Win32 |
obs-media-io/src/audio_io.rs |
2 (mod port gate) + 9 libc::pthread_* |
Policy
Each port crate has one src/platform/ module. src/platform/mod.rs is the only host-selection site in the crate (cfg_select!). Its children (unix.rs, windows.rs, …) hold the native code, and the rest of the crate gets a platform-neutral API from it. The C ABI shims in src/ffi/ also stay allowed, because the exported symbol set itself differs per OS.
Everywhere else in rust/*/src/**, a pre-expansion Dylint rejects:
#[cfg],#[cfg_attr],#![cfg]andcfg!()usingwindows,unix,target_os,target_family,target_arch,target_env,target_pointer_widthand similar host selectors;std::os::{windows,unix,linux,macos},libc::,windows_sys,windows::Win32.
Because the lint runs before cfg expansion, code compiled out for the host is checked too, so a single Linux lint lane covers every platform.
Out of scope: rust/obs-c-oracle (a test-only crate whose purpose is linking the original C), rust/tools, and integration tests under tests/. Tests stay as they are, mirroring the C tests' platform guards, and are not held to deny(unsafe_code).
Plan
- RED: add
dylints/ban_platform_cfg_outside_boundary(cdylib,dylint_linting, nightly pinned in its ownrust-toolchain.toml), adapted from soldr, with UI tests. Register it in the rootCargo.toml[workspace.metadata.dylint]and runsoldr cargo dylint --all -- --workspace --all-targetsin the./lintlane. It fails on the sites above. - GREEN, obs-util: add
src/platform/{mod,unix,windows}.rs. Move into it theCLongwidths,path_from_bytes, the Windows config BOM, theSemselection, the pipe Unix/Windows halves and theutf8Windows converter. The Win32allow(unsafe_code)sites move toplatform/windows, andlib.rsallowsunsafe_codeonly onmod ffiandmod platform. - GREEN, obs-media-io: add
src/platform/{mod,unix}.rs. Move the recursivepthread_mutex_t(InputMutex) behind a platformRecursiveMutex. Gate the Unix-onlyaudio_io::portwith a capability macro defined inplatform/mod.rs(with_audio_thread_port!), so the decision lives in the boundary. This removes thelibc::references fromaudio_io.rs; the remainingunsafein the port is still rust/obs-media-io: move audio_io.rs unsafe out of the safe core into src/ffi #294. - Docs: add the policy to
docs/rust-port/testing-policy.mdandAGENTS.md(where platform code goes, how to run the lint, how to opt out).
Acceptance
./lintruns the dylint and passes.- Removing any moved site back into a safe core fails
./lint(shown by the RED commit). ./unittestpasses. Windows and macOS CI legs pass.
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
zackees commentedon Oct 12, 2026
Claiming: #323. Plan: 1) RED commit adds the Dylint + lint-lane wiring; 2) GREEN commits move obs-util then obs-media-io behind src/platform; 3) docs. One PR, opening today.
ci: Run the Dylints on lib and bin targets only