Skip to content

Host boundary without moving files: tighten the platform ifdef ratchet, keep CI path scoping, record the repo layout policy #1051

Closed

Description

@zackees

Goal

Keep host-specific (Windows/macOS/Linux) code out of shared C/C++ files and scope CI by path, without moving any upstream file. The checks gain a few rules. The tree stays where it is.

Plan changed (2026-10-16). The first version of this issue moved libobs's host code into libobs/hosts/<os>/ and renamed every crate's src/platform/ to src/hosts/. That is dropped. We still merge upstream/master (last on 2026-10-12), and moving upstream files makes every later merge and cherry-pick fight renames. The files those moves touched (obs-nix*.c, util/platform-*, audio-monitoring/*) are also the ones the Rust ports replace. The earlier version is in this issue's edit history.

Repository layout policy

Write this down in docs/rust-port/naming.md, and link to it from AGENTS.md and rust/README.md:

  • The upstream tree stays where upstream has it: libobs/, libobs-*/, frontend/, plugins/, shared/, deps/, cmake/, test/. Don't move or rename C/C++ files to restructure. Bug fixes and ports edit them in place.
  • All Rust lives in the rust/ Cargo workspace, one crate per ported component, with rust/tools/ excluded. Add a table there mapping each C component to its crate (libobs/util ↔ rust/obs-util, libobs/media-io ↔ rust/obs-media-io, libobs/graphics ↔ rust/obs-graphics, the codec helpers ↔ rust/obs-codec, ...), so a port always has one obvious home.
  • When a C component is fully ported: delete its C sources and point its CMake target at the Rust staticlib. Don't keep a moved copy of the C.
  • Later, not now: once we stop merging upstream, the remaining C/C++ (mostly frontend/ and plugins/) may move under one root directory in a single mechanical PR. That PR holds only the git mv plus path updates (CMake, CI, docs), lands in a quiet window, and uses a neutral name, because libobs is C, not C++. That needs its own issue when the time comes.

Rust: keep what exists

  • Keep rust/<crate>/src/platform/ with its one cfg_select! in platform/mod.rs, plus src/ffi/. Keep the dylints/ban_platform_cfg_outside_boundary Dylint as it is. There is no platform → hosts rename.
  • The unix arm stays. Don't add #[path] includes to share POSIX code.
  • Out of scope: making the selector exhaustive with no _ fallback. If someone wants it later, the arm list must include FreeBSD, which upstream builds (libobs/cmake/os-freebsd.cmake).

C/C++: tighten the existing ratchet

ci/platform_ifdef_ratchet.py (#847) already fails a PR that adds a host conditional to a shared file in libobs/, frontend/, shared/ or plugins/, against ci/platform-ifdef-baseline.json. Extend it in place, without a new lint:

  1. One classifier. The ratchet keeps its own PLATFORM_TOKENS list, and that list has already drifted from ci/platform_paths.py. Make the ratchet call platform_paths.platforms(), so CI scoping and the lint always agree on which OS a file belongs to.

  2. Right OS, not just any OS. Map each macro family to an OS:

    • _WIN32, _MSC_VER, ... → windows.
    • __APPLE__, TARGET_OS_*, ... → macos.
    • __linux__, __FreeBSD__, ... → linux.
    • __unix__ → linux + macos.

    A conditional in a file classified as another OS's is an error. For example, #ifdef _WIN32 inside obs-cocoa.m fails. Today that file is skipped entirely.

  3. No multi-OS conditionals in host files. #if defined(_WIN32) || defined(__APPLE__) in a file that belongs to one OS is an error.

  4. OS headers follow the same mapping for #include and #import lines:

    • <windows.h>, <d3d*.h>, <dxgi*.h>, ... → windows.
    • <CoreFoundation/…>, <AppKit/…>, <mach/…>, ... → macos.
    • <X11/…>, <xcb/…>, <wayland-…>, <pulse/…>, <pipewire/…>, <dbus/…>, ... → linux.
    • <unistd.h>, <pthread.h>, <dlfcn.h>, ... → linux + macos.

    Including one in a shared file counts against the same per-file baseline.

  5. Strip comments and string literals before matching, and join backslash-continued lines. Then a macro named in a comment is not flagged.

  6. Permanent exceptions go in ci/platform-ifdef-exceptions.toml, one entry per file with a reason. They are only for installed public headers that must keep their conditionals, since public headers and the ABI don't change. Examples are util/c99defs.h and possibly util/threading.h and graphics/graphics.h, after review. The list may only shrink. .c/.cpp files get no permanent exceptions.

Tests go in ci/test_platform_ifdef_ratchet.py, with one RED and one GREEN case per new rule:

  • _WIN32 in a .m file fails, and __APPLE__ in obs-cocoa.m passes.
  • A two-family #if in obs-nix.c fails.
  • #include <windows.h> in libobs/obs.c fails, and #include <unistd.h> in libobs/util/threading-posix.c passes.
  • A macro in a comment or a string isn't counted, and __GNUC__ / __x86_64__ aren't counted.

CI scoping: existing paths, made permanent

  • Keep the token classifier. In ci/ci_scope.py, the legacy_platforms() fallback (token matching via ci/platform_paths.py) is not legacy any more. It is how upstream-named paths (win-capture/, mac-*, obs-nix*.c, util/platform-cocoa.m, ...) map to an OS, and they keep their names. Replace the TODO that says to delete it with a note pointing at this policy.
  • Name ambiguous files explicitly. Where a token guess is wrong or ambiguous, list the path in ci/platform_paths.py, as _MACOS_TOO already does for util/platform-nix.c, instead of renaming the file.
  • New row: libobs/cmake/os-<os>.cmake starts that OS only (today all of libobs/cmake/ is shared). Add tests in ci/test_ci_scope.py.
  • Unchanged: PLATFORM_RULE (/platform[/-](windows|macos|linux|posix)[/.]) stays as it is for new Rust and shared code laid out that way.

Draining the baseline

Remove the host conditionals already in shared files (obs-video.c, obs.c, obs-module.c, graphics/*, frontend, ...) as part of the work that touches them anyway:

  • Preferred: the Rust port of that unit, where the crate's src/platform/ holds the host split.
  • Otherwise: move the branch into the existing OS-named files behind a small function, e.g. obs-nix.c / obs-windows.c / obs-cocoa.m, or frontend/utility/platform*.{hpp,cpp}.

Each PR lowers the baseline with --update. Don't open standalone "move this file" PRs.

Phases (one PR each)

  1. Docs: the layout policy above, in naming.md, AGENTS.md and rust/README.md.
  2. Ratchet: rules 1–6 and their tests, with the baseline regenerated. No source changes.
  3. ci_scope: the os-<os>.cmake row, the TODO replaced, and explicit entries for ambiguous paths.
  4. Ongoing: baseline reductions ride along with ports and fixes.

Done when

  • Phases 1–3 are merged.
  • A PR touching only a Windows-classified file (e.g. libobs/util/platform-windows.c) runs the Windows lanes and no macOS job. A PR touching only core libobs runs Linux only. Check both on real PRs.
  • No C/C++ file was moved or renamed to get there.

Related: #847 (ifdef ratchet), #897 (path-based platform scoping), #992 / #1013 (path-scoped CI, PLATFORM_RULE), #1009 (platform folder naming), #443 (attested platform lanes), #695 / #697 (cross-compiling Windows and macOS on Linux).

Activity

  1. changed the title [-]libobs: Move all platform code behind libobs/platform/<os>/ (soldr-style boundary) so CI scopes by one path rule[/-] [+]libobs + Rust: Move all host code behind host/<os>/ (soldr-style boundary, Dylint + C lint) so CI scopes by one path rule[/+] on Oct 16, 2026
  2. changed the title [-]libobs + Rust: Move all host code behind host/<os>/ (soldr-style boundary, Dylint + C lint) so CI scopes by one path rule[/-] [+]libobs + Rust: Move all host code behind hosts/<os>/ (exhaustive cfg_select, Dylint + C lint) so CI scopes by one path rule[/+] on Oct 16, 2026
  3. changed the title [-]libobs + Rust: Move all host code behind hosts/<os>/ (exhaustive cfg_select, Dylint + C lint) so CI scopes by one path rule[/-] [+]libobs + Rust: Move all host code into libobs/hosts/<os>/ and rust/hosts/<os>/ (one exhaustive cfg_select, Dylint + C lint) so CI scopes by one path rule[/+] on Oct 16, 2026
  4. changed the title [-]libobs + Rust: Move all host code into libobs/hosts/<os>/ and rust/hosts/<os>/ (one exhaustive cfg_select, Dylint + C lint) so CI scopes by one path rule[/-] [+]libobs + Rust: Move all host code into libobs/hosts/<os>/ and each crate's src/hosts/<os>/ (exhaustive cfg_select, Dylint + C lint) so CI scopes by one path rule[/+] on Oct 16, 2026
  5. changed the title [-]libobs + Rust: Move all host code into libobs/hosts/<os>/ and each crate's src/hosts/<os>/ (exhaustive cfg_select, Dylint + C lint) so CI scopes by one path rule[/-] [+]Host boundary without moving files: tighten the platform ifdef ratchet, keep CI path scoping, record the repo layout policy[/+] on Oct 16, 2026
  6. zackees commented on Oct 16, 2026

    @zackees
    MemberAuthor

    Claiming: #1051 (phases 1–3).

    1. Docs: repo layout policy in naming.md, linked from AGENTS.md and rust/README.md.
    2. Ratchet: one classifier (platform_paths), right-OS / multi-OS / OS-header rules, comment and string stripping, public-header exceptions file, RED then GREEN tests.
    3. ci_scope: os-.cmake row, legacy TODO replaced.

    One PR, one commit per phase; first push today.

  7. added
    claimed
    on Oct 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    claimed

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions