Skip to content

meta: Move platform #if code in shared C/C++ behind a platform facade #847

Open
41 of 41 issues completed
Open

Description

@zackees

Platform #if code inside shared C/C++ files makes CI scoping guesswork. A change to an #ifdef __APPLE__ block in a shared file can't be routed to macOS CI by path, so we either run every platform on every PR or miss real platform changes. Goal: shared code calls a platform facade, and each platform's code lives in platform-named files, so ci/ci_scope.py maps paths to platforms exactly. This is the C/C++ counterpart of the Rust src/platform/ rule, which the Dylint enforces.

Measured (master, 2026-10-15)

Platform conditionals (_WIN32, _MSC_VER, __APPLE__, TARGET_OS_*, __linux__, OS_*, ...) in files whose names don't mark a platform:

area files #ifs
frontend/ 60 265
plugins/ 69 208
libobs/ 36 94
shared/ 18 51

Worst offenders: frontend/OBSApp.cpp (47), frontend/obs-main.cpp (30), frontend/settings/OBSBasicSettings.cpp (29), frontend/widgets/OBSBasic.cpp (20), libobs/obs-video.c (10), libobs/obs.c (8).

Approach

  • Frontend: extend the existing facade frontend/utility/platform.hpp (implemented by platform-osx.mm, platform-windows.cpp, platform-x11.cpp). Move each platform branch out of the shared file into a facade function with one implementation per platform. Behaviour is unchanged, and the moves are covered by tests where the code is testable (cmocka/Qt offscreen) and by the full native builds (ci-full).
  • libobs: follow the existing obs-nix.c / obs-windows.c / obs-cocoa.m split. The Rust port moves the rest into src/platform/.
  • Ratchet lint: fail any PR that adds a platform conditional to a shared-named file, with today's counts as the baseline. The baseline only goes down.
  • Upstream merges: keep each move small and mechanical (one function per facade entry), so merges from upstream OBS stay manageable.

Sub-issues (in order)

  1. Ratchet lint for platform conditionals in shared C/C++ (baseline file + ci/ test).
  2. frontend/OBSApp.cpp → facade.
  3. frontend/obs-main.cpp → facade.
  4. frontend/settings/OBSBasicSettings.cpp → facade.
  5. frontend/widgets/OBSBasic*.cpp → facade.
  6. libobs/obs-video.c, libobs/obs.c, libobs/graphics/graphics.h → existing per-platform files.
  7. Plugins, by count.

Related: #698 and #700 (platform-scoped CI), #443 (native attestation).

Done when

  • No shared-named C/C++ file has platform conditionals beyond the ones documented as unavoidable (for example the headers' export macros).
  • ci_scope.py decides macOS/Windows runs from paths alone.

Sub-issues

Sub-issues

41 of 41 Issues completed
Loading 41 sub-issues

Activity

  1. 22 remaining items

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

    No labels
    No labels

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions