You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
We need to refactor unsafe around code boundaries like ffi #297
Keep unsafe at the code boundaries (C ABI shims in src/ffi, documented OS calls) so the safe core of each port crate cannot grow new unsafe unnoticed. Follow-up to #290.
Current state (origin/master)
Crate
Lint
Allowed exceptions
obs-util
#![deny(unsafe_code)]
mod ffi; pipe.rs:151 (Win32 handles); utf8.rs:14 (MultiByteToWideChar/WideCharToMultiByte)
obs-codec
#![deny(unsafe_code)]
mod ffi
obs-graphics
#![deny(unsafe_code)]
mod ffi
obs-media-io
#![deny(unsafe_code)]
mod ffi; mod audio_io (module-wide allow, 58 unsafe tokens in audio_io.rs)
obs-c-oracle
none
~48 unsafe tokens; test-only differential oracle calling the original C, so FFI is its whole purpose
Status: #290 is merged. obs-util, obs-codec, obs-graphics and obs-media-io now #![deny(unsafe_code)] and allow it back only on mod ffi and two documented Win32 boundaries (pipe.rs, utf8.rs). A new unsafe in a safe core is now a build error.
One exception remains: mod audio_io in obs-media-io carries a module-level #[allow(unsafe_code)], because the audio-io port (#289) landed with 54 unsafe sites in its safe core just before the lint. Moving them behind src/ffi is tracked in #294, which has a RED/GREEN plan (drop the allow so the build fails with 54 errors, then refactor). Once #294 lands, this issue can close.
Proposal: adopt the platform-boundary pattern from soldr / zccache / fbuild
Those three repos solve the same problem with one platform module (or crate) plus a custom Dylint that keeps platform code inside it:
soldr: crates/soldr-platform holds one cfg_select! in lib.rs and the platform_win / platform_linux / platform_macos trees. dylints/ban_platform_cfg_outside_boundary runs pre-expansion, so code that is cfg'd out for the current target is checked too. It rejects #[cfg(windows|unix|target_os…)], #[cfg_attr] and cfg!() everywhere else, and bans references to the concrete trees from outside the crate. Sibling lints (ban_raw_process_creation, ban_raw_network_access, …) then expect raw OS APIs only inside that crate. A site opts out with #[cfg_attr(dylint_lib = "...", allow(...))]. The lints are wired in through [workspace.metadata.dylint] libraries = [{ path = "dylints/*" }].
zccache: dylints/enforce_platform_boundary allows host cfg, std::os::{windows,unix}, libc and windows_sys only in three named platform.rs files. It has no baseline or allowlist.
fbuild: has the same enforce_platform_boundary lint plus about 25 other ban_* lints.
Why this matters here
#![deny(unsafe_code)] from #290 is a normal rustc lint, so it only checks code that compiles for the target being built. obs-util/src/pipe.rs:150-153 and obs-util/src/utf8.rs:13-14 are #[cfg(windows)], so a Linux lint lane never compiles or checks them. Platform-specific unsafe can sit in the safe core today as long as it is behind a host cfg. soldr's lint docs make the same point: the pre-expansion boundary lint is what lets a Linux-only lint lane stand in for every platform.
Host cfgs in non-ffi production code on master today:
File
Sites
obs-util/src/pipe.rs
7 (19, 150, 153, 159, 169, 174, 207)
obs-util/src/bmem.rs
2
obs-util/src/config_file.rs
2
obs-util/src/file_serializer.rs
2
obs-util/src/task.rs
2
obs-util/src/threading.rs
1
obs-util/src/utf8.rs
1
obs-media-io/src/audio_io.rs
3 (239, 1136, plus the module-level #[cfg(unix)] port)
Suggested plan
Add a platform module per crate (obs-util/src/platform/{mod,unix,windows}.rs), or a shared obs-platform crate. It holds the only cfg_select! and exposes one safe API to the core.
Add rust/dylints/ban_platform_cfg_outside_boundary, ported from soldr. Allowed paths: */src/platform/** and */src/ffi/**, since the C ABI shims also need host cfgs such as ffi/native_sem.rs. Tests are scanned the same way; a test needing a host cfg uses the cfg_attr(dylint_lib…) opt-out.
Optionally add a second lint, ban_unsafe_outside_boundary. It would also run pre-expansion and reject unsafe outside ffi and platform, which covers what deny(unsafe_code) misses on cfg'd-out code. The two Win32 allow(unsafe_code) sites then move into platform/windows.rs.
Hook cargo dylint --all into ./lint and local-gate.toml with the nightly pinned the way soldr does. That needs a nightly toolchain next to rust-toolchain.toml, which the testing policy should note.
RED/GREEN: land the lint first with the sites above failing (RED), then move each site behind platform (GREEN), one crate per PR. #294 (audio_io) can follow the same shape.
Remaining checklist: #413 (audio_io engine into src/ffi, closes #294) and #414 (forbid unsafe_code in libobs-rust and obs-stream-rust; obs-c-oracle exemption documented). The platform boundary Dylint landed in #326. Once both merge, this issue can close.
Activity
zackees commentedon Oct 12, 2026
Status: #290 is merged.
obs-util,obs-codec,obs-graphicsandobs-media-ionow#![deny(unsafe_code)]and allow it back only onmod ffiand two documented Win32 boundaries (pipe.rs,utf8.rs). A newunsafein a safe core is now a build error.One exception remains:
mod audio_ioinobs-media-iocarries a module-level#[allow(unsafe_code)], because the audio-io port (#289) landed with 54unsafesites in its safe core just before the lint. Moving them behindsrc/ffiis tracked in #294, which has a RED/GREEN plan (drop the allow so the build fails with 54 errors, then refactor). Once #294 lands, this issue can close.zackees commentedon Oct 12, 2026
Proposal: adopt the platform-boundary pattern from soldr / zccache / fbuild
Those three repos solve the same problem with one platform module (or crate) plus a custom Dylint that keeps platform code inside it:
crates/soldr-platformholds onecfg_select!inlib.rsand theplatform_win/platform_linux/platform_macostrees.dylints/ban_platform_cfg_outside_boundaryruns pre-expansion, so code that is cfg'd out for the current target is checked too. It rejects#[cfg(windows|unix|target_os…)],#[cfg_attr]andcfg!()everywhere else, and bans references to the concrete trees from outside the crate. Sibling lints (ban_raw_process_creation,ban_raw_network_access, …) then expect raw OS APIs only inside that crate. A site opts out with#[cfg_attr(dylint_lib = "...", allow(...))]. The lints are wired in through[workspace.metadata.dylint] libraries = [{ path = "dylints/*" }].dylints/enforce_platform_boundaryallows host cfg,std::os::{windows,unix},libcandwindows_sysonly in three namedplatform.rsfiles. It has no baseline or allowlist.enforce_platform_boundarylint plus about 25 otherban_*lints.Why this matters here
#![deny(unsafe_code)]from #290 is a normal rustc lint, so it only checks code that compiles for the target being built.obs-util/src/pipe.rs:150-153andobs-util/src/utf8.rs:13-14are#[cfg(windows)], so a Linux lint lane never compiles or checks them. Platform-specificunsafecan sit in the safe core today as long as it is behind a host cfg. soldr's lint docs make the same point: the pre-expansion boundary lint is what lets a Linux-only lint lane stand in for every platform.Host cfgs in non-
ffiproduction code on master today:obs-util/src/pipe.rsobs-util/src/bmem.rsobs-util/src/config_file.rsobs-util/src/file_serializer.rsobs-util/src/task.rsobs-util/src/threading.rsobs-util/src/utf8.rsobs-media-io/src/audio_io.rs#[cfg(unix)]port)Suggested plan
platformmodule per crate (obs-util/src/platform/{mod,unix,windows}.rs), or a sharedobs-platformcrate. It holds the onlycfg_select!and exposes one safe API to the core.rust/dylints/ban_platform_cfg_outside_boundary, ported from soldr. Allowed paths:*/src/platform/**and*/src/ffi/**, since the C ABI shims also need host cfgs such asffi/native_sem.rs. Tests are scanned the same way; a test needing a host cfg uses thecfg_attr(dylint_lib…)opt-out.ban_unsafe_outside_boundary. It would also run pre-expansion and rejectunsafeoutsideffiandplatform, which covers whatdeny(unsafe_code)misses on cfg'd-out code. The two Win32allow(unsafe_code)sites then move intoplatform/windows.rs.cargo dylint --allinto./lintandlocal-gate.tomlwith the nightly pinned the way soldr does. That needs a nightly toolchain next torust-toolchain.toml, which the testing policy should note.RED/GREEN: land the lint first with the sites above failing (RED), then move each site behind
platform(GREEN), one crate per PR. #294 (audio_io) can follow the same shape.zackees commentedon Oct 12, 2026
Remaining checklist: #413 (audio_io engine into
src/ffi, closes #294) and #414 (forbidunsafe_codein libobs-rust and obs-stream-rust; obs-c-oracle exemption documented). The platform boundary Dylint landed in #326. Once both merge, this issue can close.zackees commentedon Oct 13, 2026
Done: #326 (platform-boundary Dylint), #413 (audio_io engine into src/ffi, closed #294), #414 (forbid unsafe_code in libobs-rust and obs-studio-rust; obs-c-oracle exemption documented). All merged.