diff --git a/.github/workflows/build-project.yaml b/.github/workflows/build-project.yaml index 6170ec3f5c..b61f29a9da 100644 --- a/.github/workflows/build-project.yaml +++ b/.github/workflows/build-project.yaml @@ -1112,6 +1112,12 @@ jobs: submodules: recursive fetch-depth: 0 + - name: Set Up uv 🐍 + uses: astral-sh/setup-uv@bec219d24cd3e171d82865faccec33120bb574f4 # v10.1.0 + with: + version: '0.13.1' + enable-cache: false + # Reuse the 339 MB of .debs every Tier 2 job downloaded (#1055): keep # them (the stock image's docker-clean config deletes them after each # install) and restore the archive dir, keyed on the list and the image. @@ -1258,6 +1264,12 @@ jobs: submodules: recursive fetch-depth: 0 + - name: Set Up uv 🐍 + uses: astral-sh/setup-uv@bec219d24cd3e171d82865faccec33120bb574f4 # v10.1.0 + with: + version: '0.13.1' + enable-cache: false + # Reuse the 339 MB of .debs every Tier 2 job downloaded (#1055): keep # them (the stock image's docker-clean config deletes them after each # install) and restore the archive dir, keyed on the list and the image. diff --git a/Cargo.lock b/Cargo.lock index 37d2b25ea8..af343a2dfa 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -93,6 +93,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f74872d07caf508b30a21f6836e7d7016a2eaf7d9ff4f48deaa58cd8a0407630" dependencies = [ "find-msvc-tools", + "jobserver", + "libc", "shlex", ] @@ -245,6 +247,12 @@ dependencies = [ "crypto-common", ] +[[package]] +name = "dunce" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "92773504d58c093f6de2459af4af33faa518c13451eb8f2b5698ed3d36e7c813" + [[package]] name = "either" version = "1.19.0" @@ -354,6 +362,16 @@ version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8f42a60cbdf9a97f5d2305f08a87dc4e09308d1276d28c869c684d7777685682" +[[package]] +name = "jobserver" +version = "0.1.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1c00acbd29eabad4a2392fa0e921c874934dbbf4194312ad20f04a0ed67a3cb3" +dependencies = [ + "getrandom 0.4.3", + "libc", +] + [[package]] name = "libc" version = "0.2.190" @@ -410,6 +428,18 @@ dependencies = [ "autocfg", ] +[[package]] +name = "obs-build" +version = "0.1.0" +dependencies = [ + "cc", + "dunce", + "libloading", + "pkg-config", + "serde_json", + "tempfile", +] + [[package]] name = "obs-c-oracle" version = "0.1.0" @@ -536,6 +566,13 @@ dependencies = [ "tungstenite", ] +[[package]] +name = "obs-sys" +version = "0.1.0" +dependencies = [ + "obs-build", +] + [[package]] name = "obs-util" version = "0.1.0" @@ -568,6 +605,12 @@ dependencies = [ "winapi", ] +[[package]] +name = "pkg-config" +version = "0.3.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6b464fbc74e149a392436b17d523f769e057cb6877f6a5c4618bc6f11800548" + [[package]] name = "ppv-lite86" version = "0.2.21" diff --git a/ci/test_binary_cap.py b/ci/test_binary_cap.py index 9ba9db6c04..139a9a5bd1 100755 --- a/ci/test_binary_cap.py +++ b/ci/test_binary_cap.py @@ -20,8 +20,9 @@ PER_CRATE_CAP = 8 # The workspace total after the #968 consolidation, plus obs-preflight's one # binary (#814). Lower it when crates merge binaries; raise it only with a -# reason in the PR. -WORKSPACE_CAP = 22 +# reason in the PR. The Cargo native-build migration adds obs-build +# (native contracts + opt-in real libobs) and opt-in obs-sys bundled contracts. +WORKSPACE_CAP = 25 def test_targets(crate: Path) -> list[str]: diff --git a/ci/test_ported_sources.py b/ci/test_ported_sources.py new file mode 100644 index 0000000000..42fd31f120 --- /dev/null +++ b/ci/test_ported_sources.py @@ -0,0 +1,45 @@ +#!/usr/bin/env -S uv run --script +"""The Tier 2 exclusion check consumes the shared source manifest.""" +import importlib.util +from pathlib import Path +import tempfile +import json +import unittest + +ROOT = Path(__file__).resolve().parent.parent +SPEC = importlib.util.spec_from_file_location("ported_sources", ROOT / "rust/tools/ported_sources.py") +PORTED = importlib.util.module_from_spec(SPEC) +SPEC.loader.exec_module(PORTED) + + +class PortedSourceTest(unittest.TestCase): + def test_current_linux_inventory_keeps_the_existing_exclusion_floor(self): + objects = PORTED.ported_objects(ROOT, "linux") + self.assertGreaterEqual(len(objects), 20) + self.assertIn("obs-data.c.h.o", objects) + self.assertIn("obs-hevc.c.h.o", objects) + self.assertEqual(len(objects), len(set(objects))) + + def test_host_and_optional_groups_select_the_actual_members(self): + with tempfile.TemporaryDirectory() as temporary: + root = Path(temporary) + build = root / "libobs/build" + build.mkdir(parents=True) + groups = { + "LIBOBS_PORTED_SOURCES": ["build/common+.h.c"], + "LIBOBS_LINUX_PORTED_SOURCES": ["build/linux+.h.c"], + "LIBOBS_WINDOWS_PORTED_SOURCES": ["build/windows+.h.c"], + "LIBOBS_HEVC_PORTED_SOURCES": ["build/hevc+.h.c"], + } + (build / "source-sets.json").write_text(json.dumps(groups)) + for group, member in [("common", "common"), ("linux", "linux"), + ("windows", "windows"), ("hevc", "hevc")]: + (build / f"{group}+.h.c").write_text(f'#include "libobs/util/{member}.c.h"\n') + self.assertEqual(PORTED.ported_objects(root, "linux"), + ["util/common.c.h.o", "util/hevc.c.h.o", "util/linux.c.h.o"]) + self.assertEqual(PORTED.ported_objects(root, "windows", hevc=False), + ["util/common.c.h.o", "util/windows.c.h.o"]) + + +if __name__ == "__main__": + unittest.main() diff --git a/ci/test_tier2_apt_cache.py b/ci/test_tier2_apt_cache.py index a3d14c49cb..9308646289 100644 --- a/ci/test_tier2_apt_cache.py +++ b/ci/test_tier2_apt_cache.py @@ -26,6 +26,12 @@ def job(name: str) -> str: class AptCacheTest(unittest.TestCase): + def test_manifest_reader_has_uv_in_both_stock_job_containers(self): + for name in ("rust-linux-tier2-build", "rust-linux-tier2"): + j = job(name) + self.assertRegex(j, r"uses: astral-sh/setup-uv@[0-9a-f]{40}", name) + self.assertLess(j.index("astral-sh/setup-uv@"), j.index("run: bash rust/tools/linux-validate/validate.sh"), name) + def test_every_tier2_linux_job_caches_apt_archives(self): for name in ("rust-linux-tier2-build", "rust-linux-tier2"): j = job(name) diff --git a/docs/features.md b/docs/features.md index 9eb2fa8074..e955b00ea9 100644 --- a/docs/features.md +++ b/docs/features.md @@ -152,6 +152,10 @@ not get a line. ### Encoding, streaming and recording +- **Codec availability follows the build.** MP4 and MOV outputs do not advertise + HEVC when it was disabled at build time. *Linux*, pending merge. PR + [#1333](https://github.com/obs-rust/obs-studio/pull/1333). + - **Enhanced Broadcasting encoder controls.** Enhanced Broadcasting stream settings can turn off B-frames and lookahead and set the preset and tuning, for lower latency than the service settings give, and show a @@ -611,6 +615,11 @@ area. follows silence. *All*, 2026-10-16. PR [#995](https://github.com/obs-rust/obs-studio/pull/995). +- Audio timestamp differences smaller than one sample no longer leave an + invalid interval in the mixer. *All*, pending merge. Issue + [#838](https://github.com/obs-rust/obs-studio/issues/838), PR + [#1385](https://github.com/obs-rust/obs-studio/pull/1385). + ### Encoding, streaming and recording - A recording no longer fails with "incomplete UTF-8 string" when a long @@ -1269,6 +1278,11 @@ area. [#1109](https://github.com/obs-rust/obs-studio/pull/1109), upstream [obsproject/obs-studio#12213](https://github.com/obsproject/obs-studio/issues/12213). +- Browser panels no longer crash during cold startup with CEF 150, and + closing OBS while its browser engine starts no longer hangs. *Linux*, + 2026-10-17. PR [#1333](https://github.com/obs-rust/obs-studio/pull/1333), + dependency [obs-browser#1](https://github.com/obs-rust/obs-browser/pull/1). + ### Security hardening - Malformed data from an RTMP server (a zero or negative chunk size, deep or diff --git a/docs/rust-port/cc-build.md b/docs/rust-port/cc-build.md new file mode 100644 index 0000000000..ddc0431ba0 --- /dev/null +++ b/docs/rust-port/cc-build.md @@ -0,0 +1,1290 @@ +# Cargo-driven OBS native build conversion + +Tracking issue: . + +The requested final state is a working OBS Rust application built through Cargo +and `cc::Build`, including shared libraries, plugins, generated files, graphics, +Qt, resources, tests and platform packaging. A core-only archive or test fixture +does not complete the conversion. + +## Maintainer-directed wrap-up + +The maintainer requested stopping further expansion and deferring remaining +C/Rust parity validation when it delays prototype launch. Follow-up +[#1390](https://github.com/obs-rust/obs-studio/issues/1390) owns that remaining +validation. Existing tests remain intact; this is not a claim of complete +parity, release readiness or completion of the full conversion in #1332. + +## Default build mode + +The user selected **unity on, compiled PCH off**. Keep both settings optional. +`libobs::Options::default()` uses that mode; bundled `obs-sys` exposes the same +choice as `OBS_SYS_UNITY=1` and `OBS_SYS_PCH=0` when no override is supplied. +Components that already list explicit unity groups preserve those boundaries. + +## Requirements carried forward + +- Native C/C++ builds must be very fast. Reuse explicit unity groups, make unity + configurable, and implement optional PCH with compiler-compatible settings and + correct dependency invalidation. The user's instruction that unity and PCH are + optional supersedes BUILD.md's always-on rule for this conversion. +- Build through soldr. Demonstrate real compiler cache hits, cold/warm timings, + no-change builds and correctness after editing source, headers and generated + inputs. A setup-soldr archive restore alone does not prove native cache reuse. +- Preserve the public C ABI, dynamic loading, plugin discovery, library identity, + exported symbols and the existing Rust implementation. Build both libobs + variants and exercise the unchanged compatibility and differential suites. +- Keep the application and bundled crates on one native build description. +- Generate files in build output directories; explicitly consume generated + outputs so stale source-tree files cannot shadow them (PR #1323). +- Preserve the complete feature surface on Linux, Windows and macOS. Verify a + real running application, scenes, recording, plugins, shutdown and applicable + websocket tests. Packaging validation must run packaged artifacts. +- Ordinary Cargo users can provide documented native tools; soldr manages the + toolchain and caching. Do not require a nested soldr invocation inside build.rs. +- Reuse existing CI workflows; no new workflow files are authorized. + +## Implementation order and evidence + +1. `obs-build`: typed native build inputs, actual cc::Build compilation, shared + linking, plugin loading and unity on/off contracts. Start with failing tests. +2. `obs-sys`: the real libobs graph, native dependencies, generated configuration + and Rust twin; unchanged C tests and symbol parity. +3. Frontend/plugins, Qt code generation and resources, platform linking and + packaging; run the existing application test battery on these artifacts. +4. Optional PCH, cache/incremental performance measurements and existing CI + integration. Retire CMake only when complete feature/test parity is evidenced. + +The existing CMake build remains the artifact and behavior reference during the +conversion. Intermediate progress must not be reported as full completion. + +## Linux libobs checkpoint + +The bundled `obs-sys` feature now compiles the real C libobs through `cc::Build`, +links `libobs.so.30`, and generates configuration, version and core-module source +files under Cargo's output directory. It uses the same canonical source manifest +as the CMake reference. libcaption remains a separate static archive; system +libraries remain dynamically linked, including when pkg-config lists a static +archive directory before its shared-library directory. + +Local evidence for this checkpoint: + +- The native build engine's three tests pass (dependency selection, generated + source/unity toggle, and a dynamically loaded plugin observing a rebuilt core). +- Bundled libobs passes its public C API version and startup/shutdown tests. +- Editing only the JSON manifest triggers CMake regeneration. Changing a + target-qualified C compiler flag reruns Cargo's bundled native build; compiler + metadata does not add unintended static-library linkage. +- Its 1,766 exported symbols exactly match the local CMake C reference. +- 51 unchanged, already-built C test executables pass against both libraries. + `ldd` confirms each executable loads the intended replacement `libobs.so.30`. + This validates the replacement library; it does not demonstrate a Cargo build + of those test executables or the Rust implementation twin. + +This checkpoint is Linux C libobs only. The application and plugins, +full test battery, macOS/Windows graphs, installation/packaging, optional PCH and +controlled build/cache benchmarks remain required. The generated version and +install paths are prototype defaults and still need release configuration. +Native dependencies are discovered using pkg-config; local Nix verification used +`PKG_CONFIG_PATH` and `CPATH` for installed packages and uthash respectively. + + +## Linux Rust implementation twin checkpoint + +`libobs::build_pair` accepts the release `libobs-rust` static archive from an +outer Cargo invocation. It compiles common C objects once, then links the C +reference and `libobs-with-rust` into separate directories with the same SONAME. +The Rust archive is whole-archive linked and its internal symbols are hidden by +the existing export map. The twin is never installed. + +Build the release archive with `soldr cargo build -p libobs-rust --release`. +With native dependencies available, set `OBS_BUILD_RUST_ARCHIVE` to the absolute +`target/release/liblibobs_rust.a` path and run +`soldr cargo test -p obs-build --features libobs-integration --test libobs`. +`OBS_BUILD_TEST_OUTPUT` optionally retains artifacts in a chosen output directory. +The test defaults to a temporary output directory. Set +`OBS_BUILD_DISABLE_HEVC=1` to exercise the disabled-HEVC configuration. GNU `nm` +is required for the Linux export comparison. + +Local evidence: both variants pass startup/shutdown and public data API roundtrip +checks, and each exports exactly the same 1,766 symbols (1,762 with HEVC disabled). +The opt-in test compares complete export sets and checks HEVC export availability. +The same 51 unchanged C +executables pass against both newly built variants with their loaded library +paths checked. The rest of the complete application/platform/test/packaging +requirements above remain outstanding. + + +## Linux transitions and filters checkpoint + +`plugins::build_transitions` and `plugins::build_filters` build actual OBS +modules through the native engine and link them to the shared C library. +The filters options preserve independent SpeexDSP and RNNoise switches. The +bundled RNNoise fallback uses a canonical JSON C source list shared with CMake; +the CMake target retains the same 18 source/header entries. + +The opt-in integration test loads these modules through `obs_open_module` and +`obs_init_module`, then verifies transition/filter registration against both +libobs variants. Each variant runs in a separate process: the shared SONAME +allows plugin dependencies to retain a previous libobs instance if both variants +are tested in the same process. This matches existing C test isolation and normal +OBS execution. These checks do not yet exercise rendering or audio processing. + + +All four SpeexDSP/RNNoise combinations pass module registration against both +variants, as does disabled HEVC with the default modules. The actual CMake +RNNoise fallback target also compiles all seven objects after the canonical-list +migration; Clippy, gersemi and the build-group/platform guards pass. System +RNNoise discovery is implemented, but this host exercises the bundled fallback. + + +## Linux OpenGL checkpoint + +`graphics::build_opengl` compiles the original OpenGL unity groups and GLAD loader, +links the shared backend, and creates its unversioned lookup name. It consumes the +same libobs options and generated configuration as the core. The Linux graph +includes X11/EGL and optional Wayland support; other platforms remain unfinished. + +With an isolated X server available through DISPLAY, set `OBS_BUILD_RENDER=1` on +the opt-in integration test to exercise real graphics. Local verification used an +owned Xvfb process allocated via `-displayfd`, with `LIBGL_ALWAYS_SOFTWARE=1` and +`GALLIUM_DRIVER=llvmpipe`. Both variants initialize Mesa OpenGL 4.6, create a scene, +and receive at least three 64x64 NV12 frames through the public raw-video callback +API. The callback verifies a valid row and the expected black Y sample (16). +The probe uses the unchanged C headers for video configuration and callbacks; +shutdown and display cleanup happen before its shared libraries unload. + +This demonstrates the native renderer and basic frame delivery. It does not yet +validate the full Qt application, recording, capture sources, all plugins, +Wayland runtime behavior or packaged artifacts. The prototype OpenGL version +number remains tied to the current OBS 33 configuration. + + +## Linux recording checkpoint + +The native engine now links executables as well as shared libraries and archives. +Its executable contract runs a program linked to a shared core that consumes a +static helper. Windows dependency mapping preserves archive paths and converts +DLL paths to import-library paths; runtime validation there remains outstanding. + +The module graph builds x264, the complete Linux obs-outputs groups and librtmp, +and FFmpeg with media playback, VAAPI, optional MPEGTS/SRT/RIST, logging and legacy +NVENC groups. It also builds the standalone FFmpeg mux executable. Shared +opts-parser, happy-eyeballs, BPM and libcaption dependencies use native archives. +The FFmpeg options follow current CMake defaults; the full option matrix and +hardware-specific behavior remain unverified. + +Set `OBS_BUILD_RECORD=1` on the opt-in integration test, with native dependencies, +ffprobe and an isolated DISPLAY available. This implies the graphics probe. Both +variants load the encoder/output modules, verify registration and exactly one +loaded SRT library, then encode an isolated blank scene using real obs_x264, +ffmpeg_aac and mp4_output. The test stops the output, releases encoders, shuts +down OBS, and validates tracks, dimensions, decoded-frame counts and duration +with ffprobe. Local recordings each contain 18 H.264 frames at 64x64 and AAC +audio, duration 0.6 seconds. They contain no desktop or device capture. + +`FfmpegArtifacts::deploy_muxer` places the helper beside the running app. The +integration stages its runner with that helper, selects the same libobs variant +for helper subprocesses, and also records through `ffmpeg_muxer` to Matroska. +All four files (MP4 and Matroska, C and Rust cores) pass the same ffprobe checks. The full Qt application, capture sources, other +modules/platforms, complete test battery, packaging and controlled performance +measurements remain required. Do not treat this checkpoint as a CMake retirement. + +## Linux sources and services checkpoint + +`plugins::build_source` provides typed selections for image sources, FreeType +text, PulseAudio, ALSA, V4L2, X11 capture and RTMP services. V4L2 preserves its +independent UDEV switch. RTMP service updates are configurable and remain off in +the integration smoke test to keep it offline. The default plugin behavior keeps +updates enabled when requested through its typed option. X11 capture and OpenGL +share the GLAD archive builder. + +Set `OBS_BUILD_SOURCES=1` on the integration test with an isolated X display and +an EWMH window manager. Local checks use Xvfb plus an isolated KWin session; +XComposite correctly declines registration on bare Xvfb without EWMH. Both cores +load these seven modules and expose their thirteen expected input/output/service +registrations. The graphics probe also creates a 64x64 white color source, +adds it to the scene and requires three NV12 frames with Y=235 after draining +previous black frames. Both cores still record validated MP4 and Matroska files. +Disabled UDEV also passes registration and rendering against both cores. +The test does not open camera or microphone devices. Hardware capture, text +rasterization, streaming and service-update behavior remain to be validated with +the full application and packaged artifact tests. + +## Linux PipeWire checkpoint + +`SourceModule::PipeWire` builds the original Linux PipeWire unity group and +includes the camera group when the discovered PipeWire version is at least +0.3.60. It enforces CMake's PipeWire 0.3.33 and Gio 2.76 minimums and uses the +shared GLAD archive. Enable its opt-in build/load check with +`OBS_BUILD_PIPEWIRE=1`. Both cores load and initialize the module after graphics +initialization, then render and shut down. Portal availability, camera +permissions and actual screen/camera capture remain unverified; module load alone +does not establish those capabilities. + +## Linux frontend API and Qt checkpoint + +`frontend::build_api` builds the original C++ frontend API as a shared library. +It preserves Linux's SONAME 30 and creates its unversioned lookup name. C++17 and +hidden inline visibility match the CMake compiler configuration. Local symbol +comparison finds exactly 101 exports in both frontend libraries, with no missing +or extra symbols. `OBS_BUILD_FRONTEND_REFERENCE` optionally enables this complete +comparison against an existing CMake artifact in the integration test. + +`qt::moc` runs Qt's meta-object compiler with the native target's include paths and +definitions and compiles its generated translation unit explicitly. It preserves +unchanged output contents/mtime. `OBS_QT_MOC` selects a host tool explicitly; +default discovery uses Qt6Core's pkg-config libexec directory. Application builds +still need UI/resource generation and complete build-script input tracking. + +Enable `OBS_BUILD_QT=1` to build the real VST module and frontend API. Both cores +load the VST module and expose its filter; the frontend API's no-callback defaults +are callable. VST editor/audio behavior, the full Qt application and resources, +other platforms and packaging remain outstanding. + +## Mixed native languages checkpoint + +Native targets now accept common compiler options plus separate C and C++ option +vectors. OBS modules use C17 for C sources and C++17/hidden inline visibility for +C++ sources. Mixed targets compile each language independently and link with the +C++ driver. The regression builds and executes a C++ standard-library program +that calls a C helper; each translation unit rejects flags intended for the other +language. All five native integration tests pass, as does the combined +core/source/Qt/PipeWire/MP4/Matroska check with frontend export comparison. + +## Qt UI, resources and widgets checkpoint + +`qt::uic` generates UI headers with the generated include directory first. +`qt::rcc` embeds resource collections as explicit C++ sources and records every +resource listed by RCC as a Cargo input. Both preserve unchanged generated files. +`OBS_QT_UIC` and `OBS_QT_RCC` select host tools for cross builds, alongside MOC. + +`frontend::add_spinbox` adds the original shared spinbox unity source, Qt Widgets +and all three generated metaobjects, with C++17 required explicitly. The Qt opt-in +integration now runs a real QApplication using the offscreen platform: construct +OBS's virtual-camera dialog from its original UI, find its controls, decode an +embedded OBS PNG, exercise both OBS spinbox types and their metaobject, process +UI events and accept the dialog through its OK button. This passes locally. +This widget test does not yet start the complete OBS application or validate a +packaged runtime/plugin path. + +## Linux frontend executable checkpoint + +`frontend::build_application` compiles and links the frontend executable using an +explicit source inventory, shared Qt interfaces, an Idian archive, JSON11, BPM, +libcaption, the frontend API and a caller-provided Rust GPU status archive. It +creates UI/plugin-path configuration in the output tree. This initial frontend +configuration is Linux with browser panels disabled; other feature/platform +configurations and release paths remain under conversion. + +Build the GPU archive with +`soldr cargo build -p obs-gpu-status-frontend --release`, then enable the integration +check with `OBS_BUILD_APP=1` and `OBS_BUILD_GPU_ARCHIVE` pointing to the resulting +`target/release/libobs_gpu_status_frontend.a`. The executable runs and reports +`--version` identifies the OBS-Studio-Rust application version as `0.1.0`, +based on OBS `33.0.0-cc-build`. +This establishes compilation, linking and CLI execution; GUI startup, runtime +staging and complete application behavior still need validation. + +The inventory includes two forms that CMake AUTOUIC discovered through header +includes. Generated metaobjects are combined into one translation unit with the +same textual header closure CMake supplies to its moc compilation. This preserves +complete Qt types without changing original headers or requiring precompilation. +Compiler include paths and identical definitions are deduplicated while retaining +order. Build/profile/version/install settings are still prototype defaults, and +controlled performance measurements have not been completed. + +## Linux staged GUI runtime checkpoint + +Set `OBS_BUILD_APP_GUI=1` with `OBS_BUILD_GPU_ARCHIVE`, native dependencies, +an isolated X display and an EWMH window manager to run the complete current +Linux graph. This implies the frontend, Qt widget probe, fourteen implemented +modules, OpenGL, source rendering and the MP4/Matroska API recording checks. + +The GUI test stages the executable, selected core, frontend API, renderer, +modules, shaders, application/plugin data and FFmpeg helper under a retained +`app-runtime-*` directory in the native output tree. Each core starts in a fresh +process with its own saved profile and white color-source scene. The test checks +startup, a mapped normal main window, the staged library and module paths in +the process map, restored source, screenshot, normal window-close shutdown and +persisted scene. Logs, process maps and screenshots remain in that runtime. +Both C and Rust cores pass these checks locally; both screenshots show the +restored white preview. The combined run also validates four H.264/AAC files +(MP4 and Matroska for each core). This is runtime evidence, not a controlled +build-performance comparison. + +The isolated test clears desktop-session Qt plugin paths and themes so a host +desktop built with another Qt installation cannot override the linked Qt's +platform plugins. It retains the linked Qt's default plugin discovery and uses +Fusion styling. System native dependencies remain installed on the host; this +development layout does not establish portable release packaging. Hardware +capture, browser/websocket features, remaining modules/platforms, +full test tiers and controlled performance measurements are still required. + +Add `OBS_BUILD_APP_RECORD=1` alongside `OBS_BUILD_APP_GUI=1` to exercise the +frontend's real recording path. Its private profile selects x264/AAC and +Matroska at 640x360/30fps; `--startrecording` starts the frontend output. The +probe requires the recording-start log, records for three seconds and closes +the window normally. ffprobe must decode at least sixty video frames and find +H.264, stereo AAC at 48kHz and the expected dimensions/duration. FFmpeg decodes +the first video frame and checks that it contains the restored white scene. +The finalized recording and ffprobe JSON remain under the retained runtime. +Both cores pass locally: each file has 98 decoded H.264 frames, 48kHz stereo AAC +and a 3.366-second container duration. Both screenshots show recording active +with the white preview. The private headless session's desktop portal backend +does not remain healthy; these checks establish no screen/camera portal capture. + +## Linux NVENC checkpoint + +`plugins::build_nvenc_pair` compiles common NVENC objects once, then links the C +CUDA loader and Rust CUDA loader variants separately. The latter accepts the +outer Cargo build's `obs-nvenc-plugin` archive and hides its Rust symbols. The +capability helper is a separate C++17 executable with thread/dynamic-loader +linkage. FFnvcodec headers must be version 12 or newer. The FFmpeg compatibility +encoder IDs remain independently configurable. + +Build `soldr cargo build -p obs-nvenc-plugin --release` and set +`OBS_BUILD_NVENC=1` on the native integration test. This opt-in check requires +a working NVIDIA driver/GPU: the helper must report support, and both plugin +variants must load and register their H.264 encoders against their corresponding +core. `OBS_BUILD_NVENC_RUST_ARCHIVE` overrides the default archive location; +`OBS_BUILD_NVENC_REFERENCE` optionally compares all exports to a CMake module. +The local comparison finds exactly eight exports in all three modules. +`OBS_BUILD_DISABLE_NVENC_FFMPEG_IDS=1` disables the compatibility IDs. + +Add `OBS_BUILD_NVENC_ENCODE=1` with recording mode to exercise the soft-frame +hardware encoder and therefore the actual CUDA driver loader. This uses 640x360 +because NVENC rejects the tiny 64x64 software probe. Both variants produce +validated H.264/AAC MP4 and Matroska files locally. Source cleanup explicitly +removes public sources from their canvas, releases owned references and drains +the destruction queue before shutdown, matching the frontend sequence. + +Nix verification provides the installed driver libraries through +`LD_LIBRARY_PATH=/run/opengl-driver/lib`. This checkpoint covers native module +loading and soft-frame H.264 encoding. OpenGL texture interoperability, +HEVC/AV1 encoding and other platforms still +need validation. + +## Linux staged GUI NVENC checkpoint + +Combining `OBS_BUILD_NVENC=1`, `OBS_BUILD_APP_GUI=1` and +`OBS_BUILD_APP_RECORD=1` now stages fifteen modules and the NVENC capability +helper. Explicit runtime variants select the C loader with the C core and the +Rust loader with the Rust core. The core's bundled-module whitelist includes +NVENC when this option is requested. + +The private frontend profile selects NVENC. In addition to the existing GUI +checks, the test requires the staged NVENC module in the process map and the +actual recording encoder's NVENC settings log. Both variants pass locally, +producing 99/100 decoded H.264 frames at 640x360 with AAC audio and white images; +screenshots show recording active and both apps shut down normally. On the +isolated Mesa display, NVENC reports its expected fallback to frame upload. +This demonstrates frontend hardware encoding through both loaders; it does +not establish direct NVIDIA OpenGL texture interop. + +## Linux Lua/Python scripting checkpoint + +`scripting::build` compiles the original shared scripting unity groups and +C++ string cache. Lua and Python remain independent options, and a supplied +frontend API enables the original frontend scripting groups. SWIG 4 or newer +generates separate language runtimes and wrappers; `OBS_SWIG` selects the host +tool. The build tracks SWIG environment/input trees, writes generated sources +and headers only when their contents change, and explicitly compiles them. + +Bindings are placed under a retained runtime root with a configurable relative +module directory (default `lib64/obs-scripting`). The scripting library uses +executable-relative discovery. Artifacts identify the enabled Lua module, +Python extension and Python wrapper explicitly; disabled-language files from +an earlier build are not an installation manifest. Release packaging must use +the selected artifacts. + +Enable the opt-in check with `OBS_BUILD_SCRIPTING=1`. It builds a native probe +against the unchanged scripting API, then runs it with each core from an +unrelated working directory and private module configuration. Real Lua and +Python scripts exercise defaults, update, properties, save, reload and unload +callbacks. Process maps must contain the intended core and generated binding, +and the supported-language list must match the build options. Logs remain in +`script-scenarios/` under the native output directory. + +`OBS_BUILD_SCRIPTING_FRONTEND=1` enables frontend bindings and verifies their +default callable behavior; the disabled mode checks that they are absent. +`OBS_BUILD_DISABLE_LUA=1` and `OBS_BUILD_DISABLE_PYTHON=1` select the independent +language cases. Local checks pass both languages with and without frontend +bindings, Lua-only with a relative native output path, and Python-only with +frontend bindings, against both cores. The environment uses SWIG 4.4.1, +LuaJIT and Python 3.13 development packages discovered through pkg-config. + +The shared-library check remains separate from the frontend Tools application +check below. Other platforms and release packaging still require conversion +and validation. + + +## Linux frontend Tools and saved GUI scripts + +`plugins::build_frontend_tools` compiles the original scene-switcher, +output-timer and optional scripting groups, their Linux/POSIX host sources, +shared Qt widgets, generated forms and moc units. Supplying scripting artifacts +enables the matching Lua/Python UI definitions and shared-library dependency. +The graph reuses the application's shared Qt interface inventory. + +Set `OBS_BUILD_FRONTEND_TOOLS=1` with `OBS_BUILD_APP_GUI=1` to stage the plugin +and enabled scripting artifacts in each private runtime. Saved Lua/Python +scripts are restored from the scene collection. The app test checks their +load/update/save/unload callbacks and persisted settings, as well as the +actual staged scripting libraries in the process map. It copies only the +selected language artifacts, excluding stale disabled-language output. + +A test-only Qt module opens Automatic Scene Switcher, Output Timer and Scripts, +checks the saved script count and each script's description/Seed property, +captures each dialog and closes it. Inspection +runs inside Qt's event loop, including Scene Switcher's nested modal loop. +The probe is part of the development test runtime and is not a release plugin. +`OBS_BUILD_DISABLE_SCRIPTING=1` exercises Tools without the scripting library. +Combine `OBS_BUILD_APP_RECORD=1` to retain the actual frontend recording checks. + +Local dual-language and scripting-disabled app checks pass against both cores, +including real frontend H.264/AAC recording and the four native API recordings. +The combined Tools, Lua/Python and NVENC configuration also passes against +both cores, with the selected C/Rust NVENC loaders and helper staged together. +All six dual-language dialog screenshots and the recording main window were +visually inspected. The disabled case requires the Scripts action to be absent. + +Both configurations can print one outstanding allocation during shutdown in +this headless desktop session. An allocation tracker identifies the original +portal sleep-inhibitor object (`portal_inhibit_info_create`); a diagnostic +nonblocking GLib main-context drain releases its pending callback and changes +`bnum_allocs()` from one to zero. The diagnostic is external to the production +build and app probe. This checkpoint establishes normal app exit and scripting +cleanup, not a zero-allocation shutdown log or portal capture support. + +Windows/macOS Tools, remaining modules, full application/capture coverage and +release packaging are still required. + +## Linux websocket server and protocol checks + +`plugins::build_websocket` compiles the pinned original obs-websocket 5.7.5 +server, its 52 C++ sources, generated moc/UI inputs and resources. Dependencies +include Qt Widgets/Svg/Network, Asio, nlohmann-json, websocketpp and qrcodegencpp. +Header/library overrides support dependencies outside the system prefixes. +The submodule source and pin are unchanged. + +Enable `OBS_BUILD_WEBSOCKET=1` with `OBS_BUILD_APP_GUI=1`. The staged application +loads the server with each core, rejects a wrong password, authenticates a real +client and exercises scenes, inputs, settings, events, batches, errors and a +decoded white source screenshot. With `OBS_BUILD_APP_RECORD=1`, the wire client +starts recording after those checks; the retained H.264/AAC recording is then +decoded and checked. A Qt probe opens Server Settings and Connect Info, checks +that the QR image contains dark and light pixels, and captures both dialogs. + +`OBS_BUILD_DISABLE_WEBSOCKET_UNITY=1` compiles the 52 separate C++ sources. +Both modes pass the GUI, wire and recording checks against both cores. Their +11 public `obs_module*` entry points agree; incidental exported C++ template +symbols differ. The core has a separate typed unity option, described below. + +The existing `test/websocket-tier4` suite also passes against both staged cores: +193/193 checks and 147/147 documented request types. The external fixture +adapter aliases its private `obs-studio` configuration directory to the renamed +product's `obs-studio-rust` directory; protocol assertions remain unchanged. +The combined websocket, Tools, Lua/Python and NVENC application passes with +17 production modules plus the test-only Qt probe. Settings/Connect Info +screenshots from both cores were visually inspected. + +These are functional checks, not controlled build-speed measurements. Browser, +remaining plugins, real capture profiles, Windows/macOS native graphs, +production packaging and configurable unity/PCH across the remaining graph +remain required. + +## Shared source inventory and Linux Tier 2 + +`rust/tools/ported_sources.py` reads `libobs/build/source-sets.json` and expands +the selected unity groups for Tier 2's native-object exclusion checks. CMake +and Cargo share the optional HEVC group in that manifest. The reader matches +the actual CMake inventory exactly: 46 Linux objects with HEVC and 45 without. +The existing minimum inventory size and Ninja graph checks remain in force. +The local validation image includes pinned uv and checks offline system-Python +startup while building the image, matching the repository's Python policy. + +This fixes the CI reader that found only one object after the source lists +moved out of CMake. Linux Tier 2 CI passes on `ca331a93d`; local source parity +and HEVC on/off lifecycle/symbol checks also pass (1766/1762 exports +respectively, identical between cores). + +## Individual libobs source compilation + +`libobs::Options::unity` defaults to true, preserving the selected explicit +groups. Set it to false to compile each implementation separately. The native +engine expands C/C++ BUILD.md groups into generated one-member translation +units, preserving their group headers and keeping the source tree unchanged. +Ordinary and explicitly generated sources retain their original paths. +Wrappers are rewritten only when their contents change. Cargo rerun metadata +tracks the groups, their headers and their implementation members; compiler +includes retain direct dependency on the original contents. + +The expander rejects conditional or otherwise unsupported group directives +instead of flattening them into a different source selection. It also rejects +duplicate members and includes outside the source root. Objective-C groups +still require platform implementation. + +`OBS_BUILD_DISABLE_CORE_UNITY=1` selects this mode in the native integration +driver. Local checks pass lifecycle/export parity with HEVC on and off against +both cores. With HEVC enabled, all 1766 exports match the retained unity-built +core exactly, and 51 existing C test executables pass against each core with +loader resolution verified. The browser-disabled GUI, websocket wire checks, +white preview/screenshot and real frontend/API recordings also pass against +both cores. These C executables were built by CMake; their build migration is +still required. The direct native fixture also verifies member/header edits +change the loaded result; that is compiler invalidation evidence, not a full +Cargo scheduling experiment. + +This establishes the core option. Other targets still need to expose it +consistently, and optional compiled PCH and controlled performance comparisons +remain outstanding. + +The subsequent stock-container CI run exposed a separate missing-uv dependency: +unlike the local Docker image, both Tier 2 jobs start from stock Ubuntu. The +existing build and test jobs now provision the same pinned uv before invoking +validation. No workflow files or jobs were added; remote verification remains +required for subsequent conversion commits. This provisioning fix passes the +build and both test modes on `ca331a93d`. + +## Building the C tests through Cargo + +`validation::build_c_tests` builds the 51 previously selected, unchanged C test +executables through the native engine, using an explicit source/dependency +inventory in `rust/obs-build/manifests/c-tests-linux.json`. It invokes no CMake. +Private implementation files get generated C translation units; test bodies +and public headers remain unchanged. Caption, happy-eyeballs, MbedTLS and +other target dependencies are explicit. Header-only fixture dependencies stay +header-only, including the fake PulseAudio test. + +`OBS_BUILD_C_TESTS=1` enables the build and execution checks in the native +integration driver. Each binary runs against both cores from a private working +directory and HOME. Loader resolution must identify the selected core; +stdout/stderr and JSON results are retained. A 60-second limit applies to each +process. + +Per-target sanitizers default on for the same four cases selected by the +original CMake configuration. The central platform helper suppresses them if +global compiler flags already select a sanitizer. The two address/undefined +cases retain their frame-pointer and no-recovery options. ELF checks confirm +the expected ASan/UBSan runtime dependencies. Set +`OBS_BUILD_DISABLE_C_TEST_SANITIZERS=1` to select the disabled option. + +Local results: 51 compiled executables and 102 successful runs with HEVC and +per-target sanitizers enabled; 50 executables and 100 successful runs with +HEVC/sanitizers disabled and individual-source libobs compilation enabled. +The disabled HEVC target is excluded and disabled sanitizer runtimes are +absent from the selected executable dependencies. This is the selected +51-test inventory, not the repository's complete C test graph; the remaining +targets and their platform/feature conditions still require conversion. + +PR CI on `ca331a93d` completed successfully, including the repaired Linux +Tier 2 build and both C/Rust test modes. Run `39078605291` on `4369949a7` +also completed successfully after the VLC and native-test builder changes, +including both Linux test modes and the selected Windows/macOS checks. +These jobs do not automatically exercise the opt-in native application driver. + +## Linux VLC media source + +`SourceModule::Vlc` builds the original VLC core and POSIX host groups. +It discovers headers through pkg-config, `OBS_VLC_INCLUDE_DIR`, `VLC_PATH` +or standard include directories. Header discovery adds no libVLC link edge: +the original plugin still loads the optional runtime dynamically. The native +check inspects the ELF dependency list to enforce that distinction. + +Set `OBS_BUILD_VLC=1` with the staged GUI and websocket checks. The real app +creates a VLC playlist source, decodes a six-second local H.264 clip, returns +a white source screenshot, reports its duration and handles pause/play/restart. +Normal shutdown saves the playlist path in the scene collection. Process maps +must contain the staged plugin and dynamically loaded libVLC. + +Both cores pass those checks, frontend recording and the four API recordings. +The combined VLC, Tools, Lua/Python, websocket and NVENC application also passes +with individual-source libobs compilation: 18 production modules plus the +test-only Qt probe. That run uses an explicit include directory with libVLC's +pkg-config lookup disabled, exercising header discovery independently. + +`OBS_BUILD_VLC_ABSENT=1` selects the runtime-absence check. In an environment +without libVLC, both cores log that the source is disabled, leave `vlc_source` +unregistered, retain the loaded plugin and exit normally. Process maps must +confirm the runtime is absent; a discovered system installation fails this +fixture rather than weakening the check. This does not establish packaging +of VLC, every codec/playlist mode or actual audio-device output. + +### Unchanged VLC compatibility tests through Cargo + +`validation::build_vlc_tests` builds all six original Linux VLC cmocka +executables: drain gate, host path, channel order, audio tracks, audio pacing +and playlist gaps. The pacing executable retains its FFmpeg dependencies. +The C sources and their assertions are unchanged. Select the lane with +`OBS_BUILD_VLC=1 OBS_BUILD_VLC_C_TESTS=1` and provide the real libVLC runtime. +It does not require the staged GUI or websocket lane. + +The integration driver runs every executable against each core, checks the +selected library with `ldd`, stages the original effects, and isolates each +working directory and temporary/configuration/data/cache directory. It retains +the original 60/120-second limits and rejects skipped tests, including exit 77. +It clears inherited cmocka filters and forces standard output formatting so +external settings cannot silently select fewer cases or hide skipped cases. +Paths are canonicalized before changing the child working directory, including +when `OBS_BUILD_TEST_OUTPUT` is relative. Results and raw logs are retained +under the output directory in `vlc-c-tests.json` and `vlc-c-test-runs/`. + +RED `a616f3c57` fails at the missing native test builder. The implemented graph +passes all twelve executions (50 cmocka cases) without skips using libVLC +3.0.23. The combined core/module/render and four MP4/MKV recording validation +took 188.79 seconds. This is runtime compatibility evidence, not a build-speed +benchmark. A local pass does not resolve the playlist audio-integrity failure +seen in prior-head PR CI and tracked by #838. + +### Graphics-dependent unchanged C tests + +`OBS_BUILD_GRAPHICS_C_TESTS=1` adds the original +`test_group_hide_transition_audio` executable to the Cargo graph. It retains +the original core/caption/cmocka/math dependencies, graphics-module definition, +effects and 120-second timeout. RED `60beca399` fails at the missing builder. +The implemented lane passes all four cases against each core (eight total), +with no skips, in a 40.15-second core/module/render invocation. The native +compiler cache reports 62 hits and two misses for that invocation. This is not +a controlled build benchmark. + +The VLC and graphics lanes share the same runner for canonical paths, core +selection, isolated directories, cmocka environment, skip rejection and logs. +The graphics lane writes `graphics-c-tests.json` and +`graphics-c-test-runs/` under the selected output directory. + +The combined graphics/VLC run passes all fourteen executable/core combinations +(58 cmocka cases), without skips, plus the lifecycle/render checks and four +validated MP4/MKV recordings. It took 222.04 seconds including runtime checks; +soldr reports 112 cache hits and zero misses. Formatting, all-target/all-feature +Clippy and the primary review pass. This validates the shared runner extraction. + +The prior-head CI run `39091137249` fails this executable against the Rust +core: all four cases report no program audio at line 216. Its log shows audio +buffering growing from zero to the 960 ms maximum before the failures. The +C-core Linux lane and Windows/macOS Tier 2 lanes pass. The local pass above +does not resolve that failure. + +An isolated diagnostic of the original `add_audio_buffering` function found +that a positive delay below one sample rounds to zero frames/ticks, leaving +`new_ts.end` uninitialized before copying it to the caller. With GCC's pattern +initialization enabled, verbatim function extraction reproduces invalid +intervals for 1, 10000 and 20833 ns delays at 48 kHz. A second probe directly +includes the original source, uses the real headers and links the native core +with no dependency stubs; it reproduces all three invalid intervals and the +valid one-frame case. A scratch copy with the local interval initialized from +the incoming interval corrects all diagnostic cases while retaining the +one-frame case, with the same real headers/core and compiler flags. This +establishes a function-level defect, not causation of the full CI failure. +No production audio source or existing C test is changed at this checkpoint. +Reproduction source and results are retained in the local reports +directory under `audio-buffering-probe/` for follow-up. + +### Audio interval regression and scoped fix + +Draft [#1385](https://github.com/obs-rust/obs-studio/pull/1385) carries the +follow-up to that diagnostic, and this branch carries the same change. +RED `a720d011f` adds a new C regression that directly includes the original +private audio implementation. Two of its five cases fail in each linked-core +mode: empty and pending buffers with a sub-sample delay. The positive one/two +tick and full-buffer controls pass. GREEN `52c577638` initializes the local +interval from the incoming interval; all five cases then pass in both modes. +Existing C tests and public headers remain unchanged. The CMake fragment +configures, builds and passes CTest locally with real imported core/caption +artifacts and headers, without dependency stubs. + +The Cargo test manifest adds the same regression. RED `d6388ca86` requires the +missing executable and observes 51 instead of 52. The manifest supports +compiler-checked optional flags and explicit linker options, preserving the +test's optional pattern initialization and section garbage collection. +The core battery now has 52 executables (51 with HEVC disabled). A full enabled +run passes all 104 executable/core combinations, with 832 reported cmocka cases +and no skip markers; the two standalone video-statistics executables do not +emit cmocka summaries. The new regression contributes five cases per mode. + +This direct-include regression checks the original C algorithm even when it +links the Rust core. It does not establish a Rust replacement for that helper, +nor that the entire intermittent CI failure in #838 is resolved. The unchanged +runtime tests and full CI remain necessary. + +With the source fix, the combined core battery, unchanged group-audio test and +browser-enabled OBS GUI pass against both cores. The app verifies actual +browser pixels/JavaScript, websocket behavior, saved configuration, frontend +H.264/AAC recording, rendering and clean OBS shutdown; the API fixture verifies +four additional MP4/MKV recordings. Runtime directories are +`app-runtime-VCOfty` and `app-runtime-BwMSdi`. The whole invocation takes +489.49 seconds, with 164 compiler-cache hits and 165 misses; it includes native +compilation and runtime tests and is not a controlled build benchmark. + +A subsequent run of all six unchanged VLC executables against both fixed cores +passes all 50 cases without skips: 180.83 seconds including runtime checks, +52 cache hits and eight misses. Formatting, Clippy and primary review pass. +The prior parent-head CI run `39092443140` (`b547ea121`) fails the unchanged +recording-shutdown wait test in mode OFF (one failing executable out of 296, +lines 121/142, tracked by #1283); three PulseAudio tests are skipped in that CI +environment. This audio interval fix does not claim to fix that separate wait +race or to explain all intermittent audio failures. + +The separate fix PR CI run `39093013032` also finishes with a failed gate: +mode ON passes, while mode OFF fails the same two recording-shutdown wait +cases at lines 121/142 (one executable out of 299). The interval regression +passes. This is not a green CI result and no retry was used to hide it. + +## Optional compiled PCH for Linux cores + +`libobs::Options::pch` defaults to false and is independent of `unity`. +Set `OBS_BUILD_PCH=1` in the native integration driver to compile the explicit +group headers with GCC or Clang on Linux. This currently covers libobs; +other targets and Windows/macOS PCH remain required work. + +The native engine accepts explicit `PrecompiledHeader` source assignments. +It compiles each header through the same `cc::Tool` and flags as its consumers, +keeping C and C++ settings separate. Artifact directories distinguish host, +target, header path, language, compiler command and environment. Compiler +invocations retain the soldr wrapper. GCC rejects invalid PCH and uses an error +header to detect fallback; Clang consumes an explicit PCH artifact. Requested +PCH therefore cannot silently fall back to parsing a normal header. + +Compilation batches preserve source order, including interleaved assignments +to different headers. A regression fixture caught constructor order changing +from 123 to 213 when assignments were initially sorted; ordered batches pass +with unity enabled and disabled. Mixed C/C++ fixtures also verify direct and +transitive header edits and language-specific flag changes affect the loaded +result. GCC 15.2.0 passes +all nine native contracts; Clang 21.1.8 passes both PCH contracts. +The real Clang core pair with unity and PCH enabled also passes the lifecycle, +public data, module registration and exact C/Rust export comparisons. The +Clang run does not include the C-test executable or GUI matrices. + +The real GCC core pair passes export/lifecycle checks and all 102 selected +C-test runs with PCH enabled, with unity enabled and disabled. PCH artifacts +are currently requested on every direct native build; repeated invocations +depend on compiler-cache behavior. These checks establish correctness for the +tested configurations, not a speedup or complete Cargo invalidation coverage. + +The combined browser-disabled Linux GUI passes against both individual-source, +PCH-built cores with VLC, frontend Tools, Lua/Python, websocket and NVENC enabled. +It exercises the saved white scene, VLC playback controls, dialog and wire +checks, frontend hardware recordings and four API recordings, then normal +shutdown. The complete build/validation invocation took 571.94 seconds; this +includes native compilation and runtime checks and is not a build benchmark. + +### Scoped core build measurements + +Corrected local GCC measurements explicitly set `NUM_JOBS=4` for the standalone +native integration process and `CARGO_BUILD_JOBS=4`. The active process +environment was inspected: both values were 4 and no Cargo jobserver was +inherited. The earlier wrapper only set Cargo's limit, so its claim of four +native jobs is withdrawn; its original observations are retained separately. + +The corrected matrix uses fixed opt-level 2 with debug information, one fresh +output directory per mode and three repeated builds. The interval covers the +C/Rust core pair and caption, excluding plugin builds, GUI checks and Cargo +startup. The host and compiler cache were shared; no cache was reset. Fresh +output is therefore not a cold-cache measurement. Trials ran in table order. +The integration driver writes `core-build-timing.json` under +`OBS_BUILD_TEST_OUTPUT`; repeat that invocation with the same directory for +additional samples. + +| Unity | Compiled PCH | Fresh output | Repeat median | Repeat range | +| --- | --- | ---: | ---: | ---: | +| On | Off | 12.60 s | 2.55 s | 2.50–2.94 s | +| On | On | 38.39 s | 5.72 s | 4.70–8.67 s | +| Off | Off | 26.38 s | 5.82 s | 5.30–6.34 s | +| Off | On | 44.18 s | 9.83 s | 9.07–11.65 s | + +All twelve repeat invocations reported zero compiler-cache misses. Cache +summaries cover the whole integration invocation, not just the timed core pair. +These results support unity on / PCH off as the default for this measured core +case. PCH preparation and per-header compilation batches still need performance +work. This does not establish full application build time, clean-cache +performance, a CMake comparison or Cargo no-op behavior. + +### Audit of duplicate PCH generation + +At the user's request, the GCC Linux core-pair build was audited with temporary +request tracing and forwarding C/C++ compiler wrappers. Both audited invocations +passed the real core integration test. The first invocation used the audit +wrappers' compiler identity; the next reused the same artifacts and flags. + +| Invocation | PCH requests | Distinct PCH artifacts | Compiler executions | +| --- | ---: | ---: | ---: | +| Initial audited build | 18 | 14 | 14 | +| Warm repeat | 18 | 14 | 0 | + +Some headers recur in nonadjacent source batches and across the common/C/Rust +variant stages. There are four redundant compiler-cache requests per core-pair +build, but the trace did not find duplicate compiler generation: each initial +artifact was compiled once, and soldr served every warm request from cache +(the whole warm invocation reported 64 hits and zero misses). + +The PCH path signature selects an artifact namespace; it is not a freshness +check. Generation must not be skipped merely because that file exists: direct +headers, transitive headers, flags and compiler identity still require correct +dependency validation. An optimization can deduplicate requests within an +immutable build invocation while preserving source/constructor order. Persistent +reuse needs a separate validity check. Temporary tracing was removed after the +audit. The earlier PCH timings describe this implementation, including cache +request and batch overhead; they do not establish an intrinsic PCH speed limit. + +## Bundled obs-sys configuration and Cargo scheduling + +The `bundled` feature exposes the core build modes through environment variables: + +| Variable | Values | Default | +| --- | --- | --- | +| `OBS_SYS_UNITY` | `0` or `1` | `1` | +| `OBS_SYS_PCH` | `0` or `1` | `0` | + +The options are independent. Empty, non-text or other values fail configuration +before native compilation. PCH currently requires Linux GCC or Clang, as above. +With the native dependencies installed, for example: + +```sh +OBS_SYS_UNITY=0 OBS_SYS_PCH=1 soldr cargo test -p obs-sys --features bundled --test native +``` + +The build script tracks both variables and passes them to the shared libobs +builder. Four bundled contracts cover parsing/validation, requested versus +compiled settings, the public API version and native startup/shutdown. Tests +read the inherited environment without mutating process-global settings. + +A local fifteen-invocation Cargo experiment used a separate target directory, +four compilation jobs and the shared host/compiler cache. All four mode +combinations passed. Changing either option made Cargo mark `obs-sys` dirty +for that variable. An invalid PCH value failed the build script before changing +the native library. Five no-change invocations reported the package fresh and +kept the native library's nanosecond timestamp unchanged, including PCH modes. + +The experiment then made successive temporary edits to three private inputs, +changing one additional file per step with unity and PCH enabled. Each change +made Cargo rerun the build script. +A separate process loaded the resulting library and asserted its changed +public API return value or version string: + +| Input | Observable change | Invocation time | Reported cache hits/misses | +| --- | --- | ---: | ---: | +| `libobs/obs.c.h` | API version increment | 14.15 s | 52 / 1 | +| `libobs/build/libobs.pch.h` | Further API version increment | 19.54 s | 47 / 6 | +| `libobs/obsversion.c.in` | Generated version string suffix | 11.07 s | 52 / 1 | + +Times and cache summaries cover the whole Cargo/test invocation, not just +native compilation. These are observed incremental cases on a shared host, +not isolated benchmarks. All temporary inputs were restored; a final build +returned the original API values and its subsequent no-change run stayed fresh. +This verifies selected core input scheduling, not every generated frontend, +plugin, SDK or packaging dependency. The full conversion remains incomplete. + +PR CI run `39080352730` on `5f04b9f0a` completed successfully after the PCH +checkpoint, including both Linux core test modes and the selected Windows/macOS +lanes. Run `39081209344` on `352bac56d` also completed successfully for the +bundled-mode changes, including both Linux modes and selected Windows/macOS lanes. + +## Linux browser build + +`plugins::build_browser` builds the pinned `obs-browser` module and its +`obs-browser-page` subprocess helper. It uses the existing CEF SDK's shared +library and wrapper archive; it does not build Chromium. The SDK must provide +`include/`, `Release/`, `Resources/` and the prebuilt CEF wrapper archive. +`BrowserOptions` selects the SDK directory, Qt panels and unity compilation. +The Linux implementation requires CEF >=95, nlohmann_json >=3.11, X11 and libdrm. +The pinned browser source unconditionally includes `QApplication` and uses +`QToolTip`, so Qt Widgets headers and libraries are required even with panels +disabled. That mode omits panel sources and exports. Enabled panels use the +original Qt sources and generated MOCs. + +Browser unity compilation uses three explicit, ordered groups to avoid duplicate +Base64 declarations and default arguments in the untouched submodule sources. +Individual compilation uses the same source inventory. The helper has its own +source list and CEF dependencies. `BrowserArtifacts::deploy_runtime` copies the +CEF Release and Resources trees and the helper beside the browser module, +including locales, data packs and auxiliary shared libraries. These SDK resource +directories are Cargo build inputs. + +`frontend::build_application_with_options` enables the original custom-browser +dock implementation and generated Qt interfaces through `browser_panels`. +The existing `build_application` entry point retains its default configuration. +For the integration driver, set `OBS_BUILD_BROWSER=1` and `OBS_CEF_ROOT` to the +SDK root. `OBS_BUILD_DISABLE_BROWSER_UNITY=1` selects individual browser +compilation; `OBS_BUILD_DISABLE_BROWSER_PANELS=1` disables the panel interfaces. +The GUI browser tests also require `OBS_BUILD_WEBSOCKET=1` to exercise the +JavaScript bridge through the public source and scene APIs. + +The SDK used locally is the Linux x86_64 CEF 7871 archive pinned by +`CMakePresets.json`, with SHA256 +`8ffc64d06ea74da613eeda7f2aa5d4e98661af6fa3ed8c68724c9a6e4e89ea8e`. +Its CEF header reports 150.0.19. Host verification supplies installed CEF runtime +dependencies through a private loader path; it does not modify system libraries. +This browser implementation currently targets Linux. Other platforms, production +SDK acquisition, installation and packaged runtime validation remain unfinished. + +Browser validation is in progress. The module/helper build contracts pass with +unity and panels independently enabled or disabled, including helper execution, +CEF linkage and panel export selection. The panels-enabled unity and individual +modules each export the same 22 symbols. In the staged GUI, the original custom +dock editor accepts real delegate edits, creates a browser dock, navigates to a +local page and receives its JavaScript-generated readiness title. + +During development, the full browser GUI test failed at the browser source's +local-file navigation. The input is active and showing at the requested 128×72 dimensions, +but its screenshots remain transparent. A diagnostic CEF DevTools session finds +the requested `http://absolute/…` target with an `about:blank` page context; an +owned-process trace observes the initial paint but no call to the local-file +scheme handler. Individual compilation reproduces this failure. An additional +diagnostic run caught `CefTask_0_CToCpp called with invalid version -1` during +cold panel initialization. The dependency fix and isolated credential-store +fixture correction below resolve these observed failures in the tested Linux +runtime; this does not establish all-platform or packaged application parity. The new checks +retain their rendering, JavaScript bridge, helper-process and saved-profile +requirements. Existing C tests and public headers remain unchanged. + +### Browser startup investigation + +A CMake reference build of the original browser module and helper reproduces +the local-file failure inside the same Cargo-built frontend and core. This +rules out browser unity compilation as its cause; it does not establish what +a complete CMake-built application does. Explicitly selecting the global CEF +request context did not fix it and was discarded. + +The cold-start API-version abort has a separate focused regression in a sister +`obs-browser` checkout. Linking the real browser objects and queuing a task +before initialization aborts with the original module and safely rejects the +task with the proposed fix. Real module startup followed by immediate unload +also aborts with the original module and exits successfully with the fix. +The dependency draft [obs-browser#1](https://github.com/obs-rust/obs-browser/pull/1) +proposes commit `0c3b700` (the current experimental pin). It waits for context readiness for ordinary tasks, +handles source destruction before readiness, and coordinates unload with +initialization success or failure. A follow-up dependency test at `4f26bda` +now exercises real CEF initialization failure: a second process shares the +first process's locked profile, waits for the actual initialization-failure +message, then unloads cleanly. Both the original and fixed modules pass this +failure-path characterization; it does not distinguish the startup-race fix. +The parent's production pin remains `0c3b700`. Browser-source rendering is +verified in the disposable Linux test profile described below. + +### Isolated browser credential store + +A CEF network trace narrows the blank local source to an unfinished global +persistent-cookie key load in the isolated desktop session. The custom panel's +separate cookie store completes. Selecting Chromium's basic password store +inside a fresh disposable test profile completes the global cookie load and +passes the existing browser source color/JavaScript callback, WebSocket, +recording, saved-scene and shutdown checks. A second runtime-only run with the +basic store and no network tracing also passes. This diagnoses the isolated +credential-service integration; it does not verify normal desktop keyring +integration. No production credential-store option is changed. Full native +Cargo GUI validation now passes against both C and Rust core variants, including +the original dock editor, actual native dock pixels, local source HTML/JavaScript +callback, staged helper subprocesses, saved configuration, recordings and normal +shutdown. The full invocation took 510.62 s and reported 27 cache hits / 199 +misses; it used the earlier uncapped native test environment and is not a +controlled build benchmark. A warm repeat with both job limits explicitly set +to 4 passes in 77.56 s, with 226 cache hits and zero misses. Its interval includes +GUI checks and recordings against both cores; it is not a compile-only timing. + + +## Optional FDK AAC encoder checkpoint + +`plugins::build_fdk` builds the original `obs-libfdk` unity group as a dynamically +loaded module through `cc::Build`, discovering the `fdk-aac` SDK through +pkg-config. This optional encoder remains disabled by default, matching the +original CMake option. Set `OBS_BUILD_FDK=1` in the native integration driver to +build, load and exercise it. GUI selection alone does not enable FDK. + +The RED commit `a0bc15642` fails at the unimplemented native builder. With the +builder implemented, the integration test passes against both the C and Rust +cores in 24.77 s. Each core records MP4 and MKV with the actual `libfdk_aac` +encoder; ffprobe verifies AAC LC, 48 kHz stereo, decoded audio frames, H.264 video +frames and recording duration. No usable soldr statistics were available for +that invocation, so it does not establish cache performance. The existing +headless path with FDK disabled also passes (12.80 s), using `ffmpeg_aac` for +all four recordings. + +A reference build invokes the original `plugins/obs-libfdk/CMakeLists.txt`, +using the same FDK 2.0.3 SDK and Cargo-built core. Both modules export exactly +the same six dynamic symbols. This verifies module exports; it is not a +complete CMake application or a cross-platform runtime comparison. The default +GUI/browser path is checked separately to ensure adding this optional encoder +does not make it mandatory. + + +## Optional JACK and sndio audio modules + +`SourceModule::Jack` and `SourceModule::Sndio` build the original Linux unity +groups as dynamic modules through `cc::Build`, with pkg-config dependencies +`jack` and `sndio`. Both remain disabled by default, including ordinary GUI +runs. Select them independently with `OBS_BUILD_JACK=1` and +`OBS_BUILD_SNDIO=1` in the integration driver. The GUI core-module whitelist +includes each only when explicitly selected. The sndio target retains the +original `-Wno-error=vla` option. + +RED `452911b5c` fails at the unimplemented optional audio module graph. With +that graph implemented, both modules load and register their original +`jack_output_capture` and `sndio_output_capture` input IDs against both C and +Rust cores; the existing graphics and four-recording checks also pass (20.52 s). +Reference builds invoke each original CMake target with the same SDKs (JACK +1.9.22 and sndio 1.10.0). Each module exports exactly the same seven symbols as +its Cargo-built counterpart. The JACK reference needs an explicit include path +because its original finder's pkg-config include hint uses the singular name. +No CMake source list was recreated for these reference builds. + +### Actual input capture + +The new C fixture uses unchanged public OBS headers and real audio clients. It +sends distinct stereo samples (left 0.25, right -0.125) through each original +source, requiring at least three matching packets at the public source audio +capture callback. Event waits are bounded; JACK clients close, the sndio writer +thread joins, callbacks are removed and sources are released before the local +probe state is destroyed. No existing upstream C test or public header changes. + +- JACK: start a separately named non-realtime `jackd` dummy server, export its + `JACK_DEFAULT_SERVER`, and set `OBS_BUILD_JACK=1 OBS_BUILD_JACK_CAPTURE=1`. + The fixture connects its writer to the real OBS source's two JACK ports. +- sndio: start an owned `sndiod` with playback/monitor mode (`-m play,mon`) and + a named sub-device, set `OBS_BUILD_SNDIO=1`, and pass its descriptor as + `OBS_BUILD_SNDIO_CAPTURE_DEVICE` (for example `snd,11/capture` for server + unit 11 and sub-device `capture`). The fixture writes through the real sndio + client API and observes the monitor source. Use a clocked audio backend. +- Either capture flag requests the existing graphics probe and initializes + stereo audio; recording is optional. The existing probe still requires an + X11 display and an OpenGL implementation. These are Linux integration tests. + +A direct ALSA null backend did not drive sndiod: its watchdog timed out and the +sample test failed. Keeping the assertions intact, the validated fixture routes +sndiod through ALSA's PulseAudio plugin into a private PulseAudio null sink. +No desktop audio service or physical input is used. The combined run passes +against both cores, exercises both input captures in each of the four recording +processes, and validates all recordings (33.67 s, 96 cache hits / zero misses). +That interval includes runtime capture and recordings; it is not a compile-only +benchmark. Capture-only validation with recording disabled also passes against +both cores (15.53 s), exercising both inputs without relying on recording to +initialize audio. Real physical-device routing, platform graphs and packaged audio +runtime remain separate requirements of the full conversion. + + +Independent JACK-only and sndio-only configurations also pass. The staged +GUI/browser invocation with both optional modules selected passes against both +cores, including native dock/source rendering, JavaScript/WebSocket checks, +recordings, saved configuration and shutdown (102.18 s, 226 cache hits / two +misses). This is a combined build/runtime interval, not a controlled compiler +benchmark or proof of physical-device capture. + + +## Intel QSV native module + +`plugins::build_qsv` builds the original Linux x86_64 QSV C/C++ groups in CMake source +order, using oneVPL >= 2.9, libva and libva-drm. It retains the host-definition +header, language standards, switch warning exception and inline visibility. +`QsvOptions` supports HEVC, unity and compiled PCH independently; its default is +HEVC on, unity on, PCH off. The integration driver selects the target with +`OBS_BUILD_QSV=1`, with `OBS_BUILD_DISABLE_QSV_UNITY` and `OBS_BUILD_QSV_PCH` +controlling its compilation. Its HEVC setting follows `OBS_BUILD_DISABLE_HEVC`. +The full CMake graph enables QSV by default; the integration driver's opt-in is +not a change to that product default. + +RED `3f0a49d4f` fails at the missing builder; implementation `5c511b9d2` adds the +native graph and isolated CMake runtime comparison. The initial build/load and +four H.264/AAC recordings pass against both cores (34.56 s). The controlled +reference uses each original QSV CMake target, matching the project's inline +visibility and optimization, against the same SDKs (oneVPL 2.16 and libva 2.23). +The finder needs the pkg-config include root explicitly on this Nix host. +`OBS_BUILD_QSV_REFERENCE` requires exact dynamic exports and compares encoder +registrations after loading that actual reference module with each core in a +fresh process. Reference runs preserve the real graphics/module/lifecycle +checks; their recording is omitted to avoid overwriting the validated clips. + +The first unity/PCH-off case passes with seven matching exports and matching +registrations. Both cores and the CMake reference expose no QSV encoders on this +host. This proves graceful loading without a detected implementation; Intel +hardware encoding and texture interoperability remain unverified. The complete option matrix passes, with seven matching exports and four fresh +CMake reference runtime comparisons per row: + +| QSV unity | QSV PCH | HEVC | Full invocation | Cache hits / misses | +| --- | --- | --- | ---: | ---: | +| On | Off | On | 25.46 s | 96 / 1 | +| Off | Off | Off | 25.98 s | 97 / 1 | +| On | On | On | 30.56 s | 93 / 8 | +| Off | On | Off | 29.90 s | 91 / 12 | + +Each invocation includes both cores, native compilation, real MP4/MKV recordings +and reference runtime checks. These are functional validation intervals with a +shared cache, not controlled PCH performance measurements. Disabled rows also +check the public MP4/MOV codec lists. Compiled PCH remains off by default. + +### HEVC-disabled MP4 build regression + +The QSV matrix's HEVC-disabled recording case exposed unconditional HEVC calls +in the existing MP4 muxer. Both Cargo and the original CMake output target fail +to link against the disabled core, with unresolved `obs_parse_hevc_header` and +`obs_parse_hevc_packet`. The original CMake reference uses its actual target, +SDK libraries and shared dependencies, and `--no-undefined` to require a valid +module. The failure is not QSV-specific. + +RED `0c73e4776` additionally requires MP4/MOV advertised codecs to agree with the +build option. The fix gates the HEVC-only helpers, call sites and recognition +with `ENABLE_HEVC`, and removes HEVC from the disabled outputs' codec lists, +following the existing FLV output pattern. Enabled source bodies remain intact. +The original CMake output target now links successfully with HEVC disabled. +The next disabled recording run exposes one VA-API codec switch case calling +`vaapi_device_hevc_supported` despite that helper's declaration and definition +being conditional. Guarding the case with the same feature macro makes it use +the existing unsupported-codec fallback when disabled. Enabled behavior stays +unchanged. These regressions were found by keeping real recordings in the +HEVC-disabled option matrix. +No public header or existing upstream C test is edited. Full application, +physical Intel hardware, cross-platform and release packaging parity remain +requirements of the complete conversion. + + +The full staged GUI/browser invocation with global HEVC disabled and QSV +selected passes against both cores (424.83 s, 110 cache hits / 118 misses). +It verifies native dock/source pixels, JavaScript/WebSocket behavior, saved +configuration, frontend recording and normal shutdown. With +`OBS_BUILD_MOV_RECORD=1` (requiring recording/FFmpeg targets), the API fixture +also records and decodes MP4, MKV and MOV against each core. Both MOV artifacts +contain H.264/AAC and the QuickTime `qt ` major brand. Six additional CMake QSV +reference runtime comparisons pass. This interval includes native compilation +and application checks; it is not a compile-only or controlled cache benchmark. +Intel hardware encoding remains unverified. + + +## Linux WebRTC / WHIP Cargo graph + +RED `2923db820` requires the real WebRTC output and service module and fails +at the missing builder. `plugins::build_webrtc` now compiles the original +POSIX and core C++ groups in their original order through `cc::Build`, links +to the selected shared libobs, libdatachannel SDK and libcurl, and retains the +original module data. Unity defaults on and compiled PCH defaults off; both +can be selected independently through `WebRtcOptions`. Its HEVC setting +follows the global option. The integration fixture checks WHIP's advertised +video/audio codecs as well as the output/service registrations. + +The explicit `DataChannelSdk` supplies include/library paths and the media +and websocket interface definitions from that SDK's build. Media support is +required and the headers must report libdatachannel >= 0.20, matching the +original dependency requirement. The tested SDK is the shared build of +libdatachannel version 0.24.1 with both interface features enabled. Linux is +implemented; other platforms return an explicit unsupported-graph error. +Static SDK linkage and other SDK feature combinations have not been validated. + +Enable the existing opt-in integration driver with `OBS_BUILD_WEBRTC=1`, +`OBS_DATACHANNEL_INCLUDE_DIR` and `OBS_DATACHANNEL_LIBRARY`. +`OBS_DATACHANNEL_DISABLE_WEBSOCKET` describes an SDK built without that feature; +it must match the supplied SDK. `OBS_BUILD_DISABLE_WEBRTC_UNITY` and +`OBS_BUILD_WEBRTC_PCH` select the module's build modes. + +The new `tests/libobs/whip_receiver.py` wraps the native test command and +provides a real localhost WHIP receiver using pinned aiortc/aiohttp/numpy. +It authenticates the SDP POST and resource DELETE, negotiates a real peer, +and decodes received media. The native fixture uses the public OBS service, +output and encoder APIs, x264 video and FFmpeg Opus audio; no transport stub +or mocked encoder is involved. Each core sends a rendered 64x64 scene and a +48 kHz stereo 1 kHz tone. The receiver checks decoded pixels, advancing +media timestamps, audio format, tone frequency/RMS, connected state and +resource deletion. The existing four MP4/MKV recording assertions remain. +The wrapper propagates command failures and bounds its owned process group +with a configurable timeout; it does not stop shared services. + +The first stream run passes against both cores (20.71 seconds, 96 compiler +cache hits and zero misses). An actual reference module built using the +original `plugins/obs-webrtc/CMakeLists.txt` has the same 26 dynamic exports +as the native module, including seven public OBS module entry points. +Both link dynamically to libobs, libdatachannel and libcurl. The integration +driver compares those exports when `OBS_BUILD_WEBRTC_REFERENCE` is supplied; +`OBS_BUILD_WEBRTC_USE_REFERENCE` explicitly selects that module for a separate +reference runtime run. That flag requires a reference path and never counts +as native-module streaming coverage. + +This checkpoint validates H.264/Opus streaming on Linux. Actual HEVC/AV1 +streaming, simulcast, external services, Windows/macOS and release packaging +remain required work; codec registration alone does not prove those paths. + +The four unity/PCH combinations each pass two native-module WHIP streams and +four MP4/MKV recordings. The separate CMake reference run passes the same +receiver and recording checks against both cores: + +| WebRTC unity | WebRTC compiled PCH | Module used at runtime | Native invocation | Cache hits / misses | +| --- | --- | --- | ---: | ---: | +| On | Off | Cargo | 56.62 s | 12 / 84 | +| Off | Off | Cargo | 25.73 s | 94 / 4 | +| On | On | Cargo | 29.10 s | 93 / 4 | +| Off | On | Cargo | 25.17 s | 96 / 4 | +| On | Off | CMake reference | 19.52 s | 95 / 0 | + +These are complete native test invocations including runtime/recording checks, +using a shared host/cache in table order. They do not measure isolated compile +time, a cold cache or an intrinsic PCH performance difference. Each native +mode compares its complete export set with the original CMake module before +runtime; the reference row explicitly substitutes that original module. + + +With global HEVC disabled, a further native-module run passes the advertised +`h264;av1` video/`opus` audio codec checks, two real H.264/Opus streams and four +recordings against both cores (55.70 seconds, 41 cache hits / 54 misses). +This does not exercise actual HEVC or AV1 media. The original WHIP service's +own codec list remains unchanged; it advertises HEVC independently of the +output option, which is existing behavior rather than a newly fixed path. + +### Existing standalone WHIP tests + +A focused test in the existing opt-in Cargo target `libobs` builds the unchanged +`test_whip_rtp_timestamp.c` and `test_whip_host_os_name.cpp` sources using +`validation::build_webrtc_tests`. RED `a425f96d8` fails at the missing builder; +the implemented graph passes all six RTP-clock cases and both POSIX host-name +cases, with no skips, in 1.27 seconds. These helpers require neither libobs +nor libdatachannel. They run once, not once per core, and do not establish +coverage of a Rust replacement. C and C++ language options are separate, +matching the original test source languages. Each executable has a bounded +60-second runtime; cmocka filters are removed and explicit case totals are +checked. The helper graph currently supports Linux. + +```sh +soldr cargo test -p obs-build --features libobs-integration --test libobs -- webrtc_tests::original_whip_clock_and_host_tests_pass_without_a_core_or_sdk --exact --nocapture +``` + +The selected native graph now contains 52 core executables, six VLC tests, +one graphics test and two standalone WHIP tests. It is not the complete OBS +test battery. A static inventory of this worktree's `test/cmocka/tests.d` +finds 238 literal executable declarations before evaluating platform/option +conditions; recent reference CI runs contain 299 configured tests. That +inventory is a gap-finding aid, not an evaluated replacement for CTest. + + +The consolidated helper test passes all eight cases again in 0.69 seconds, +with one unrelated integration test filtered out. The workspace remains at +its existing cap of 25 Cargo integration binaries; no cap increase is needed. + +A broader app/VLC/browser invocation exposed a harness error after 480.98 +seconds: it tried to copy its own integration executable only after lengthy +native compilation, and that path no longer existed following concurrent +Cargo rebuilds. All 104 core executable runs had completed before this +failure; no GUI or WHIP-stream pass is claimed from that invocation. The +fixture now snapshots its executable at parent startup, before native builds, +and deploys FFmpeg/NVENC helpers beside that snapshot later. Review and Clippy +pass for this staging change. The failed log is retained, and the full runtime +battery is rerun with no overlapping Cargo commands in this worktree. + + +The next broad invocation reaches renderer setup, then catches a second +fixture bug: the WHIP guard required `OBS_BUILD_RECORD` to be explicitly set, +while the parent enables recording implicitly for `OBS_BUILD_APP_GUI`. +The guard now uses the parent's existing `enabled` helper, preserving the +same recording requirement for both entry paths. That failed invocation +passes all 104 core executions and both standalone WHIP executables first; +it does not reach GUI, VLC/group-audio or streaming validation. + +At the user's request, the remaining conversion and broad validation are +being deferred. A final focused app/streaming attempt is interrupted after +the shared Soldr daemon loses its control connection; final Clippy also +reports a daemon connection reset rather than a source diagnostic. The +previous completed Clippy/review runs and streaming matrix remain valid for +the code they exercised. The final guard change is reviewed locally, but a +successful final-head app run and lint rerun remain outstanding. No shared +broker or daemon is restarted. Keep the PR draft. + +Deferred work retains the original scope: remaining plugin graphs and full +native test coverage; Windows/macOS graphs and runtime; physical capture and +hardware codec paths; SDK acquisition, standalone obs-sys publishing and +release installation/packaging; graph-wide unity/PCH controls and controlled +full-app performance measurements. This checkpoint is not the completed +CMake replacement and must not be merged as one. diff --git a/frontend/build/cargo-sources.json b/frontend/build/cargo-sources.json new file mode 100644 index 0000000000..76f2fecfbf --- /dev/null +++ b/frontend/build/cargo-sources.json @@ -0,0 +1,345 @@ +{ + "common": [ + "frontend/build/frontend.app-obs-main+.hpp.cpp", + "frontend/build/frontend.app-obsstudioapi+.hpp.cpp", + "frontend/OBSStudioAPI.hpp", + "frontend/build/frontend.app-obsapp+.hpp.cpp", + "frontend/OBSApp.hpp", + "frontend/build/frontend.app+.hpp.cpp", + "frontend/build/frontend.components+.hpp.cpp", + "frontend/components/AbsoluteSlider.hpp", + "frontend/components/AccessibleAlignmentCell.hpp", + "frontend/components/AccessibleAlignmentSelector.hpp", + "frontend/components/AlignmentSelector.hpp", + "frontend/components/ApplicationAudioCaptureToolbar.hpp", + "frontend/components/AudioCaptureToolbar.hpp", + "frontend/components/BalanceSlider.hpp", + "frontend/components/BrowserToolbar.hpp", + "frontend/components/ClickableLabel.hpp", + "frontend/components/ColorSourceToolbar.hpp", + "frontend/components/ComboSelectToolbar.hpp", + "frontend/components/DelButton.hpp", + "frontend/components/DeviceCaptureToolbar.hpp", + "frontend/build/frontend.components-2+.hpp.cpp", + "frontend/components/DisplayCaptureToolbar.hpp", + "frontend/components/EditWidget.hpp", + "frontend/components/FlowFrame.hpp", + "frontend/components/FlowLayout.hpp", + "frontend/components/FocusList.hpp", + "frontend/components/GameCaptureToolbar.hpp", + "frontend/build/frontend.components-infochip+.hpp.cpp", + "frontend/components/InfoChip.hpp", + "frontend/components/ImageSourceToolbar.hpp", + "frontend/components/MediaControls.hpp", + "frontend/components/MenuButton.hpp", + "frontend/components/MenuCheckBox.hpp", + "frontend/components/Multiview.hpp", + "frontend/components/MuteCheckBox.hpp", + "frontend/build/frontend.components-3+.hpp.cpp", + "frontend/components/OBSAdvAudioCtrl.hpp", + "frontend/components/OBSPreviewScalingComboBox.hpp", + "frontend/components/OBSPreviewScalingLabel.hpp", + "frontend/components/OBSSourceLabel.hpp", + "frontend/components/SceneTree.hpp", + "frontend/components/SilentUpdateCheckBox.hpp", + "frontend/components/SilentUpdateSpinBox.hpp", + "frontend/components/SourceSelectButton.hpp", + "frontend/components/SourceToolbar.hpp", + "frontend/components/SourceTree.hpp", + "frontend/components/SourceTreeDelegate.hpp", + "frontend/build/frontend.components-sourcetreeitem+.hpp.cpp", + "frontend/components/SourceTreeItem.hpp", + "frontend/components/SourceTreeModel.hpp", + "frontend/build/frontend.components-4+.hpp.cpp", + "frontend/components/TextSourceToolbar.hpp", + "frontend/components/UIValidation.hpp", + "frontend/components/UrlPushButton.hpp", + "frontend/components/VisibilityItemDelegate.hpp", + "frontend/components/VisibilityItemWidget.hpp", + "frontend/components/VolumeAccessibleInterface.hpp", + "frontend/components/VolumeControl.hpp", + "frontend/components/VolumeMeter.hpp", + "frontend/components/VolumeMeterSnapshot.hpp", + "frontend/components/VolumeName.hpp", + "frontend/components/VolumeSlider.hpp", + "frontend/build/frontend.components-5+.hpp.cpp", + "frontend/components/WindowCaptureToolbar.hpp", + "frontend/build/frontend.dialogs+.hpp.cpp", + "frontend/dialogs/LogUploadDialog.hpp", + "frontend/dialogs/NameDialog.hpp", + "frontend/dialogs/OAuthLogin.hpp", + "frontend/dialogs/OBSAbout.hpp", + "frontend/dialogs/OBSBasicAdvAudio.hpp", + "frontend/build/frontend.dialogs-obsbasicfilters+.hpp.cpp", + "frontend/dialogs/OBSBasicFilters.hpp", + "frontend/build/frontend.dialogs-obsbasicinteraction+.hpp.cpp", + "frontend/dialogs/OBSBasicInteraction.hpp", + "frontend/build/frontend.dialogs-obsbasicproperties+.hpp.cpp", + "frontend/dialogs/OBSBasicProperties.hpp", + "frontend/dialogs/OBSBasicSourceSelect.hpp", + "frontend/dialogs/OBSBasicTransform.hpp", + "frontend/dialogs/OBSBasicVCamConfig.hpp", + "frontend/dialogs/OBSLogViewer.hpp", + "frontend/dialogs/OBSMissingFiles.hpp", + "frontend/build/frontend.dialogs-2+.hpp.cpp", + "frontend/dialogs/OBSRemux.hpp", + "frontend/dialogs/OBSWhatsNew.hpp", + "frontend/build/frontend.docks+.hpp.cpp", + "frontend/docks/OBSDock.hpp", + "frontend/build/frontend.models+.hpp.cpp", + "frontend/models/Rect.hpp", + "frontend/models/SceneCollection.hpp", + "frontend/build/frontend.oauth+.hpp.cpp", + "frontend/oauth/Auth.hpp", + "frontend/oauth/AuthListener.hpp", + "frontend/oauth/OAuth.hpp", + "frontend/forms/AutoConfigFinishPage.ui", + "frontend/forms/AutoConfigStartPage.ui", + "frontend/forms/AutoConfigStreamPage.ui", + "frontend/forms/AutoConfigTestPage.ui", + "frontend/forms/AutoConfigVideoPage.ui", + "frontend/forms/ColorSelect.ui", + "frontend/forms/LogUploadDialog.ui", + "frontend/forms/OBSAbout.ui", + "frontend/forms/OBSAdvAudio.ui", + "frontend/forms/OBSBasic.ui", + "frontend/forms/OBSBasicControls.ui", + "frontend/forms/OBSBasicFilters.ui", + "frontend/forms/OBSBasicInteraction.ui", + "frontend/forms/OBSBasicProperties.ui", + "frontend/forms/OBSBasicSettings.ui", + "frontend/forms/OBSBasicSourceSelect.ui", + "frontend/forms/OBSBasicVCamConfig.ui", + "frontend/forms/OBSExtraBrowsers.ui", + "frontend/forms/OBSImporter.ui", + "frontend/forms/OBSMissingFiles.ui", + "frontend/forms/OBSRemux.ui", + "frontend/forms/StatusBarWidget.ui", + "frontend/forms/PluginManagerWindow.ui", + "frontend/forms/obs.qrc", + "frontend/forms/source-toolbar/browser-source-toolbar.ui", + "frontend/forms/source-toolbar/color-source-toolbar.ui", + "frontend/forms/source-toolbar/device-select-toolbar.ui", + "frontend/forms/source-toolbar/game-capture-toolbar.ui", + "frontend/forms/source-toolbar/image-source-toolbar.ui", + "frontend/forms/source-toolbar/media-controls.ui", + "frontend/forms/source-toolbar/text-source-toolbar.ui", + "frontend/build/frontend.settings+.hpp.cpp", + "frontend/settings/OBSBasicSettings.hpp", + "frontend/build/frontend.settings-obshotkeybackground+.hpp.cpp", + "frontend/settings/OBSHotkeyBackground.hpp", + "frontend/settings/OBSHotkeyBackgroundBanner.hpp", + "frontend/build/frontend.settings-obshotkeycapture+.hpp.cpp", + "frontend/settings/OBSHotkeyCapture.hpp", + "frontend/settings/OBSHotkeyEdit.hpp", + "frontend/settings/OBSHotkeyLabel.hpp", + "frontend/settings/OBSHotkeyWidget.hpp", + "frontend/build/frontend.utility+.hpp.cpp", + "frontend/utility/AdvancedOutput.hpp", + "frontend/utility/BaseLexer.hpp", + "frontend/build/frontend.utility-basicoutputhandler+.hpp.cpp", + "frontend/utility/BasicOutputHandler.hpp", + "frontend/utility/CrashHandler.hpp", + "frontend/build/frontend.utility-crash-sentinel-dir+.hpp.cpp", + "frontend/utility/crash-sentinel-dir.hpp", + "frontend/utility/settings-migration.hpp", + "frontend/utility/unclean-launch.hpp", + "frontend/utility/output-start-log.hpp", + "frontend/utility/FFmpegCodec.hpp", + "frontend/utility/FFmpegFormat.hpp", + "frontend/utility/FFmpegShared.hpp", + "frontend/utility/frontend-api-call.hpp", + "frontend/build/frontend.utility-filter-clipboard+.h.c", + "frontend/utility/filter-clipboard.h", + "frontend/utility/GoLiveAPI_CensoredJson.hpp", + "frontend/utility/GoLiveAPI_Network.hpp", + "frontend/utility/GoLiveAPI_PostData.hpp", + "frontend/build/frontend.utility-media-time+.h.c", + "frontend/utility/media-time.h", + "frontend/build/frontend.utility-missing-files-list+.h.c", + "frontend/utility/missing-files-list.h", + "frontend/utility/MissingFilesModel.hpp", + "frontend/utility/MissingFilesPathItemDelegate.hpp", + "frontend/utility/MultitrackVideoError.hpp", + "frontend/build/frontend.utility-2+.hpp.cpp", + "frontend/utility/MultitrackVideoOutput.hpp", + "frontend/build/frontend.utility-multitrack-encoder-override+.h.c", + "frontend/utility/multitrack-encoder-override.h", + "frontend/utility/NativeEventFilter.hpp", + "frontend/build/frontend.utility-output-filename-format+.h.c", + "frontend/utility/output-filename-format.h", + "frontend/build/frontend.utility-replay-buffer-estimate+.hpp.cpp", + "frontend/utility/replay-buffer-estimate.hpp", + "frontend/build/frontend.utility-replay-buffer-naming+.h.c", + "frontend/utility/replay-buffer-naming.h", + "frontend/build/frontend.utility-output-filename-reserve+.h.c", + "frontend/utility/output-filename-reserve.h", + "frontend/build/frontend.utility-output-rescale+.h.c", + "frontend/utility/output-rescale.h", + "frontend/build/frontend.utility-menu-text+.h.c", + "frontend/utility/menu-text.h", + "frontend/build/frontend.utility-multitrack-ladder+.h.c", + "frontend/utility/multitrack-ladder.h", + "frontend/build/frontend.utility-product-name+.h.c", + "frontend/build/frontend.utility-record-disk-space+.h.c", + "frontend/utility/record-disk-space.h", + "frontend/utility/product-name.h", + "frontend/build/frontend.utility-profile-activate+.h.c", + "frontend/utility/profile-activate.h", + "frontend/build/frontend.utility-profile-remove+.h.c", + "frontend/utility/profile-remove.h", + "frontend/build/frontend.utility-preview-audio-sources+.hpp.cpp", + "frontend/utility/preview-audio-sources.hpp", + "frontend/build/frontend.utility-saved-transition+.h.c", + "frontend/utility/saved-transition.h", + "frontend/build/frontend.utility-scene-collection-migration+.hpp.cpp", + "frontend/utility/scene-collection-migration.hpp", + "frontend/build/frontend.utility-scene-list-remove+.h.c", + "frontend/utility/scene-list-remove.h", + "frontend/build/frontend.utility-service-encoder-settings+.h.c", + "frontend/utility/service-encoder-settings.h", + "frontend/build/frontend.utility-source-select-list+.hpp.cpp", + "frontend/utility/source-select-list.hpp", + "frontend/build/frontend.utility-stream-service-select+.h.c", + "frontend/utility/stream-service-select.h", + "frontend/build/frontend.utility-studio-mode-exit+.h.c", + "frontend/utility/studio-mode-exit.h", + "frontend/build/frontend.utility-studio-mode-swap+.h.c", + "frontend/utility/studio-mode-swap.h", + "frontend/build/frontend.utility-tbar-position+.h.c", + "frontend/utility/tbar-position.h", + "frontend/build/frontend.utility-transform-clipboard+.h.c", + "frontend/utility/transform-clipboard.h", + "frontend/build/frontend.utility-visibility-transition+.h.c", + "frontend/utility/visibility-transition.h", + "frontend/utility/OBSCanvas.hpp", + "frontend/utility/OBSEventFilter.hpp", + "frontend/utility/OBSProxyStyle.hpp", + "frontend/utility/OBSTheme.hpp", + "frontend/utility/OBSThemeVariable.hpp", + "frontend/utility/OBSTranslator.hpp", + "frontend/utility/PreviewProgramSizeObserver.hpp", + "frontend/utility/QuickTransition.hpp", + "frontend/utility/RemoteTextThread.hpp", + "frontend/utility/RemuxEntryPathItemDelegate.hpp", + "frontend/utility/RemuxQueueModel.hpp", + "frontend/utility/RemuxWorker.hpp", + "frontend/utility/ResizeSignaler.hpp", + "frontend/build/frontend.utility-3+.hpp.cpp", + "frontend/utility/SceneRenameDelegate.hpp", + "frontend/build/frontend.utility-screenshotobj+.hpp.cpp", + "frontend/utility/ScreenshotObj.hpp", + "frontend/utility/SettingsEventFilter.hpp", + "frontend/utility/SimpleOutput.hpp", + "frontend/utility/StartMultiTrackVideoStreamingGuard.hpp", + "frontend/utility/SurfaceEventFilter.hpp", + "frontend/utility/ThumbnailItem.hpp", + "frontend/utility/ThumbnailManager.hpp", + "frontend/utility/ThumbnailView.hpp", + "frontend/utility/VCamConfig.hpp", + "frontend/utility/audio-encoders.hpp", + "frontend/utility/display-helpers.hpp", + "frontend/utility/item-widget-helpers.hpp", + "frontend/utility/models/multitrack-video.hpp", + "frontend/build/frontend.utility-c+.h.c", + "frontend/utility/obf.h", + "frontend/utility/platform.hpp", + "frontend/build/frontend.utility-screenshot-render+.hpp.cpp", + "frontend/utility/screenshot-render.hpp", + "frontend/utility/system-info.hpp", + "frontend/utility/undo_stack.hpp", + "frontend/build/frontend.widgets+.hpp.cpp", + "frontend/widgets/AudioMixer.hpp", + "frontend/widgets/ColorSelect.hpp", + "frontend/widgets/OBSBasic.hpp", + "frontend/build/frontend.widgets-2+.hpp.cpp", + "frontend/build/frontend.widgets-3+.hpp.cpp", + "frontend/build/frontend.widgets-4+.hpp.cpp", + "frontend/widgets/OBSBasicControls.hpp", + "frontend/widgets/OBSBasicPreview.hpp", + "frontend/widgets/OBSBasicStats.hpp", + "frontend/widgets/OBSBasicStatusBar.hpp", + "frontend/widgets/OBSMainWindow.hpp", + "frontend/widgets/OBSProjector.hpp", + "frontend/build/frontend.widgets-obsqtdisplay+.hpp.cpp", + "frontend/widgets/OBSQTDisplay.hpp", + "frontend/widgets/StatusBarWidget.hpp", + "frontend/build/frontend.wizards+.hpp.cpp", + "frontend/wizards/AutoConfig.hpp", + "frontend/wizards/AutoConfigStartPage.hpp", + "frontend/wizards/AutoConfigStreamPage.hpp", + "frontend/wizards/AutoConfigTestPage.hpp", + "frontend/wizards/AutoConfigVideoPage.hpp", + "frontend/wizards/TestMode.hpp", + "frontend/build/frontend.importers+.hpp.cpp", + "frontend/importer/ImporterEntryPathItemDelegate.hpp", + "frontend/importer/ImporterModel.hpp", + "frontend/importer/OBSImporter.hpp", + "frontend/importers/importers.hpp", + "frontend/utility/obs-gpu-status.h", + "frontend/build/frontend.gpu-status+.hpp.cpp", + "frontend/utility/GpuStatus.hpp", + "frontend/build/frontend.plugin-manager-installedpluginrow+.hpp.cpp", + "frontend/plugin-manager/InstalledPluginRow.hpp", + "frontend/build/frontend.plugin-manager-pluginmanager+.hpp.cpp", + "frontend/plugin-manager/PluginManager.hpp", + "frontend/build/frontend.plugin-manager-pluginmanagerwindow+.hpp.cpp", + "frontend/plugin-manager/PluginManagerWindow.hpp", + "frontend/plugin-manager/PluginModuleLoader.hpp", + "frontend/forms/OBSBasicTransform.ui", + "frontend/forms/OBSLogViewer.ui" + ], + "linux": [ + "frontend/build/frontend.linux+.hpp.cpp", + "frontend/build/frontend.native-event-filter+.hpp.cpp", + "frontend/build/frontend.x11+.hpp.cpp", + "frontend/build/frontend.plugin-manager-linux+.hpp.cpp" + ], + "interfaces": { + "shared/qt/wrappers": [ + "shared/qt/wrappers/build/qt-wrappers.core+.hpp.cpp", + "shared/qt/wrappers/qt-wrappers.hpp" + ], + "shared/qt/plain-text-edit": [ + "shared/qt/plain-text-edit/build/qt-plain-text-edit.core+.hpp.cpp", + "shared/qt/plain-text-edit/plain-text-edit.hpp" + ], + "shared/qt/vertical-scroll-area": [ + "shared/qt/vertical-scroll-area/build/qt-vertical-scroll-area.core+.hpp.cpp", + "shared/qt/vertical-scroll-area/vertical-scroll-area.hpp" + ], + "shared/qt/slider-ignorewheel": [ + "shared/qt/slider-ignorewheel/build/qt-slider-ignorewheel.core+.hpp.cpp", + "shared/qt/slider-ignorewheel/slider-ignorewheel.hpp" + ], + "shared/qt/icon-label": [ + "shared/qt/icon-label/build/qt-icon-label.core+.hpp.cpp", + "shared/qt/icon-label/IconLabel.hpp" + ], + "shared/qt/idian": [ + "shared/qt/idian/build/idian.core+.hpp.cpp", + "shared/qt/idian/include/Idian/CheckBox.hpp", + "shared/qt/idian/include/Idian/CollapsibleGroup.hpp", + "shared/qt/idian/include/Idian/ComboBox.hpp", + "shared/qt/idian/include/Idian/ExpandButton.hpp", + "shared/qt/idian/include/Idian/Idian.hpp", + "shared/qt/idian/include/Idian/InlineButton.hpp", + "shared/qt/idian/include/Idian/ListHeader.hpp", + "shared/qt/idian/include/Idian/Row.hpp", + "shared/qt/idian/include/Idian/RowDoubleSpinBox.hpp", + "shared/qt/idian/include/Idian/RowInfo.hpp", + "shared/qt/idian/include/Idian/RowList.hpp", + "shared/qt/idian/include/Idian/RowSpinBox.hpp", + "shared/qt/idian/include/Idian/StateEventFilter.hpp", + "shared/qt/idian/include/Idian/ToggleSwitch.hpp", + "shared/qt/idian/include/Idian/Utils.hpp" + ], + "shared/properties-view": [ + "shared/properties-view/build/properties-view.core+.hpp.cpp", + "shared/properties-view/double-slider.hpp", + "shared/properties-view/properties-view.hpp", + "shared/properties-view/properties-view.moc.hpp", + "shared/properties-view/spinbox-ignorewheel.hpp" + ] + } +} diff --git a/libobs/build/source-sets.json b/libobs/build/source-sets.json new file mode 100644 index 0000000000..ecaf25a03b --- /dev/null +++ b/libobs/build/source-sets.json @@ -0,0 +1,170 @@ +{ + "LIBOBS_SOURCES": [ + "obs-audio-controls.h", + "obs-av1.h", + "obs-avc.h", + "obs-config.h", + "obs-core-modules-loader.h", + "obs-data.h", + "obs-defs.h", + "obs-encoder.h", + "obs-ffmpeg-compat.h", + "obs-hotkey.h", + "obs-hotkeys.h", + "obs-host/com.h", + "obs-host/default-monitoring-device.h", + "obs-host/defs.h", + "obs-host/display-clear-workaround.h", + "obs-host/display-srgb-clear.h", + "obs-host/graphics-thread.h", + "obs-host/graphics-thread-hooks.h", + "obs-host/module-paths.h", + "obs-host/module-symbols.h", + "obs-host/shared-texture.h", + "obs-interaction.h", + "obs-internal.h", + "obs-missing-files.h", + "obs-module.h", + "obs-nal.h", + "obs-output.h", + "obs-properties.h", + "obs-scene-bounds.h", + "obs-scene.h", + "obs-service.h", + "obs-source.h", + "obs.h", + "obs.hpp", + "util/array-serializer.h", + "util/base.h", + "util/bitstream.h", + "util/bmem.h", + "util/buffered-file-serializer.h", + "util/c99defs.h", + "util/cf-lexer.h", + "util/cf-parser.h", + "util/config-file.h", + "util/crc32.h", + "util/curl/curl-helper.h", + "util/darray.h", + "util/deque.h", + "util/dstr.h", + "util/file-serializer.h", + "util/lexer.h", + "util/pipe.h", + "util/platform.h", + "util/profiler-snapshot.h", + "util/profiler.h", + "util/profiler.hpp", + "util/serializer.h", + "util/source-profiler.h", + "util/sse-intrin.h", + "util/task.h", + "util/text-lookup.h", + "util/threading.h", + "util/utf8.h", + "util/uthash.h", + "util/util.hpp", + "util/util_uint128.h", + "util/util_uint64.h", + "callback/calldata.h", + "callback/decl.h", + "callback/proc.h", + "callback/signal.h", + "media-io/audio-io.h", + "media-io/audio-math.h", + "media-io/audio-resampler.h", + "media-io/format-conversion.h", + "media-io/frame-rate.h", + "media-io/media-io-defs.h", + "media-io/media-remux.h", + "media-io/video-frame.h", + "media-io/video-io.h", + "media-io/video-scaler.h", + "graphics/axisang.h", + "graphics/bounds.h", + "graphics/device-exports.h", + "graphics/effect-parser.h", + "graphics/effect.h", + "graphics/graphics-internal.h", + "graphics/graphics.h", + "graphics/half.h", + "graphics/image-file.h", + "graphics/input.h", + "graphics/libnsgif/lzw.h", + "graphics/libnsgif/nsgif.h", + "graphics/math-defs.h", + "graphics/math-extra.h", + "graphics/matrix3.h", + "graphics/matrix4.h", + "graphics/plane.h", + "graphics/quat.h", + "graphics/shader-parser.h", + "graphics/srgb.h", + "graphics/vec2.h", + "graphics/vec3.h", + "graphics/vec4.h", + "build/libobs.core+.h.c", + "build/libobs.core-output+.h.c", + "build/libobs.core-source+.h.c", + "build/libobs.util+.h.c", + "build/libobs.util-libc+.h.c", + "build/libobs.graphics+.h.c", + "build/libobs.media+.h.c", + "build/libobs.nsgif+.h.c", + "build/libobs.platform+.h.c" + ], + "LIBOBS_PORTED_SOURCES": [ + "build/libobs.ported-util+.h.c", + "build/libobs.ported-util-io+.h.c", + "build/libobs.ported-media+.h.c", + "build/libobs.ported-data+.h.c", + "build/libobs.ported-graphics+.h.c" + ], + "LIBOBS_RUST_SOURCES": [ + "build/libobs.rust-variadic+.h.c" + ], + "LIBOBS_WINDOWS_SOURCES": [ + "audio-monitoring/win32/wasapi-output.h", + "util/threading-windows.h", + "util/windows/CoTaskMemPtr.hpp", + "util/windows/device-enum.h", + "util/windows/HRError.hpp", + "util/windows/win-registry.h", + "util/windows/win-version.h", + "util/windows/window-helpers.h", + "build/libobs.windows+.h.c", + "build/libobs.windows-crash-handler+.h.c" + ], + "LIBOBS_WINDOWS_PORTED_SOURCES": [ + "build/libobs.ported-windows+.h.c", + "build/libobs.ported-windows-pipe+.h.c", + "build/libobs.ported-windows-platform+.h.c" + ], + "LIBOBS_MACOS_SOURCES": [ + "audio-monitoring/osx/mac-helpers.h", + "util/apple/cfstring-utils.h", + "util/threading-posix.h", + "build/libobs.macos+.h.c", + "build/libobs.macos-cocoa+.h.m", + "build/libobs.macos-loader+.h.m" + ], + "LIBOBS_MACOS_PORTED_SOURCES": [ + "build/libobs.ported-posix+.h.c", + "build/libobs.ported-posix-threading+.h.c", + "build/libobs.ported-macos-cocoa+.h.m" + ], + "LIBOBS_LINUX_SOURCES": [ + "obs-nix-platform.h", + "obs-nix-x11-keymap.h", + "util/threading-posix.h", + "build/libobs.nix+.h.c", + "build/libobs.nix-main+.h.c" + ], + "LIBOBS_LINUX_PORTED_SOURCES": [ + "build/libobs.ported-posix+.h.c", + "build/libobs.ported-posix-threading+.h.c" + ], + "LIBOBS_HEVC_PORTED_SOURCES": [ + "build/libobs.ported-hevc+.h.c" + ] +} diff --git a/libobs/cmake/sources.cmake b/libobs/cmake/sources.cmake index c1ac28b1a9..3c24ab9290 100644 --- a/libobs/cmake/sources.cmake +++ b/libobs/cmake/sources.cmake @@ -17,186 +17,30 @@ # is WINDOWS, MACOS or LINUX; LINUX also covers FreeBSD and OpenBSD, # which build obs-nix.c the same way. -set( - LIBOBS_SOURCES - obs-audio-controls.h - obs-av1.h - obs-avc.h - obs-config.h - obs-core-modules-loader.h - obs-data.h - obs-defs.h - obs-encoder.h - obs-ffmpeg-compat.h - obs-hotkey.h - obs-hotkeys.h - obs-host/com.h - obs-host/default-monitoring-device.h - obs-host/defs.h - obs-host/display-clear-workaround.h - obs-host/display-srgb-clear.h - obs-host/graphics-thread.h - obs-host/graphics-thread-hooks.h - obs-host/module-paths.h - obs-host/module-symbols.h - obs-host/shared-texture.h - obs-interaction.h - obs-internal.h - obs-missing-files.h - obs-module.h - obs-nal.h - obs-output.h - obs-properties.h - obs-scene-bounds.h - obs-scene.h - obs-service.h - obs-source.h - obs.h - obs.hpp - util/array-serializer.h - util/base.h - util/bitstream.h - util/bmem.h - util/buffered-file-serializer.h - util/c99defs.h - util/cf-lexer.h - util/cf-parser.h - util/config-file.h - util/crc32.h - util/curl/curl-helper.h - util/darray.h - util/deque.h - util/dstr.h - util/file-serializer.h - util/lexer.h - util/pipe.h - util/platform.h - util/profiler-snapshot.h - util/profiler.h - util/profiler.hpp - util/serializer.h - util/source-profiler.h - util/sse-intrin.h - util/task.h - util/text-lookup.h - util/threading.h - util/utf8.h - util/uthash.h - util/util.hpp - util/util_uint128.h - util/util_uint64.h - callback/calldata.h - callback/decl.h - callback/proc.h - callback/signal.h - media-io/audio-io.h - media-io/audio-math.h - media-io/audio-resampler.h - media-io/format-conversion.h - media-io/frame-rate.h - media-io/media-io-defs.h - media-io/media-remux.h - media-io/video-frame.h - media-io/video-io.h - media-io/video-scaler.h - graphics/axisang.h - graphics/bounds.h - graphics/device-exports.h - graphics/effect-parser.h - graphics/effect.h - graphics/graphics-internal.h - graphics/graphics.h - graphics/half.h - graphics/image-file.h - graphics/input.h - graphics/libnsgif/lzw.h - graphics/libnsgif/nsgif.h - graphics/math-defs.h - graphics/math-extra.h - graphics/matrix3.h - graphics/matrix4.h - graphics/plane.h - graphics/quat.h - graphics/shader-parser.h - graphics/srgb.h - graphics/vec2.h - graphics/vec3.h - graphics/vec4.h - build/libobs.core+.h.c - build/libobs.core-output+.h.c - build/libobs.core-source+.h.c - build/libobs.util+.h.c - build/libobs.util-libc+.h.c - build/libobs.graphics+.h.c - build/libobs.media+.h.c - build/libobs.nsgif+.h.c - build/libobs.platform+.h.c -) - -set( - LIBOBS_PORTED_SOURCES - build/libobs.ported-util+.h.c - build/libobs.ported-util-io+.h.c - build/libobs.ported-media+.h.c - build/libobs.ported-data+.h.c - build/libobs.ported-graphics+.h.c -) - -set(LIBOBS_RUST_SOURCES build/libobs.rust-variadic+.h.c) +# Canonical source lists are shared with obs-build and bundled obs-sys. +set(_libobs_source_manifest "${CMAKE_CURRENT_LIST_DIR}/../build/source-sets.json") +set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS "${_libobs_source_manifest}") +file(READ "${_libobs_source_manifest}" _libobs_source_sets) +string(JSON _set_count LENGTH "${_libobs_source_sets}") +math(EXPR _set_last "${_set_count} - 1") +foreach(_set_index RANGE ${_set_last}) + string(JSON _name MEMBER "${_libobs_source_sets}" ${_set_index}) + string(JSON _source_count LENGTH "${_libobs_source_sets}" "${_name}") + set(${_name} "") + if(_source_count GREATER 0) + math(EXPR _source_last "${_source_count} - 1") + foreach(_source_index RANGE ${_source_last}) + string(JSON _source GET "${_libobs_source_sets}" "${_name}" ${_source_index}) + list(APPEND ${_name} "${_source}") + endforeach() + endif() +endforeach() if(ENABLE_HEVC) list(APPEND LIBOBS_SOURCES obs-hevc.h) - list(APPEND LIBOBS_PORTED_SOURCES build/libobs.ported-hevc+.h.c) + list(APPEND LIBOBS_PORTED_SOURCES ${LIBOBS_HEVC_PORTED_SOURCES}) endif() -set( - LIBOBS_WINDOWS_SOURCES - audio-monitoring/win32/wasapi-output.h - util/threading-windows.h - util/windows/CoTaskMemPtr.hpp - util/windows/device-enum.h - util/windows/HRError.hpp - util/windows/win-registry.h - util/windows/win-version.h - util/windows/window-helpers.h - build/libobs.windows+.h.c - build/libobs.windows-crash-handler+.h.c -) -set( - LIBOBS_WINDOWS_PORTED_SOURCES - build/libobs.ported-windows+.h.c - build/libobs.ported-windows-pipe+.h.c - build/libobs.ported-windows-platform+.h.c -) - -set( - LIBOBS_MACOS_SOURCES - audio-monitoring/osx/mac-helpers.h - util/apple/cfstring-utils.h - util/threading-posix.h - build/libobs.macos+.h.c - build/libobs.macos-cocoa+.h.m - build/libobs.macos-loader+.h.m -) -set( - LIBOBS_MACOS_PORTED_SOURCES - build/libobs.ported-posix+.h.c - build/libobs.ported-posix-threading+.h.c - build/libobs.ported-macos-cocoa+.h.m -) - -# Linux and the BSDs. Optional parts (PulseAudio, GIO, Wayland) stay in -# cmake/os-linux.cmake and cmake/os-freebsd.cmake, next to their find_package. -set( - LIBOBS_LINUX_SOURCES - obs-nix-platform.h - obs-nix-x11-keymap.h - util/threading-posix.h - build/libobs.nix+.h.c - build/libobs.nix-main+.h.c -) -set(LIBOBS_LINUX_PORTED_SOURCES build/libobs.ported-posix+.h.c build/libobs.ported-posix-threading+.h.c) - # Adds a host's lists (libobs/CMakeLists.txt): its sources to the # objects both libobs binaries share, its ported C to libobs only # (libobs-with-rust gets the staticlib instead). diff --git a/libobs/obs-audio.c.h b/libobs/obs-audio.c.h index e5e70b1b86..b0a6c92dea 100644 --- a/libobs/obs-audio.c.h +++ b/libobs/obs-audio.c.h @@ -359,7 +359,8 @@ static void set_fixed_audio_buffering(struct obs_core_audio *audio, size_t sampl static void add_audio_buffering(struct obs_core_audio *audio, size_t sample_rate, struct ts_info *ts, uint64_t min_ts, const char *buffering_name) { - struct ts_info new_ts; + /* A sub-sample offset adds no ticks, so the loop may leave end untouched. */ + struct ts_info new_ts = *ts; uint64_t offset; uint64_t frames; size_t total_ms; diff --git a/plugins/obs-browser b/plugins/obs-browser index 1e313ae2f0..0c3b7000d4 160000 --- a/plugins/obs-browser +++ b/plugins/obs-browser @@ -1 +1 @@ -Subproject commit 1e313ae2f08596dc77157e4c9a604b7510da0a61 +Subproject commit 0c3b7000d40e89c19734f9f7f3288015f6134082 diff --git a/plugins/obs-ffmpeg/obs-ffmpeg-vaapi.c.h b/plugins/obs-ffmpeg/obs-ffmpeg-vaapi.c.h index 9a5dff40ae..0cbd66e853 100644 --- a/plugins/obs-ffmpeg/obs-ffmpeg-vaapi.c.h +++ b/plugins/obs-ffmpeg/obs-ffmpeg-vaapi.c.h @@ -1023,8 +1023,10 @@ static bool vaapi_device_codec_supported(const char *path, enum codec_type codec switch (codec) { case CODEC_H264: return vaapi_device_h264_supported(path); +#ifdef ENABLE_HEVC case CODEC_HEVC: return vaapi_device_hevc_supported(path); +#endif case CODEC_AV1: return vaapi_device_av1_supported(path); default: diff --git a/plugins/obs-filters/build/rnnoise-sources.json b/plugins/obs-filters/build/rnnoise-sources.json new file mode 100644 index 0000000000..acef349075 --- /dev/null +++ b/plugins/obs-filters/build/rnnoise-sources.json @@ -0,0 +1,9 @@ +[ + "rnnoise/src/celt_lpc.c", + "rnnoise/src/denoise.c", + "rnnoise/src/kiss_fft.c", + "rnnoise/src/pitch.c", + "rnnoise/src/rnn.c", + "rnnoise/src/rnn_data.c", + "rnnoise/src/rnn_reader.c" +] diff --git a/plugins/obs-filters/cmake/rnnoise.cmake b/plugins/obs-filters/cmake/rnnoise.cmake index baf76d32ef..95c4ee4e0c 100644 --- a/plugins/obs-filters/cmake/rnnoise.cmake +++ b/plugins/obs-filters/cmake/rnnoise.cmake @@ -10,25 +10,31 @@ if(ENABLE_RNNOISE) message(WARNING "No RNNoise library found. Using internal RNNoise version instead.") add_library(obs-rnnoise OBJECT) + # Canonical native source list shared with the Cargo build. + set(_obs_rnnoise_manifest "${CMAKE_CURRENT_SOURCE_DIR}/build/rnnoise-sources.json") + set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS "${_obs_rnnoise_manifest}") + file(READ "${_obs_rnnoise_manifest}" _obs_rnnoise_json) + string(JSON _obs_rnnoise_count LENGTH "${_obs_rnnoise_json}") + math(EXPR _obs_rnnoise_last "${_obs_rnnoise_count} - 1") + set(_obs_rnnoise_sources "") + foreach(_index RANGE ${_obs_rnnoise_last}) + string(JSON _source GET "${_obs_rnnoise_json}" ${_index}) + list(APPEND _obs_rnnoise_sources "${_source}") + endforeach() + target_sources( obs-rnnoise PRIVATE + ${_obs_rnnoise_sources} rnnoise/src/_kiss_fft_guts.h rnnoise/src/arch.h - rnnoise/src/celt_lpc.c rnnoise/src/celt_lpc.h rnnoise/src/common.h - rnnoise/src/denoise.c - rnnoise/src/kiss_fft.c rnnoise/src/kiss_fft.h rnnoise/src/opus_types.h - rnnoise/src/pitch.c rnnoise/src/pitch.h - rnnoise/src/rnn.c rnnoise/src/rnn.h - rnnoise/src/rnn_data.c rnnoise/src/rnn_data.h - rnnoise/src/rnn_reader.c rnnoise/src/tansig_table.h PUBLIC rnnoise/include/rnnoise.h ) diff --git a/plugins/obs-outputs/mp4-mux.c.h b/plugins/obs-outputs/mp4-mux.c.h index 1a938c9c58..47f8de2ffa 100644 --- a/plugins/obs-outputs/mp4-mux.c.h +++ b/plugins/obs-outputs/mp4-mux.c.h @@ -453,6 +453,7 @@ static size_t mp4_write_avcC(struct mp4_mux *mux, obs_encoder_t *enc) return box_size; } +#ifdef ENABLE_HEVC /// ISO/IEC 14496-15 8.4.1.1 HEVCConfigurationBox static size_t mp4_write_hvcC(struct mp4_mux *mux, obs_encoder_t *enc) { @@ -477,6 +478,8 @@ static size_t mp4_write_hvcC(struct mp4_mux *mux, obs_encoder_t *enc) return box_size; } +#endif + /// AV1 ISOBMFF 2.3. AV1 Codec Configuration Box static size_t mp4_write_av1C(struct mp4_mux *mux, obs_encoder_t *enc) { @@ -672,6 +675,7 @@ static size_t mp4_write_avc1(struct mp4_mux *mux, obs_encoder_t *enc) return write_box_size(s, start); } +#ifdef ENABLE_HEVC /// ISO/IEC 14496-15 8.4.1.1 HEVCSampleEntry static size_t mp4_write_hvc1(struct mp4_mux *mux, obs_encoder_t *enc) { @@ -700,6 +704,8 @@ static size_t mp4_write_hvc1(struct mp4_mux *mux, obs_encoder_t *enc) return write_box_size(s, start); } +#endif + /// AV1 ISOBMFF 2.2. AV1 Sample Entry static size_t mp4_write_av01(struct mp4_mux *mux, obs_encoder_t *enc) { @@ -1296,8 +1302,10 @@ static size_t mp4_write_stsd(struct mp4_mux *mux, struct mp4_track *track) if (track->type == TRACK_VIDEO) { if (track->codec == MP4_CODEC_H264) mp4_write_avc1(mux, track->encoder); +#ifdef ENABLE_HEVC else if (track->codec == MP4_CODEC_HEVC) mp4_write_hvc1(mux, track->encoder); +#endif else if (track->codec == MP4_CODEC_AV1) mp4_write_av01(mux, track->encoder); else if (track->codec == MP4_CODEC_PRORES) @@ -2750,8 +2758,10 @@ static inline enum mp4_codec get_codec(obs_encoder_t *enc) if (strcmp(codec, "h264") == 0) return MP4_CODEC_H264; +#ifdef ENABLE_HEVC if (strcmp(codec, "hevc") == 0) return MP4_CODEC_HEVC; +#endif if (strcmp(codec, "av1") == 0) return MP4_CODEC_AV1; if (strcmp(codec, "prores") == 0) @@ -2928,8 +2938,10 @@ bool mp4_mux_submit_packet(struct mp4_mux *mux, struct encoder_packet *pkt) } else { if (track->codec == MP4_CODEC_H264) obs_parse_avc_packet(&parsed_packet, pkt); +#ifdef ENABLE_HEVC else if (track->codec == MP4_CODEC_HEVC) obs_parse_hevc_packet(&parsed_packet, pkt); +#endif else if (track->codec == MP4_CODEC_AV1) obs_parse_av1_packet(&parsed_packet, pkt); else if (track->codec == MP4_CODEC_PRORES) diff --git a/plugins/obs-outputs/mp4-output.c.h b/plugins/obs-outputs/mp4-output.c.h index 48aa17a915..1f5fb06e77 100644 --- a/plugins/obs-outputs/mp4-output.c.h +++ b/plugins/obs-outputs/mp4-output.c.h @@ -596,7 +596,11 @@ uint64_t mp4_output_total_bytes(void *data) struct obs_output_info mp4_output_info = { .id = "mp4_output", .flags = OBS_OUTPUT_AV | OBS_OUTPUT_ENCODED | OBS_OUTPUT_MULTI_TRACK_AV | OBS_OUTPUT_CAN_PAUSE, +#ifdef ENABLE_HEVC .encoded_video_codecs = "h264;hevc;av1", +#else + .encoded_video_codecs = "h264;av1", +#endif .encoded_audio_codecs = "aac;alac;flac;opus", .get_name = mp4_output_name, .create = mp4_output_create, @@ -611,7 +615,11 @@ struct obs_output_info mp4_output_info = { struct obs_output_info mov_output_info = { .id = "mov_output", .flags = OBS_OUTPUT_AV | OBS_OUTPUT_ENCODED | OBS_OUTPUT_MULTI_TRACK_AV | OBS_OUTPUT_CAN_PAUSE, +#ifdef ENABLE_HEVC .encoded_video_codecs = "h264;hevc;prores", +#else + .encoded_video_codecs = "h264;prores", +#endif .encoded_audio_codecs = "aac;alac", .get_name = mov_output_name, .create = mov_output_create, diff --git a/rust/obs-build/Cargo.toml b/rust/obs-build/Cargo.toml new file mode 100644 index 0000000000..ec0dac525d --- /dev/null +++ b/rust/obs-build/Cargo.toml @@ -0,0 +1,25 @@ +[package] +name = "obs-build" +version = "0.1.0" +description = "Cargo-driven native OBS build graph and cc::Build execution" +edition.workspace = true +rust-version.workspace = true +license.workspace = true +publish.workspace = true + +[features] +libobs-integration = [] + +[dependencies] +dunce = "=1.0.5" +cc = { version = "=1.6.0", features = ["parallel"] } +pkg-config = "=0.3.34" +serde_json = "=1.0.151" + +[dev-dependencies] +libloading.workspace = true +tempfile = "=3.27.0" + +[[test]] +name = "libobs" +required-features = ["libobs-integration"] diff --git a/rust/obs-build/build.rs b/rust/obs-build/build.rs new file mode 100644 index 0000000000..fb8d6e97a1 --- /dev/null +++ b/rust/obs-build/build.rs @@ -0,0 +1,10 @@ +fn main() { + println!( + "cargo:rustc-env=OBS_BUILD_HOST={}", + std::env::var("HOST").unwrap() + ); + println!( + "cargo:rustc-env=OBS_BUILD_TARGET={}", + std::env::var("TARGET").unwrap() + ); +} diff --git a/rust/obs-build/manifests/c-tests-linux.json b/rust/obs-build/manifests/c-tests-linux.json new file mode 100644 index 0000000000..e51805e408 --- /dev/null +++ b/rust/obs-build/manifests/c-tests-linux.json @@ -0,0 +1,472 @@ +[ + { + "name": "test_serializer", + "sources": [ + "test/cmocka/test_serializer.c" + ] + }, + { + "name": "test_darray", + "sources": [ + "test/cmocka/test_darray.c" + ] + }, + { + "name": "test_bitstream", + "sources": [ + "test/cmocka/test_bitstream.c" + ] + }, + { + "name": "test_os_path", + "sources": [ + "test/cmocka/test_os_path.c" + ] + }, + { + "name": "test_hotkey_load", + "sources": [ + "test/cmocka/test_hotkey_load.c", + "libobs/obs-hotkey.c.h" + ], + "definitions": [ + "obs=hotkey_test_obs" + ], + "archives": [ + "caption" + ] + }, + { + "name": "test_config_save", + "sources": [ + "test/cmocka/test_config_save.c" + ] + }, + { + "name": "test_file_serializer_safe", + "sources": [ + "test/cmocka/test_file_serializer_safe.c" + ] + }, + { + "name": "test_quick_write", + "sources": [ + "test/cmocka/test_quick_write.c" + ] + }, + { + "name": "test_av1", + "sources": [ + "test/cmocka/test_av1.c" + ] + }, + { + "name": "test_nal", + "sources": [ + "test/cmocka/test_nal.c" + ] + }, + { + "name": "test_avc", + "sources": [ + "test/cmocka/test_avc.c", + "libobs/obs-avc.c.h" + ], + "sanitizers": "undefined" + }, + { + "name": "test_avc_parse", + "sources": [ + "test/cmocka/test_avc_parse.c" + ] + }, + { + "name": "test_hevc", + "sources": [ + "test/cmocka/test_hevc.c" + ] + }, + { + "name": "test_formatted_filename", + "sources": [ + "test/cmocka/test_formatted_filename.c", + "libobs/util/platform.c.h", + "libobs/util/utf8.c.h" + ], + "sanitizers": "address,undefined" + }, + { + "name": "test_crc32", + "sources": [ + "test/cmocka/test_crc32.c" + ] + }, + { + "name": "test_utf8", + "sources": [ + "test/cmocka/test_utf8.c", + "libobs/util/utf8.c.h" + ], + "sanitizers": "address,undefined" + }, + { + "name": "test_dstr", + "sources": [ + "test/cmocka/test_dstr.c" + ] + }, + { + "name": "test_dstr_regressions", + "sources": [ + "test/cmocka/test_dstr_regressions.c" + ] + }, + { + "name": "test_lexer", + "sources": [ + "test/cmocka/test_lexer.c" + ] + }, + { + "name": "test_cf_lexer", + "sources": [ + "test/cmocka/test_cf_lexer.c" + ] + }, + { + "name": "test_text_lookup", + "sources": [ + "test/cmocka/test_text_lookup.c" + ] + }, + { + "name": "test_base", + "sources": [ + "test/cmocka/test_base.c" + ] + }, + { + "name": "test_bmem", + "sources": [ + "test/cmocka/test_bmem.c" + ] + }, + { + "name": "test_file_serializer", + "sources": [ + "test/cmocka/test_file_serializer.c" + ] + }, + { + "name": "test_config_file", + "sources": [ + "test/cmocka/test_config_file.c" + ] + }, + { + "name": "test_threading", + "sources": [ + "test/cmocka/test_threading.c" + ] + }, + { + "name": "test_video_stats_race", + "sources": [ + "test/cmocka/test_video_stats_race.c" + ] + }, + { + "name": "test_task", + "sources": [ + "test/cmocka/test_task.c" + ] + }, + { + "name": "test_pipe", + "sources": [ + "test/cmocka/test_pipe.c" + ] + }, + { + "name": "test_profiler", + "sources": [ + "test/cmocka/test_profiler.c" + ] + }, + { + "name": "test_platform", + "sources": [ + "test/cmocka/test_platform.c" + ] + }, + { + "name": "test_dtostr_exponent", + "sources": [ + "test/cmocka/test_dtostr_exponent.c" + ] + }, + { + "name": "test_quat", + "sources": [ + "test/cmocka/test_quat.c" + ] + }, + { + "name": "test_axisang", + "sources": [ + "test/cmocka/test_axisang.c" + ] + }, + { + "name": "test_vec2", + "sources": [ + "test/cmocka/test_vec2.c" + ] + }, + { + "name": "test_vec3", + "sources": [ + "test/cmocka/test_vec3.c" + ] + }, + { + "name": "test_vec4", + "sources": [ + "test/cmocka/test_vec4.c" + ] + }, + { + "name": "test_video_fourcc", + "sources": [ + "test/cmocka/test_video_fourcc.c" + ] + }, + { + "name": "test_video_matrices", + "sources": [ + "test/cmocka/test_video_matrices.c" + ] + }, + { + "name": "test_video_io_inlines", + "sources": [ + "test/cmocka/test_video_io_inlines.c" + ] + }, + { + "name": "test_util_uint64", + "sources": [ + "test/cmocka/test_util_uint64.c" + ] + }, + { + "name": "test_svt_av1", + "sources": [ + "test/cmocka/test_svt_av1.c", + "plugins/obs-ffmpeg/obs-ffmpeg-video-encoders.c.h", + "shared/opts-parser/opts-parser.c.h" + ], + "definitions": [ + "obs_encoder_video=svt_test_encoder_video", + "video_output_get_info=svt_test_video_info", + "obs_encoder_get_width=svt_test_encoder_size", + "obs_encoder_get_height=svt_test_encoder_size", + "obs_encoder_get_name=svt_test_encoder_name", + "obs_encoder_set_last_error=svt_test_set_last_error" + ], + "includes": [ + "shared/opts-parser" + ], + "packages": [ + "libavcodec", + "libavformat", + "libavutil" + ] + }, + { + "name": "test_rtmp_error", + "sources": [ + "test/cmocka/test_rtmp_error.c", + "plugins/obs-outputs/librtmp/rtmp.c", + "plugins/obs-outputs/librtmp/amf.c", + "plugins/obs-outputs/librtmp/log.c", + "plugins/obs-outputs/librtmp/parseurl.c", + "plugins/obs-outputs/librtmp/hashswf.c" + ], + "includes": [ + "plugins/obs-outputs", + "shared/happy-eyeballs", + "shared/happy-eyeballs/hosts/posix" + ], + "definitions": [ + "USE_MBEDTLS", + "CRYPTO" + ], + "packages": [ + "mbedtls", + "mbedx509", + "mbedcrypto", + "zlib" + ], + "archives": [ + "happy-eyeballs" + ] + }, + { + "name": "test_rtmp_chunk_size", + "sources": [ + "test/cmocka/test_rtmp_chunk_size.c", + "plugins/obs-outputs/librtmp/rtmp.c", + "plugins/obs-outputs/librtmp/amf.c", + "plugins/obs-outputs/librtmp/log.c", + "plugins/obs-outputs/librtmp/parseurl.c", + "plugins/obs-outputs/librtmp/hashswf.c" + ], + "includes": [ + "plugins/obs-outputs", + "shared/happy-eyeballs", + "shared/happy-eyeballs/hosts/posix" + ], + "definitions": [ + "USE_MBEDTLS", + "CRYPTO" + ], + "packages": [ + "mbedtls", + "mbedx509", + "mbedcrypto", + "zlib" + ], + "archives": [ + "happy-eyeballs" + ] + }, + { + "name": "test_amf_decode", + "sources": [ + "test/cmocka/test_amf_decode.c", + "plugins/obs-outputs/librtmp/rtmp.c", + "plugins/obs-outputs/librtmp/amf.c", + "plugins/obs-outputs/librtmp/log.c", + "plugins/obs-outputs/librtmp/parseurl.c", + "plugins/obs-outputs/librtmp/hashswf.c" + ], + "includes": [ + "plugins/obs-outputs", + "shared/happy-eyeballs", + "shared/happy-eyeballs/hosts/posix" + ], + "definitions": [ + "USE_MBEDTLS", + "CRYPTO" + ], + "packages": [ + "mbedtls", + "mbedx509", + "mbedcrypto", + "zlib" + ], + "archives": [ + "happy-eyeballs" + ], + "sanitizers": "undefined", + "compile_options": [ + "-fsigned-char" + ] + }, + { + "name": "test_flv_mux", + "sources": [ + "test/cmocka/test_flv_mux.c", + "plugins/obs-outputs/flv-mux.c.h", + "plugins/obs-outputs/librtmp/amf.c", + "plugins/obs-outputs/librtmp/log.c" + ], + "definitions": [ + "NO_CRYPTO" + ], + "includes": [ + "plugins/obs-outputs", + "shared/bpm", + "shared/opts-parser" + ] + }, + { + "name": "test_cube_lut", + "sources": [ + "test/cmocka/test_cube_lut.c", + "plugins/obs-filters/cube-lut.c.h" + ], + "includes": [ + "plugins/obs-filters" + ] + }, + { + "name": "test_pipewire_reconnect", + "sources": [ + "test/cmocka/test_pipewire_reconnect.c", + "plugins/linux-pipewire/reconnect-policy.c.h" + ], + "includes": [ + "plugins/linux-pipewire", + "deps/glad/include" + ], + "packages": [ + "libpipewire-0.3" + ], + "header_packages": [ + "libdrm", + "gio-unix-2.0" + ] + }, + { + "name": "test_pulse_reconnect", + "sources": [ + "test/cmocka/test_pulse_reconnect.c", + "plugins/linux-pulseaudio/pulse-reconnect.c.h" + ], + "includes": [ + "plugins/linux-pulseaudio" + ], + "packages": [ + "libpulse" + ] + }, + { + "name": "test_pulse_default_id", + "sources": [ + "test/cmocka/test_pulse_default_id.c", + "libobs/audio-monitoring/pulse/pulseaudio-wrapper.c.h" + ], + "includes": [ + "libobs/audio-monitoring/pulse" + ], + "header_packages": [ + "libpulse" + ] + }, + { + "name": "test_video_frame", + "sources": [ + "test/cmocka/test_video_frame.c" + ] + }, + { + "name": "test_audio_buffering_subsample", + "sources": [ + "test/cmocka/test_audio_buffering_subsample.c" + ], + "compile_options_if_supported": [ + "-ftrivial-auto-var-init=pattern" + ], + "link_options": [ + "-Wl,--gc-sections" + ], + "packages": [ + "zlib" + ], + "archives": [ + "caption" + ] + } +] diff --git a/rust/obs-build/manifests/obs-browser.json b/rust/obs-build/manifests/obs-browser.json new file mode 100644 index 0000000000..725fd23fe7 --- /dev/null +++ b/rust/obs-build/manifests/obs-browser.json @@ -0,0 +1,29 @@ +{ + "common": [ + "browser-app.cpp", + "browser-client.cpp", + "browser-dummy-client.cpp", + "browser-scheme.cpp", + "deps/base64/base64.cpp", + "deps/signal-restore.cpp", + "deps/wide-string.cpp", + "obs-browser-plugin.cpp", + "obs-browser-source.cpp" + ], + "panels": [ + "panel/browser-panel-client.cpp", + "panel/browser-panel.cpp", + "panel/browser-panel.hpp", + "panel/browser-panel-internal.hpp" + ], + "unity_start": [ + "browser-app.cpp", + "deps/base64/base64.cpp", + "obs-browser-source.cpp" + ], + "helper": [ + "browser-app.cpp", + "browser-dummy-client.cpp", + "obs-browser-page/obs-browser-page-main.cpp" + ] +} diff --git a/rust/obs-build/manifests/obs-websocket.json b/rust/obs-build/manifests/obs-websocket.json new file mode 100644 index 0000000000..efda7c12a3 --- /dev/null +++ b/rust/obs-build/manifests/obs-websocket.json @@ -0,0 +1,90 @@ +{ + "version": "5.7.5", + "rpc_version": 1, + "inputs": [ + "src/Config.cpp", + "src/Config.h", + "src/forms/ConnectInfo.cpp", + "src/forms/ConnectInfo.h", + "src/forms/resources.qrc", + "src/forms/SessionDuration.h", + "src/forms/SettingsDialog.cpp", + "src/forms/SettingsDialog.h", + "src/obs-websocket.cpp", + "src/obs-websocket.h", + "src/WebSocketApi.cpp", + "src/WebSocketApi.h", + "src/websocketserver/rpc/WebSocketSession.h", + "src/websocketserver/types/WebSocketCloseCode.h", + "src/websocketserver/types/WebSocketOpCode.h", + "src/websocketserver/WebSocketServer.cpp", + "src/websocketserver/WebSocketServer.h", + "src/websocketserver/WebSocketServer_Protocol.cpp", + "src/eventhandler/EventHandler.cpp", + "src/eventhandler/EventHandler.h", + "src/eventhandler/EventHandler_Canvases.cpp", + "src/eventhandler/EventHandler_Config.cpp", + "src/eventhandler/EventHandler_Filters.cpp", + "src/eventhandler/EventHandler_General.cpp", + "src/eventhandler/EventHandler_Inputs.cpp", + "src/eventhandler/EventHandler_MediaInputs.cpp", + "src/eventhandler/EventHandler_Outputs.cpp", + "src/eventhandler/EventHandler_SceneItems.cpp", + "src/eventhandler/EventHandler_Scenes.cpp", + "src/eventhandler/EventHandler_Transitions.cpp", + "src/eventhandler/EventHandler_Ui.cpp", + "src/eventhandler/types/EventSubscription.h", + "src/requesthandler/RequestBatchHandler.cpp", + "src/requesthandler/RequestBatchHandler.h", + "src/requesthandler/RequestHandler.cpp", + "src/requesthandler/RequestHandler.h", + "src/requesthandler/RequestHandler_Canvases.cpp", + "src/requesthandler/RequestHandler_Config.cpp", + "src/requesthandler/RequestHandler_Filters.cpp", + "src/requesthandler/RequestHandler_General.cpp", + "src/requesthandler/RequestHandler_Inputs.cpp", + "src/requesthandler/RequestHandler_MediaInputs.cpp", + "src/requesthandler/RequestHandler_Outputs.cpp", + "src/requesthandler/RequestHandler_Record.cpp", + "src/requesthandler/RequestHandler_SceneItems.cpp", + "src/requesthandler/RequestHandler_Scenes.cpp", + "src/requesthandler/RequestHandler_Sources.cpp", + "src/requesthandler/RequestHandler_Stream.cpp", + "src/requesthandler/RequestHandler_Transitions.cpp", + "src/requesthandler/RequestHandler_Ui.cpp", + "src/requesthandler/rpc/Request.cpp", + "src/requesthandler/rpc/Request.h", + "src/requesthandler/rpc/RequestBatchRequest.cpp", + "src/requesthandler/rpc/RequestBatchRequest.h", + "src/requesthandler/rpc/RequestResult.cpp", + "src/requesthandler/rpc/RequestResult.h", + "src/requesthandler/types/RequestBatchExecutionType.h", + "src/requesthandler/types/RequestStatus.h", + "src/utils/Compat.cpp", + "src/utils/Compat.h", + "src/utils/Crypto.cpp", + "src/utils/Crypto.h", + "src/utils/ImageFormat.cpp", + "src/utils/ImageFormat.h", + "src/utils/Json.cpp", + "src/utils/Json.h", + "src/utils/Obs.cpp", + "src/utils/Obs.h", + "src/utils/Obs_ActionHelper.cpp", + "src/utils/Obs_ArrayHelper.cpp", + "src/utils/Obs_NumberHelper.cpp", + "src/utils/Obs_ObjectHelper.cpp", + "src/utils/Obs_SearchHelper.cpp", + "src/utils/Obs_StringHelper.cpp", + "src/utils/Obs_VolumeMeter.cpp", + "src/utils/Obs_VolumeMeter.h", + "src/utils/Obs_VolumeMeter_Helpers.h", + "src/utils/Platform.cpp", + "src/utils/Platform.h", + "src/utils/SourceScreenshot.cpp", + "src/utils/SourceScreenshot.h", + "src/utils/Utils.h", + "src/forms/ConnectInfo.ui", + "src/forms/SettingsDialog.ui" + ] +} diff --git a/rust/obs-build/src/deps.rs b/rust/obs-build/src/deps.rs new file mode 100644 index 0000000000..a82b292ec2 --- /dev/null +++ b/rust/obs-build/src/deps.rs @@ -0,0 +1,26 @@ +//! Shared native archives used by plugins and the frontend. +use crate::{NativeBuild, SharedLibrary, libobs::add_package}; +use std::path::{Path, PathBuf}; + +pub(crate) fn shared_archive( + build: &NativeBuild, + root: &Path, + name: &str, +) -> Result { + let mut library = SharedLibrary { + name: name.into(), + sources: vec![root.join(format!("shared/{name}/build/{name}.core+.h.c"))], + include_dirs: vec![ + root.into(), + root.join("libobs"), + root.join("shared").join(name), + root.join("deps/libcaption"), + root.join("deps/libcaption/caption"), + build.output.join("config"), + ], + ..SharedLibrary::default() + }; + crate::platform::configure_shared_dependency(&build.target, root, name, &mut library)?; + add_package(&mut library, &build.target, "simde")?; + build.static_library(&library) +} diff --git a/rust/obs-build/src/frontend.rs b/rust/obs-build/src/frontend.rs new file mode 100644 index 0000000000..b41bddc4a0 --- /dev/null +++ b/rust/obs-build/src/frontend.rs @@ -0,0 +1,297 @@ +//! Native frontend support libraries and application build graph. +use crate::{NativeBuild, SharedLibrary, libobs::add_package}; +use std::path::{Path, PathBuf}; + +pub fn build_api(build: &NativeBuild, root: &Path, core: &Path) -> Result { + let root = root.canonicalize().map_err(|e| e.to_string())?; + let mut library = SharedLibrary { + name: "obs-frontend-api".into(), + sources: vec![root.join("frontend/api/build/obs-frontend-api.core+.hpp.cpp")], + include_dirs: vec![ + root.clone(), + root.join("libobs"), + root.join("frontend/api"), + build.output.join("config"), + ], + dependencies: vec![core.canonicalize().map_err(|e| e.to_string())?], + ..SharedLibrary::default() + }; + crate::platform::configure_frontend_api(&build.target, &mut library)?; + add_package(&mut library, &build.target, "simde")?; + let artifact = build.shared_library(&library)?; + let lookup = artifact.with_file_name(crate::platform::shared_filename( + &build.target, + &library.name, + )); + if artifact != lookup { + std::fs::copy(&artifact, lookup).map_err(|e| e.to_string())?; + } + Ok(artifact) +} + +/// Add the shared Qt spinbox interface sources to a native target. +pub fn add_spinbox( + build: &NativeBuild, + root: &Path, + library: &mut SharedLibrary, +) -> Result<(), String> { + let root = root.canonicalize().map_err(|e| e.to_string())?; + crate::platform::configure_cpp17(&build.target, library); + let directory = root.join("shared/qt/obs-spinbox"); + library + .sources + .push(directory.join("build/qt-obs-spinbox.core+.hpp.cpp")); + library.include_dirs.push(directory.clone()); + add_package(library, &build.target, "Qt6Widgets")?; + for name in ["AutoSelectLineEdit", "DoubleSpinBox", "SpinBox"] { + crate::qt::moc( + library, + &directory.join(format!("{name}.hpp")), + &build + .output + .join(&library.name) + .join(format!("qt/moc_{name}.cpp")), + )?; + } + Ok(()) +} + +#[derive(Default)] +pub struct ApplicationOptions { + pub browser_panels: bool, +} + +/// Build the Linux frontend with the default optional features. +pub fn build_application( + build: &NativeBuild, + root: &Path, + core: &Path, + api: &Path, + gpu_status_archive: &Path, +) -> Result { + build_application_with_options( + build, + root, + core, + api, + gpu_status_archive, + &ApplicationOptions::default(), + ) +} + +/// Build the Linux frontend graph with its optional browser-panel interface. +pub fn build_application_with_options( + build: &NativeBuild, + root: &Path, + core: &Path, + api: &Path, + gpu_status_archive: &Path, + options: &ApplicationOptions, +) -> Result { + let root = root.canonicalize().map_err(|e| e.to_string())?; + let manifest_path = root.join("frontend/build/cargo-sources.json"); + let manifest: serde_json::Value = + serde_json::from_slice(&std::fs::read(&manifest_path).map_err(|e| e.to_string())?) + .map_err(|e| e.to_string())?; + let mut common: Vec = + serde_json::from_value(manifest["common"].clone()).map_err(|e| e.to_string())?; + let interfaces: std::collections::BTreeMap> = + serde_json::from_value(manifest["interfaces"].clone()).map_err(|e| e.to_string())?; + let config = build.output.join("frontend-config"); + std::fs::create_dir_all(&config).map_err(|e| e.to_string())?; + let mut library = SharedLibrary { + name: "obs-studio-rust".into(), + include_dirs: vec![ + config.clone(), + root.clone(), + root.join("frontend"), + root.join("frontend/api"), + root.join("libobs"), + root.join("shared/bpm"), + root.join("deps/json11"), + build.output.join("config"), + ], + dependencies: vec![ + core.canonicalize().map_err(|e| e.to_string())?, + api.canonicalize().map_err(|e| e.to_string())?, + ], + ..SharedLibrary::default() + }; + crate::platform::configure_application(&build.target, &root, &manifest, &config, &mut library)?; + if options.browser_panels { + library.definitions.push(("BROWSER_AVAILABLE".into(), None)); + library + .include_dirs + .push(root.join("plugins/obs-browser/panel")); + common.extend( + [ + "frontend/build/frontend.browserpanels+.hpp.cpp", + "frontend/dialogs/OBSExtraBrowsers.hpp", + "frontend/docks/BrowserDock.hpp", + "frontend/utility/ExtraBrowsersDelegate.hpp", + "frontend/utility/ExtraBrowsersModel.hpp", + "plugins/obs-browser/panel/browser-panel.hpp", + ] + .map(str::to_owned), + ); + } + for package in [ + "simde", + "Qt6Widgets", + "Qt6Network", + "Qt6Svg", + "Qt6Xml", + "libcurl", + "libavcodec", + "libavutil", + "libavformat", + "nlohmann_json", + ] { + add_package(&mut library, &build.target, package)?; + } + let version_manifest = std::fs::read_to_string(root.join("rust/libobs-rust/Cargo.toml")) + .map_err(|e| e.to_string())?; + let version = version_manifest + .lines() + .find_map(|line| { + line.strip_prefix("version = \"") + .and_then(|line| line.strip_suffix('"')) + }) + .ok_or("libobs-rust package version missing")?; + library.definitions.extend([ + ( + "OBS_RUST_VERSION".into(), + Some(serde_json::to_string(version).map_err(|e| e.to_string())?), + ), + ("OBS_GPU_STATUS".into(), Some("1".into())), + ( + "QT_ENABLE_STRICT_MODE_UP_TO".into(), + Some("0xFF0000".into()), + ), + ]); + let mut ui_config = + std::fs::read_to_string(root.join("frontend/cmake/templates/ui-config.h.in")) + .map_err(|e| e.to_string())?; + for (name, value) in [ + ("OAUTH_BASE_URL", "https://auth.obsproject.com/"), + ("TWITCH_CLIENTID", ""), + ("TWITCH_HASH", "0"), + ("RESTREAM_CLIENTID", ""), + ("RESTREAM_HASH", "0"), + ("YOUTUBE_CLIENTID", ""), + ("YOUTUBE_SECRET", ""), + ("YOUTUBE_CLIENTID_HASH", "0"), + ("YOUTUBE_SECRET_HASH", "0"), + ] { + ui_config = ui_config.replace(&format!("@{name}@"), value); + } + write(&config.join("ui-config.h"), &ui_config)?; + for directory in interfaces.keys() { + let path = root.join(directory); + library + .include_dirs + .push(if directory == "shared/qt/idian" { + path.join("include") + } else { + path + }); + } + library + .include_dirs + .push(root.join("shared/qt/obs-spinbox")); + add_inputs(build, &root, &mut library, &common)?; + add_spinbox(build, &root, &mut library)?; + for (directory, inputs) in interfaces { + let path = root.join(&directory); + if directory == "shared/qt/idian" { + let mut idian = SharedLibrary { + name: "obs-idian".into(), + include_dirs: vec![root.clone(), path.join("include")], + ..SharedLibrary::default() + }; + crate::platform::configure_cpp_module(&build.target, &mut idian)?; + for package in ["Qt6Widgets", "Qt6Svg"] { + add_package(&mut idian, &build.target, package)?; + } + add_inputs(build, &root, &mut idian, &inputs)?; + crate::qt::combine_moc( + &mut idian, + &build.output.join("obs-idian/qt/mocs_compilation.cpp"), + &root.join("shared/qt/idian/build/idian.pch.hpp"), + )?; + library.dependencies.push(build.static_library(&idian)?); + library.include_dirs.push(path.join("include")); + } else { + library.include_dirs.push(path); + add_inputs(build, &root, &mut library, &inputs)?; + } + } + library.sources.push(root.join("deps/json11/json11.cpp")); + library + .dependencies + .push(crate::deps::shared_archive(build, &root, "bpm")?); + library + .dependencies + .push(crate::libobs::build_caption(build, &root)?); + library.dependencies.push( + gpu_status_archive + .canonicalize() + .map_err(|e| e.to_string())?, + ); + crate::qt::combine_moc( + &mut library, + &build.output.join("obs-studio-rust/qt/mocs_compilation.cpp"), + &root.join("frontend/build/frontend-components.pch.hpp"), + )?; + build.executable(&library) +} + +pub(crate) fn add_inputs( + build: &NativeBuild, + root: &Path, + library: &mut SharedLibrary, + inputs: &[String], +) -> Result<(), String> { + let generated = build.output.join(&library.name).join("qt"); + // All generated UI headers must exist before moc preprocesses widget headers. + for input in inputs + .iter() + .filter(|input| input.ends_with(".ui") || input.ends_with(".qrc")) + { + let path = root.join(input); + let stem = path + .file_stem() + .and_then(|name| name.to_str()) + .ok_or("invalid Qt input name")?; + if input.ends_with(".ui") { + crate::qt::uic(library, &path, &generated.join(format!("ui_{stem}.h")))?; + } else { + crate::qt::rcc(library, &path, &generated.join(format!("qrc_{stem}.cpp")))?; + } + } + for input in inputs { + let path = root.join(input); + if input.ends_with(".c") || input.ends_with(".cpp") { + library.sources.push(path); + } else if input.ends_with(".hpp") || input.ends_with(".h") { + let header = + std::fs::read_to_string(&path).map_err(|e| format!("{}: {e}", path.display()))?; + if header.lines().any(|line| { + ["Q_OBJECT", "Q_GADGET", "Q_NAMESPACE"] + .iter() + .any(|keyword| line.trim_start().starts_with(keyword)) + }) { + let name = input.replace(['/', '.', '-'], "_"); + crate::qt::moc(library, &path, &generated.join(format!("moc_{name}.cpp")))?; + } + } + } + Ok(()) +} + +pub(crate) fn write(path: &Path, content: &str) -> Result<(), String> { + if std::fs::read_to_string(path).ok().as_deref() != Some(content) { + std::fs::write(path, content).map_err(|e| e.to_string())?; + } + Ok(()) +} diff --git a/rust/obs-build/src/graphics.rs b/rust/obs-build/src/graphics.rs new file mode 100644 index 0000000000..bcaeef707e --- /dev/null +++ b/rust/obs-build/src/graphics.rs @@ -0,0 +1,48 @@ +//! Graphics backends built from the shared native OBS configuration. +use crate::{NativeBuild, SharedLibrary, libobs::Options}; +use std::path::{Path, PathBuf}; + +pub fn build_opengl( + build: &NativeBuild, + root: &Path, + core: &Path, + options: &Options, +) -> Result { + let root = root.canonicalize().map_err(|e| e.to_string())?; + let mut library = SharedLibrary { + name: "obs-opengl".into(), + sources: vec![root.join("libobs-opengl/build/opengl.core+.h.c")], + include_dirs: vec![ + root.clone(), + root.join("libobs"), + root.join("libobs-opengl"), + root.join("deps/glad/include"), + build.output.join("config"), + ], + dependencies: vec![core.canonicalize().map_err(|e| e.to_string())?], + ..SharedLibrary::default() + }; + crate::platform::configure_opengl(&build.target, &root, options, &mut library)?; + library.dependencies.push(build_glad(build, &root)?); + let artifact = build.shared_library(&library)?; + let linker_name = artifact.with_file_name(crate::platform::shared_filename( + &build.target, + "obs-opengl", + )); + if artifact != linker_name { + std::fs::copy(&artifact, &linker_name).map_err(|e| e.to_string())?; + } + Ok(artifact) +} + +pub(crate) fn build_glad(build: &NativeBuild, root: &Path) -> Result { + let mut glad = SharedLibrary { + name: "obsglad".into(), + sources: vec![root.join("deps/glad/src/glad.c")], + include_dirs: vec![root.join("deps/glad/include")], + ..SharedLibrary::default() + }; + crate::platform::configure_module(&build.target, &mut glad)?; + crate::platform::configure_glad(&build.target, root, &mut glad)?; + build.static_library(&glad) +} diff --git a/rust/obs-build/src/groups.rs b/rust/obs-build/src/groups.rs new file mode 100644 index 0000000000..4c93ca7d22 --- /dev/null +++ b/rust/obs-build/src/groups.rs @@ -0,0 +1,141 @@ +//! Preserve explicit source inventories while compiling each member separately. +use std::{ + collections::HashSet, + fs, + path::{Path, PathBuf}, +}; + +pub(crate) fn headers( + root: &Path, + sources: &[PathBuf], +) -> Result, String> { + let mut headers = std::collections::BTreeMap::>::new(); + for source in sources { + let content = + fs::read_to_string(source).map_err(|e| format!("read {}: {e}", source.display()))?; + let first = content.lines().map(str::trim).find(|line| { + !line.is_empty() + && !line.starts_with("/*") + && !line.starts_with('*') + && !line.starts_with("//") + }); + let Some(include) = first + .and_then(|line| line.strip_prefix("#include \"")) + .and_then(|line| line.strip_suffix('"')) + else { + continue; + }; + if !(include.ends_with(".pch.h") || include.ends_with(".pch.hpp")) { + continue; + } + let header = + dunce::canonicalize(root.join(include)).map_err(|e| format!("PCH {include}: {e}"))?; + headers.entry(header).or_default().push(source.clone()); + } + Ok(headers + .into_iter() + .map(|(header, sources)| crate::PrecompiledHeader { header, sources }) + .collect()) +} + +pub(crate) fn separate( + root: &Path, + output: &Path, + sources: &[PathBuf], +) -> Result, String> { + let root = dunce::canonicalize(root).map_err(|e| e.to_string())?; + let mut result = Vec::new(); + let mut seen = HashSet::new(); + for source in sources { + let name = source + .file_name() + .and_then(|s| s.to_str()) + .ok_or("non-UTF8 source name")?; + let (suffix, language) = if name.ends_with("+.h.c") { + (".c.h", "c") + } else if name.ends_with("+.hpp.cpp") { + (".cpp.hpp", "cpp") + } else { + result.push(source.clone()); + continue; + }; + println!("cargo:rerun-if-changed={}", source.display()); + let content = + fs::read_to_string(source).map_err(|e| format!("read {}: {e}", source.display()))?; + let mut headers = Vec::new(); + let mut members = Vec::new(); + for line in content.lines().map(str::trim) { + if line.is_empty() + || line.starts_with("/*") + || line.starts_with('*') + || line.starts_with("//") + { + continue; + } + // Fail closed if a group acquires conditionals or other directives: + // selecting members must not silently change their build semantics. + let include = line + .strip_prefix("#include \"") + .and_then(|s| s.strip_suffix('"')) + .ok_or_else(|| { + format!( + "cannot separate non-include group line in {}: {line}", + source.display() + ) + })?; + let path = dunce::canonicalize(root.join(include)) + .map_err(|e| format!("group include {include}: {e}"))?; + if !path.starts_with(&root) { + return Err(format!("group include leaves source root: {include}")); + } + println!("cargo:rerun-if-changed={}", path.display()); + if include.ends_with(suffix) { + members.push(path); + } else { + headers.push(path); + } + } + if members.is_empty() { + return Err(format!( + "group contains no {suffix} implementation members: {}", + source.display() + )); + } + for member in members { + if !seen.insert(member.clone()) { + return Err(format!( + "implementation appears in multiple groups: {}", + member.display() + )); + } + let relative = member.strip_prefix(&root).map_err(|e| e.to_string())?; + let wrapper = output.join(relative).with_extension(format!( + "{}.{}", + relative + .extension() + .and_then(|s| s.to_str()) + .unwrap_or_default(), + language + )); + let mut unit = + String::from("/* Individual translation unit generated by obs-build. */\n"); + for include in headers.iter().chain(std::iter::once(&member)) { + let path = dunce::simplified(include) + .to_str() + .ok_or("non-UTF8 include path")? + .replace('\\', "/"); + if path.contains(['\n', '\r', '"']) { + return Err(format!("include path cannot be represented: {path:?}")); + } + unit.push_str(&format!("#include \"{path}\"\n")); + } + if fs::read_to_string(&wrapper).ok().as_deref() != Some(&unit) { + fs::create_dir_all(wrapper.parent().ok_or("wrapper has no parent")?) + .map_err(|e| e.to_string())?; + fs::write(&wrapper, unit).map_err(|e| e.to_string())?; + } + result.push(wrapper); + } + } + Ok(result) +} diff --git a/rust/obs-build/src/lib.rs b/rust/obs-build/src/lib.rs new file mode 100644 index 0000000000..aee4dac5ec --- /dev/null +++ b/rust/obs-build/src/lib.rs @@ -0,0 +1,284 @@ +//! Native compilation and dynamic linking for the Cargo-driven OBS build. +//! +//! This engine owns native artifacts. Cargo remains responsible for compiling +//! Rust crates; native compiles go through cc::Build and inherit soldr's tools. +#![forbid(unsafe_code)] + +use std::{fs, path::PathBuf}; + +mod deps; +pub mod frontend; +pub mod graphics; +mod groups; +pub mod libobs; +mod pch; +mod platform; +pub mod plugins; +pub mod qt; +pub mod scripting; +pub mod validation; + +#[derive(Clone, Debug)] +pub struct PrecompiledHeader { + pub header: PathBuf, + pub sources: Vec, +} + +#[derive(Clone, Debug, Default)] +pub struct SharedLibrary { + pub name: String, + pub sources: Vec, + /// Objects compiled once and reused by multiple shared-library variants. + pub precompiled_objects: Vec, + pub include_dirs: Vec, + pub dependencies: Vec, + pub unity: bool, + /// Explicit source-to-header assignments; empty disables compiled PCH. + pub precompiled_headers: Vec, + pub definitions: Vec<(String, Option)>, + pub compile_options: Vec, + pub c_compile_options: Vec, + pub cpp_compile_options: Vec, + pub link_options: Vec, + pub file_name: Option, +} + +#[derive(Clone, Debug)] +pub struct NativeBuild { + pub host: String, + pub target: String, + pub output: PathBuf, +} + +struct CompilationBatch { + cpp: bool, + header: Option, + sources: Vec, +} + +impl NativeBuild { + /// Expand explicit BUILD.md groups into individual translation units. + pub fn separate_group_sources( + &self, + root: &std::path::Path, + sources: &[PathBuf], + ) -> Result, String> { + groups::separate(root, &self.output.join("individual-sources"), sources) + } + + /// Compile through cc::Build, then link a native shared library. + pub fn shared_library(&self, library: &SharedLibrary) -> Result { + let (output, cpp_link, mut objects) = self.objects(library)?; + objects.extend(library.precompiled_objects.iter().cloned()); + let artifact = output.join( + library + .file_name + .clone() + .unwrap_or_else(|| platform::shared_filename(&self.target, &library.name)), + ); + let compiler = self.compiler(library, &output, cpp_link).get_compiler(); + let mut command = compiler.to_command(); + platform::configure_shared_link( + &self.target, + &mut command, + &artifact, + &objects, + &library.dependencies, + compiler.is_like_msvc(), + )?; + command.args(&library.link_options); + let result = command + .output() + .map_err(|e| format!("execute linker {command:?}: {e}"))?; + if !result.status.success() { + return Err(format!( + "link {} failed ({})\n{}\n{}", + library.name, + result.status, + String::from_utf8_lossy(&result.stdout), + String::from_utf8_lossy(&result.stderr) + )); + } + Ok(artifact) + } + + /// Compile and link an executable with the native shared dependencies. + pub fn executable(&self, target: &SharedLibrary) -> Result { + let (output, cpp, mut objects) = self.objects(target)?; + objects.extend(target.precompiled_objects.iter().cloned()); + let artifact = output.join( + target + .file_name + .clone() + .unwrap_or_else(|| platform::executable_filename(&self.target, &target.name)), + ); + let compiler = self.compiler(target, &output, cpp).get_compiler(); + let mut command = compiler.to_command(); + platform::configure_executable_link( + &self.target, + &mut command, + &artifact, + &objects, + &target.dependencies, + compiler.is_like_msvc(), + )?; + command.args(&target.link_options); + let result = command + .output() + .map_err(|e| format!("execute linker {command:?}: {e}"))?; + if !result.status.success() { + return Err(format!( + "link executable {} failed ({})\n{}\n{}", + target.name, + result.status, + String::from_utf8_lossy(&result.stdout), + String::from_utf8_lossy(&result.stderr) + )); + } + Ok(artifact) + } + + /// Build an archive with the same compiler, flags and source grouping. + pub fn static_library(&self, library: &SharedLibrary) -> Result { + let (output, cpp, objects) = self.objects(library)?; + self.compiler(library, &output, cpp) + .try_create_archive(&library.name, objects) + .map_err(|e| e.to_string()) + } + + fn objects(&self, library: &SharedLibrary) -> Result<(PathBuf, bool, Vec), String> { + if library.name.is_empty() + || !library + .name + .bytes() + .all(|c| c.is_ascii_alphanumeric() || c == b'-' || c == b'_') + { + return Err(format!("invalid native target name {:?}", library.name)); + } + if library.sources.is_empty() { + return Err(format!("{} has no sources", library.name)); + } + let output = self.output.join(&library.name); + fs::create_dir_all(&output).map_err(|e| format!("create {}: {e}", output.display()))?; + let output = dunce::canonicalize(&output).map_err(|e| e.to_string())?; + let mut assignments = std::collections::BTreeMap::new(); + for assignment in &library.precompiled_headers { + let header = dunce::canonicalize(&assignment.header) + .map_err(|e| format!("{}: {e}", assignment.header.display()))?; + for source in &assignment.sources { + let source = dunce::canonicalize(source).map_err(|e| e.to_string())?; + if assignments.insert(source.clone(), header.clone()).is_some() { + return Err(format!( + "duplicate PCH source assignment: {}", + source.display() + )); + } + } + } + let mut batches: Vec = Vec::new(); + for source in &library.sources { + let absolute = + dunce::canonicalize(source).map_err(|e| format!("{}: {e}", source.display()))?; + let cpp = match source.extension().and_then(|e| e.to_str()) { + Some("c") => false, + Some("cpp" | "cc" | "cxx") => true, + other => { + return Err(format!( + "unsupported native source language {other:?}: {}", + source.display() + )); + } + }; + let header = assignments.remove(&absolute); + // Keep translation-unit and constructor order. Combining all users + // of the same header would move interleaved source files around. + match batches.last_mut() { + Some(previous) if previous.cpp == cpp && previous.header == header => { + previous.sources.push(absolute); + } + _ => batches.push(CompilationBatch { + cpp, + header, + sources: vec![absolute], + }), + } + } + if !assignments.is_empty() { + return Err("PCH assignment refers to sources outside this target".into()); + } + let cpp_link = batches.iter().any(|batch| batch.cpp); + let mut objects = Vec::new(); + for (index, batch) in batches.into_iter().enumerate() { + let CompilationBatch { + cpp, + header, + sources, + } = batch; + let mut compiler = self.compiler(library, &output, cpp); + if let Some(header) = header { + pch::apply(self, &mut compiler, cpp, &header)?; + } + if library.unity { + let group = output.join(format!("unity-{index}.{}", if cpp { "cpp" } else { "c" })); + let mut content = String::from("/* Generated by obs-build. */\n"); + for source in &sources { + let path = source.to_str().ok_or("non-UTF8 native source path")?; + if path.contains(['\n', '\r', '"']) { + return Err(format!( + "source path cannot be represented in an include: {path:?}" + )); + } + content.push_str(&format!("#include \"{}\"\n", path.replace('\\', "/"))); + } + // Do not invalidate a warm compiler cache by touching unchanged groups. + if fs::read_to_string(&group).ok().as_deref() != Some(&content) { + fs::write(&group, content).map_err(|e| e.to_string())?; + } + compiler.file(group); + } else { + compiler.files(sources); + } + objects.extend( + compiler + .try_compile_intermediates() + .map_err(|e| e.to_string())?, + ); + } + Ok((output, cpp_link, objects)) + } + + fn compiler(&self, library: &SharedLibrary, output: &std::path::Path, cpp: bool) -> cc::Build { + let mut compiler = cc::Build::new(); + compiler + .host(&self.host) + .target(&self.target) + .out_dir(output) + .opt_level(2) + .debug(true) + .pic(true) + .cpp(cpp) + // Intermediate compilation and archive creation do not emit link + // directives. Keep cc's compiler/archiver environment tracking so + // target-qualified flags invalidate Cargo's bundled native build. + .cargo_metadata(true); + let mut includes = std::collections::HashSet::new(); + for directory in &library.include_dirs { + if includes.insert(directory) { + compiler.include(dunce::simplified(directory)); + } + } + let mut definitions = std::collections::HashSet::new(); + for (name, value) in &library.definitions { + if definitions.insert((name, value)) { + compiler.define(name, value.as_deref()); + } + } + compiler.flags(&library.compile_options); + compiler.flags(if cpp { + &library.cpp_compile_options + } else { + &library.c_compile_options + }); + compiler + } +} diff --git a/rust/obs-build/src/libobs.rs b/rust/obs-build/src/libobs.rs new file mode 100644 index 0000000000..c232e47f38 --- /dev/null +++ b/rust/obs-build/src/libobs.rs @@ -0,0 +1,331 @@ +//! The native libobs graph, shared by bundled obs-sys and the application build. +use crate::{NativeBuild, SharedLibrary}; +use std::{ + collections::BTreeMap, + fs, + path::{Path, PathBuf}, +}; + +#[derive(Clone, Debug)] +pub struct Options { + /// Keep explicit BUILD.md unity groups; false compiles their members separately. + pub unity: bool, + /// Compile the explicit group headers; independent of the unity option. + pub pch: bool, + pub hevc: bool, + pub wayland: bool, + pub pulseaudio: bool, + pub gio: bool, + pub core_modules: Vec, +} + +impl Default for Options { + fn default() -> Self { + Self { + unity: true, + pch: false, + hevc: true, + wayland: true, + pulseaudio: true, + gio: true, + core_modules: vec![], + } + } +} + +/// Build the real C libobs, including generated configuration and native dependencies. +pub fn build(build: &NativeBuild, root: &Path) -> Result { + build_with_options(build, root, &Options::default()) +} + +pub fn build_with_options( + build: &NativeBuild, + root: &Path, + options: &Options, +) -> Result { + let plan = prepare(build, root, options)?; + let mut library = plan.common; + add_variant(build, &plan.root, &plan.sets, options, &mut library, None)?; + finish(build, &library) +} + +struct Plan { + common: SharedLibrary, + root: PathBuf, + sets: BTreeMap>, +} + +fn prepare(build: &NativeBuild, root: &Path, options: &Options) -> Result { + let root = root.canonicalize().map_err(|e| e.to_string())?; + let manifest = root.join("libobs/build/source-sets.json"); + let sets: BTreeMap> = + serde_json::from_slice(&fs::read(&manifest).map_err(|e| e.to_string())?) + .map_err(|e| format!("read {}: {e}", manifest.display()))?; + let config = build.output.join("config"); + fs::create_dir_all(&config).map_err(|e| e.to_string())?; + let config = config.canonicalize().map_err(|e| e.to_string())?; + let mut library = SharedLibrary { + name: "obs".into(), + include_dirs: vec![ + root.clone(), + root.join("libobs"), + root.join("deps/libcaption"), + root.join("deps/libcaption/caption"), + config.clone(), + ], + definitions: vec![ + ("IS_LIBOBS".into(), None), + ("__STDC_CONSTANT_MACROS".into(), None), + ], + // Source manifests already contain explicit unity groups. Preserve their + // boundaries: merging all groups into one TU would introduce collisions. + unity: false, + ..SharedLibrary::default() + }; + append_sources(&sets, "LIBOBS_SOURCES", &root, &mut library)?; + if options.hevc { + library.definitions.push(("ENABLE_HEVC".into(), None)); + } + crate::platform::configure_libobs(&build.target, &root, options, &sets, &mut library)?; + for package in [ + "libavformat", + "libavcodec", + "libavutil", + "libswscale", + "libswresample", + "jansson", + "zlib", + "simde", + ] { + add_package(&mut library, &build.target, package)?; + } + library.dependencies.push(build_caption(build, &root)?); + let mut header = String::from( + "#pragma once\n#define OBS_DATA_PATH \"share/obs\"\n#define OBS_PLUGIN_PATH \"lib64/obs-modules/core\"\n#define OBS_PLUGIN_DESTINATION \"lib64/obs-modules\"\n#define OBS_RELEASE_CANDIDATE 0\n#define OBS_BETA 6\n", + ); + for (enabled, name) in [ + (options.gio, "GIO_FOUND"), + (options.pulseaudio, "PULSEAUDIO_FOUND"), + (options.wayland, "ENABLE_WAYLAND"), + ] { + if enabled { + header.push_str(&format!("#define {name}\n")); + } + } + write_if_changed(&config.join("obsconfig.h"), &header)?; + let version = fs::read_to_string(root.join("libobs/obsversion.c.in")) + .map_err(|e| e.to_string())? + .replace("@OBS_VERSION@", "33.0.0-cc-build") + .replace("@OBS_VERSION_CANONICAL@", "33.0.0") + .replace("@OBS_COMMIT@", "cc-build"); + let version_source = config.join("obsversion.c"); + write_if_changed(&version_source, &version)?; + library.sources.push(version_source); + let names = options + .core_modules + .iter() + .map(|name| serde_json::to_string(name).map_err(|e| e.to_string())) + .collect::, _>>()?; + let module_names = if names.is_empty() { + "NULL".into() + } else { + names.join(",\n") + }; + let modules = fs::read_to_string(root.join("libobs/obs-core-modules.c.in")) + .map_err(|e| e.to_string())? + .replace("@OBS_CORE_MODULE_LIST@", &module_names) + .replace("@OBS_CORE_MODULE_COUNT@", &names.len().to_string()); + let module_source = config.join("obs-core-modules.c"); + write_if_changed(&module_source, &modules)?; + library.sources.push(module_source); + if !options.unity { + library.sources = build.separate_group_sources(&root, &library.sources)?; + } + if options.pch { + library.precompiled_headers = crate::groups::headers(&root, &library.sources)?; + } + Ok(Plan { + common: library, + root, + sets, + }) +} + +fn finish(build: &NativeBuild, library: &SharedLibrary) -> Result { + let artifact = build.shared_library(library)?; + let linker_name = + artifact.with_file_name(crate::platform::shared_filename(&build.target, "obs")); + if linker_name != artifact { + fs::copy(&artifact, &linker_name) + .map_err(|e| format!("create {}: {e}", linker_name.display()))?; + } + Ok(artifact) +} + +fn add_variant( + build: &NativeBuild, + root: &Path, + sets: &BTreeMap>, + options: &Options, + library: &mut SharedLibrary, + rust_archive: Option<&Path>, +) -> Result<(), String> { + if rust_archive.is_some() { + append_sources(sets, "LIBOBS_RUST_SOURCES", root, library)?; + } else { + append_sources(sets, "LIBOBS_PORTED_SOURCES", root, library)?; + if options.hevc { + append_sources(sets, "LIBOBS_HEVC_PORTED_SOURCES", root, library)?; + } + } + crate::platform::configure_libobs_variant(build, root, options, sets, library, rust_archive)?; + if !options.unity { + library.sources = build.separate_group_sources(root, &library.sources)?; + } + if options.pch { + library.precompiled_headers = crate::groups::headers(root, &library.sources)?; + } + Ok(()) +} + +pub(crate) fn append_sources( + sets: &BTreeMap>, + name: &str, + root: &Path, + library: &mut SharedLibrary, +) -> Result<(), String> { + let sources = sets + .get(name) + .ok_or_else(|| format!("missing source set {name}"))?; + library.sources.extend( + sources + .iter() + .filter(|s| { + s.ends_with(".c") || s.ends_with(".cpp") || s.ends_with(".m") || s.ends_with(".mm") + }) + .map(|s| root.join("libobs").join(s)), + ); + Ok(()) +} + +pub(crate) fn add_package( + library: &mut SharedLibrary, + target: &str, + package: &str, +) -> Result<(), String> { + let dependency = pkg_config::Config::new() + .cargo_metadata(false) + .probe(package) + .map_err(|e| format!("native dependency {package}: {e}"))?; + library.include_dirs.extend(dependency.include_paths); + // pkg-config stores these in a randomly seeded HashMap. Stable command + // ordering prevents equivalent definitions from changing compiler cache keys. + let mut definitions: Vec<_> = dependency.defines.into_iter().collect(); + definitions.sort(); + library.definitions.extend(definitions); + for path in &dependency.link_paths { + library.link_options.push(format!("-L{}", path.display())); + library + .link_options + .push(format!("-Wl,-rpath,{}", path.display())); + } + for name in dependency.libs { + // Some pkg-config files list a static archive directory before their + // shared directory. Resolve across every directory before allowing the + // linker to fall back to -l, which otherwise silently embeds the archive. + if let Some(path) = + crate::platform::package_shared_library(target, &dependency.link_paths, &name) + { + library.link_options.push(path.display().to_string()); + } else { + library.link_options.push(format!("-l{name}")); + } + } + Ok(()) +} + +pub(crate) fn build_caption(build: &NativeBuild, root: &Path) -> Result { + let mut caption = SharedLibrary { + name: "caption".into(), + include_dirs: vec![ + root.join("deps/libcaption"), + root.join("deps/libcaption/caption"), + ], + compile_options: vec![], + definitions: vec![("__STDC_CONSTANT_MACROS".into(), None)], + ..SharedLibrary::default() + }; + crate::platform::configure_caption(&build.target, &mut caption)?; + for source in [ + "caption", + "cea708", + "eia608", + "eia608_charmap", + "eia608_from_utf8", + "mpeg", + "scc", + "srt", + "utf8", + "xds", + ] { + caption + .sources + .push(root.join(format!("deps/libcaption/src/{source}.c"))); + } + build.static_library(&caption) +} + +fn write_if_changed(path: &Path, text: &str) -> Result<(), String> { + if fs::read_to_string(path).ok().as_deref() != Some(text) { + fs::write(path, text).map_err(|e| format!("write {}: {e}", path.display()))?; + } + Ok(()) +} + +/// Both ABI-compatible variants; only the C reference is installed. +#[derive(Debug)] +pub struct Libraries { + pub reference: PathBuf, + pub with_rust: PathBuf, +} + +/// Compile common native sources once, then link C and Rust implementation twins. +pub fn build_pair( + build: &NativeBuild, + root: &Path, + options: &Options, + rust_archive: &Path, +) -> Result { + // The Rust staticlib is built by the outer Cargo invocation, never a nested + // Cargo process inside obs-sys/build.rs (which would wait on its own lock). + if !rust_archive.is_file() { + return Err(format!( + "Rust archive does not exist: {}", + rust_archive.display() + )); + } + let plan = prepare(build, root, options)?; + let mut common = plan.common; + common.name = "obs-common".into(); + let (_, _, objects) = build.objects(&common)?; + common.sources.clear(); + common.precompiled_headers.clear(); + common.precompiled_objects = objects; + let mut reference = common.clone(); + reference.name = "obs".into(); + add_variant(build, &plan.root, &plan.sets, options, &mut reference, None)?; + let mut with_rust = common; + with_rust.name = "obs-with-rust".into(); + add_variant( + build, + &plan.root, + &plan.sets, + options, + &mut with_rust, + Some(rust_archive), + )?; + Ok(Libraries { + reference: finish(build, &reference)?, + with_rust: finish(build, &with_rust)?, + }) +} diff --git a/rust/obs-build/src/pch.rs b/rust/obs-build/src/pch.rs new file mode 100644 index 0000000000..11566e5ae1 --- /dev/null +++ b/rust/obs-build/src/pch.rs @@ -0,0 +1,87 @@ +//! Build PCH through the same cc tool and flags used by its consumers. +use crate::NativeBuild; +use std::{ + fs, + hash::{Hash, Hasher}, + path::Path, +}; + +pub(crate) fn apply( + build: &NativeBuild, + compiler: &mut cc::Build, + cpp: bool, + header: &Path, +) -> Result<(), String> { + let tool = compiler.get_compiler(); + let kind = crate::platform::pch_kind(&build.target, &tool)?; + let mut signature = std::collections::hash_map::DefaultHasher::new(); + ( + &build.host, + &build.target, + header, + cpp, + tool.path(), + tool.args(), + tool.env(), + ) + .hash(&mut signature); + let directory = build + .output + .join("pch") + .join(format!("{:016x}", signature.finish())); + fs::create_dir_all(&directory).map_err(|e| e.to_string())?; + let directory = dunce::canonicalize(directory).map_err(|e| e.to_string())?; + let source = directory.join("prefix-input.h"); + let path = dunce::simplified(header) + .to_str() + .ok_or("non-UTF8 PCH path")? + .replace('\\', "/"); + if path.contains(['\n', '\r', '"']) { + return Err(format!("unrepresentable PCH include: {path:?}")); + } + crate::frontend::write(&source, &format!("#include \"{path}\"\n"))?; + println!("cargo:rerun-if-changed={}", header.display()); + let artifact = directory.join(match kind { + crate::platform::PchKind::Gnu => "prefix.h.gch", + crate::platform::PchKind::Clang => "prefix.pch", + }); + let mut command = tool.to_command(); + command + .args(["-x", if cpp { "c++-header" } else { "c-header" }, "-c"]) + .arg(&source) + .arg("-o") + .arg(&artifact); + let result = command + .output() + .map_err(|e| format!("execute PCH compiler: {e}"))?; + if !result.status.success() { + return Err(format!( + "PCH {} failed ({})\n{}\n{}", + header.display(), + result.status, + String::from_utf8_lossy(&result.stdout), + String::from_utf8_lossy(&result.stderr) + )); + } + match kind { + crate::platform::PchKind::Gnu => { + let fallback = directory.join("prefix.h"); + // GCC otherwise ignores an unusable PCH silently. The fallback + // header makes requested PCH consumption a checked invariant. + crate::frontend::write( + &fallback, + "#error obs-build requested PCH was not consumed\n", + )?; + compiler + .flag("-Werror=invalid-pch") + .flag("-include") + .flag(fallback.to_str().ok_or("non-UTF8 PCH fallback path")?); + } + crate::platform::PchKind::Clang => { + compiler + .flag("-include-pch") + .flag(artifact.to_str().ok_or("non-UTF8 PCH artifact path")?); + } + } + Ok(()) +} diff --git a/rust/obs-build/src/platform/libobs_linux.rs b/rust/obs-build/src/platform/libobs_linux.rs new file mode 100644 index 0000000000..8400c917a1 --- /dev/null +++ b/rust/obs-build/src/platform/libobs_linux.rs @@ -0,0 +1,111 @@ +use crate::{ + SharedLibrary, + libobs::{Options, add_package, append_sources}, +}; +use std::{collections::BTreeMap, path::Path}; + +pub fn configure( + target: &str, + root: &Path, + options: &Options, + sets: &BTreeMap>, + library: &mut SharedLibrary, +) -> Result<(), String> { + append_sources(sets, "LIBOBS_LINUX_SOURCES", root, library)?; + library.file_name = Some("libobs.so.30".into()); + library + .definitions + .push(("OBS_INSTALL_PREFIX".into(), Some("\"/usr/local\"".into()))); + library + .definitions + .push(("SIMDE_ENABLE_OPENMP".into(), None)); + library.compile_options.extend( + [ + "-std=gnu17", + "-fno-strict-aliasing", + "-fvisibility=hidden", + "-fopenmp-simd", + ] + .map(String::from), + ); + library + .link_options + .extend(["-pthread", "-ldl", "-lm"].map(String::from)); + for package in ["x11", "x11-xcb", "xcb", "uuid"] { + add_package(library, target, package)?; + } + if options.pulseaudio { + add_package(library, target, "libpulse")?; + library + .sources + .push(root.join("libobs/build/libobs.pulse+.h.c")); + } else { + library + .sources + .push(root.join("libobs/build/libobs.null-audio+.h.c")); + } + if options.gio { + add_package(library, target, "gio-2.0")?; + library + .sources + .push(root.join("libobs/build/libobs.nix-dbus+.h.c")); + } + if options.wayland { + for package in ["wayland-client", "xkbcommon"] { + add_package(library, target, package)?; + } + library + .sources + .push(root.join("libobs/build/libobs.nix-wayland+.h.c")); + if options.gio { + library + .sources + .push(root.join("libobs/build/libobs.nix-portal-shortcuts+.h.c")); + library + .definitions + .push(("HAVE_GLOBAL_SHORTCUTS_PORTAL".into(), None)); + } + } + Ok(()) +} + +pub fn configure_variant( + root: &Path, + options: &Options, + sets: &BTreeMap>, + library: &mut SharedLibrary, + rust_archive: Option<&Path>, + config: &Path, +) -> Result<(), String> { + if let Some(archive) = rust_archive { + let archive = archive.canonicalize().map_err(|e| e.to_string())?; + let export_map = if options.hevc { + root.join("libobs/cmake/rust-exports.map") + } else { + // The static archive contains every port, while the C reference + // excludes HEVC when disabled. Match that public symbol surface. + let original = std::fs::read_to_string(root.join("libobs/cmake/rust-exports.map")) + .map_err(|e| e.to_string())?; + let disabled = original.replace("local:", "local:\n obs_hevc_keyframe;\n obs_parse_hevc_packet;\n obs_parse_hevc_packet_priority;\n obs_extract_hevc_headers;"); + let output = config.join("rust-exports-no-hevc.map"); + if std::fs::read_to_string(&output).ok().as_deref() != Some(&disabled) { + std::fs::write(&output, disabled).map_err(|e| e.to_string())?; + } + output + }; + let mut options = vec![ + "-Wl,--whole-archive".into(), + archive.display().to_string(), + "-Wl,--no-whole-archive".into(), + format!("-Wl,--version-script={}", export_map.display()), + ]; + // rustc --print native-static-libs for this target also requires util, + // rt and gcc_s; uuid/pthread/m/dl already follow through libobs. + options.extend(["-lutil", "-lrt", "-lgcc_s"].map(String::from)); + options.append(&mut library.link_options); + library.link_options = options; + } else { + append_sources(sets, "LIBOBS_LINUX_PORTED_SOURCES", root, library)?; + } + Ok(()) +} diff --git a/rust/obs-build/src/platform/mod.rs b/rust/obs-build/src/platform/mod.rs new file mode 100644 index 0000000000..aaccd590cc --- /dev/null +++ b/rust/obs-build/src/platform/mod.rs @@ -0,0 +1,944 @@ +//! Native target naming and linker conventions. Decisions use the requested +//! target triple, so a cross build never silently uses the build host's ABI. + +use std::{ + path::{Path, PathBuf}, + process::Command, +}; + +mod libobs_linux; + +pub(crate) enum PchKind { + Gnu, + Clang, +} + +pub(crate) fn pch_kind(target: &str, compiler: &cc::Tool) -> Result { + if !target.contains("linux") { + return Err(format!("compiled PCH for {target} is not implemented yet")); + } + if compiler.is_like_clang() && !compiler.is_like_msvc() { + Ok(PchKind::Clang) + } else if compiler.is_like_gnu() { + Ok(PchKind::Gnu) + } else { + Err("compiled PCH requires Linux GCC or Clang".into()) + } +} + +pub fn configure_libobs( + target: &str, + root: &Path, + options: &crate::libobs::Options, + sets: &std::collections::BTreeMap>, + library: &mut crate::SharedLibrary, +) -> Result<(), String> { + if target.contains("linux") { + libobs_linux::configure(target, root, options, sets, library) + } else { + Err(format!( + "real libobs native graph for {target} is not implemented yet" + )) + } +} + +pub fn shared_filename(target: &str, name: &str) -> String { + if target.contains("windows") { + format!("{name}.dll") + } else if target.contains("apple") { + format!("lib{name}.dylib") + } else { + format!("lib{name}.so") + } +} + +pub fn configure_shared_link( + target: &str, + command: &mut Command, + artifact: &Path, + objects: &[PathBuf], + dependencies: &[PathBuf], + msvc: bool, +) -> Result<(), String> { + if target.contains("windows") { + if msvc { + command.arg("/LD").args(objects); + command.args(dependencies.iter().map(|p| dependency_link_name(p, true))); + command + .arg("/link") + .arg(format!("/OUT:{}", artifact.display())) + .arg(format!( + "/IMPLIB:{}", + artifact.with_extension("lib").display() + )); + } else { + command.arg("-shared").args(objects); + command.args(dependencies.iter().map(|p| dependency_link_name(p, false))); + command.arg("-o").arg(artifact).arg(format!( + "-Wl,--out-implib,{}", + artifact.with_extension("dll.a").display() + )); + } + } else { + command.arg(if target.contains("apple") { + "-dynamiclib" + } else { + "-shared" + }); + command + .args(objects) + .args(dependencies) + .arg("-o") + .arg(artifact); + let filename = artifact + .file_name() + .ok_or("shared library has no filename")? + .to_string_lossy(); + if target.contains("apple") { + command.arg(format!("-Wl,-install_name,@rpath/{filename}")); + command.arg("-Wl,-rpath,@loader_path"); + } else { + command.arg(format!("-Wl,-soname,{filename}")); + command.arg("-Wl,--no-undefined"); + command.arg("-Wl,-rpath,$ORIGIN"); + } + for dependency in dependencies { + let parent = dependency + .parent() + .ok_or("dependency has no parent directory")?; + command.arg(format!("-Wl,-rpath,{}", parent.display())); + } + } + Ok(()) +} + +/// Prefer a shared dependency even when a .pc file lists static paths first. +fn package_shared_library_name(target: &str, name: &str) -> Option { + if target.contains("linux") { + Some(format!("lib{name}.so")) + } else if target.contains("apple") { + Some(format!("lib{name}.dylib")) + } else { + // Windows requires import-library handling rather than linking the DLL. + None + } +} + +pub fn package_shared_library(target: &str, paths: &[PathBuf], name: &str) -> Option { + let filename = package_shared_library_name(target, name)?; + paths + .iter() + .map(|path| path.join(&filename)) + .find(|path| path.is_file()) +} + +pub fn configure_libobs_variant( + build: &crate::NativeBuild, + root: &Path, + options: &crate::libobs::Options, + sets: &std::collections::BTreeMap>, + library: &mut crate::SharedLibrary, + rust_archive: Option<&Path>, +) -> Result<(), String> { + if build.target.contains("linux") { + libobs_linux::configure_variant( + root, + options, + sets, + library, + rust_archive, + &build.output.join("config"), + ) + } else { + Err(format!( + "real libobs variant for {} is not implemented yet", + build.target + )) + } +} + +pub fn configure_module(target: &str, library: &mut crate::SharedLibrary) -> Result<(), String> { + if target.contains("linux") { + library.file_name = Some(format!("{}.so", library.name)); + if !library + .c_compile_options + .iter() + .any(|option| option == "-std=gnu17") + { + library.c_compile_options.push("-std=gnu17".into()); + } + for flag in ["-fno-strict-aliasing", "-fvisibility=hidden"] { + if !library.compile_options.iter().any(|option| option == flag) { + library.compile_options.push(flag.into()); + } + } + for flag in ["-lm", "-pthread"] { + if !library.link_options.iter().any(|option| option == flag) { + library.link_options.push(flag.into()); + } + } + Ok(()) + } else { + Err(format!( + "native OBS module graph for {target} is not implemented yet" + )) + } +} + +pub fn configure_opengl( + target: &str, + root: &Path, + options: &crate::libobs::Options, + library: &mut crate::SharedLibrary, +) -> Result<(), String> { + if !target.contains("linux") { + return Err(format!( + "native OpenGL graph for {target} is not implemented yet" + )); + } + configure_module(target, library)?; + library.file_name = Some("libobs-opengl.so.33".into()); + library + .sources + .push(root.join("libobs-opengl/build/opengl.nix+.h.c")); + for package in ["simde", "libdrm", "gl", "egl", "x11", "x11-xcb", "xcb"] { + crate::libobs::add_package(library, target, package)?; + } + if options.wayland { + library + .sources + .push(root.join("libobs-opengl/build/opengl.nix-wayland+.h.c")); + for package in ["wayland-egl", "wayland-client"] { + crate::libobs::add_package(library, target, package)?; + } + } + library.link_options.push("-ldl".into()); + Ok(()) +} + +pub fn configure_glad( + target: &str, + root: &Path, + library: &mut crate::SharedLibrary, +) -> Result<(), String> { + if target.contains("linux") { + library.sources.push(root.join("deps/glad/src/glad_egl.c")); + Ok(()) + } else { + Err(format!( + "native GL loader graph for {target} is not implemented yet" + )) + } +} + +fn dependency_link_name(path: &Path, msvc: bool) -> PathBuf { + let path = dunce::simplified(path); + if path + .extension() + .and_then(|s| s.to_str()) + .is_some_and(|s| s.eq_ignore_ascii_case("dll")) + { + path.with_extension(if msvc { "lib" } else { "dll.a" }) + } else { + // Static archives already name linker inputs; they are not DLLs. + path.into() + } +} + +pub fn executable_filename(target: &str, name: &str) -> String { + if target.contains("windows") { + format!("{name}.exe") + } else { + name.into() + } +} + +pub fn configure_executable_link( + target: &str, + command: &mut Command, + artifact: &Path, + objects: &[PathBuf], + dependencies: &[PathBuf], + msvc: bool, +) -> Result<(), String> { + command.args(objects); + if target.contains("windows") { + command.args( + dependencies + .iter() + .map(|path| dependency_link_name(path, msvc)), + ); + if msvc { + command + .arg("/link") + .arg(format!("/OUT:{}", artifact.display())); + } else { + command.arg("-o").arg(artifact); + } + } else { + command.args(dependencies).arg("-o").arg(artifact); + command.arg(if target.contains("apple") { + "-Wl,-rpath,@executable_path" + } else { + "-Wl,-rpath,$ORIGIN" + }); + for dependency in dependencies { + let parent = dependency + .parent() + .ok_or("dependency has no parent directory")?; + command.arg(format!("-Wl,-rpath,{}", parent.display())); + } + } + Ok(()) +} + +pub fn configure_caption(target: &str, library: &mut crate::SharedLibrary) -> Result<(), String> { + configure_module(target, library)?; + library.compile_options.push("-fopenmp-simd".into()); + Ok(()) +} + +pub fn configure_shared_dependency( + target: &str, + root: &Path, + name: &str, + library: &mut crate::SharedLibrary, +) -> Result<(), String> { + configure_module(target, library)?; + if name == "happy-eyeballs" { + library + .include_dirs + .push(root.join("shared/happy-eyeballs/hosts/posix")); + } + Ok(()) +} + +pub fn configure_outputs( + target: &str, + root: &Path, + library: &mut crate::SharedLibrary, +) -> Result<(), String> { + if !target.contains("linux") { + return Err(format!( + "native outputs graph for {target} is not implemented yet" + )); + } + library + .include_dirs + .push(root.join("shared/happy-eyeballs/hosts/posix")); + Ok(()) +} + +pub fn configure_ffmpeg( + target: &str, + root: &Path, + library: &mut crate::SharedLibrary, +) -> Result<(), String> { + if !target.contains("linux") { + return Err(format!( + "native FFmpeg graph for {target} is not implemented yet" + )); + } + for group in ["vaapi", "vaapi-device-select", "vaapi-probe-policy"] { + library + .sources + .push(root.join(format!("plugins/obs-ffmpeg/build/obs-ffmpeg.{group}+.h.c"))); + } + for package in ["libva", "libva-drm", "libpci", "libdrm"] { + crate::libobs::add_package(library, target, package)?; + } + Ok(()) +} + +pub fn configure_qsv( + target: &str, + root: &Path, + options: &crate::plugins::QsvOptions, + library: &mut crate::SharedLibrary, +) -> Result<(), String> { + if !target.contains("linux") { + return Err(format!( + "QSV native graph for {target} is not implemented yet" + )); + } + if !target.starts_with("x86_64-") { + return Err(format!("QSV requires an x86_64 target, received {target}")); + } + pkg_config::Config::new() + .cargo_metadata(false) + .atleast_version("2.9") + .probe("vpl") + .map_err(|e| e.to_string())?; + for package in ["vpl", "libva", "libva-drm"] { + crate::libobs::add_package(library, target, package)?; + } + for group in ["linux+.hpp.cpp", "linux-c+.h.c", "core+.hpp.cpp", "c+.h.c"] { + library + .sources + .push(root.join(format!("plugins/obs-qsv11/build/obs-qsv11.{group}"))); + } + library.cpp_compile_options.push("-std=gnu++17".into()); + library + .cpp_compile_options + .push("-fvisibility-inlines-hidden".into()); + library.compile_options.push("-Wno-error=switch".into()); + library.definitions.push(( + "OBS_QSV_HOST_DEFS".into(), + Some("\"plugins/obs-qsv11/bits/linux_defs.h\"".into()), + )); + if options.hevc { + library.definitions.push(("ENABLE_HEVC".into(), None)); + } + Ok(()) +} + +pub fn configure_webrtc_tests( + target: &str, + library: &mut crate::SharedLibrary, +) -> Result<(), String> { + if !target.contains("linux") { + return Err(format!( + "standalone WHIP test graph for {target} is not implemented yet" + )); + } + library.c_compile_options.push("-std=gnu17".into()); + library.cpp_compile_options.push("-std=gnu++17".into()); + library.link_options.push("-lm".into()); + Ok(()) +} + +pub fn configure_webrtc( + target: &str, + root: &Path, + library: &mut crate::SharedLibrary, +) -> Result<(), String> { + if !target.contains("linux") { + return Err(format!( + "WebRTC native graph for {target} is not implemented yet" + )); + } + for group in ["posix", "core"] { + library.sources.push(root.join(format!( + "plugins/obs-webrtc/build/obs-webrtc.{group}+.hpp.cpp" + ))); + } + library + .cpp_compile_options + .extend(["-std=gnu++17".into(), "-fvisibility-inlines-hidden".into()]); + Ok(()) +} + +pub fn configure_source( + target: &str, + root: &Path, + source: crate::plugins::SourceModule, + library: &mut crate::SharedLibrary, +) -> Result<(), String> { + use crate::{libobs::add_package, plugins::SourceModule}; + if !target.contains("linux") { + return Err(format!( + "source module graph for {target} is not implemented yet" + )); + } + let groups: &[&str] = match source { + SourceModule::Jack | SourceModule::Sndio => &["nix"], + SourceModule::Vlc => &["core", "posix"], + SourceModule::PipeWire => &["nix"], + SourceModule::Image => &["core", "slideshow", "posix"], + SourceModule::Text => &["core", "nix"], + SourceModule::PulseAudio | SourceModule::Alsa | SourceModule::X11Capture => &["nix"], + SourceModule::V4l2 { udev: true } => &["nix", "nix-output", "nix-udev"], + SourceModule::V4l2 { udev: false } => &["nix", "nix-output"], + SourceModule::RtmpServices { .. } => &["core"], + }; + library.sources.extend( + groups + .iter() + .map(|group| root.join(format!("plugins/{0}/build/{0}.{group}+.h.c", source.name()))), + ); + let packages: &[&str] = match source { + SourceModule::Vlc => &[], + SourceModule::PipeWire => &["libpipewire-0.3", "gio-unix-2.0", "libdrm"], + SourceModule::Image => &[], + SourceModule::Text => &["freetype2", "fontconfig"], + SourceModule::PulseAudio => &["libpulse"], + SourceModule::Jack => &["jack"], + SourceModule::Sndio => &["sndio"], + SourceModule::Alsa => &["alsa"], + SourceModule::V4l2 { .. } => &["libv4l2", "libavcodec", "libavformat", "libavutil"], + SourceModule::X11Capture => &[ + "x11", + "x11-xcb", + "xcb", + "xcb-xfixes", + "xcb-randr", + "xcb-shm", + "xcb-xinerama", + "xcb-composite", + ], + SourceModule::RtmpServices { .. } => &["libcurl", "jansson"], + }; + for package in packages { + add_package(library, target, package)?; + } + match source { + SourceModule::Sndio => { + library.compile_options.push("-Wno-error=vla".into()); + } + SourceModule::Vlc => { + // Upstream loads libVLC at runtime and gracefully disables this + // source when it is absent. Consume headers without a link edge. + let headers = pkg_config::Config::new() + .cargo_metadata(false) + .probe("libvlc") + .ok(); + for variable in ["OBS_VLC_INCLUDE_DIR", "VLC_PATH"] { + println!("cargo:rerun-if-env-changed={variable}"); + } + let mut includes = Vec::new(); + if let Some(path) = std::env::var_os("OBS_VLC_INCLUDE_DIR") { + includes.push(std::path::PathBuf::from(path)); + } + if let Some(path) = std::env::var_os("VLC_PATH") { + includes.push(std::path::PathBuf::from(path).join("include")); + } + if let Some(headers) = headers { + includes.extend(headers.include_paths); + let mut definitions: Vec<_> = headers.defines.into_iter().collect(); + definitions.sort(); + library.definitions.extend(definitions); + } + includes.extend(["/usr/include".into(), "/usr/local/include".into()]); + if !includes + .iter() + .any(|path| path.join("vlc/libvlc.h").is_file()) + { + return Err("VLC headers not found; set OBS_VLC_INCLUDE_DIR or VLC_PATH".into()); + } + library.include_dirs.extend(includes); + } + SourceModule::PipeWire => { + pkg_config::Config::new() + .cargo_metadata(false) + .atleast_version("2.76") + .probe("gio-2.0") + .map_err(|e| e.to_string())?; + pkg_config::Config::new() + .cargo_metadata(false) + .atleast_version("0.3.33") + .probe("libpipewire-0.3") + .map_err(|e| e.to_string())?; + if pkg_config::Config::new() + .cargo_metadata(false) + .atleast_version("0.3.60") + .probe("libpipewire-0.3") + .is_ok() + { + library + .sources + .push(root.join("plugins/linux-pipewire/build/linux-pipewire.nix-camera+.h.c")); + } + library.include_dirs.push(root.join("deps/glad/include")); + } + SourceModule::V4l2 { udev: true } => { + add_package(library, target, "libudev")?; + library.definitions.push(("HAVE_UDEV".into(), None)); + } + SourceModule::X11Capture => { + library.include_dirs.push(root.join("deps/glad/include")); + } + SourceModule::RtmpServices { updates } => { + library + .sources + .push(root.join("shared/file-updater/build/file-updater.core+.h.c")); + library.include_dirs.push(root.join("shared/file-updater")); + library.definitions.push(( + "SERVICES_URL".into(), + Some("\"https://obsproject.com/obs2_update/rtmp-services\"".into()), + )); + if updates { + library + .definitions + .push(("ENABLE_SERVICE_UPDATES".into(), None)); + } + } + _ => {} + } + Ok(()) +} + +pub fn configure_c_tests( + build: &crate::NativeBuild, + library: &mut crate::SharedLibrary, + sanitizer: Option<&str>, +) -> Result<(), String> { + if !build.target.contains("linux") { + return Err(format!( + "C test graph for {} is not implemented yet", + build.target + )); + } + library.compile_options.extend([ + "-std=gnu17".into(), + "-pthread".into(), + "-Wno-double-promotion".into(), + "-Wno-cast-qual".into(), + "-Wno-format-nonliteral".into(), + "-Wno-shadow".into(), + "-fno-strict-aliasing".into(), + "-fvisibility=hidden".into(), + "-fopenmp-simd".into(), + ]); + library + .definitions + .push(("SIMDE_ENABLE_OPENMP".into(), None)); + library.link_options.extend([ + "-pthread".into(), + "-lm".into(), + "-Wl,--export-dynamic".into(), + ]); + let compiler = build.compiler(library, &build.output, false).get_compiler(); + let mut already_sanitized = compiler + .args() + .iter() + .any(|arg| arg.to_string_lossy().contains("-fsanitize=")); + for variable in [ + "CXXFLAGS".into(), + "HOST_CXXFLAGS".into(), + "TARGET_CXXFLAGS".into(), + format!("CXXFLAGS_{}", build.target), + format!("CXXFLAGS_{}", build.target.replace('-', "_")), + ] { + println!("cargo:rerun-if-env-changed={variable}"); + already_sanitized |= std::env::var_os(variable) + .is_some_and(|flags| flags.to_string_lossy().contains("-fsanitize=")); + } + if let Some(sanitizer) = sanitizer.filter(|_| !already_sanitized) { + let flag = format!("-fsanitize={sanitizer}"); + library + .compile_options + .extend([flag.clone(), "-fno-omit-frame-pointer".into()]); + if sanitizer.split(',').any(|name| name == "undefined") { + library + .compile_options + .push("-fno-sanitize-recover=undefined".into()); + } + library.link_options.push(flag); + } + Ok(()) +} + +pub fn configure_cpp17(target: &str, library: &mut crate::SharedLibrary) { + let standard = if target.contains("msvc") { + "/std:c++17" + } else { + "-std=gnu++17" + }; + if !library + .cpp_compile_options + .iter() + .any(|option| option == standard) + { + library.cpp_compile_options.push(standard.into()); + } +} + +pub fn configure_scripting(target: &str, library: &mut crate::SharedLibrary) -> Result<(), String> { + if !target.contains("linux") { + return Err("scripting native graph is currently Linux-only".into()); + } + configure_cpp_module(target, library)?; + library.file_name = None; + library.c_compile_options.push("-Wno-cast-qual".into()); + Ok(()) +} + +pub fn configure_frontend_tools( + target: &str, + root: &Path, + library: &mut crate::SharedLibrary, +) -> Result<(), String> { + configure_cpp_module(target, library)?; + // configure_cpp_module currently admits only Linux. + for group in [ + "frontend-tools.linux+.hpp.cpp", + "frontend-tools.host-posix+.h.c", + ] { + library + .sources + .push(root.join("plugins/frontend-tools/build").join(group)); + } + crate::libobs::add_package(library, target, "x11")?; + Ok(()) +} + +pub fn python_library_name(target: &str, libraries: &[String]) -> Result { + if !target.contains("linux") { + return Err("Python library discovery is currently Linux-only".into()); + } + let library = libraries + .iter() + .find(|name| name.starts_with("python")) + .ok_or("Python pkg-config lacks a Python library")?; + Ok(format!("lib{library}.so")) +} + +pub fn scripting_module_name(target: &str, language: &str) -> Result { + if !target.contains("linux") { + return Err("scripting binding naming is currently Linux-only".into()); + } + match language { + "lua" => Ok("obslua.so".into()), + "python" => Ok("_obspython.so".into()), + _ => Err(format!("unknown scripting language {language}")), + } +} + +pub fn configure_nvenc( + target: &str, + root: &Path, + library: &mut crate::SharedLibrary, +) -> Result<(), String> { + if !target.contains("linux") { + return Err("NVENC native graph is currently Linux-only".into()); + } + for group in ["caps-cache-linux", "linux", "caps-cache", "override"] { + library + .sources + .push(root.join(format!("plugins/obs-nvenc/build/obs-nvenc.{group}+.h.c"))); + } + Ok(()) +} + +pub fn configure_nvenc_rust( + target: &str, + library: &mut crate::SharedLibrary, +) -> Result<(), String> { + if !target.contains("linux") { + return Err("NVENC Rust loader native linking is currently Linux-only".into()); + } + library.link_options.extend([ + "-Wl,--exclude-libs,ALL".into(), + "-ldl".into(), + "-lpthread".into(), + "-lm".into(), + ]); + Ok(()) +} + +pub fn configure_nvenc_helper( + target: &str, + library: &mut crate::SharedLibrary, +) -> Result<(), String> { + if !target.contains("linux") { + return Err("NVENC capability helper native linking is currently Linux-only".into()); + } + configure_cpp17(target, library); + library + .link_options + .extend(["-pthread".into(), "-ldl".into()]); + Ok(()) +} + +pub fn configure_cpp_module( + target: &str, + library: &mut crate::SharedLibrary, +) -> Result<(), String> { + configure_module(target, library)?; + configure_cpp17(target, library); + library + .cpp_compile_options + .push("-fvisibility-inlines-hidden".into()); + Ok(()) +} + +pub fn configure_frontend_api( + target: &str, + library: &mut crate::SharedLibrary, +) -> Result<(), String> { + configure_cpp_module(target, library)?; + library.file_name = Some("libobs-frontend-api.so.30".into()); + Ok(()) +} + +pub fn configure_vst( + target: &str, + root: &Path, + library: &mut crate::SharedLibrary, +) -> Result<(), String> { + configure_cpp_module(target, library)?; + library + .sources + .push(root.join("plugins/obs-vst/build/obs-vst.linux+.hpp.cpp")); + crate::libobs::add_package(library, target, "xcb")?; + Ok(()) +} + +pub fn configure_application( + target: &str, + root: &Path, + manifest: &serde_json::Value, + config: &Path, + library: &mut crate::SharedLibrary, +) -> Result<(), String> { + if !target.contains("linux") { + return Err(format!( + "frontend application graph for {target} is not implemented yet" + )); + } + configure_cpp_module(target, library)?; + library.file_name = None; + let inputs: Vec = + serde_json::from_value(manifest["linux"].clone()).map_err(|e| e.to_string())?; + library + .sources + .extend(inputs.iter().map(|path| root.join(path))); + for package in ["Qt6DBus", "libpci", "x11", "x11-xcb", "xcb"] { + crate::libobs::add_package(library, target, package)?; + } + library.definitions.extend([ + ("OBS_INSTALL_PREFIX".into(), Some("\"/usr/local\"".into())), + ("DL_OPENGL".into(), Some("\"libobs-opengl.so.33\"".into())), + ("DL_D3D11".into(), Some("\"\"".into())), + ("DL_METAL".into(), Some("\"\"".into())), + ]); + library + .link_options + .extend(["-lgcc_s", "-lutil", "-lrt", "-ldl"].map(String::from)); + let mut paths = + std::fs::read_to_string(root.join("frontend/plugin-manager/LoaderPaths_Linux.hpp.in")) + .map_err(|e| e.to_string())?; + for (name, value) in [ + ("OBS_PLATFORM_INSTALL_PATH", "/usr/local/"), + ("OBS_PLATFORM_LIBRARY_PATH", "lib64/"), + ("OBS_PLATFORM_DATA_PATH", "share/"), + ( + "OBS_PLATFORM_PLUGIN_MODULE_PATH", + "/usr/local/lib64/obs-modules/plugins", + ), + ( + "OBS_PLATFORM_PLUGIN_DATA_PATH", + "/usr/local/share/obs/obs-modules/plugins", + ), + ] { + paths = paths.replace(&format!("@{name}@"), value); + } + let output = config.join("LoaderPaths_Linux.hpp"); + if std::fs::read_to_string(&output).ok().as_deref() != Some(&paths) { + std::fs::write(output, paths).map_err(|e| e.to_string())?; + } + Ok(()) +} + +pub fn configure_browser( + target: &str, + root: &Path, + library: &mut crate::SharedLibrary, +) -> Result<(), String> { + configure_cpp_module(target, library)?; + library + .cpp_compile_options + .retain(|flag| !flag.starts_with("-std=")); + library.cpp_compile_options.push("-std=c++20".into()); + library.sources.extend([ + root.join("plugins/obs-browser/drm-format.cpp"), + root.join("plugins/obs-browser/deps/ip-string-posix.cpp"), + ]); + for package in ["x11", "libdrm"] { + crate::libobs::add_package(library, target, package)?; + } + library.link_options.push("-ldl".into()); + Ok(()) +} + +pub fn configure_browser_helper( + target: &str, + library: &mut crate::SharedLibrary, +) -> Result<(), String> { + if !target.contains("linux") { + return Err(format!("browser helper for {target} is not implemented")); + } + library.cpp_compile_options.push("-std=c++20".into()); + library + .link_options + .extend(["-pthread".into(), "-ldl".into()]); + Ok(()) +} + +pub fn configure_websocket(target: &str, library: &mut crate::SharedLibrary) -> Result<(), String> { + configure_cpp_module(target, library)?; + fn include(variable: &str, header: &str) -> Result { + println!("cargo:rerun-if-env-changed={variable}"); + let candidates = match std::env::var_os(variable) { + Some(path) => vec![PathBuf::from(path)], + None => vec![ + PathBuf::from("/usr/include"), + PathBuf::from("/usr/local/include"), + PathBuf::from("/usr/include/qrcodegen"), + PathBuf::from("/usr/local/include/qrcodegen"), + ], + }; + candidates + .into_iter() + .find(|path| path.join(header).is_file()) + .ok_or_else(|| { + format!("obs-websocket requires {header}; set {variable} to its include directory") + }) + } + let websocket = include("OBS_WEBSOCKETPP_INCLUDE_DIR", "websocketpp/version.hpp")?; + let version_path = websocket.join("websocketpp/version.hpp"); + println!("cargo:rerun-if-changed={}", version_path.display()); + let header = std::fs::read_to_string(&version_path).map_err(|e| e.to_string())?; + let version = |name: &str| -> Result { + header + .lines() + .find(|line| line.contains(name)) + .and_then(|line| line.split('=').nth(1)) + .and_then(|value| value.trim().trim_end_matches(';').parse().ok()) + .ok_or_else(|| format!("cannot read WebSocket++ {name}")) + }; + if (version("major_version")?, version("minor_version")?) < (0, 8) { + return Err("obs-websocket requires WebSocket++ >=0.8".into()); + } + library.include_dirs.push(websocket); + library + .include_dirs + .push(include("OBS_QRCODEGEN_INCLUDE_DIR", "qrcodegen.hpp")?); + println!("cargo:rerun-if-env-changed=OBS_QRCODEGEN_LIBRARY"); + if let Some(path) = std::env::var_os("OBS_QRCODEGEN_LIBRARY") { + library.dependencies.push( + PathBuf::from(path) + .canonicalize() + .map_err(|e| e.to_string())?, + ); + } else { + library.link_options.push("-lqrcodegencpp".into()); + } + Ok(()) +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn shared_dependency_wins_over_an_earlier_static_archive() { + let dir = tempfile::tempdir().unwrap(); + let archive_dir = dir.path().join("static"); + let shared_dir = dir.path().join("shared"); + std::fs::create_dir_all(&archive_dir).unwrap(); + std::fs::create_dir_all(&shared_dir).unwrap(); + std::fs::write(archive_dir.join("libz.a"), []).unwrap(); + let shared = shared_dir.join("libz.so"); + std::fs::write(&shared, []).unwrap(); + let paths = [archive_dir, shared_dir]; + assert_eq!( + package_shared_library("x86_64-unknown-linux-gnu", &paths, "z"), + Some(shared) + ); + assert_eq!( + package_shared_library("x86_64-unknown-linux-gnu", &paths, "missing"), + None + ); + } +} diff --git a/rust/obs-build/src/plugins.rs b/rust/obs-build/src/plugins.rs new file mode 100644 index 0000000000..ca543f9f96 --- /dev/null +++ b/rust/obs-build/src/plugins.rs @@ -0,0 +1,604 @@ +//! Native OBS module builds using the same engine as bundled libobs. +use crate::{NativeBuild, SharedLibrary, deps::shared_archive, libobs::add_package}; +use std::path::{Path, PathBuf}; +mod browser; +mod frontend_tools; +mod websocket; +pub use browser::{ + Artifacts as BrowserArtifacts, Options as BrowserOptions, build as build_browser, +}; +pub use frontend_tools::build as build_frontend_tools; +pub use websocket::{Options as WebsocketOptions, build as build_websocket}; + +#[derive(Debug)] +pub struct Module { + pub library: PathBuf, + pub data: PathBuf, +} + +#[derive(Debug)] +pub struct NvencArtifacts { + pub reference: Module, + pub with_rust: Module, + pub helper: PathBuf, +} + +pub fn build_nvenc_pair( + build: &NativeBuild, + root: &Path, + core: &Path, + rust_archive: &Path, + ffmpeg_ids: bool, +) -> Result { + let root = root.canonicalize().map_err(|e| e.to_string())?; + pkg_config::Config::new() + .cargo_metadata(false) + .atleast_version("12") + .probe("ffnvcodec") + .map_err(|e| format!("NVENC requires ffnvcodec >=12: {e}"))?; + let mut library = module(build, &root, core, "obs-nvenc")?; + library.include_dirs.push(root.join("deps/glad/include")); + crate::platform::configure_nvenc(&build.target, &root, &mut library)?; + add_package(&mut library, &build.target, "ffnvcodec")?; + library.include_dirs.push(root.join("shared/opts-parser")); + library + .dependencies + .push(shared_archive(build, &root, "opts-parser")?); + library + .dependencies + .push(crate::graphics::build_glad(build, &root)?); + if ffmpeg_ids { + library + .definitions + .push(("REGISTER_FFMPEG_IDS".into(), None)); + } + // Both plugins share all objects except their CUDA driver loader. + let mut common = library.clone(); + common.name = "obs-nvenc-common".into(); + library.precompiled_objects = build.objects(&common)?.2; + library.sources = vec![root.join("plugins/obs-nvenc/build/obs-nvenc.cuda-load+.h.c")]; + let reference = Module { + library: build.shared_library(&library)?, + data: root.join("plugins/obs-nvenc/data"), + }; + library.name = "obs-nvenc-with-rust".into(); + library.file_name = reference + .library + .file_name() + .map(|name| name.to_string_lossy().into_owned()); + library.sources = vec![root.join("plugins/obs-nvenc/build/obs-nvenc.cuda-load-rust+.h.c")]; + library + .dependencies + .push(rust_archive.canonicalize().map_err(|e| e.to_string())?); + crate::platform::configure_nvenc_rust(&build.target, &mut library)?; + let with_rust = Module { + library: build.shared_library(&library)?, + data: reference.data.clone(), + }; + let mut helper = SharedLibrary { + name: "obs-nvenc-test".into(), + sources: vec![ + root.join("plugins/obs-nvenc/obs-nvenc-test/build/obs-nvenc-test.core+.hpp.cpp"), + ], + include_dirs: vec![root.clone()], + ..SharedLibrary::default() + }; + add_package(&mut helper, &build.target, "ffnvcodec")?; + crate::platform::configure_nvenc_helper(&build.target, &mut helper)?; + Ok(NvencArtifacts { + reference, + with_rust, + helper: build.executable(&helper)?, + }) +} + +#[derive(Clone, Debug)] +pub struct FiltersOptions { + pub speexdsp: bool, + pub rnnoise: bool, +} + +impl Default for FiltersOptions { + fn default() -> Self { + Self { + speexdsp: true, + rnnoise: true, + } + } +} + +pub fn build_transitions(build: &NativeBuild, root: &Path, core: &Path) -> Result { + let root = root.canonicalize().map_err(|e| e.to_string())?; + let library = module(build, &root, core, "obs-transitions")?; + finish(build, &root, library) +} + +pub fn build_filters( + build: &NativeBuild, + root: &Path, + core: &Path, + options: &FiltersOptions, +) -> Result { + let root = root.canonicalize().map_err(|e| e.to_string())?; + let mut library = module(build, &root, core, "obs-filters")?; + if options.speexdsp { + add_package(&mut library, &build.target, "speexdsp")?; + library + .definitions + .push(("LIBSPEEXDSP_ENABLED".into(), None)); + } + if options.rnnoise { + if add_package(&mut library, &build.target, "rnnoise").is_err() { + // Match OBS's Linux fallback when no system RNNoise is installed. + let directory = root.join("plugins/obs-filters"); + let sources: Vec = serde_json::from_slice( + &std::fs::read(directory.join("build/rnnoise-sources.json")) + .map_err(|e| e.to_string())?, + ) + .map_err(|e| e.to_string())?; + let rnnoise = SharedLibrary { + name: "obs-rnnoise".into(), + sources: sources + .iter() + .map(|source| directory.join(source)) + .collect(), + include_dirs: vec![directory.join("rnnoise/include")], + definitions: vec![("COMPILE_OPUS".into(), None)], + compile_options: library.compile_options.clone(), + ..SharedLibrary::default() + }; + library.dependencies.push(build.static_library(&rnnoise)?); + library.include_dirs.extend(rnnoise.include_dirs); + } + library + .definitions + .push(("LIBRNNOISE_ENABLED".into(), None)); + } + if options.speexdsp || options.rnnoise { + library + .sources + .push(root.join("plugins/obs-filters/build/obs-filters.noise-suppress+.h.c")); + library + .definitions + .push(("HAS_NOISEREDUCTION".into(), None)); + } + finish(build, &root, library) +} + +fn module( + build: &NativeBuild, + root: &Path, + core: &Path, + name: &str, +) -> Result { + let mut library = SharedLibrary { + name: name.into(), + sources: vec![root.join(format!("plugins/{name}/build/{name}.core+.h.c"))], + include_dirs: vec![ + root.into(), + root.join("libobs"), + root.join("plugins").join(name), + build.output.join("config"), + ], + dependencies: vec![core.canonicalize().map_err(|e| e.to_string())?], + ..SharedLibrary::default() + }; + crate::platform::configure_module(&build.target, &mut library)?; + // libobs public graphics headers expose SIMDe vector types. + add_package(&mut library, &build.target, "simde")?; + Ok(library) +} + +fn finish(build: &NativeBuild, root: &Path, library: SharedLibrary) -> Result { + Ok(Module { + data: root.join("plugins").join(&library.name).join("data"), + library: build.shared_library(&library)?, + }) +} + +#[derive(Clone, Debug)] +pub struct FfmpegOptions { + pub logging: bool, + pub mpegts: bool, + pub nvenc: bool, + pub mux_debug: bool, +} + +impl Default for FfmpegOptions { + fn default() -> Self { + Self { + logging: false, + mpegts: true, + nvenc: false, + mux_debug: false, + } + } +} + +#[derive(Debug)] +pub struct FfmpegArtifacts { + pub module: Module, + pub muxer: PathBuf, +} + +impl FfmpegArtifacts { + /// Deploy the mux helper beside the executable that loads the module. + pub fn deploy_muxer(&self, bin_dir: &Path) -> Result { + let name = self + .muxer + .file_name() + .ok_or("FFmpeg helper has no filename")?; + std::fs::create_dir_all(bin_dir) + .map_err(|e| format!("create {}: {e}", bin_dir.display()))?; + let destination = bin_dir.join(name); + let source = self.muxer.canonicalize().map_err(|e| e.to_string())?; + if destination.canonicalize().ok().as_ref() == Some(&source) { + return Ok(destination); + } + std::fs::copy(&self.muxer, &destination).map_err(|e| { + format!( + "deploy {} to {}: {e}", + self.muxer.display(), + destination.display() + ) + })?; + Ok(destination) + } +} + +/// Build the optional original FDK AAC encoder module. +pub fn build_fdk(build: &NativeBuild, root: &Path, core: &Path) -> Result { + let root = root.canonicalize().map_err(|e| e.to_string())?; + let mut library = module(build, &root, core, "obs-libfdk")?; + add_package(&mut library, &build.target, "fdk-aac")?; + finish(build, &root, library) +} + +#[derive(Clone, Debug)] +pub struct DataChannelSdk { + pub include_dir: PathBuf, + pub library: PathBuf, + pub media: bool, + pub websocket: bool, +} + +#[derive(Clone, Copy, Debug)] +pub struct WebRtcOptions { + pub hevc: bool, + pub unity: bool, + pub pch: bool, +} + +impl Default for WebRtcOptions { + fn default() -> Self { + Self { + hevc: true, + unity: true, + pch: false, + } + } +} + +/// Build the original WebRTC WHIP output and service module. +pub fn build_webrtc( + build: &NativeBuild, + root: &Path, + core: &Path, + sdk: &DataChannelSdk, + options: &WebRtcOptions, +) -> Result { + if !sdk.media { + return Err("OBS WebRTC requires libdatachannel media support".into()); + } + let root = root.canonicalize().map_err(|e| e.to_string())?; + let include = sdk.include_dir.canonicalize().map_err(|e| e.to_string())?; + let version = std::fs::read_to_string(include.join("rtc/version.h")) + .map_err(|e| format!("read libdatachannel version: {e}"))?; + let mut numbers = Vec::new(); + for field in [ + "RTC_VERSION_MAJOR", + "RTC_VERSION_MINOR", + "RTC_VERSION_PATCH", + ] { + let number = version + .lines() + .find_map(|line| { + let mut words = line.split_whitespace(); + (words.next() == Some("#define") && words.next() == Some(field)) + .then(|| words.next().and_then(|word| word.parse::().ok())) + .flatten() + }) + .ok_or_else(|| format!("invalid libdatachannel version field {field}"))?; + numbers.push(number); + } + if (numbers[0], numbers[1], numbers[2]) < (0, 20, 0) { + return Err("OBS WebRTC requires libdatachannel >= 0.20".into()); + } + let mut library = module(build, &root, core, "obs-webrtc")?; + library.sources.clear(); + library.include_dirs.push(include); + library + .dependencies + .push(sdk.library.canonicalize().map_err(|e| e.to_string())?); + for (name, enabled) in [ + ("RTC_ENABLE_MEDIA", sdk.media), + ("RTC_ENABLE_WEBSOCKET", sdk.websocket), + ] { + library + .definitions + .push((name.into(), Some(u8::from(enabled).to_string()))); + } + add_package(&mut library, &build.target, "libcurl")?; + if options.hevc { + library.definitions.push(("ENABLE_HEVC".into(), None)); + } + crate::platform::configure_webrtc(&build.target, &root, &mut library)?; + if !options.unity { + library.sources = build.separate_group_sources(&root, &library.sources)?; + } + if options.pch { + library.precompiled_headers = crate::groups::headers(&root, &library.sources)?; + } + println!("cargo:rerun-if-changed={}", sdk.include_dir.display()); + println!("cargo:rerun-if-changed={}", sdk.library.display()); + finish(build, &root, library) +} + +#[derive(Clone, Copy, Debug)] +pub struct QsvOptions { + pub hevc: bool, + pub unity: bool, + pub pch: bool, +} + +impl Default for QsvOptions { + fn default() -> Self { + Self { + hevc: true, + unity: true, + pch: false, + } + } +} + +/// Build the original Intel Quick Sync encoder module. +pub fn build_qsv( + build: &NativeBuild, + root: &Path, + core: &Path, + options: &QsvOptions, +) -> Result { + let root = root.canonicalize().map_err(|e| e.to_string())?; + let mut library = module(build, &root, core, "obs-qsv11")?; + library.sources.clear(); + crate::platform::configure_qsv(&build.target, &root, options, &mut library)?; + if !options.unity { + library.sources = build.separate_group_sources(&root, &library.sources)?; + } + if options.pch { + library.precompiled_headers = crate::groups::headers(&root, &library.sources)?; + } + finish(build, &root, library) +} + +pub fn build_x264(build: &NativeBuild, root: &Path, core: &Path) -> Result { + let root = root.canonicalize().map_err(|e| e.to_string())?; + let mut library = module(build, &root, core, "obs-x264")?; + library.include_dirs.push(root.join("shared/opts-parser")); + library + .dependencies + .push(shared_archive(build, &root, "opts-parser")?); + add_package(&mut library, &build.target, "x264")?; + finish(build, &root, library) +} + +pub fn build_outputs( + build: &NativeBuild, + root: &Path, + core: &Path, + options: &crate::libobs::Options, +) -> Result { + let root = root.canonicalize().map_err(|e| e.to_string())?; + let mut library = module(build, &root, core, "obs-outputs")?; + for group in ["av1", "mp4-mux", "rtmp", "net-if"] { + library.sources.push(root.join(format!( + "plugins/obs-outputs/build/obs-outputs.{group}+.h.c" + ))); + } + if options.hevc { + library + .sources + .push(root.join("plugins/obs-outputs/build/obs-outputs.hevc+.h.c")); + library.definitions.push(("ENABLE_HEVC".into(), None)); + } + for source in [ + "amf", "cencode", "hashswf", "log", "md5", "parseurl", "rtmp", + ] { + library + .sources + .push(root.join(format!("plugins/obs-outputs/librtmp/{source}.c"))); + } + for name in ["opts-parser", "happy-eyeballs", "bpm"] { + library.include_dirs.push(root.join("shared").join(name)); + library + .dependencies + .push(shared_archive(build, &root, name)?); + } + library + .dependencies + .push(crate::libobs::build_caption(build, &root)?); + library + .definitions + .extend(["USE_MBEDTLS", "CRYPTO"].map(|name| (name.into(), None))); + for package in ["mbedtls", "mbedx509", "mbedcrypto", "zlib", "jansson"] { + add_package(&mut library, &build.target, package)?; + } + crate::platform::configure_outputs(&build.target, &root, &mut library)?; + finish(build, &root, library) +} + +pub fn build_ffmpeg( + build: &NativeBuild, + root: &Path, + core: &Path, + options: &crate::libobs::Options, + features: &FfmpegOptions, +) -> Result { + let root = root.canonicalize().map_err(|e| e.to_string())?; + let mut library = module(build, &root, core, "obs-ffmpeg")?; + for group in ["mux", "output", "source", "video-encoders"] { + library + .sources + .push(root.join(format!("plugins/obs-ffmpeg/build/obs-ffmpeg.{group}+.h.c"))); + } + for (enabled, group, definition) in [ + (features.logging, "logging", "ENABLE_FFMPEG_LOGGING"), + (features.nvenc, "nvenc", "ENABLE_FFMPEG_NVENC"), + (features.mpegts, "mpegts", "NEW_MPEGTS_OUTPUT"), + ] { + if enabled { + library + .sources + .push(root.join(format!("plugins/obs-ffmpeg/build/obs-ffmpeg.{group}+.h.c"))); + library.definitions.push((definition.into(), None)); + } + } + if options.hevc { + library.definitions.push(("ENABLE_HEVC".into(), None)); + } + for group in ["cache", "core"] { + library.sources.push(root.join(format!( + "shared/media-playback/build/media-playback.{group}+.h.c" + ))); + } + library.include_dirs.extend([ + root.join("shared/media-playback"), + root.join("shared/opts-parser"), + ]); + library + .dependencies + .push(shared_archive(build, &root, "opts-parser")?); + for package in [ + "libavcodec", + "libavfilter", + "libavformat", + "libavdevice", + "libavutil", + "libswscale", + "libswresample", + ] { + add_package(&mut library, &build.target, package)?; + } + if features.mpegts { + for package in ["librist", "srt"] { + add_package(&mut library, &build.target, package)?; + } + } + crate::platform::configure_ffmpeg(&build.target, &root, &mut library)?; + let module = finish(build, &root, library)?; + let mut mux = SharedLibrary { + name: "obs-ffmpeg-mux".into(), + sources: vec![root.join("plugins/obs-ffmpeg/ffmpeg-mux/build/ffmpeg-mux.core+.h.c")], + include_dirs: vec![ + root.clone(), + root.join("libobs"), + root.join("plugins/obs-ffmpeg/ffmpeg-mux"), + build.output.join("config"), + ], + dependencies: vec![core.into()], + ..SharedLibrary::default() + }; + crate::platform::configure_module(&build.target, &mut mux)?; + // Executable naming, not the MODULE filename selected by configure_module. + mux.file_name = None; + if features.mux_debug { + mux.definitions + .push(("ENABLE_FFMPEG_MUX_DEBUG".into(), None)); + } + for package in ["simde", "libavcodec", "libavutil", "libavformat"] { + add_package(&mut mux, &build.target, package)?; + } + Ok(FfmpegArtifacts { + module, + muxer: build.executable(&mux)?, + }) +} + +/// Built-in source and service modules with independent optional features. +#[derive(Clone, Copy, Debug)] +pub enum SourceModule { + Vlc, + Image, + Text, + PulseAudio, + Jack, + Sndio, + PipeWire, + Alsa, + V4l2 { udev: bool }, + X11Capture, + RtmpServices { updates: bool }, +} + +impl SourceModule { + pub fn name(self) -> &'static str { + match self { + Self::Vlc => "vlc-video", + Self::Image => "image-source", + Self::Text => "text-freetype2", + Self::PulseAudio => "linux-pulseaudio", + Self::Jack => "linux-jack", + Self::Sndio => "sndio", + Self::PipeWire => "linux-pipewire", + Self::Alsa => "linux-alsa", + Self::V4l2 { .. } => "linux-v4l2", + Self::X11Capture => "linux-capture", + Self::RtmpServices { .. } => "rtmp-services", + } + } +} + +pub fn build_source( + build: &NativeBuild, + root: &Path, + core: &Path, + source: SourceModule, +) -> Result { + let root = root.canonicalize().map_err(|e| e.to_string())?; + let mut library = module(build, &root, core, source.name())?; + library.sources.clear(); + crate::platform::configure_source(&build.target, &root, source, &mut library)?; + if matches!(source, SourceModule::Jack) + && build + .compiler(&library, &build.output, false) + .get_compiler() + .is_like_clang() + { + library + .c_compile_options + .push("-Wno-error=sign-compare".into()); + } + if matches!(source, SourceModule::X11Capture | SourceModule::PipeWire) { + library + .dependencies + .push(crate::graphics::build_glad(build, &root)?); + } + finish(build, &root, library) +} + +pub fn build_vst(build: &NativeBuild, root: &Path, core: &Path) -> Result { + let root = root.canonicalize().map_err(|e| e.to_string())?; + let mut library = module(build, &root, core, "obs-vst")?; + library.sources = vec![root.join("plugins/obs-vst/build/obs-vst.core+.hpp.cpp")]; + library + .include_dirs + .push(root.join("plugins/obs-vst/vst_header")); + crate::platform::configure_vst(&build.target, &root, &mut library)?; + add_package(&mut library, &build.target, "Qt6Widgets")?; + crate::qt::moc( + &mut library, + &root.join("plugins/obs-vst/headers/VSTPlugin.h"), + &build.output.join("obs-vst/qt/moc_VSTPlugin.cpp"), + )?; + finish(build, &root, library) +} diff --git a/rust/obs-build/src/plugins/browser.rs b/rust/obs-build/src/plugins/browser.rs new file mode 100644 index 0000000000..0b7dbaf181 --- /dev/null +++ b/rust/obs-build/src/plugins/browser.rs @@ -0,0 +1,226 @@ +//! The original browser source, browser-panel interfaces and CEF helper. +use super::{Module, finish, module}; +use crate::{NativeBuild, SharedLibrary, frontend, libobs::add_package}; +use std::path::{Path, PathBuf}; + +pub struct Options { + pub cef_root: PathBuf, + pub panels: bool, + pub unity: bool, +} + +pub struct Artifacts { + pub module: Module, + pub helper: PathBuf, + pub cef_root: PathBuf, +} + +impl Artifacts { + /// Place CEF resources and its subprocess helper beside the browser module. + pub fn deploy_runtime(&self, directory: &Path) -> Result<(), String> { + fn copy_tree(source: &Path, destination: &Path) -> Result<(), String> { + std::fs::create_dir_all(destination).map_err(|e| e.to_string())?; + for entry in std::fs::read_dir(source).map_err(|e| e.to_string())? { + let entry = entry.map_err(|e| e.to_string())?; + let target = destination.join(entry.file_name()); + if entry.file_type().map_err(|e| e.to_string())?.is_dir() { + copy_tree(&entry.path(), &target)?; + } else { + std::fs::copy(entry.path(), target).map_err(|e| e.to_string())?; + } + } + Ok(()) + } + for name in ["Release", "Resources"] { + let source = self.cef_root.join(name); + println!("cargo:rerun-if-changed={}", source.display()); + copy_tree(&source, directory)?; + } + std::fs::copy( + &self.helper, + directory.join( + self.helper + .file_name() + .ok_or("browser helper has no filename")?, + ), + ) + .map_err(|e| e.to_string())?; + Ok(()) + } +} + +pub fn build( + build: &NativeBuild, + root: &Path, + core: &Path, + api: &Path, + options: &Options, +) -> Result { + let root = dunce::canonicalize(root).map_err(|e| e.to_string())?; + let source = root.join("plugins/obs-browser"); + let sdk = dunce::canonicalize(&options.cef_root).map_err(|e| format!("CEF SDK: {e}"))?; + let mut library = module(build, &root, core, "obs-browser")?; + library.sources.clear(); + crate::platform::configure_browser(&build.target, &root, &mut library)?; + let host_sources = std::mem::take(&mut library.sources); + println!("cargo:rerun-if-changed={}", source.display()); + println!("cargo:rerun-if-changed={}", sdk.join("include").display()); + let version = std::fs::read_to_string(sdk.join("include/cef_version.h")) + .map_err(|e| format!("CEF version header: {e}"))?; + let major: u32 = version + .lines() + .find_map(|line| line.strip_prefix("#define CEF_VERSION_MAJOR ")) + .ok_or("CEF major version missing")? + .trim() + .parse() + .map_err(|e| format!("CEF version: {e}"))?; + if major < 95 { + return Err("obs-browser requires CEF >=95".into()); + } + let find = |candidates: &[&str]| -> Result { + candidates + .iter() + .map(|path| sdk.join(path)) + .find(|path| path.is_file()) + .ok_or_else(|| format!("CEF SDK lacks {}", candidates.join(" or "))) + .and_then(|path| dunce::canonicalize(path).map_err(|e| e.to_string())) + }; + let cef = find(&["Release/libcef.so", "libcef.so"])?; + let wrapper = find(&[ + "build/libcef_dll_wrapper/libcef_dll_wrapper.a", + "libcef_dll_wrapper/libcef_dll_wrapper.a", + "build/libcef_dll/libcef_dll_wrapper.a", + ])?; + for path in [&cef, &wrapper] { + println!("cargo:rerun-if-changed={}", path.display()); + } + library.include_dirs.extend([ + sdk.clone(), + sdk.join("include"), + source.join("deps"), + source.join("panel"), + root.join("frontend/api"), + root.join("plugins/obs-websocket/lib"), + ]); + library + .dependencies + .extend([api.into(), wrapper.clone(), cef.clone()]); + pkg_config::Config::new() + .cargo_metadata(false) + .atleast_version("3.11") + .probe("nlohmann_json") + .map_err(|e| format!("obs-browser requires nlohmann_json >=3.11: {e}"))?; + // The pinned source uses QApplication headers and QToolTip symbols outside + // the optional panel implementation, so both modes require Qt Widgets. + for package in ["nlohmann_json", "Qt6Widgets"] { + add_package(&mut library, &build.target, package)?; + } + let manifest: std::collections::BTreeMap> = + serde_json::from_str(include_str!("../../manifests/obs-browser.json")) + .map_err(|e| e.to_string())?; + let inputs = manifest + .get("common") + .ok_or("browser sources missing")? + .clone(); + if options.panels { + library.definitions.push(("BROWSER_AVAILABLE".into(), None)); + } + let inputs: Vec<_> = inputs + .iter() + .map(|path| format!("plugins/obs-browser/{path}")) + .collect(); + frontend::add_inputs(build, &root, &mut library, &inputs)?; + library.sources.extend(host_sources); + if options.panels { + let inputs: Vec<_> = manifest + .get("panels") + .ok_or("browser panel sources missing")? + .iter() + .map(|path| format!("plugins/obs-browser/{path}")) + .collect(); + frontend::add_inputs(build, &root, &mut library, &inputs)?; + } + if options.unity { + library.sources = unity_groups( + build, + &source, + &library.sources, + manifest + .get("unity_start") + .ok_or("browser unity boundaries missing")?, + )?; + } + let module = finish(build, &root, library)?; + let mut helper = SharedLibrary { + name: "obs-browser-page".into(), + file_name: Some("obs-browser-page".into()), + sources: manifest + .get("helper") + .ok_or("browser helper sources missing")? + .iter() + .map(|path| source.join(path)) + .collect(), + include_dirs: vec![ + sdk.clone(), + sdk.join("include"), + source.clone(), + source.join("deps"), + source.join("obs-browser-page"), + ], + dependencies: vec![wrapper, cef], + unity: options.unity, + ..SharedLibrary::default() + }; + crate::platform::configure_browser_helper(&build.target, &mut helper)?; + add_package(&mut helper, &build.target, "nlohmann_json")?; + Ok(Artifacts { + module, + helper: build.executable(&helper)?, + cef_root: sdk, + }) +} + +fn unity_groups( + build: &NativeBuild, + source: &Path, + sources: &[PathBuf], + starts: &[String], +) -> Result, String> { + let boundaries: Vec<_> = starts.iter().map(|path| source.join(path)).collect(); + if boundaries.first() != sources.first() + || boundaries + .iter() + .any(|path| sources.iter().filter(|p| *p == path).count() != 1) + { + return Err("browser unity boundaries do not match source inventory".into()); + } + let output = build.output.join("obs-browser/unity"); + std::fs::create_dir_all(&output).map_err(|e| e.to_string())?; + let mut groups = Vec::new(); + let mut content = String::new(); + for path in sources { + if boundaries.contains(path) { + if !content.is_empty() { + let group = output.join(format!("browser-{}.cpp", groups.len())); + frontend::write(&group, &content)?; + groups.push(group); + } + content = String::from("/* Generated explicit browser unity group. */\n"); + } + let path = dunce::canonicalize(path).map_err(|e| e.to_string())?; + let path = path + .to_str() + .ok_or("non-UTF8 browser source path")? + .replace('\\', "/"); + if path.contains(['"', '\n', '\r']) { + return Err("unrepresentable browser source path".into()); + } + content.push_str(&format!("#include \"{path}\"\n")); + } + if !content.is_empty() { + let group = output.join(format!("browser-{}.cpp", groups.len())); + frontend::write(&group, &content)?; + groups.push(group); + } + Ok(groups) +} diff --git a/rust/obs-build/src/plugins/frontend_tools.rs b/rust/obs-build/src/plugins/frontend_tools.rs new file mode 100644 index 0000000000..defd86032f --- /dev/null +++ b/rust/obs-build/src/plugins/frontend_tools.rs @@ -0,0 +1,95 @@ +//! Qt frontend tools and optional scripting interface. +use super::{Module, finish, module}; +use crate::{NativeBuild, frontend, scripting}; +use std::path::Path; + +pub fn build( + build: &NativeBuild, + root: &Path, + core: &Path, + api: &Path, + scripting: Option<&scripting::Artifacts>, +) -> Result { + let root = root.canonicalize().map_err(|e| e.to_string())?; + let mut library = module(build, &root, core, "frontend-tools")?; + library.sources = ["core+.hpp.cpp", "c+.h.c", "output-timer+.hpp.cpp"] + .iter() + .map(|group| { + root.join(format!( + "plugins/frontend-tools/build/frontend-tools.{group}" + )) + }) + .collect(); + library.include_dirs.push(root.join("frontend/api")); + library + .dependencies + .push(api.canonicalize().map_err(|e| e.to_string())?); + crate::platform::configure_frontend_tools(&build.target, &root, &mut library)?; + crate::libobs::add_package(&mut library, &build.target, "Qt6Widgets")?; + let manifest: serde_json::Value = serde_json::from_slice( + &std::fs::read(root.join("frontend/build/cargo-sources.json")) + .map_err(|e| e.to_string())?, + ) + .map_err(|e| e.to_string())?; + let interfaces: std::collections::BTreeMap> = + serde_json::from_value(manifest["interfaces"].clone()).map_err(|e| e.to_string())?; + // These are the same shared Qt interfaces compiled into the application. + for (directory, inputs) in interfaces + .iter() + .filter(|(directory, _)| directory.as_str() != "shared/qt/idian") + { + library.include_dirs.push(root.join(directory)); + frontend::add_inputs(build, &root, &mut library, inputs)?; + } + frontend::add_spinbox(build, &root, &mut library)?; + let mut inputs: Vec = [ + "auto-scene-switcher.hpp", + "output-timer.hpp", + "forms/auto-scene-switcher.ui", + "forms/captions.ui", + "forms/output-timer.ui", + "forms/scripts.ui", + ] + .iter() + .map(|name| format!("plugins/frontend-tools/{name}")) + .collect(); + if let Some(scripting) = scripting { + library.dependencies.push(scripting.library.clone()); + library.include_dirs.push(root.join("shared/obs-scripting")); + library.definitions.push(("ENABLE_SCRIPTING".into(), None)); + if scripting.lua_module.is_some() { + library.definitions.push(("LUAJIT_FOUND".into(), None)); + } + if scripting.python_module.is_some() { + library.definitions.push(("Python_FOUND".into(), None)); + } + inputs.extend([ + "plugins/frontend-tools/build/frontend-tools.scripts+.hpp.cpp".into(), + "plugins/frontend-tools/scripts.hpp".into(), + ]); + } + frontend::add_inputs(build, &root, &mut library, &inputs)?; + // Moc sees the same complete type definitions as the original groups. + let mut context = String::new(); + for header in [ + "plugins/frontend-tools/build/frontend-tools.pch.hpp", + "plugins/frontend-tools/build/frontend-tools-output-timer.pch.hpp", + "shared/properties-view/build/properties-view.pch.hpp", + "shared/qt/obs-spinbox/build/qt-obs-spinbox.pch.hpp", + ] { + context.push_str(&format!("#include \"{header}\"\n")); + } + if scripting.is_some() { + context + .push_str("#include \"plugins/frontend-tools/build/frontend-tools-scripts.pch.hpp\"\n"); + } + let generated = build.output.join("frontend-tools/qt"); + let prefix = generated.join("moc-context.hpp"); + frontend::write(&prefix, &context)?; + crate::qt::combine_moc( + &mut library, + &generated.join("mocs_compilation.cpp"), + &prefix, + )?; + finish(build, &root, library) +} diff --git a/rust/obs-build/src/plugins/websocket.rs b/rust/obs-build/src/plugins/websocket.rs new file mode 100644 index 0000000000..4f42a70d94 --- /dev/null +++ b/rust/obs-build/src/plugins/websocket.rs @@ -0,0 +1,79 @@ +//! Original obs-websocket plugin, including its Qt interfaces and resources. +use super::{Module, finish, module}; +use crate::{NativeBuild, frontend, libobs::add_package}; +use std::path::Path; + +pub struct Options { + pub unity: bool, +} + +impl Default for Options { + fn default() -> Self { + Self { unity: true } + } +} + +pub fn build( + build: &NativeBuild, + root: &Path, + core: &Path, + api: &Path, + options: &Options, +) -> Result { + let root = root.canonicalize().map_err(|e| e.to_string())?; + println!( + "cargo:rerun-if-changed={}", + root.join("plugins/obs-websocket").display() + ); + let manifest: serde_json::Value = + serde_json::from_str(include_str!("../../manifests/obs-websocket.json")) + .map_err(|e| e.to_string())?; + let mut library = module(build, &root, core, "obs-websocket")?; + library.sources.clear(); + library.unity = options.unity; + library.dependencies.push(api.into()); + library.include_dirs.extend([ + root.join("frontend/api"), + root.join("plugins/obs-websocket/src"), + root.join("plugins/obs-websocket/lib"), + ]); + crate::platform::configure_websocket(&build.target, &mut library)?; + for (package, minimum) in [("nlohmann_json", "3.11"), ("asio", "1.12.1")] { + pkg_config::Config::new() + .cargo_metadata(false) + .atleast_version(minimum) + .probe(package) + .map_err(|e| format!("obs-websocket requires {package} >= {minimum}: {e}"))?; + add_package(&mut library, &build.target, package)?; + } + for package in ["Qt6Widgets", "Qt6Svg", "Qt6Network"] { + add_package(&mut library, &build.target, package)?; + } + library.definitions.push(("ASIO_STANDALONE".into(), None)); + let generated = build.output.join("obs-websocket/qt"); + std::fs::create_dir_all(&generated).map_err(|e| e.to_string())?; + library.include_dirs.insert(0, generated.clone()); + let template = root.join("plugins/obs-websocket/src/plugin-macros.h.in"); + println!("cargo:rerun-if-changed={}", template.display()); + let content = std::fs::read_to_string(&template) + .map_err(|e| e.to_string())? + .replace( + "@obs-websocket_VERSION@", + manifest["version"] + .as_str() + .ok_or("websocket version missing")?, + ) + .replace( + "@OBS_WEBSOCKET_RPC_VERSION@", + &manifest["rpc_version"].to_string(), + ); + frontend::write(&generated.join("plugin-macros.generated.h"), &content)?; + let inputs: Vec = + serde_json::from_value(manifest["inputs"].clone()).map_err(|e| e.to_string())?; + let inputs: Vec = inputs + .iter() + .map(|input| format!("plugins/obs-websocket/{input}")) + .collect(); + frontend::add_inputs(build, &root, &mut library, &inputs)?; + finish(build, &root, library) +} diff --git a/rust/obs-build/src/qt.rs b/rust/obs-build/src/qt.rs new file mode 100644 index 0000000000..b2c7eb664d --- /dev/null +++ b/rust/obs-build/src/qt.rs @@ -0,0 +1,154 @@ +//! Explicit Qt code generation for native Cargo targets. +use crate::SharedLibrary; +use std::{ + path::{Path, PathBuf}, + process::Command, +}; + +/// Generate one moc translation unit using the target's includes and definitions. +/// Cross builds can provide a host executable through OBS_QT_MOC. +pub fn moc(library: &mut SharedLibrary, header: &Path, output: &Path) -> Result { + let mut command = command("moc")?; + for directory in &library.include_dirs { + command.arg("-I").arg(directory); + } + for (name, value) in &library.definitions { + command.arg(match value { + Some(value) => format!("-D{name}={value}"), + None => format!("-D{name}"), + }); + } + generate(command, header, output)?; + library.sources.push(output.into()); + Ok(output.into()) +} + +/// Generate a UI header and put its output directory first in the include search. +pub fn uic(library: &mut SharedLibrary, form: &Path, output: &Path) -> Result { + generate(command("uic")?, form, output)?; + let directory = output + .parent() + .ok_or("UI output has no parent directory")? + .canonicalize() + .map_err(|e| e.to_string())?; + library.include_dirs.retain(|path| path != &directory); + library.include_dirs.insert(0, directory); + Ok(output.into()) +} + +/// Embed a resource collection and track each resource file as a Cargo input. +pub fn rcc( + library: &mut SharedLibrary, + resources: &Path, + output: &Path, +) -> Result { + let resources = resources.canonicalize().map_err(|e| e.to_string())?; + let mut list = command("rcc")?; + list.arg("--list"); + let files = run(list, &resources)?; + for file in std::str::from_utf8(&files) + .map_err(|e| e.to_string())? + .lines() + { + let path = resources + .parent() + .ok_or("resource input has no parent")? + .join(file); + println!("cargo:rerun-if-changed={}", path.display()); + } + let name = resources + .file_stem() + .and_then(|name| name.to_str()) + .ok_or("invalid resource collection name")?; + let mut compiler = command("rcc")?; + compiler.arg("--name").arg(name); + generate(compiler, &resources, output)?; + library.sources.push(output.into()); + Ok(output.into()) +} + +fn command(name: &str) -> Result { + let variable = format!("OBS_QT_{}", name.to_ascii_uppercase()); + println!("cargo:rerun-if-env-changed={variable}"); + let executable = if let Some(path) = std::env::var_os(variable) { + PathBuf::from(path) + } else { + PathBuf::from(pkg_config::get_variable("Qt6Core", "libexecdir").map_err(|e| e.to_string())?) + .join(name) + }; + Ok(Command::new(executable)) +} + +fn run(mut command: Command, input: &Path) -> Result, String> { + let input = input.canonicalize().map_err(|e| e.to_string())?; + println!("cargo:rerun-if-changed={}", input.display()); + let result = command + .arg(&input) + .output() + .map_err(|e| format!("execute Qt tool: {e}"))?; + if !result.status.success() { + return Err(format!( + "Qt tool {command:?} failed: {}", + String::from_utf8_lossy(&result.stderr) + )); + } + Ok(result.stdout) +} + +fn generate(command: Command, input: &Path, output: &Path) -> Result<(), String> { + let code = run(command, input)?; + if code.is_empty() { + return Err(format!("Qt tool produced no code for {}", input.display())); + } + if let Some(parent) = output.parent() { + std::fs::create_dir_all(parent).map_err(|e| e.to_string())?; + } + if std::fs::read(output).ok().as_deref() != Some(code.as_slice()) { + std::fs::write(output, code).map_err(|e| e.to_string())?; + } + Ok(()) +} + +/// Combine generated metaobjects with the target's textual header closure. +/// This mirrors Qt's mocs_compilation.cpp without requiring precompiled headers. +pub fn combine_moc( + library: &mut SharedLibrary, + output: &Path, + prelude: &Path, +) -> Result<(), String> { + let directory = output.parent().ok_or("moc group output has no parent")?; + let is_moc = |path: &PathBuf| { + path.parent() == Some(directory) + && path + .file_name() + .and_then(|name| name.to_str()) + .is_some_and(|name| name.starts_with("moc_")) + }; + let sources: Vec<_> = library + .sources + .iter() + .filter(|path| is_moc(path)) + .cloned() + .collect(); + if sources.is_empty() { + return Ok(()); + } + let mut content = String::from("/* Generated Qt metaobject group. */\n"); + for path in std::iter::once(prelude.to_owned()).chain(sources) { + let path = path.canonicalize().map_err(|e| e.to_string())?; + let name = path + .to_str() + .ok_or("non-UTF8 moc include")? + .replace('\\', "/"); + if name.contains(['\n', '\r', '"']) { + return Err("moc include path contains a quote or newline".into()); + } + content.push_str(&format!("#include \"{name}\"\n")); + } + if std::fs::read_to_string(output).ok().as_deref() != Some(&content) { + std::fs::write(output, content).map_err(|e| e.to_string())?; + } + library.sources.retain(|path| !is_moc(path)); + library.sources.push(output.into()); + Ok(()) +} diff --git a/rust/obs-build/src/scripting.rs b/rust/obs-build/src/scripting.rs new file mode 100644 index 0000000000..c2902acb96 --- /dev/null +++ b/rust/obs-build/src/scripting.rs @@ -0,0 +1,297 @@ +//! Native scripting library and generated language bindings. +use crate::{NativeBuild, SharedLibrary, libobs::add_package}; +use std::path::{Path, PathBuf}; + +#[derive(Clone, Debug)] +pub struct Options { + pub lua: bool, + pub python: bool, + /// Binding directory relative to the runtime root containing bin/. + pub module_dir: PathBuf, +} + +impl Default for Options { + fn default() -> Self { + Self { + lua: true, + python: true, + module_dir: "lib64/obs-scripting".into(), + } + } +} + +#[derive(Debug)] +pub struct Artifacts { + pub library: PathBuf, + pub runtime: PathBuf, + pub lua_module: Option, + pub python_module: Option, + pub python_wrapper: Option, +} + +pub fn build( + build: &NativeBuild, + root: &Path, + core: &Path, + frontend: Option<&Path>, + options: &Options, +) -> Result { + if !options.lua && !options.python { + return Err("scripting requires at least one enabled language".into()); + } + let module_dir = options + .module_dir + .to_str() + .ok_or("non-UTF8 scripting module path")?; + if module_dir.is_empty() + || module_dir.contains(['"', '\\', '\n', '\r']) + || !options + .module_dir + .components() + .all(|part| matches!(part, std::path::Component::Normal(_))) + { + return Err("scripting module path must be a relative runtime directory".into()); + } + let root = root.canonicalize().map_err(|e| e.to_string())?; + let directory = root.join("shared/obs-scripting"); + let generated = build.output.join("scripting-generated"); + std::fs::create_dir_all(generated.join("swig")).map_err(|e| e.to_string())?; + let generated = generated.canonicalize().map_err(|e| e.to_string())?; + let runtime_root = build.output.join("runtime"); + std::fs::create_dir_all(&runtime_root).map_err(|e| e.to_string())?; + let runtime_root = runtime_root.canonicalize().map_err(|e| e.to_string())?; + let bindings = runtime_root.join(&options.module_dir); + std::fs::create_dir_all(&bindings).map_err(|e| e.to_string())?; + let bindings = bindings.canonicalize().map_err(|e| e.to_string())?; + let swig = swig()?; + let mut library = SharedLibrary { + name: "obs-scripting".into(), + sources: vec![ + directory.join("build/obs-scripting.core+.h.c"), + directory.join("build/obs-scripting.cstrcache+.hpp.cpp"), + ], + include_dirs: vec![ + generated.clone(), + root.clone(), + directory.clone(), + root.join("libobs"), + build.output.join("config"), + ], + dependencies: vec![core.canonicalize().map_err(|e| e.to_string())?], + definitions: vec![("SCRIPT_DIR".into(), Some(format!("\"{module_dir}\"")))], + ..SharedLibrary::default() + }; + crate::platform::configure_scripting(&build.target, &mut library)?; + add_package(&mut library, &build.target, "simde")?; + if let Some(api) = frontend { + library + .dependencies + .push(api.canonicalize().map_err(|e| e.to_string())?); + library.include_dirs.push(root.join("frontend/api")); + library.definitions.push(("ENABLE_FRONTEND".into(), None)); + } + let binding_base = library.clone(); + if options.lua { + add_package(&mut library, &build.target, "luajit")?; + library.definitions.push(("LUAJIT_FOUND".into(), None)); + library + .sources + .push(directory.join("build/obs-scripting.lua+.h.c")); + runtime(&swig, "lua", &generated.join("swig/swigluarun.h"))?; + if frontend.is_some() { + library + .sources + .push(directory.join("build/obs-scripting.lua-frontend+.h.c")); + } + } + if options.python { + let python = pkg_config::Config::new() + .cargo_metadata(false) + .atleast_version("3.8") + .probe("python3-embed") + .map_err(|e| e.to_string())?; + let python_name = crate::platform::python_library_name(&build.target, &python.libs)?; + write( + &generated.join("obspython.h"), + &format!("#pragma once\n#define PYTHON_LIB \"{python_name}\"\n"), + )?; + library.definitions.extend([ + ("Python_FOUND".into(), None), + ("ENABLE_SCRIPTING".into(), None), + ("PYTHON_LIB".into(), Some(format!("\"{python_name}\""))), + ]); + add_package(&mut library, &build.target, "python3-embed")?; + library + .sources + .push(directory.join("build/obs-scripting.python+.h.c")); + runtime(&swig, "python", &generated.join("swig/swigpyrun.h"))?; + if frontend.is_some() { + library + .sources + .push(directory.join("build/obs-scripting.python-frontend+.h.c")); + } + } + // Track the input trees SWIG reads, including nested %include files. + for input in [&directory, &root.join("libobs"), &root.join("frontend/api")] { + println!("cargo:rerun-if-changed={}", input.display()); + } + let artifact = build.shared_library(&library)?; + let mut result = Artifacts { + library: artifact.clone(), + runtime: runtime_root, + lua_module: None, + python_module: None, + python_wrapper: None, + }; + for (enabled, language, module_name) in [ + (options.lua, "lua", "obslua"), + (options.python, "python", "obspython"), + ] { + if !enabled { + continue; + } + let output = generated.join(language); + std::fs::create_dir_all(&output).map_err(|e| e.to_string())?; + let temporary = output.join(format!("{module_name}_wrap.next.c")); + let mut command = std::process::Command::new(&swig); + command.arg(format!("-{language}")); + for include in &library.include_dirs { + command.arg(format!("-I{}", include.display())); + } + command.arg(format!("-DSWIG_TYPE_TABLE={module_name}")); + command.arg(if language == "lua" { + "-DSWIG_LUA_INTERPRETER_NO_DEBUG" + } else { + "-DSWIG_PYTHON_INTERPRETER_NO_DEBUG" + }); + if language == "python" { + command.arg("-DPy_ENABLE_SHARED=1"); + } + if frontend.is_some() { + command.arg("-DENABLE_FRONTEND"); + } + command + .arg("-outdir") + .arg(&output) + .arg("-o") + .arg(&temporary) + .arg(directory.join(module_name).join(format!("{module_name}.i"))); + run(&mut command)?; + let source = output.join(format!("{module_name}_wrap.c")); + write( + &source, + &std::fs::read_to_string(&temporary).map_err(|e| e.to_string())?, + )?; + let mut module = binding_base.clone(); + add_package( + &mut module, + &build.target, + if language == "lua" { + "luajit" + } else { + "python3-embed" + }, + )?; + module.name = module_name.into(); + module.sources = vec![ + source, + directory.join("build/obs-scripting.cstrcache+.hpp.cpp"), + ]; + module.dependencies.push(artifact.clone()); + module + .definitions + .push(("SWIG_TYPE_TABLE".into(), Some(module_name.into()))); + module.definitions.push(( + if language == "lua" { + "SWIG_LUA_INTERPRETER_NO_DEBUG" + } else { + "SWIG_PYTHON_INTERPRETER_NO_DEBUG" + } + .into(), + None, + )); + if language == "python" { + module + .definitions + .push(("Py_ENABLE_SHARED".into(), Some("1".into()))); + } + module.file_name = Some(crate::platform::scripting_module_name( + &build.target, + language, + )?); + let compiled = build.shared_library(&module)?; + let installed = bindings.join( + compiled + .file_name() + .ok_or("binding module has no filename")?, + ); + std::fs::copy(&compiled, &installed).map_err(|e| e.to_string())?; + if language == "lua" { + result.lua_module = Some(installed); + } else { + result.python_module = Some(installed); + let wrapper = bindings.join("obspython.py"); + write( + &wrapper, + &std::fs::read_to_string(output.join("obspython.py")).map_err(|e| e.to_string())?, + )?; + result.python_wrapper = Some(wrapper); + } + } + Ok(result) +} + +fn swig() -> Result { + println!("cargo:rerun-if-env-changed=OBS_SWIG"); + println!("cargo:rerun-if-env-changed=SWIG_LIB"); + let tool = std::env::var_os("OBS_SWIG") + .map(PathBuf::from) + .unwrap_or_else(|| "swig".into()); + let output = std::process::Command::new(&tool) + .arg("-version") + .output() + .map_err(|e| format!("execute SWIG {}: {e}", tool.display()))?; + let version = String::from_utf8_lossy(&output.stdout); + let major = version + .lines() + .find_map(|line| line.trim().strip_prefix("SWIG Version ")) + .and_then(|value| value.split('.').next()) + .and_then(|value| value.parse::().ok()); + if !output.status.success() || !major.is_some_and(|major| major >= 4) { + return Err(format!("SWIG >=4 is required: {version}")); + } + Ok(tool) +} + +fn runtime(swig: &Path, language: &str, path: &Path) -> Result<(), String> { + let temporary = path.with_extension("next.h"); + run(std::process::Command::new(swig) + .arg(format!("-{language}")) + .arg("-external-runtime") + .arg(&temporary))?; + write( + path, + &std::fs::read_to_string(&temporary).map_err(|e| e.to_string())?, + ) +} + +fn run(command: &mut std::process::Command) -> Result<(), String> { + let result = command + .output() + .map_err(|e| format!("execute {command:?}: {e}"))?; + if !result.status.success() { + return Err(format!( + "SWIG {command:?} failed: {}\n{}", + String::from_utf8_lossy(&result.stdout), + String::from_utf8_lossy(&result.stderr) + )); + } + Ok(()) +} + +fn write(path: &Path, contents: &str) -> Result<(), String> { + if std::fs::read_to_string(path).ok().as_deref() != Some(contents) { + std::fs::write(path, contents).map_err(|e| e.to_string())?; + } + Ok(()) +} diff --git a/rust/obs-build/src/validation.rs b/rust/obs-build/src/validation.rs new file mode 100644 index 0000000000..ea869d20f1 --- /dev/null +++ b/rust/obs-build/src/validation.rs @@ -0,0 +1,325 @@ +//! Build the unchanged native C tests through the Cargo native engine. +use crate::{NativeBuild, SharedLibrary, libobs::add_package}; +use std::{ + collections::{BTreeSet, HashMap}, + path::{Path, PathBuf}, +}; + +pub struct Executable { + pub name: String, + pub path: PathBuf, +} + +pub struct Options { + pub hevc: bool, + pub per_target_sanitizers: bool, +} + +impl Default for Options { + fn default() -> Self { + Self { + hevc: true, + per_target_sanitizers: true, + } + } +} + +/// Build the unchanged standalone WHIP clock and POSIX host tests. +pub fn build_webrtc_tests(build: &NativeBuild, root: &Path) -> Result, String> { + let root = dunce::canonicalize(root).map_err(|e| e.to_string())?; + let mut base = SharedLibrary { + include_dirs: vec![root.clone(), root.join("plugins/obs-webrtc")], + ..SharedLibrary::default() + }; + crate::platform::configure_webrtc_tests(&build.target, &mut base)?; + add_package(&mut base, &build.target, "cmocka")?; + let mut result = Vec::new(); + for (name, extension) in [ + ("test_whip_rtp_timestamp", "c"), + ("test_whip_host_os_name", "cpp"), + ] { + let library = SharedLibrary { + name: name.into(), + sources: vec![root.join(format!("test/cmocka/{name}.{extension}"))], + ..base.clone() + }; + result.push(Executable { + name: name.into(), + path: build.executable(&library)?, + }); + } + for directory in ["test/cmocka", "plugins/obs-webrtc"] { + println!("cargo:rerun-if-changed={}", root.join(directory).display()); + } + Ok(result) +} + +/// Build unchanged cmocka tests that require the native graphics module. +pub fn build_graphics_tests( + build: &NativeBuild, + root: &Path, + core: &Path, + graphics: &Path, +) -> Result, String> { + let root = dunce::canonicalize(root).map_err(|e| e.to_string())?; + let graphics = dunce::canonicalize(graphics).map_err(|e| e.to_string())?; + let quoted = serde_json::to_string(graphics.to_str().ok_or("non-UTF8 graphics test path")?) + .map_err(|e| e.to_string())?; + let name = "test_group_hide_transition_audio"; + let mut library = SharedLibrary { + name: name.into(), + sources: vec![root.join(format!("test/cmocka/{name}.c"))], + include_dirs: vec![ + root.join("libobs"), + root.join("deps/libcaption"), + build.output.join("config"), + ], + definitions: vec![("GRAPHICS_MODULE_PATH".into(), Some(quoted))], + dependencies: vec![core.into(), crate::libobs::build_caption(build, &root)?], + ..SharedLibrary::default() + }; + crate::platform::configure_c_tests(build, &mut library, None)?; + for package in ["cmocka", "simde"] { + add_package(&mut library, &build.target, package)?; + } + println!("cargo:rerun-if-changed={}", library.sources[0].display()); + println!( + "cargo:rerun-if-changed={}", + root.join("libobs/data").display() + ); + Ok(vec![Executable { + name: name.into(), + path: build.executable(&library)?, + }]) +} + +/// Build the unchanged VLC compatibility tests against the real native modules. +pub fn build_vlc_tests( + build: &NativeBuild, + root: &Path, + core: &Path, + vlc: &crate::plugins::Module, + graphics: &Path, +) -> Result, String> { + let root = dunce::canonicalize(root).map_err(|e| e.to_string())?; + let mut base = SharedLibrary { + include_dirs: vec![ + root.clone(), + root.join("libobs"), + root.join("test/cmocka"), + root.join("plugins/vlc-video"), + build.output.join("config"), + ], + dependencies: vec![core.into()], + ..SharedLibrary::default() + }; + crate::platform::configure_c_tests(build, &mut base, None)?; + for package in ["cmocka", "simde"] { + add_package(&mut base, &build.target, package)?; + } + for (name, path) in [ + ("VLC_MODULE_PATH", vlc.library.as_path()), + ("VLC_DATA_PATH", vlc.data.as_path()), + ("GRAPHICS_MODULE_PATH", graphics), + ] { + let path = dunce::canonicalize(path).map_err(|e| e.to_string())?; + let quoted = serde_json::to_string(path.to_str().ok_or("non-UTF8 VLC test path")?) + .map_err(|e| e.to_string())?; + base.definitions.push((name.into(), Some(quoted))); + } + let mut result = Vec::new(); + for name in [ + "test_vlc_drain_gate", + "test_vlc_host_path", + "test_vlc_channel_order", + "test_vlc_audio_track", + "test_vlc_audio_pacing", + "test_vlc_playlist_gap", + ] { + let mut library = SharedLibrary { + name: name.into(), + sources: vec![root.join(format!("test/cmocka/{name}.c"))], + ..base.clone() + }; + if name == "test_vlc_audio_pacing" { + for package in ["libavcodec", "libavformat", "libavutil"] { + add_package(&mut library, &build.target, package)?; + } + } + result.push(Executable { + name: name.into(), + path: build.executable(&library)?, + }); + } + for directory in ["test/cmocka", "plugins/vlc-video", "libobs/data"] { + println!("cargo:rerun-if-changed={}", root.join(directory).display()); + } + Ok(result) +} + +pub fn build_c_tests( + build: &NativeBuild, + root: &Path, + core: &Path, + options: &Options, +) -> Result, String> { + let root = dunce::canonicalize(root).map_err(|e| e.to_string())?; + let manifest: Vec = + serde_json::from_str(include_str!("../manifests/c-tests-linux.json")) + .map_err(|e| e.to_string())?; + let mut result = Vec::new(); + let mut archives = HashMap::new(); + let mut watched: BTreeSet = ["libobs", "test/cmocka", "deps/libcaption"] + .into_iter() + .map(|path| root.join(path)) + .collect(); + let mut base = SharedLibrary { + include_dirs: vec![ + root.clone(), + root.join("libobs"), + root.join("deps/libcaption"), + root.join("test/cmocka"), + build.output.join("config"), + ], + dependencies: vec![core.into()], + ..SharedLibrary::default() + }; + if options.hevc { + base.definitions.push(("ENABLE_HEVC".into(), None)); + } + for package in ["cmocka", "simde"] { + add_package(&mut base, &build.target, package)?; + } + // Shared group headers expose Jansson declarations even to a private AVC + // implementation fixture. Header discovery adds no new runtime link edge. + headers_only(&mut base, "jansson")?; + for spec in manifest { + let name = spec["name"].as_str().ok_or("C test name missing")?; + if name == "test_hevc" && !options.hevc { + continue; + } + let mut library = SharedLibrary { + name: name.into(), + ..base.clone() + }; + let sanitizer = options + .per_target_sanitizers + .then(|| spec["sanitizers"].as_str()) + .flatten(); + crate::platform::configure_c_tests(build, &mut library, sanitizer)?; + for source in strings(&spec, "sources")? { + // Watch each selected component, including its group headers, rather + // than the repository root (which may contain native build output). + let component: PathBuf = Path::new(source).components().take(2).collect(); + if source.starts_with("plugins/") || source.starts_with("shared/") { + watched.insert(root.join(component)); + } + let source = root.join(source); + let source = if source.to_string_lossy().ends_with(".c.h") { + let relative = source.strip_prefix(&root).map_err(|e| e.to_string())?; + let wrapper = build + .output + .join(name) + .join("inputs") + .join(relative) + .with_extension("h.c"); + let include = source + .to_str() + .ok_or("non-UTF8 C test source")? + .replace('\\', "/"); + if include.contains(['\n', '\r', '"']) { + return Err(format!("unrepresentable C test include {include:?}")); + } + std::fs::create_dir_all(wrapper.parent().ok_or("C test wrapper has no parent")?) + .map_err(|e| e.to_string())?; + crate::frontend::write(&wrapper, &format!("#include \"{include}\"\n"))?; + wrapper + } else { + source + }; + library.sources.push(source); + } + for include in strings(&spec, "includes")? { + library.include_dirs.push(root.join(include)); + } + for define in strings(&spec, "definitions")? { + let (name, value) = define + .split_once('=') + .map_or((define, None), |(name, value)| { + (name, Some(value.to_string())) + }); + library.definitions.push((name.into(), value)); + } + for package in strings(&spec, "packages")? { + add_package(&mut library, &build.target, package)?; + } + for package in strings(&spec, "header_packages")? { + headers_only(&mut library, package)?; + } + library.compile_options.extend( + strings(&spec, "compile_options")? + .into_iter() + .map(String::from), + ); + for flag in strings(&spec, "compile_options_if_supported")? { + if build + .compiler(&library, &build.output, false) + .is_flag_supported(flag) + .map_err(|e| e.to_string())? + { + library.compile_options.push(flag.into()); + } + } + library.link_options.extend( + strings(&spec, "link_options")? + .into_iter() + .map(String::from), + ); + for archive in strings(&spec, "archives")? { + if !archives.contains_key(archive) { + let path = if archive == "caption" { + crate::libobs::build_caption(build, &root)? + } else { + crate::deps::shared_archive(build, &root, archive)? + }; + archives.insert(archive.to_string(), path); + } + library.dependencies.push(archives[archive].clone()); + } + result.push(Executable { + name: name.into(), + path: build.executable(&library)?, + }); + } + for directory in watched { + println!("cargo:rerun-if-changed={}", directory.display()); + } + Ok(result) +} + +fn headers_only(library: &mut SharedLibrary, package: &str) -> Result<(), String> { + let headers = pkg_config::Config::new() + .cargo_metadata(false) + .probe(package) + .map_err(|e| e.to_string())?; + library.include_dirs.extend(headers.include_paths); + let mut definitions: Vec<_> = headers.defines.into_iter().collect(); + definitions.sort(); + library.definitions.extend(definitions); + Ok(()) +} + +fn strings<'a>(spec: &'a serde_json::Value, key: &str) -> Result, String> { + match spec.get(key) { + None => Ok(vec![]), + Some(value) => value + .as_array() + .ok_or_else(|| format!("C test {key} is not an array"))? + .iter() + .map(|item| { + item.as_str() + .ok_or_else(|| format!("C test {key} entry is not a string")) + }) + .collect(), + } +} diff --git a/rust/obs-build/tests/libobs.rs b/rust/obs-build/tests/libobs.rs new file mode 100644 index 0000000000..6d28eb3c1a --- /dev/null +++ b/rust/obs-build/tests/libobs.rs @@ -0,0 +1,1289 @@ +//! Opt-in integration against real native dependencies and libobs-rust. +use obs_build::{NativeBuild, frontend, graphics, libobs, plugins, scripting}; +use std::{ffi::c_void, path::PathBuf}; +#[path = "libobs/application.rs"] +mod application; +#[path = "libobs/native_tests.rs"] +mod native_tests; +#[path = "libobs/qt.rs"] +mod qt; +#[path = "libobs/render.rs"] +mod render; +#[path = "libobs/scripting.rs"] +mod script_tests; +#[path = "libobs/tools.rs"] +mod tools; +#[path = "libobs/vlc.rs"] +mod vlc_tests; +#[path = "libobs/webrtc.rs"] +mod webrtc_tests; + +#[test] +fn c_and_rust_twins_preserve_public_data_lifecycle_and_module_apis() { + if let Some(path) = std::env::var_os("OBS_BUILD_TEST_CORE") { + let modules: Vec<(PathBuf, PathBuf)> = + serde_json::from_str(&std::env::var("OBS_BUILD_TEST_MODULES").unwrap()).unwrap(); + let modules: Vec<_> = modules + .into_iter() + .map(|(library, data)| plugins::Module { library, data }) + .collect(); + exercise( + &PathBuf::from(path), + &modules, + std::env::var_os("OBS_BUILD_DISABLE_HEVC").is_none(), + ); + return; + } + let root = PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("../.."); + let archive = PathBuf::from( + std::env::var_os("OBS_BUILD_RUST_ARCHIVE") + .expect("build libobs-rust in release mode, then set OBS_BUILD_RUST_ARCHIVE"), + ); + let output = tempfile::tempdir().unwrap(); + let build = NativeBuild { + host: env!("OBS_BUILD_HOST").into(), + target: env!("OBS_BUILD_TARGET").into(), + output: std::env::var_os("OBS_BUILD_TEST_OUTPUT") + .map(PathBuf::from) + .unwrap_or_else(|| output.path().into()), + }; + // Snapshot before native builds: another Cargo invocation can replace the + // original integration executable while this long-running process lives. + let bin = build.output.join("test-bin"); + std::fs::create_dir_all(&bin).unwrap(); + let runner = bin.join("obs-native-integration"); + std::fs::copy(std::env::current_exe().unwrap(), &runner).unwrap(); + let mut options = libobs::Options { + pch: std::env::var_os("OBS_BUILD_PCH").is_some(), + unity: std::env::var_os("OBS_BUILD_DISABLE_CORE_UNITY").is_none(), + hevc: std::env::var_os("OBS_BUILD_DISABLE_HEVC").is_none(), + core_modules: if enabled("OBS_BUILD_APP_GUI") { + [ + "obs-transitions", + "obs-filters", + "image-source", + "text-freetype2", + "linux-pulseaudio", + "linux-alsa", + "linux-v4l2", + "linux-capture", + "rtmp-services", + "linux-pipewire", + "obs-vst", + "obs-x264", + "obs-outputs", + "obs-ffmpeg", + ] + .into_iter() + .map(String::from) + .collect() + } else { + vec![] + }, + ..libobs::Options::default() + }; + if enabled("OBS_BUILD_APP_GUI") && std::env::var_os("OBS_BUILD_BROWSER").is_some() { + assert!( + std::env::var_os("OBS_BUILD_WEBSOCKET").is_some(), + "browser GUI validation requires websocket" + ); + options.core_modules.push("obs-browser".into()); + } + for (flag, name) in [ + ("OBS_BUILD_JACK", "linux-jack"), + ("OBS_BUILD_SNDIO", "sndio"), + ] { + if enabled("OBS_BUILD_APP_GUI") && std::env::var_os(flag).is_some() { + options.core_modules.push(name.into()); + } + } + if enabled("OBS_BUILD_APP_GUI") && std::env::var_os("OBS_BUILD_FDK").is_some() { + options.core_modules.push("obs-libfdk".into()); + } + if enabled("OBS_BUILD_APP_GUI") && std::env::var_os("OBS_BUILD_QSV").is_some() { + options.core_modules.push("obs-qsv11".into()); + } + if enabled("OBS_BUILD_APP_GUI") && std::env::var_os("OBS_BUILD_WEBRTC").is_some() { + options.core_modules.push("obs-webrtc".into()); + } + if enabled("OBS_BUILD_APP_GUI") && std::env::var_os("OBS_BUILD_NVENC").is_some() { + options.core_modules.push("obs-nvenc".into()); + } + if std::env::var_os("OBS_BUILD_FRONTEND_TOOLS").is_some() { + assert!( + std::env::var_os("OBS_BUILD_APP_GUI").is_some(), + "frontend Tools test requires OBS_BUILD_APP_GUI=1" + ); + options.core_modules.push("frontend-tools".into()); + } + if std::env::var_os("OBS_BUILD_WEBSOCKET").is_some() { + assert!( + enabled("OBS_BUILD_APP_GUI"), + "websocket test requires the GUI" + ); + options.core_modules.push("obs-websocket".into()); + } + if std::env::var_os("OBS_BUILD_VLC").is_some() { + assert!( + std::env::var_os("OBS_BUILD_VLC_C_TESTS").is_some() || enabled("OBS_BUILD_APP_GUI"), + "VLC integration requires either C tests or the staged GUI" + ); + if enabled("OBS_BUILD_APP_GUI") { + assert!( + std::env::var_os("OBS_BUILD_WEBSOCKET").is_some(), + "VLC GUI integration requires the websocket client" + ); + options.core_modules.push("vlc-video".into()); + } + } + if std::env::var_os("OBS_BUILD_FRONTEND_TOOLS").is_some() + || std::env::var_os("OBS_BUILD_WEBSOCKET").is_some() + { + options.core_modules.push("native-frontend-probe".into()); + } + let core_started = std::time::Instant::now(); + let libraries = libobs::build_pair(&build, &root, &options, &archive).unwrap(); + let core_wall_seconds = core_started.elapsed().as_secs_f64(); + std::fs::write( + build.output.join("core-build-timing.json"), + serde_json::to_vec_pretty( + &serde_json::json!({"unity":options.unity,"pch":options.pch,"hevc":options.hevc, + "target":build.target,"wall_seconds":core_wall_seconds}), + ) + .unwrap(), + ) + .unwrap(); + assert_ne!(libraries.reference, libraries.with_rust); + assert_eq!(exports(&libraries.reference), exports(&libraries.with_rust)); + if std::env::var_os("OBS_BUILD_C_TESTS").is_some() { + let executables = obs_build::validation::build_c_tests( + &build, + &root, + &libraries.reference, + &obs_build::validation::Options { + hevc: options.hevc, + per_target_sanitizers: std::env::var_os("OBS_BUILD_DISABLE_C_TEST_SANITIZERS") + .is_none(), + }, + ) + .unwrap(); + assert_eq!(executables.len(), if options.hevc { 52 } else { 51 }); + let mut results = Vec::new(); + for core in [&libraries.reference, &libraries.with_rust] { + let variant = core + .parent() + .unwrap() + .file_name() + .unwrap() + .to_string_lossy(); + for test in &executables { + let directory = build + .output + .join("c-test-runs") + .join(variant.as_ref()) + .join(&test.name); + std::fs::create_dir_all(&directory).unwrap(); + let home = directory.join("home"); + std::fs::create_dir_all(&home).unwrap(); + let paths = std::env::join_paths( + std::iter::once(core.parent().unwrap().to_path_buf()).chain( + std::env::split_paths( + &std::env::var_os("LD_LIBRARY_PATH").unwrap_or_default(), + ), + ), + ) + .unwrap(); + let resolution = std::process::Command::new("ldd") + .arg(&test.path) + .env("LD_LIBRARY_PATH", &paths) + .output() + .unwrap(); + assert!(resolution.status.success()); + assert!( + String::from_utf8_lossy(&resolution.stdout).contains(core.to_str().unwrap()), + "{} did not resolve the selected core", + test.name + ); + let mut child = std::process::Command::new(&test.path) + .current_dir(&directory) + .env("LD_LIBRARY_PATH", paths) + .env("HOME", &home) + .env("XDG_CONFIG_HOME", home.join(".config")) + .env("XDG_DATA_HOME", home.join(".local/share")) + .env("XDG_CACHE_HOME", home.join(".cache")) + .stdout(std::fs::File::create(directory.join("stdout.log")).unwrap()) + .stderr(std::fs::File::create(directory.join("stderr.log")).unwrap()) + .spawn() + .unwrap(); + let deadline = std::time::Instant::now() + std::time::Duration::from_secs(60); + let status = loop { + if let Some(status) = child.try_wait().unwrap() { + break status; + } + if std::time::Instant::now() >= deadline { + child.kill().unwrap(); + child.wait().unwrap(); + panic!("{} against {variant} exceeded 60 seconds", test.name); + } + std::thread::sleep(std::time::Duration::from_millis(10)); + }; + assert!( + status.success(), + "{} against {variant} failed: {}", + test.name, + std::fs::read_to_string(directory.join("stderr.log")).unwrap() + ); + results.push( + serde_json::json!({"variant": variant, "test":test.name, "exit":status.code()}), + ); + } + } + std::fs::write( + build.output.join("c-tests.json"), + serde_json::to_vec_pretty(&results).unwrap(), + ) + .unwrap(); + } + let nvenc = if std::env::var_os("OBS_BUILD_NVENC").is_some() { + let archive = std::env::var_os("OBS_BUILD_NVENC_RUST_ARCHIVE") + .map(PathBuf::from) + .unwrap_or_else(|| root.join("target/release/libobs_nvenc_plugin.a")); + let nvenc = plugins::build_nvenc_pair( + &build, + &root, + &libraries.reference, + &archive, + std::env::var_os("OBS_BUILD_DISABLE_NVENC_FFMPEG_IDS").is_none(), + ) + .unwrap(); + assert_eq!( + exports(&nvenc.reference.library), + exports(&nvenc.with_rust.library) + ); + let output = std::process::Command::new(&nvenc.helper).output().unwrap(); + assert!(output.status.success()); + assert!(String::from_utf8_lossy(&output.stdout).contains("nvenc_supported=true")); + std::fs::write(build.output.join("nvenc-capabilities.ini"), &output.stdout).unwrap(); + if let Some(reference) = std::env::var_os("OBS_BUILD_NVENC_REFERENCE") { + assert_eq!( + exports(&nvenc.reference.library), + exports(&PathBuf::from(reference)) + ); + } + Some(nvenc) + } else { + None + }; + let filters = plugins::FiltersOptions { + speexdsp: std::env::var_os("OBS_BUILD_DISABLE_SPEEXDSP").is_none(), + rnnoise: std::env::var_os("OBS_BUILD_DISABLE_RNNOISE").is_none(), + }; + let tools_enabled = std::env::var_os("OBS_BUILD_FRONTEND_TOOLS").is_some(); + let scripting_enabled = (std::env::var_os("OBS_BUILD_SCRIPTING").is_some() || tools_enabled) + && std::env::var_os("OBS_BUILD_DISABLE_SCRIPTING").is_none(); + let scripting_api = (scripting_enabled + && (std::env::var_os("OBS_BUILD_SCRIPTING_FRONTEND").is_some() || tools_enabled)) + .then(|| frontend::build_api(&build, &root, &libraries.reference).unwrap()); + let script_artifacts = if scripting_enabled { + let artifacts = scripting::build( + &build, + &root, + &libraries.reference, + scripting_api.as_deref(), + &scripting::Options { + lua: std::env::var_os("OBS_BUILD_DISABLE_LUA").is_none(), + python: std::env::var_os("OBS_BUILD_DISABLE_PYTHON").is_none(), + ..scripting::Options::default() + }, + ) + .unwrap(); + script_tests::exercise( + &build, + &root, + &artifacts, + &[&libraries.reference, &libraries.with_rust], + scripting_api.is_some(), + ); + Some(artifacts) + } else { + None + }; + let mut modules = vec![ + plugins::build_transitions(&build, &root, &libraries.reference).unwrap(), + plugins::build_filters(&build, &root, &libraries.reference, &filters).unwrap(), + ]; + for (flag, source) in [ + ("OBS_BUILD_JACK", plugins::SourceModule::Jack), + ("OBS_BUILD_SNDIO", plugins::SourceModule::Sndio), + ] { + if std::env::var_os(flag).is_some() { + modules + .push(plugins::build_source(&build, &root, &libraries.reference, source).unwrap()); + } + } + if std::env::var_os("OBS_BUILD_FDK").is_some() { + modules.push(plugins::build_fdk(&build, &root, &libraries.reference).unwrap()); + } + let qsv_enabled = std::env::var_os("OBS_BUILD_QSV").is_some(); + if std::env::var_os("OBS_BUILD_WEBRTC").is_some() { + let mut module = plugins::build_webrtc( + &build, + &root, + &libraries.reference, + &plugins::DataChannelSdk { + include_dir: std::env::var_os("OBS_DATACHANNEL_INCLUDE_DIR") + .map(PathBuf::from) + .expect("set OBS_DATACHANNEL_INCLUDE_DIR"), + library: std::env::var_os("OBS_DATACHANNEL_LIBRARY") + .map(PathBuf::from) + .expect("set OBS_DATACHANNEL_LIBRARY"), + media: true, + websocket: std::env::var_os("OBS_DATACHANNEL_DISABLE_WEBSOCKET").is_none(), + }, + &plugins::WebRtcOptions { + hevc: options.hevc, + unity: std::env::var_os("OBS_BUILD_DISABLE_WEBRTC_UNITY").is_none(), + pch: std::env::var_os("OBS_BUILD_WEBRTC_PCH").is_some(), + }, + ) + .unwrap(); + if let Some(reference) = std::env::var_os("OBS_BUILD_WEBRTC_REFERENCE") { + let reference = PathBuf::from(reference).canonicalize().unwrap(); + assert_eq!(exports(&module.library), exports(&reference)); + if std::env::var_os("OBS_BUILD_WEBRTC_USE_REFERENCE").is_some() { + module.library = reference; + println!("WebRTC runtime uses original CMake module"); + } + } else { + assert!( + std::env::var_os("OBS_BUILD_WEBRTC_USE_REFERENCE").is_none(), + "set OBS_BUILD_WEBRTC_REFERENCE before selecting its runtime" + ); + } + modules.push(module); + } + if qsv_enabled { + let module = plugins::build_qsv( + &build, + &root, + &libraries.reference, + &plugins::QsvOptions { + hevc: options.hevc, + unity: std::env::var_os("OBS_BUILD_DISABLE_QSV_UNITY").is_none(), + pch: std::env::var_os("OBS_BUILD_QSV_PCH").is_some(), + }, + ) + .unwrap(); + if let Some(reference) = std::env::var_os("OBS_BUILD_QSV_REFERENCE") { + assert_eq!(exports(&module.library), exports(&PathBuf::from(reference))); + } + modules.push(module); + } + if std::env::var_os("OBS_BUILD_VLC").is_some() { + let vlc = plugins::build_source( + &build, + &root, + &libraries.reference, + plugins::SourceModule::Vlc, + ) + .unwrap(); + let dynamic = std::process::Command::new("readelf") + .arg("-d") + .arg(&vlc.library) + .output() + .unwrap(); + assert!(dynamic.status.success()); + assert!( + !String::from_utf8_lossy(&dynamic.stdout).contains("libvlc.so"), + "VLC must remain an optional runtime dependency" + ); + modules.push(vlc); + } + if enabled("OBS_BUILD_SOURCES") { + for source in [ + plugins::SourceModule::Image, + plugins::SourceModule::Text, + plugins::SourceModule::PulseAudio, + plugins::SourceModule::Alsa, + plugins::SourceModule::V4l2 { + udev: std::env::var_os("OBS_BUILD_DISABLE_UDEV").is_none(), + }, + plugins::SourceModule::X11Capture, + // Offline smoke tests must not start the update service. + plugins::SourceModule::RtmpServices { updates: false }, + ] { + modules + .push(plugins::build_source(&build, &root, &libraries.reference, source).unwrap()); + } + } + if enabled("OBS_BUILD_PIPEWIRE") { + modules.push( + plugins::build_source( + &build, + &root, + &libraries.reference, + plugins::SourceModule::PipeWire, + ) + .unwrap(), + ); + } + let browser_enabled = std::env::var_os("OBS_BUILD_BROWSER").is_some(); + let frontend = + (enabled("OBS_BUILD_QT") || enabled("OBS_BUILD_APP") || browser_enabled).then(|| { + qt::exercise(&build, &root); + modules.push(plugins::build_vst(&build, &root, &libraries.reference).unwrap()); + scripting_api.clone().unwrap_or_else(|| { + frontend::build_api(&build, &root, &libraries.reference).unwrap() + }) + }); + let frontend_tools = tools_enabled.then(|| { + plugins::build_frontend_tools( + &build, + &root, + &libraries.reference, + frontend + .as_deref() + .expect("frontend Tools test requires OBS_BUILD_APP_GUI=1"), + script_artifacts.as_ref(), + ) + .unwrap() + }); + let websocket = std::env::var_os("OBS_BUILD_WEBSOCKET").map(|_| { + plugins::build_websocket( + &build, + &root, + &libraries.reference, + frontend + .as_deref() + .expect("websocket requires the frontend API"), + &plugins::WebsocketOptions { + unity: std::env::var_os("OBS_BUILD_DISABLE_WEBSOCKET_UNITY").is_none(), + }, + ) + .unwrap() + }); + let browser = browser_enabled.then(|| { + let artifacts = plugins::build_browser( + &build, + &root, + &libraries.reference, + frontend.as_ref().unwrap(), + &plugins::BrowserOptions { + cef_root: PathBuf::from( + std::env::var_os("OBS_CEF_ROOT").expect("set OBS_CEF_ROOT to the CEF SDK"), + ), + panels: std::env::var_os("OBS_BUILD_DISABLE_BROWSER_PANELS").is_none(), + unity: std::env::var_os("OBS_BUILD_DISABLE_BROWSER_UNITY").is_none(), + }, + ) + .unwrap(); + assert!(artifacts.helper.is_file()); + assert!(artifacts.cef_root.join("include/cef_version.h").is_file()); + let symbols = exports(&artifacts.module.library); + for symbol in ["obs_browser_create_qcef", "obs_browser_qcef_version_export"] { + assert_eq!( + symbols.contains(symbol), + std::env::var_os("OBS_BUILD_DISABLE_BROWSER_PANELS").is_none() + ); + } + for symbol in [ + "obs_module_load", + "obs_module_set_pointer", + "obs_module_ver", + ] { + assert!( + symbols.contains(symbol), + "missing browser entry point {symbol}" + ); + } + for path in [&artifacts.helper, &artifacts.module.library] { + let deps = std::process::Command::new("readelf") + .args(["-d"]) + .arg(path) + .output() + .unwrap(); + assert!(deps.status.success()); + let deps = String::from_utf8_lossy(&deps.stdout); + assert!(deps.contains("libcef.so")); + } + let result = std::process::Command::new(&artifacts.helper) + .output() + .unwrap(); + // CEF documents -1 when no subprocess type was requested. Linux main + // exposes that as 255; executing it also checks runtime library loading. + assert_eq!( + result.status.code(), + Some(255), + "CEF helper: {}", + String::from_utf8_lossy(&result.stderr) + ); + artifacts + }); + if let Some(browser) = &browser { + std::fs::write(build.output.join("browser-build.json"), serde_json::to_vec_pretty(&serde_json::json!({"module":browser.module.library,"helper":browser.helper,"cef_root":browser.cef_root})).unwrap()).unwrap(); + } + if let (Some(frontend), Some(reference)) = + (&frontend, std::env::var_os("OBS_BUILD_FRONTEND_REFERENCE")) + { + assert_eq!(exports(frontend), exports(&PathBuf::from(reference))); + } + let mut application = None; + if enabled("OBS_BUILD_APP") { + let gpu_archive = PathBuf::from( + std::env::var_os("OBS_BUILD_GPU_ARCHIVE") + .expect("build obs-gpu-status-frontend in release mode first"), + ); + let executable = frontend::build_application_with_options( + &build, + &root, + &libraries.reference, + frontend.as_ref().unwrap(), + &gpu_archive, + &frontend::ApplicationOptions { + browser_panels: browser_enabled + && std::env::var_os("OBS_BUILD_DISABLE_BROWSER_PANELS").is_none(), + }, + ) + .unwrap(); + let output = std::process::Command::new(&executable) + .arg("--version") + .output() + .unwrap(); + assert!( + output.status.success(), + "{}\n{}", + String::from_utf8_lossy(&output.stdout), + String::from_utf8_lossy(&output.stderr) + ); + assert!(String::from_utf8_lossy(&output.stdout).contains("33.0")); + println!( + "OBS application version: {}", + String::from_utf8_lossy(&output.stdout).trim() + ); + application = Some(executable); + } + let mut ffmpeg = None; + if enabled("OBS_BUILD_RECORD") { + modules.push(plugins::build_x264(&build, &root, &libraries.reference).unwrap()); + modules + .push(plugins::build_outputs(&build, &root, &libraries.reference, &options).unwrap()); + let artifacts = plugins::build_ffmpeg( + &build, + &root, + &libraries.reference, + &options, + &plugins::FfmpegOptions::default(), + ) + .unwrap(); + modules.push(plugins::Module { + library: artifacts.module.library.clone(), + data: artifacts.module.data.clone(), + }); + ffmpeg = Some(artifacts); + } + // Mirror the app layout: the module launches its helper beside the process. + if ffmpeg.is_some() || nvenc.is_some() { + let bin = runner.parent().unwrap(); + if let Some(ffmpeg) = &ffmpeg { + let helper = ffmpeg.deploy_muxer(bin).unwrap(); + assert!(helper.is_file()); + } + if let Some(nvenc) = &nvenc { + std::fs::copy(&nvenc.helper, bin.join(nvenc.helper.file_name().unwrap())).unwrap(); + } + } + let wants_graphics = enabled("OBS_BUILD_RENDER") + || enabled("OBS_BUILD_RECORD") + || enabled("OBS_BUILD_SOURCES") + || enabled("OBS_BUILD_PIPEWIRE") + || nvenc.is_some() + || qsv_enabled + || captures_audio() + || std::env::var_os("OBS_BUILD_VLC_C_TESTS").is_some() + || std::env::var_os("OBS_BUILD_GRAPHICS_C_TESTS").is_some(); + let renderer = wants_graphics + .then(|| graphics::build_opengl(&build, &root, &libraries.reference, &options).unwrap()); + let probe = renderer + .as_ref() + .map(|_| render::build(&build, &root, &libraries.reference)); + if std::env::var_os("OBS_BUILD_GRAPHICS_C_TESTS").is_some() { + let tests = obs_build::validation::build_graphics_tests( + &build, + &root, + &libraries.reference, + renderer.as_ref().unwrap(), + ) + .unwrap(); + assert_eq!(tests.len(), 1); + native_tests::exercise( + &build, + &root, + &libraries.reference, + &libraries.with_rust, + &tests, + "graphics", + ); + } + if std::env::var_os("OBS_BUILD_VLC_C_TESTS").is_some() { + let vlc = modules + .iter() + .find(|module| module.library.file_name() == Some(std::ffi::OsStr::new("vlc-video.so"))) + .expect("VLC compatibility tests require OBS_BUILD_VLC=1"); + vlc_tests::exercise( + &build, + &root, + &libraries.reference, + &libraries.with_rust, + vlc, + renderer.as_ref().unwrap(), + ); + } + if enabled("OBS_BUILD_APP_GUI") { + let gui_probe = (frontend_tools.is_some() || websocket.is_some()).then(|| { + tools::build( + &build, + &root, + &libraries.reference, + frontend.as_ref().unwrap(), + ) + }); + application::exercise( + application::Inputs { + root: &root, + build: &build, + executable: application.as_ref().unwrap(), + api: frontend.as_ref().unwrap(), + renderer: renderer.as_ref().unwrap(), + ffmpeg: ffmpeg.as_ref().unwrap(), + nvenc_helper: nvenc.as_ref().map(|nvenc| nvenc.helper.as_path()), + modules: &modules, + frontend_tools: frontend_tools.as_ref(), + websocket: websocket.as_ref(), + browser: browser.as_ref(), + script_artifacts: if tools_enabled { + script_artifacts.as_ref() + } else { + None + }, + gui_probe: gui_probe.as_ref(), + }, + &[ + application::Variant { + core: &libraries.reference, + nvenc: nvenc.as_ref().map(|nvenc| &nvenc.reference), + }, + application::Variant { + core: &libraries.with_rust, + nvenc: nvenc.as_ref().map(|nvenc| &nvenc.with_rust), + }, + ], + ) + .unwrap(); + } + // libobs twins intentionally share one SONAME. Loading both in one process + // can retain a prior plugin's dependency and bind it to the wrong OBS state. + // Run each variant in the same fresh-process isolation as the C tests. + let modules: Vec<_> = modules + .iter() + .map(|module| (&module.library, &module.data)) + .collect(); + let mov_recording = std::env::var_os("OBS_BUILD_MOV_RECORD").is_some(); + if mov_recording { + assert!(enabled("OBS_BUILD_RECORD") && ffmpeg.is_some()); + } + let outputs: &[(&str, &str)] = if mov_recording { + &[ + ("mp4_output", "mp4"), + ("ffmpeg_muxer", "mkv"), + ("mov_output", "mov"), + ] + } else if ffmpeg.is_some() { + &[("mp4_output", "mp4"), ("ffmpeg_muxer", "mkv")] + } else { + &[("mp4_output", "mp4")] + }; + let mut qsv_registrations = Vec::>::new(); + for (path, (output_id, extension)) in [&libraries.reference, &libraries.with_rust] + .into_iter() + .flat_map(|path| outputs.iter().map(move |output| (path, output))) + { + let mut selected = modules.clone(); + if let Some(nvenc) = &nvenc { + let module = if path == &libraries.with_rust { + &nvenc.with_rust + } else { + &nvenc.reference + }; + selected.push((&module.library, &module.data)); + } + let serialized = serde_json::to_string(&selected).unwrap(); + let mut command = std::process::Command::new(&runner); + if *output_id != "mp4_output" { + command.env_remove("OBS_BUILD_WHIP_ENDPOINT"); + } + command.env("OBS_BUILD_TEST_OUTPUT_ID", output_id); + if let Some(frontend) = &frontend { + command.env("OBS_BUILD_TEST_FRONTEND_API", frontend); + } + // The helper is a fresh process; select the same twin as its parent. + let mut search = vec![path.parent().unwrap().to_owned()]; + search.extend(std::env::split_paths( + &std::env::var_os("LD_LIBRARY_PATH").unwrap_or_default(), + )); + command.env("LD_LIBRARY_PATH", std::env::join_paths(search).unwrap()); + if let Some(renderer) = &renderer { + command.env("OBS_BUILD_TEST_RENDERER", renderer); + command.env("OBS_BUILD_TEST_PROBE", probe.as_ref().unwrap()); + } + let recording = enabled("OBS_BUILD_RECORD").then(|| { + let variant = path + .parent() + .unwrap() + .file_name() + .unwrap() + .to_str() + .unwrap(); + build + .output + .join(format!("recording-{variant}.{extension}")) + }); + if let Some(recording) = &recording { + command.env("OBS_BUILD_TEST_RECORDING", recording); + } + let run = command + .args([ + "--exact", + "c_and_rust_twins_preserve_public_data_lifecycle_and_module_apis", + "--nocapture", + ]) + .env("OBS_BUILD_TEST_CORE", path) + .env("OBS_BUILD_TEST_MODULES", &serialized) + .output() + .unwrap(); + for line in String::from_utf8_lossy(&run.stdout).lines().filter(|line| { + line.contains("Loading up OpenGL") + || line.contains("cc::Build graphics device") + || line.contains("cc::Build recording") + || line.contains("cc::Build color source") + || line.contains("cc::Build audio encoder") + || line.contains("cc::Build JACK capture") + || line.contains("cc::Build sndio capture") + || line.contains("cc::Build QSV encoders") + || line.contains("cc::Build WHIP") + }) { + println!("{}: {line}", path.display()); + } + assert!( + run.status.success(), + "{}\n{}\n{}", + run.status, + String::from_utf8_lossy(&run.stdout), + String::from_utf8_lossy(&run.stderr) + ); + if qsv_enabled { + let stdout = String::from_utf8_lossy(&run.stdout); + let encoders: Vec = serde_json::from_str( + stdout + .lines() + .find_map(|line| { + line.split_once("cc::Build QSV encoders: ") + .map(|(_, ids)| ids) + }) + .expect("QSV capability inventory was not exercised"), + ) + .unwrap(); + if let Some(reference) = std::env::var_os("OBS_BUILD_QSV_REFERENCE") { + let reference = PathBuf::from(reference); + let mut replaced = false; + for (binary, _) in &mut selected { + if binary.file_name() == Some(std::ffi::OsStr::new("obs-qsv11.so")) { + *binary = &reference; + replaced = true; + } + } + assert!(replaced, "QSV reference did not replace the built module"); + let mut oracle = std::process::Command::new(command.get_program()); + oracle.args(command.get_args()); + for (key, value) in command.get_envs() { + if let Some(value) = value { + oracle.env(key, value); + } else { + oracle.env_remove(key); + } + } + let oracle = oracle + .env( + "OBS_BUILD_TEST_MODULES", + serde_json::to_string(&selected).unwrap(), + ) + .env_remove("OBS_BUILD_TEST_RECORDING") + .output() + .unwrap(); + assert!( + oracle.status.success(), + "{}\n{}", + String::from_utf8_lossy(&oracle.stdout), + String::from_utf8_lossy(&oracle.stderr) + ); + let oracle_stdout = String::from_utf8_lossy(&oracle.stdout); + let reference_ids: Vec = serde_json::from_str( + oracle_stdout + .lines() + .find_map(|line| { + line.split_once("cc::Build QSV encoders: ") + .map(|(_, ids)| ids) + }) + .expect("reference QSV inventory was not exercised"), + ) + .unwrap(); + assert_eq!( + encoders, reference_ids, + "QSV registrations differ from CMake" + ); + println!("QSV reference runtime matched for {}", path.display()); + } + if let Some(first) = qsv_registrations.first() { + assert_eq!( + &encoders, first, + "QSV registrations differ across core variants" + ); + } + qsv_registrations.push(encoders); + std::fs::write( + build.output.join("qsv-registrations.json"), + serde_json::to_vec_pretty(&qsv_registrations).unwrap(), + ) + .unwrap(); + } + if std::env::var_os("OBS_BUILD_FDK").is_some() && recording.is_some() { + assert!( + String::from_utf8_lossy(&run.stdout) + .contains("cc::Build audio encoder: libfdk_aac") + ); + } + if std::env::var_os("OBS_BUILD_JACK_CAPTURE").is_some() { + assert!(String::from_utf8_lossy(&run.stdout).contains("cc::Build JACK capture:")); + } + if std::env::var_os("OBS_BUILD_SNDIO_CAPTURE_DEVICE").is_some() { + assert!(String::from_utf8_lossy(&run.stdout).contains("cc::Build sndio capture:")); + } + if let Some(recording) = recording { + verify_recording(&recording); + } + } +} + +fn exercise(path: &std::path::Path, modules: &[plugins::Module], hevc: bool) { + let module_config = tempfile::tempdir().unwrap(); + let module_config_path = + std::ffi::CString::new(module_config.path().to_str().unwrap()).unwrap(); + // SAFETY: these signatures come from the unchanged obs.h/obs-data.h. + // Symbols are called only while their library is loaded, data handles + // are released, and each library owns its complete startup/shutdown. + unsafe { + let library = libloading::Library::new(path).unwrap(); + for symbol in [ + b"obs_hevc_keyframe".as_slice(), + b"obs_parse_hevc_packet".as_slice(), + b"obs_parse_hevc_packet_priority".as_slice(), + b"obs_extract_hevc_headers".as_slice(), + ] { + assert_eq!(library.get::(symbol).is_ok(), hevc); + } + let frontend = std::env::var_os("OBS_BUILD_TEST_FRONTEND_API") + .map(|path| libloading::Library::new(path).unwrap()); + if let Some(frontend) = &frontend { + assert!(!frontend + .get:: bool>(b"obs_frontend_recording_active") + .unwrap()()); + assert!( + frontend + .get:: *mut c_void>(b"obs_frontend_get_main_window") + .unwrap()() + .is_null() + ); + } + let probe = std::env::var_os("OBS_BUILD_TEST_PROBE") + .map(|path| libloading::Library::new(path).unwrap()); + if let Some(probe) = &probe { + let open = probe + .get:: bool>(b"obs_fixture_open_display") + .unwrap(); + assert!(open(), "isolated X11 display could not be opened"); + } + let startup = library + .get:: bool>(b"obs_startup") + .unwrap(); + let shutdown = library + .get::(b"obs_shutdown") + .unwrap(); + let create = library + .get:: *mut c_void>(b"obs_data_create") + .unwrap(); + let set = library + .get::( + b"obs_data_set_int", + ) + .unwrap(); + let get = library + .get:: i64>( + b"obs_data_get_int", + ) + .unwrap(); + let release = library + .get::(b"obs_data_release") + .unwrap(); + assert!(startup( + c"en-US".as_ptr(), + module_config_path.as_ptr(), + std::ptr::null_mut() + )); + if let Some(probe) = &probe { + let renderer = + std::ffi::CString::new(std::env::var("OBS_BUILD_TEST_RENDERER").unwrap()).unwrap(); + let data_path = PathBuf::from(env!("CARGO_MANIFEST_DIR")) + .join("../../libobs/data") + .canonicalize() + .unwrap(); + let data_path = std::ffi::CString::new(format!("{}/", data_path.display())).unwrap(); + let initialize = + probe + .get:: i32>(b"obs_fixture_initialize") + .unwrap(); + assert_eq!( + initialize( + renderer.as_ptr(), + data_path.as_ptr(), + enabled("OBS_BUILD_RECORD") || captures_audio() + ), + 0 + ); + } + let open = library + .get:: i32>(b"obs_open_module") + .unwrap(); + let init = library + .get:: bool>(b"obs_init_module") + .unwrap(); + for module in modules { + let binary = std::ffi::CString::new(module.library.to_str().unwrap()).unwrap(); + let data_path = std::ffi::CString::new(module.data.to_str().unwrap()).unwrap(); + let mut handle = std::ptr::null_mut(); + assert_eq!(open(&mut handle, binary.as_ptr(), data_path.as_ptr()), 0); + assert!(init(handle)); + } + let mut expected_types = vec![ + (b"obs_enum_transition_types".as_slice(), "fade_transition"), + (b"obs_enum_filter_types".as_slice(), "noise_suppress_filter"), + (b"obs_enum_filter_types".as_slice(), "gain_filter"), + ]; + for (flag, id) in [ + ("OBS_BUILD_JACK", "jack_output_capture"), + ("OBS_BUILD_SNDIO", "sndio_output_capture"), + ] { + if std::env::var_os(flag).is_some() { + expected_types.push((b"obs_enum_input_types".as_slice(), id)); + } + } + if std::env::var_os("OBS_BUILD_FDK").is_some() { + expected_types.push((b"obs_enum_encoder_types".as_slice(), "libfdk_aac")); + } + if std::env::var_os("OBS_BUILD_NVENC").is_some() { + expected_types.extend([ + (b"obs_enum_encoder_types".as_slice(), "obs_nvenc_h264_soft"), + (b"obs_enum_encoder_types".as_slice(), "obs_nvenc_h264_tex"), + (b"obs_enum_encoder_types".as_slice(), "ffmpeg_nvenc"), + ]); + } + if enabled("OBS_BUILD_RECORD") { + let codecs = library + .get:: *const std::ffi::c_char>( + b"obs_get_output_supported_video_codecs", + ) + .unwrap(); + for id in [c"mp4_output", c"mov_output"] { + let supported = codecs(id.as_ptr()); + assert!(!supported.is_null()); + let supported = std::ffi::CStr::from_ptr(supported).to_str().unwrap(); + assert_eq!( + supported.split(';').any(|codec| codec == "hevc"), + hevc, + "output HEVC advertisement does not match the build option" + ); + } + expected_types.extend([ + (b"obs_enum_encoder_types".as_slice(), "obs_x264"), + (b"obs_enum_encoder_types".as_slice(), "ffmpeg_aac"), + (b"obs_enum_output_types".as_slice(), "mp4_output"), + (b"obs_enum_output_types".as_slice(), "ffmpeg_muxer"), + ]); + let maps = std::fs::read_to_string("/proc/self/maps").unwrap(); + let srt: std::collections::BTreeSet<_> = maps + .lines() + .filter_map(|line| line.split_whitespace().last()) + .filter(|path| path.contains("/libsrt.so")) + .collect(); + assert_eq!( + srt.len(), + 1, + "exactly one SRT shared library must be loaded" + ); + } + if enabled("OBS_BUILD_SOURCES") { + expected_types.extend([ + (b"obs_enum_input_types".as_slice(), "image_source"), + (b"obs_enum_input_types".as_slice(), "color_source"), + (b"obs_enum_input_types".as_slice(), "slideshow"), + (b"obs_enum_input_types".as_slice(), "text_ft2_source"), + (b"obs_enum_input_types".as_slice(), "pulse_input_capture"), + (b"obs_enum_input_types".as_slice(), "pulse_output_capture"), + (b"obs_enum_input_types".as_slice(), "alsa_input_capture"), + (b"obs_enum_input_types".as_slice(), "v4l2_input"), + (b"obs_enum_input_types".as_slice(), "xshm_input"), + (b"obs_enum_input_types".as_slice(), "xcomposite_input"), + (b"obs_enum_output_types".as_slice(), "virtualcam_output"), + (b"obs_enum_service_types".as_slice(), "rtmp_common"), + (b"obs_enum_service_types".as_slice(), "rtmp_custom"), + ]); + } + if enabled("OBS_BUILD_QT") { + expected_types.push((b"obs_enum_filter_types".as_slice(), "vst_filter")); + } + if std::env::var_os("OBS_BUILD_WEBRTC").is_some() { + for (symbol, expected) in [ + ( + b"obs_get_output_supported_video_codecs".as_slice(), + if hevc { "h264;hevc;av1" } else { "h264;av1" }, + ), + (b"obs_get_output_supported_audio_codecs".as_slice(), "opus"), + ] { + let codecs = library + .get:: *const std::ffi::c_char>(symbol) + .unwrap(); + let supported = codecs(c"whip_output".as_ptr()); + assert!(!supported.is_null()); + assert_eq!( + std::ffi::CStr::from_ptr(supported).to_str().unwrap(), + expected + ); + } + expected_types.extend([ + (b"obs_enum_output_types".as_slice(), "whip_output"), + (b"obs_enum_service_types".as_slice(), "whip_custom"), + ]); + } + for (symbol, expected) in expected_types { + let enumerate = library + .get:: bool>(symbol) + .unwrap(); + let mut found = false; + for index in 0..1024 { + let mut name = std::ptr::null(); + if !enumerate(index, &mut name) { + break; + } + assert!(!name.is_null()); + found |= std::ffi::CStr::from_ptr(name).to_str().unwrap() == expected; + } + let enabled = expected != "noise_suppress_filter" + || std::env::var_os("OBS_BUILD_DISABLE_SPEEXDSP").is_none() + || std::env::var_os("OBS_BUILD_DISABLE_RNNOISE").is_none(); + let enabled = enabled + && (expected != "ffmpeg_nvenc" + || std::env::var_os("OBS_BUILD_DISABLE_NVENC_FFMPEG_IDS").is_none()); + assert_eq!(found, enabled, "unexpected registration of {expected}"); + } + if std::env::var_os("OBS_BUILD_QSV").is_some() { + let enumerate = library + .get:: bool>( + b"obs_enum_encoder_types", + ) + .unwrap(); + let mut ids = Vec::new(); + for index in 0..1024 { + let mut id = std::ptr::null(); + if !enumerate(index, &mut id) { + break; + } + let id = std::ffi::CStr::from_ptr(id).to_str().unwrap(); + if id.starts_with("obs_qsv11") { + assert!(hevc || !id.contains("hevc")); + ids.push(id.to_owned()); + } + } + ids.sort(); + println!( + "cc::Build QSV encoders: {}", + serde_json::to_string(&ids).unwrap() + ); + } + if let Some(probe) = &probe { + let render = probe + .get:: i32>(b"obs_fixture_render") + .unwrap(); + let recording = std::env::var("OBS_BUILD_TEST_RECORDING") + .ok() + .map(|path| std::ffi::CString::new(path).unwrap()); + let output_id = std::ffi::CString::new( + std::env::var("OBS_BUILD_TEST_OUTPUT_ID").unwrap_or_else(|_| "mp4_output".into()), + ) + .unwrap(); + assert_eq!( + render( + recording + .as_ref() + .map_or(std::ptr::null(), |path| path.as_ptr()), + output_id.as_ptr() + ), + 0, + "graphics/frame rendering failed" + ); + if std::env::var_os("OBS_BUILD_JACK_CAPTURE").is_some() { + assert!(std::env::var_os("OBS_BUILD_JACK").is_some()); + assert_eq!( + probe + .get:: i32>(b"obs_fixture_capture_jack") + .unwrap()(), + 0, + "JACK source did not receive the isolated writer's stereo samples" + ); + } + if let Ok(device) = std::env::var("OBS_BUILD_SNDIO_CAPTURE_DEVICE") { + assert!(std::env::var_os("OBS_BUILD_SNDIO").is_some()); + let device = std::ffi::CString::new(device).unwrap(); + assert_eq!( + probe + .get:: i32>( + b"obs_fixture_capture_sndio", + ) + .unwrap()(device.as_ptr()), + 0, + "sndio source did not receive the isolated writer's stereo samples" + ); + } + } + let data = create(); + assert!(!data.is_null()); + set(data, c"value".as_ptr(), -9223372036854775807); + assert_eq!(get(data, c"value".as_ptr()), -9223372036854775807); + release(data); + shutdown(); + if let Some(probe) = &probe { + probe + .get::(b"obs_fixture_close_display") + .unwrap()(); + } + } +} + +fn exports(path: &std::path::Path) -> std::collections::BTreeSet { + // This opt-in integration currently exercises the Linux native graph. + let result = std::process::Command::new("nm") + .args(["-D", "--defined-only"]) + .arg(path) + .output() + .expect("GNU nm is required for the Linux libobs export contract"); + assert!( + result.status.success(), + "{}", + String::from_utf8_lossy(&result.stderr) + ); + String::from_utf8(result.stdout) + .unwrap() + .lines() + .filter_map(|line| line.split_whitespace().last()) + .map(|name| name.split('@').next().unwrap().to_owned()) + .collect() +} + +fn verify_recording(path: &std::path::Path) { + let result = std::process::Command::new("ffprobe") + .args([ + "-v", + "error", + "-count_frames", + "-show_entries", + "stream=codec_name,profile,sample_rate,channels,width,height,nb_read_frames:format=duration", + "-of", + "json", + ]) + .arg(path) + .output() + .expect("ffprobe is required for recording integration"); + assert!( + result.status.success(), + "{}", + String::from_utf8_lossy(&result.stderr) + ); + let document: serde_json::Value = serde_json::from_slice(&result.stdout).unwrap(); + let streams = document["streams"].as_array().unwrap(); + let video = streams + .iter() + .find(|stream| stream["codec_name"] == "h264") + .expect("missing H.264 track"); + let (width, height) = if std::env::var_os("OBS_BUILD_NVENC_ENCODE").is_some() { + (640, 360) + } else { + (64, 64) + }; + assert_eq!(video["width"], width); + assert_eq!(video["height"], height); + assert!( + video["nb_read_frames"] + .as_str() + .unwrap() + .parse::() + .unwrap() + >= 10 + ); + let audio = streams + .iter() + .find(|stream| stream["codec_name"] == "aac") + .expect("missing AAC track"); + if std::env::var_os("OBS_BUILD_FDK").is_some() { + assert_eq!(audio["profile"], "LC"); + assert_eq!(audio["sample_rate"], "48000"); + assert_eq!(audio["channels"], 2); + } + assert!( + audio["nb_read_frames"] + .as_str() + .unwrap() + .parse::() + .unwrap() + > 0 + ); + assert!( + document["format"]["duration"] + .as_str() + .unwrap() + .parse::() + .unwrap() + >= 0.2 + ); + println!("validated recording: {}", path.display()); +} + +fn enabled(name: &str) -> bool { + std::env::var_os(name).is_some() || std::env::var_os("OBS_BUILD_APP_GUI").is_some() +} + +fn captures_audio() -> bool { + std::env::var_os("OBS_BUILD_JACK_CAPTURE").is_some() + || std::env::var_os("OBS_BUILD_SNDIO_CAPTURE_DEVICE").is_some() +} diff --git a/rust/obs-build/tests/libobs/application.rs b/rust/obs-build/tests/libobs/application.rs new file mode 100644 index 0000000000..a2ab369d0b --- /dev/null +++ b/rust/obs-build/tests/libobs/application.rs @@ -0,0 +1,310 @@ +//! Full frontend runtime validation with an isolated profile and display. +use obs_build::{NativeBuild, SharedLibrary, plugins, scripting}; +use std::path::{Path, PathBuf}; + +pub struct Inputs<'a> { + pub root: &'a Path, + pub build: &'a NativeBuild, + pub executable: &'a Path, + pub api: &'a Path, + pub renderer: &'a Path, + pub ffmpeg: &'a plugins::FfmpegArtifacts, + pub nvenc_helper: Option<&'a Path>, + pub modules: &'a [plugins::Module], + pub websocket: Option<&'a plugins::Module>, + pub browser: Option<&'a plugins::BrowserArtifacts>, + pub frontend_tools: Option<&'a plugins::Module>, + pub script_artifacts: Option<&'a scripting::Artifacts>, + pub gui_probe: Option<&'a plugins::Module>, +} + +pub struct Variant<'a> { + pub core: &'a Path, + pub nvenc: Option<&'a plugins::Module>, +} + +pub fn exercise(inputs: Inputs<'_>, variants: &[Variant<'_>]) -> Result<(), String> { + let inspector = inspector(inputs.build)?; + for variant in variants { + let core = variant.core; + // Retain this owned runtime, profile, log and screenshot as evidence. + let runtime = tempfile::Builder::new() + .prefix("app-runtime-") + .tempdir_in(&inputs.build.output) + .map_err(|e| e.to_string())? + .keep(); + let bin = runtime.join("bin"); + let libraries = runtime.join("lib64"); + std::fs::create_dir_all(&bin).map_err(|e| e.to_string())?; + std::fs::create_dir_all(&libraries).map_err(|e| e.to_string())?; + copy(inputs.executable, &bin.join("obs-studio-rust"))?; + for library in [core, inputs.api, inputs.renderer] { + copy( + library, + &libraries.join( + library + .file_name() + .ok_or("runtime library has no filename")?, + ), + )?; + } + inputs.ffmpeg.deploy_muxer(&bin)?; + if let Some(scripts) = inputs.script_artifacts { + let library_name = scripts + .library + .file_name() + .ok_or("scripting library has no filename")?; + copy(&scripts.library, &libraries.join(library_name))?; + let mut modules = Vec::new(); + let mut languages = Vec::new(); + for (language, module) in [ + ("lua", scripts.lua_module.as_deref()), + ("python", scripts.python_module.as_deref()), + ] { + if let Some(module) = module { + let relative = module + .strip_prefix(&scripts.runtime) + .map_err(|e| e.to_string())?; + copy(module, &runtime.join(relative))?; + modules.push(relative.to_string_lossy().into_owned()); + languages.push(language); + } + } + if let Some(wrapper) = &scripts.python_wrapper { + copy( + wrapper, + &runtime.join( + wrapper + .strip_prefix(&scripts.runtime) + .map_err(|e| e.to_string())?, + ), + )?; + } + let metadata = serde_json::json!({"library": format!("lib64/{}", library_name.to_string_lossy()), "modules": modules, "languages": languages}); + std::fs::write( + runtime.join("expected-scripting.json"), + serde_json::to_vec(&metadata).map_err(|e| e.to_string())?, + ) + .map_err(|e| e.to_string())?; + } + if let Some(helper) = inputs.nvenc_helper { + copy( + helper, + &bin.join(helper.file_name().ok_or("NVENC helper has no filename")?), + )?; + } + copy_tree( + &inputs.root.join("libobs/data"), + &runtime.join("share/obs/libobs"), + )?; + copy_tree( + &inputs.root.join("frontend/data"), + &runtime.join("share/obs/obs-studio"), + )?; + copy( + &inputs.root.join("AUTHORS"), + &runtime.join("share/obs/obs-studio/authors"), + )?; + let mut names = Vec::new(); + for module in inputs + .modules + .iter() + .chain(variant.nvenc) + .chain(inputs.frontend_tools) + .chain(inputs.websocket) + .chain(inputs.browser.map(|browser| &browser.module)) + .chain(inputs.gui_probe) + { + let name = module + .library + .file_stem() + .and_then(|name| name.to_str()) + .ok_or("invalid module filename")?; + let target = runtime.join("lib64/obs-modules/core"); + std::fs::create_dir_all(&target).map_err(|e| e.to_string())?; + copy( + &module.library, + &target.join(module.library.file_name().ok_or("module has no filename")?), + )?; + copy_tree( + &module.data, + &runtime.join("share/obs/obs-modules/core").join(name), + )?; + names.push(name); + } + std::fs::write( + runtime.join("expected-modules.json"), + serde_json::to_vec(&names).map_err(|e| e.to_string())?, + ) + .map_err(|e| e.to_string())?; + if let Some(browser) = inputs.browser { + browser.deploy_runtime(&runtime.join("lib64/obs-modules/core"))?; + } + // D-Bus activated services can inherit standard streams after the + // launcher exits. Files let us wait for the owned launcher without + // waiting indefinitely for every inherited pipe writer to disappear. + let probe_log = runtime.join("application-probe.log"); + let log = std::fs::File::create(&probe_log).map_err(|e| e.to_string())?; + let errors = log.try_clone().map_err(|e| e.to_string())?; + let result = std::process::Command::new("dbus-run-session") + .args(["--", "uv", "run", "--no-project", "python"]) + .arg( + inputs + .root + .join("rust/obs-build/tests/libobs/application_probe.py"), + ) + .arg("--runtime") + .arg(&runtime) + .arg("--inspector") + .arg(&inspector) + .stdout(log) + .stderr(errors) + .status() + .map_err(|e| e.to_string())?; + if !result.success() { + return Err(format!( + "{} GUI runtime {} failed: {}\n{}", + core.display(), + runtime.display(), + result, + std::fs::read_to_string(&probe_log).map_err(|e| e.to_string())? + )); + } + println!( + "OBS GUI runtime passed for {}: {}", + core.display(), + runtime.display() + ); + } + Ok(()) +} + +fn copy(source: &Path, target: &Path) -> Result<(), String> { + if let Some(parent) = target.parent() { + std::fs::create_dir_all(parent).map_err(|e| e.to_string())?; + } + std::fs::copy(source, target) + .map(|_| ()) + .map_err(|e| format!("copy {} to {}: {e}", source.display(), target.display())) +} + +pub(super) fn copy_tree(source: &Path, target: &Path) -> Result<(), String> { + std::fs::create_dir_all(target).map_err(|e| e.to_string())?; + for entry in std::fs::read_dir(source).map_err(|e| e.to_string())? { + let entry = entry.map_err(|e| e.to_string())?; + let destination = target.join(entry.file_name()); + if entry.path().is_dir() { + copy_tree(&entry.path(), &destination)?; + } else { + copy(&entry.path(), &destination)?; + } + } + Ok(()) +} + +fn inspector(build: &NativeBuild) -> Result { + let source = build.output.join("application-window-probe.c"); + if std::fs::read_to_string(&source).ok().as_deref() != Some(WINDOW_PROBE) { + std::fs::write(&source, WINDOW_PROBE).map_err(|e| e.to_string())?; + } + let mut target = SharedLibrary { + name: "application-window-probe".into(), + sources: vec![source], + ..SharedLibrary::default() + }; + let x11 = pkg_config::Config::new() + .cargo_metadata(false) + .probe("x11") + .map_err(|e| e.to_string())?; + target.include_dirs.extend(x11.include_paths); + for path in x11.link_paths { + target.link_options.extend([ + format!("-L{}", path.display()), + format!("-Wl,-rpath,{}", path.display()), + ]); + } + target + .link_options + .extend(x11.libs.iter().map(|name| format!("-l{name}"))); + build.executable(&target) +} + +const WINDOW_PROBE: &str = r#" +#include +#include +#include +#include +#include + +static int ignore_error(Display *display, XErrorEvent *error) { (void)display; (void)error; return 0; } + +static int matches(Display *display, Window window, unsigned long pid) +{ + Atom type; + int format; + unsigned long length, remaining; + unsigned char *value = NULL; + if (XGetWindowProperty(display, window, XInternAtom(display, "_NET_WM_PID", False), 0, 1, False, + XA_CARDINAL, &type, &format, &length, &remaining, &value) != Success || !value) + return 0; + int same = format == 32 && length == 1 && *(unsigned long *)value == pid; + XFree(value); + if (!same) + return 0; + XWindowAttributes attributes; + if (!XGetWindowAttributes(display, window, &attributes) || attributes.map_state != IsViewable || + attributes.width < 300 || attributes.height < 200) + return 0; + value = NULL; + if (XGetWindowProperty(display, window, XInternAtom(display, "_NET_WM_WINDOW_TYPE", False), 0, 32, False, + XA_ATOM, &type, &format, &length, &remaining, &value) != Success || !value) + return 0; + Atom normal = XInternAtom(display, "_NET_WM_WINDOW_TYPE_NORMAL", False); + int result = 0; + if (format == 32) + for (unsigned long i = 0; i < length; ++i) + result |= ((Atom *)value)[i] == normal; + XFree(value); + return result; +} + +static Window find(Display *display, Window window, unsigned long pid) +{ + if (matches(display, window, pid)) + return window; + Window root, parent, *children = NULL, result = 0; + unsigned count = 0; + if (XQueryTree(display, window, &root, &parent, &children, &count)) + for (unsigned i = 0; i < count && !result; ++i) + result = find(display, children[i], pid); + if (children) + XFree(children); + return result; +} + +int main(int argc, char **argv) +{ + if (argc != 3) + return 2; + Display *display = XOpenDisplay(NULL); + if (!display) + return 3; + XSetErrorHandler(ignore_error); + Window window = find(display, DefaultRootWindow(display), strtoul(argv[2], NULL, 10)); + if (!window) { XCloseDisplay(display); return 1; } + if (strcmp(argv[1], "close") == 0) { + XEvent event = {0}; + event.xclient.type = ClientMessage; + event.xclient.window = window; + event.xclient.message_type = XInternAtom(display, "WM_PROTOCOLS", False); + event.xclient.format = 32; + event.xclient.data.l[0] = XInternAtom(display, "WM_DELETE_WINDOW", False); + event.xclient.data.l[1] = CurrentTime; + XSendEvent(display, window, False, NoEventMask, &event); + XFlush(display); + } + printf("%lu\n", window); + XCloseDisplay(display); + return 0; +} +"#; diff --git a/rust/obs-build/tests/libobs/application_probe.py b/rust/obs-build/tests/libobs/application_probe.py new file mode 100644 index 0000000000..eb11e39275 --- /dev/null +++ b/rust/obs-build/tests/libobs/application_probe.py @@ -0,0 +1,319 @@ +#!/usr/bin/env -S uv run --script +"""Run a staged frontend with an owned scene/profile on an isolated X display.""" +from __future__ import annotations + +import argparse +import configparser +import json +import os +from pathlib import Path +import select +import secrets +import socket +import subprocess +import time +import uuid + + +def profile(runtime: Path) -> Path: + if os.environ.get("OBS_BUILD_BROWSER"): + (runtime / "browser-panel.html").write_text( + '' + ) + config = runtime / "user-config/obs-studio-rust" + config.mkdir(parents=True) + browser_accel = "BrowserHWAccel=false\n" if os.environ.get("LIBGL_ALWAYS_SOFTWARE") == "1" else "" + (config / "global.ini").write_text(f"[General]\nLastVersion=4294967295\n{browser_accel}") + (config / "user.ini").write_text( + "[General]\nLanguage=en-US\nFirstRun=true\nConfirmOnExit=false\n" + "[Basic]\nProfile=NativeSmoke\nProfileDir=NativeSmoke\n" + "SceneCollection=NativeSmoke\nSceneCollectionFile=NativeSmoke\n" + ) + selected = config / "basic/profiles/NativeSmoke" + selected.mkdir(parents=True) + (selected / "basic.ini").write_text( + "[General]\nName=NativeSmoke\n[Video]\nBaseCX=640\nBaseCY=360\n" + "OutputCX=640\nOutputCY=360\nFPSType=0\nFPSCommon=30\n" + "[Audio]\nSampleRate=48000\nChannelSetup=Stereo\n" + ) + if os.environ.get("OBS_BUILD_APP_RECORD"): + recordings = runtime / "recordings" + recordings.mkdir() + encoder = "nvenc" if os.environ.get("OBS_BUILD_NVENC") else "x264" + with (selected / "basic.ini").open("a") as output: + output.write( + "[Output]\nMode=Simple\n[SimpleOutput]\n" + f"FilePath={recordings}\nRecFormat2=mkv\nRecQuality=Small\n" + f"RecEncoder={encoder}\nRecAudioEncoder=aac\nRecTracks=1\n" + "StreamAudioEncoder=aac\nABitrate=128\nVBitrate=1000\n" + ) + color = {"name": "Native white", "id": "color_source_v3", "uuid": str(uuid.uuid4()), + "settings": {"width": 640, "height": 360, "color": 0xFFFFFFFF}, "volume": 1.0} + scene = {"name": "Native scene", "id": "scene", "uuid": str(uuid.uuid4()), + "settings": {"items": [{"name": color["name"], "source_uuid": color["uuid"], "visible": True}]}} + scenes = config / "basic/scenes" + scenes.mkdir(parents=True) + modules = {} + manifest = runtime / "expected-scripting.json" + if manifest.exists(): + scripts = runtime / "saved-scripts" + scripts.mkdir() + modules["scripts-tool"] = [] + for language in json.loads(manifest.read_text())["languages"]: + path = scripts / ("native_gui.lua" if language == "lua" else "native_gui.py") + path.write_text(LUA_SCRIPT if language == "lua" else PYTHON_SCRIPT) + modules["scripts-tool"].append({"path": str(path), "settings": {"seed": 41}}) + (scenes / "NativeSmoke.json").write_text(json.dumps({ + "name": "NativeSmoke", "current_scene": "Native scene", "current_program_scene": "Native scene", + "scene_order": [{"name": "Native scene"}], "sources": [color, scene], "modules": modules, + })) + if os.environ.get("OBS_BUILD_WEBSOCKET"): + with socket.socket() as reservation: + reservation.bind(("127.0.0.1", 0)) + port = reservation.getsockname()[1] + password = secrets.token_hex(16) + directory = config / "plugin_config/obs-websocket" + directory.mkdir(parents=True) + (directory / "config.json").write_text(json.dumps({ + "first_load": False, "server_enabled": True, "server_port": port, + "alerts_enabled": False, "auth_required": True, "server_password": password, + })) + (runtime / "expected-websocket.json").write_text(json.dumps({"port": port, "password": password})) + return config + + +def main() -> None: + parser = argparse.ArgumentParser() + parser.add_argument("--runtime", type=Path, required=True) + parser.add_argument("--inspector", type=Path, required=True) + args = parser.parse_args() + runtime = args.runtime.resolve() + config = profile(runtime) + env = dict(os.environ) + env.update(XDG_CONFIG_HOME=str(runtime / "user-config"), XDG_DATA_HOME=str(runtime / "user-data"), + XDG_CACHE_HOME=str(runtime / "user-cache"), QT_QPA_PLATFORM="xcb", + QT_QPA_PLATFORMTHEME="", QT_STYLE_OVERRIDE="Fusion") + # Desktop-session paths may select plugins from a different Qt installation. + # Use the linked Qt library's own default plugin paths for this isolated test. + env.pop("QT_PLUGIN_PATH", None) + env.pop("QT_QPA_PLATFORM_PLUGIN_PATH", None) + for variable in ["PYTHONHOME", "PYTHONPATH", "LUA_PATH", "LUA_CPATH"]: + env.pop(variable, None) + manifest = runtime / "expected-scripting.json" + scripting = json.loads(manifest.read_text()) if manifest.exists() else None + env["OBS_BUILD_GUI_EVIDENCE"] = str(runtime) + env["OBS_BUILD_GUI_SCRIPT_COUNT"] = str(len(scripting["languages"])) if scripting else "-1" + env["LD_LIBRARY_PATH"] = str(runtime / "lib64") + os.pathsep + env.get("LD_LIBRARY_PATH", "") + env.pop("OBS_DATA_PATH", None) + env.pop("WAYLAND_DISPLAY", None) + recording = bool(os.environ.get("OBS_BUILD_APP_RECORD")) + if os.environ.get("OBS_BUILD_NVENC"): + assert (runtime / "bin/obs-nvenc-test").is_file(), "NVENC capability helper was not staged" + command = [str(runtime / "bin/obs-studio-rust"), "--multi", "--only-bundled-plugins", + "--disable-shutdown-check", "--disable-updater", "--disable-missing-files-check", "--unfiltered_log"] + if os.environ.get("OBS_BUILD_BROWSER"): + # This fresh disposable profile contains no user credentials. Avoid an + # interactive desktop keyring unlock blocking CEF's initial cookie load + # in the isolated Xvfb/D-Bus session. Production launch is unaffected. + command.append("--password-store=basic") + # The wire probe starts recording after its other protocol checks, keeping + # dependency setup and network checks outside the timed recording interval. + wire_recording = recording and bool(os.environ.get("OBS_BUILD_WEBSOCKET")) + if recording and not wire_recording: + command.append("--startrecording") + app = subprocess.Popen(command, env=env, cwd=runtime, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) + log = bytearray() + drained = False + try: + deadline = time.monotonic() + 45 + ready = False + while time.monotonic() < deadline: + if app.poll() is not None: + raise RuntimeError(f"frontend exited during startup: {app.returncode}") + if select.select([app.stdout], [], [], 0.2)[0]: + chunk = os.read(app.stdout.fileno(), 65536) + log.extend(chunk) + (runtime / "application.log").write_bytes(log) + if b"error: cc::Build" in log: + raise RuntimeError(f"frontend GUI probe failed; see {runtime / 'application.log'}") + tools_ready = not (os.environ.get("OBS_BUILD_FRONTEND_TOOLS") or os.environ.get("OBS_BUILD_WEBSOCKET")) or b"cc::Build frontend Tools dialogs verified" in log + if b"==== Startup complete" in log and tools_ready and (not recording or wire_recording or b"==== Recording Start" in log): + found = subprocess.run([str(args.inspector), "find", str(app.pid)], env=env, capture_output=True) + if found.returncode == 0: + ready = True + break + if not ready: + raise RuntimeError("frontend did not finish startup and map a normal main window") + maps = Path(f"/proc/{app.pid}/maps").read_text() + (runtime / "application.maps").write_text(maps) + for name in ["libobs.so.30", "libobs-frontend-api.so.30", "libobs-opengl.so.33"]: + assert str(runtime / "lib64" / name) in maps, f"staged {name} was not loaded" + for name in json.loads((runtime / "expected-modules.json").read_text()): + assert str(runtime / "lib64/obs-modules/core" / (name + ".so")) in maps, f"module {name} was not loaded" + if os.environ.get("OBS_BUILD_BROWSER"): + assert str(runtime / "lib64/obs-modules/core/libcef.so") in maps, "staged CEF was not loaded" + if os.environ.get("OBS_BUILD_VLC"): + if os.environ.get("OBS_BUILD_VLC_ABSENT"): + assert "libvlc.so.5" not in maps, "VLC absence fixture found a runtime" + assert b"VLC video source disabled" in log, "missing VLC was not handled gracefully" + else: + assert "libvlc.so.5" in maps, "VLC runtime was not loaded dynamically" + if os.environ.get("OBS_BUILD_NVENC"): + assert str(runtime / "lib64/obs-modules/core/obs-nvenc.so") in maps, "staged NVENC was not loaded" + if scripting: + for relative in [scripting["library"], *scripting["modules"]]: + assert str(runtime / relative) in maps, f"staged scripting artifact was not loaded: {relative}" + for language in scripting["languages"]: + assert f"native-gui-{language}-loaded".encode() in log, f"saved {language} script did not run" + if os.environ.get("OBS_BUILD_FRONTEND_TOOLS"): + for name in ["tools-scene-switcher.png", "tools-output-timer.png", *(["tools-scripts.png"] if scripting else [])]: + assert (runtime / name).is_file(), f"missing Tools dialog evidence: {name}" + if os.environ.get("OBS_BUILD_WEBSOCKET"): + for name in ["websocket-settings.png", "websocket-connect-info.png"]: + assert (runtime / name).is_file(), f"missing websocket dialog evidence: {name}" + wire = ["uv", "run", "--no-project", str(Path(__file__).with_name("websocket_probe.py")), + "--runtime", str(runtime)] + if recording: + wire.append("--recording") + subprocess.run(wire, env=env, check=True, timeout=60) + if os.environ.get("OBS_BUILD_BROWSER"): + verify_browser_helpers(runtime, app.pid) + assert b"Native white" in log, "saved color source was not restored" + if recording: + # Keep the actual frontend output running long enough to decode a + # meaningful recording. Window-close must finalize the mux helper. + time.sleep(3) + subprocess.run(["ffmpeg", "-v", "error", "-y", "-f", "x11grab", "-video_size", "1280x720", + "-i", env["DISPLAY"], "-frames:v", "1", str(runtime / "application.png")], env=env, + check=True, capture_output=True, timeout=15) + subprocess.run([str(args.inspector), "close", str(app.pid)], env=env, check=True, capture_output=True) + remainder, _ = app.communicate(timeout=30) + log.extend(remainder) + drained = True + (runtime / "application.log").write_bytes(log) + assert app.returncode == 0, f"frontend shutdown failed: {app.returncode}" + assert b"==== Shutting down" in log, "frontend did not enter normal shutdown" + saved = json.loads((config / "basic/scenes/NativeSmoke.json").read_text()) + assert any(source.get("name") == "Native white" for source in saved["sources"]), "saved scene was lost" + if os.environ.get("OBS_BUILD_VLC") and not os.environ.get("OBS_BUILD_VLC_ABSENT"): + source = next(source for source in saved["sources"] if source.get("name") == "Native VLC") + assert source["settings"]["playlist"][0]["value"] == str(runtime / "vlc-white.mkv"), "VLC playlist was not saved" + if os.environ.get("OBS_BUILD_BROWSER"): + source = next(source for source in saved["sources"] if source.get("name") == "Native browser") + assert source["settings"]["local_file"] == str(runtime / "browser-source.html") + if not os.environ.get("OBS_BUILD_DISABLE_BROWSER_PANELS"): + settings = configparser.ConfigParser(interpolation=None) + settings.read(config / "user.ini") + docks = json.loads(settings["BasicWindow"]["ExtraBrowserDocks"]) + assert any(dock["title"] == "Native CEF Panel" and dock["url"] == (runtime / "browser-panel.html").as_uri() for dock in docks), "browser dock was not saved" + if scripting: + scripts = saved["modules"]["scripts-tool"] + assert len(scripts) == len(scripting["languages"]), "saved script list changed" + for script in scripts: + assert script["settings"]["updated"] == 42 and script["settings"]["saved"] == 43, "script callbacks did not persist settings" + for language in scripting["languages"]: + assert f"native-gui-{language}-unloaded".encode() in log, f"{language} unload callback did not run" + if recording: + if os.environ.get("OBS_BUILD_NVENC"): + assert b"[obs-nvenc: 'simple_video_recording'] settings:" in log, "frontend did not use NVENC" + recordings = list((runtime / "recordings").glob("*.mkv")) + assert len(recordings) == 1, "frontend did not create the requested recording" + verify_recording(recordings[0], env) + print(f"OBS normal window, staged libraries/modules, saved scene, screenshot and clean shutdown: {runtime}") + finally: + if not drained: + if app.poll() is None: + app.terminate() + try: + remainder, _ = app.communicate(timeout=5) + except subprocess.TimeoutExpired: + app.kill() + remainder, _ = app.communicate(timeout=5) + log.extend(remainder) + (runtime / "application.log").write_bytes(log) + + +def verify_browser_helpers(runtime: Path, parent: int) -> None: + descendants = {parent} + found = {} + for _ in range(8): + children = set() + for pid in descendants: + for entry in Path(f"/proc/{pid}/task").glob("*/children"): + try: + children.update(int(value) for value in entry.read_text().split()) + except FileNotFoundError: + pass + new = children - descendants + descendants.update(new) + if not new: + break + helper = str(runtime / "lib64/obs-modules/core/obs-browser-page") + for pid in descendants - {parent}: + try: + command = Path(f"/proc/{pid}/cmdline").read_bytes().replace(b"\0", b" ").decode() + if helper in command and "--type=renderer" in command: + maps = Path(f"/proc/{pid}/maps").read_text() + assert str(runtime / "lib64/obs-modules/core/libcef.so") in maps, "renderer used an unstaged CEF" + found[pid] = command + except FileNotFoundError: + pass + assert found, "staged browser renderer helper was not running" + (runtime / "browser-helpers.json").write_text(json.dumps(found, indent=2)) + + +def verify_recording(path: Path, env: dict[str, str]) -> None: + result = subprocess.run( + ["ffprobe", "-v", "error", "-count_frames", "-show_streams", "-show_format", "-of", "json", str(path)], + env=env, check=True, capture_output=True, timeout=15, + ) + report = json.loads(result.stdout) + path.with_suffix(".ffprobe.json").write_text(json.dumps(report, indent=2)) + video = next(stream for stream in report["streams"] if stream["codec_type"] == "video") + audio = next(stream for stream in report["streams"] if stream["codec_type"] == "audio") + assert video["codec_name"] == "h264" and (video["width"], video["height"]) == (640, 360) + assert int(video["nb_read_frames"]) >= 60, "frontend recording has too few decoded frames" + assert audio["codec_name"] == "aac" and int(audio["sample_rate"]) == 48000 and audio["channels"] == 2 + assert 2 <= float(report["format"]["duration"]) <= 15, "unexpected frontend recording duration" + frame = subprocess.run( + ["ffmpeg", "-v", "error", "-i", str(path), "-vf", "scale=1:1", "-frames:v", "1", + "-f", "rawvideo", "-pix_fmt", "rgb24", "pipe:1"], + env=env, check=True, capture_output=True, timeout=15, + ).stdout + assert len(frame) == 3 and min(frame) >= 240, "frontend did not record the restored white source" + print(f"Validated actual frontend H264/AAC recording and white frame: {path}") + + +LUA_SCRIPT = """ +obs = obslua +function script_description() return 'Native GUI Lua' end +function script_defaults(settings) obs.obs_data_set_default_int(settings, 'seed', 41) end +function script_update(settings) obs.obs_data_set_int(settings, 'updated', obs.obs_data_get_int(settings, 'seed') + 1) end +function script_save(settings) obs.obs_data_set_int(settings, 'saved', obs.obs_data_get_int(settings, 'updated') + 1) end +function script_load(settings) obs.script_log(obs.LOG_INFO, 'native-gui-lua-loaded') end +function script_unload() obs.script_log(obs.LOG_INFO, 'native-gui-lua-unloaded') end +function script_properties() + local props = obs.obs_properties_create() + obs.obs_properties_add_int(props, 'seed', 'Seed', 0, 100, 1) + return props +end +""" + +PYTHON_SCRIPT = """ +import obspython as obs +def script_description(): return 'Native GUI Python' +def script_defaults(settings): obs.obs_data_set_default_int(settings, 'seed', 41) +def script_update(settings): obs.obs_data_set_int(settings, 'updated', obs.obs_data_get_int(settings, 'seed') + 1) +def script_save(settings): obs.obs_data_set_int(settings, 'saved', obs.obs_data_get_int(settings, 'updated') + 1) +def script_load(settings): obs.script_log(obs.LOG_INFO, 'native-gui-python-loaded') +def script_unload(): obs.script_log(obs.LOG_INFO, 'native-gui-python-unloaded') +def script_properties(): + props = obs.obs_properties_create() + obs.obs_properties_add_int(props, 'seed', 'Seed', 0, 100, 1) + return props +""" + + +if __name__ == "__main__": + main() diff --git a/rust/obs-build/tests/libobs/native_tests.rs b/rust/obs-build/tests/libobs/native_tests.rs new file mode 100644 index 0000000000..1e1a8ac863 --- /dev/null +++ b/rust/obs-build/tests/libobs/native_tests.rs @@ -0,0 +1,111 @@ +//! Runs unchanged native tests with isolated paths and verified core selection. +use obs_build::{NativeBuild, validation::Executable}; +use std::path::Path; + +pub fn exercise( + build: &NativeBuild, + root: &Path, + core: &Path, + rust_core: &Path, + tests: &[Executable], + suite: &str, +) { + let mut results = Vec::new(); + let mut failures = Vec::new(); + for selected in [core, rust_core] { + let selected = dunce::canonicalize(selected).unwrap(); + let variant = selected + .parent() + .unwrap() + .file_name() + .unwrap() + .to_str() + .unwrap(); + let search = std::env::join_paths( + std::iter::once(selected.parent().unwrap().to_owned()).chain(std::env::split_paths( + &std::env::var_os("LD_LIBRARY_PATH").unwrap_or_default(), + )), + ) + .unwrap(); + for test in tests { + let directory = build + .output + .join(format!("{suite}-c-test-runs")) + .join(variant) + .join(&test.name); + std::fs::create_dir_all(directory.join("tmp")).unwrap(); + let directory = dunce::canonicalize(directory).unwrap(); + let executable = dunce::canonicalize(&test.path).unwrap(); + for name in ["config", "data", "cache"] { + std::fs::create_dir_all(directory.join(name)).unwrap(); + } + super::application::copy_tree( + &root.join("libobs/data"), + &directory.join("share/obs/libobs"), + ) + .unwrap(); + let resolution = std::process::Command::new("ldd") + .arg(&executable) + .env("LD_LIBRARY_PATH", &search) + .output() + .unwrap(); + assert!(resolution.status.success()); + assert!( + String::from_utf8_lossy(&resolution.stdout).contains(selected.to_str().unwrap()), + "{} did not resolve the selected core", + test.name + ); + std::fs::write(directory.join("dependencies.log"), &resolution.stdout).unwrap(); + let deadline = match test.name.as_str() { + "test_vlc_audio_track" + | "test_vlc_audio_pacing" + | "test_vlc_playlist_gap" + | "test_group_hide_transition_audio" => "120s", + _ => "60s", + }; + let started = std::time::Instant::now(); + let status = std::process::Command::new("timeout") + .args(["--kill-after=5s", deadline]) + .arg(&executable) + .current_dir(&directory) + .env("LD_LIBRARY_PATH", &search) + .env("TMPDIR", directory.join("tmp")) + .env("XDG_CONFIG_HOME", directory.join("config")) + .env("XDG_DATA_HOME", directory.join("data")) + .env("XDG_CACHE_HOME", directory.join("cache")) + .env("CMOCKA_MESSAGE_OUTPUT", "STDOUT") + .env_remove("CMOCKA_TEST_FILTER") + .env_remove("CMOCKA_SKIP_FILTER") + .stdout(std::fs::File::create(directory.join("stdout.log")).unwrap()) + .stderr(std::fs::File::create(directory.join("stderr.log")).unwrap()) + .status() + .unwrap(); + let stdout = std::fs::read_to_string(directory.join("stdout.log")).unwrap(); + let stderr = std::fs::read_to_string(directory.join("stderr.log")).unwrap(); + let skipped = status.code() == Some(77) + || stdout.contains("SKIPPED") + || stderr.contains("SKIPPED"); + let passed = status.success() && !skipped; + println!( + "cc::Build {suite} C test: {variant}/{} exit {status}, skipped={skipped}", + test.name + ); + results.push(serde_json::json!({"variant":variant,"name":test.name, + "status":status.code(),"skipped":skipped,"passed":passed, + "seconds":started.elapsed().as_secs_f64(),"directory":directory})); + std::fs::write( + build.output.join(format!("{suite}-c-tests.json")), + serde_json::to_vec_pretty(&results).unwrap(), + ) + .unwrap(); + if !passed { + failures.push(format!("{variant}/{} ({})", test.name, directory.display())); + } + } + } + assert!( + failures.is_empty(), + "{suite} compatibility failures or skips: {}", + failures.join(", ") + ); +} diff --git a/rust/obs-build/tests/libobs/qt.rs b/rust/obs-build/tests/libobs/qt.rs new file mode 100644 index 0000000000..838411221a --- /dev/null +++ b/rust/obs-build/tests/libobs/qt.rs @@ -0,0 +1,81 @@ +//! Executes real OBS Qt widgets with generated UI and embedded resources. +use obs_build::{NativeBuild, SharedLibrary, frontend, qt}; +use std::path::Path; + +pub fn exercise(build: &NativeBuild, root: &Path) { + let source = build.output.join("qt-widget-probe.cpp"); + if std::fs::read_to_string(&source).ok().as_deref() != Some(SOURCE) { + std::fs::write(&source, SOURCE).unwrap(); + } + let mut library = SharedLibrary { + name: "qt-widget-probe".into(), + sources: vec![source], + include_dirs: vec![root.into()], + ..SharedLibrary::default() + }; + qt::uic( + &mut library, + &root.join("frontend/forms/OBSBasicVCamConfig.ui"), + &build + .output + .join("qt-widget-probe/generated/ui_OBSBasicVCamConfig.h"), + ) + .unwrap(); + qt::rcc( + &mut library, + &root.join("frontend/forms/obs.qrc"), + &build.output.join("qt-widget-probe/generated/qrc_obs.cpp"), + ) + .unwrap(); + frontend::add_spinbox(build, root, &mut library).unwrap(); + let executable = build.executable(&library).unwrap(); + let result = std::process::Command::new(executable) + .env("QT_QPA_PLATFORM", "offscreen") + .output() + .unwrap(); + assert!( + result.status.success(), + "{}\n{}\n{}", + result.status, + String::from_utf8_lossy(&result.stdout), + String::from_utf8_lossy(&result.stderr) + ); + println!("OBS Qt UI, resources and spinbox widget probe passed"); +} + +const SOURCE: &str = r#" +#include +#include +#include +#include +#include +#include "ui_OBSBasicVCamConfig.h" +#include "shared/qt/obs-spinbox/SpinBox.hpp" +#include "shared/qt/obs-spinbox/DoubleSpinBox.hpp" + +int main(int argc, char **argv) +{ + QApplication app(argc, argv); + QDialog dialog; + Ui::OBSBasicVCamConfig ui; + ui.setupUi(&dialog); + if (!dialog.findChild("outputType") || !dialog.findChild("outputSelection")) + return 91; + QPixmap icon(":/res/images/obs.png"); + if (icon.isNull()) + return 92; + OBS::SpinBox spin(&dialog); + spin.setRange(-10, 100); + spin.setValue(42); + OBS::DoubleSpinBox decimal(&dialog); + decimal.setDecimals(3); + decimal.setValue(3.125); + if (spin.value() != 42 || decimal.value() != 3.125 || + strcmp(spin.metaObject()->className(), "OBS::SpinBox") != 0) + return 93; + dialog.show(); + app.processEvents(); + ui.buttonBox->button(QDialogButtonBox::Ok)->click(); + return dialog.result() == QDialog::Accepted ? 0 : 94; +} +"#; diff --git a/rust/obs-build/tests/libobs/render.rs b/rust/obs-build/tests/libobs/render.rs new file mode 100644 index 0000000000..da6ec98eee --- /dev/null +++ b/rust/obs-build/tests/libobs/render.rs @@ -0,0 +1,425 @@ +//! Uses the unchanged C headers for graphics/video structs and callbacks. +use obs_build::{NativeBuild, SharedLibrary}; +use std::path::{Path, PathBuf}; + +pub fn build(build: &NativeBuild, root: &Path, core: &Path) -> PathBuf { + std::fs::create_dir_all(&build.output).unwrap(); + let source = build.output.join("graphics-probe.c"); + let content = SOURCE.replace("/* WHIP_PROBE */", include_str!("whip-probe.c")); + if std::fs::read_to_string(&source).ok().as_deref() != Some(&content) { + std::fs::write(&source, content).unwrap(); + } + let mut library = SharedLibrary { + name: "graphics-probe".into(), + sources: vec![source], + include_dirs: vec![ + root.into(), + root.join("libobs"), + build.output.join("config"), + ], + dependencies: vec![core.into()], + compile_options: vec!["-std=gnu17".into()], + ..SharedLibrary::default() + }; + let mut packages = vec!["simde", "x11"]; + if std::env::var_os("OBS_BUILD_WHIP_ENDPOINT").is_some() { + assert!(std::env::var_os("OBS_BUILD_WEBRTC").is_some()); + assert!(super::enabled("OBS_BUILD_RECORD")); + library.definitions.push(("OBS_FIXTURE_WHIP".into(), None)); + library.link_options.push("-lm".into()); + } + if std::env::var_os("OBS_BUILD_JACK_CAPTURE").is_some() { + packages.push("jack"); + library.definitions.push(("OBS_FIXTURE_JACK".into(), None)); + } + if std::env::var_os("OBS_BUILD_SNDIO_CAPTURE_DEVICE").is_some() { + packages.push("sndio"); + library.definitions.push(("OBS_FIXTURE_SNDIO".into(), None)); + } + for package in packages { + let dependency = pkg_config::Config::new() + .cargo_metadata(false) + .probe(package) + .unwrap(); + library.include_dirs.extend(dependency.include_paths); + for path in dependency.link_paths { + library.link_options.push(format!("-L{}", path.display())); + } + library + .link_options + .extend(dependency.libs.iter().map(|name| format!("-l{name}"))); + } + build.shared_library(&library).unwrap() +} + +const SOURCE: &str = r#" +#include +#include +#include +#include +#include +#include +#include +#ifdef OBS_FIXTURE_JACK +#include +#endif +#ifdef OBS_FIXTURE_SNDIO +#include +#include +#include +#endif + +static Display *test_display; +static atomic_uint frames; +static atomic_uint invalid_frames; +static atomic_uint expected_y = 16; +static uint32_t fixture_width = 64, fixture_height = 64; + +#if defined(OBS_FIXTURE_JACK) || defined(OBS_FIXTURE_SNDIO) +struct capture_probe { + os_event_t *ready; + atomic_uint packets; +#ifdef OBS_FIXTURE_JACK + jack_port_t *ports[2]; +#endif +}; + +static void receive_audio(void *opaque, obs_source_t *source, + const struct audio_data *audio, bool muted) +{ + (void)source; + struct capture_probe *probe = opaque; + if (muted || !audio->frames || !audio->data[0] || !audio->data[1]) + return; + const float left = ((const float *)audio->data[0])[0]; + const float right = ((const float *)audio->data[1])[0]; + if (left > 0.24f && left < 0.26f && right < -0.12f && right > -0.13f && + atomic_fetch_add(&probe->packets, 1) + 1 >= 3) + os_event_signal(probe->ready); +} +#endif + +#ifdef OBS_FIXTURE_JACK +static int send_jack_audio(jack_nframes_t frames, void *opaque) +{ + struct capture_probe *probe = opaque; + float *left = jack_port_get_buffer(probe->ports[0], frames); + float *right = jack_port_get_buffer(probe->ports[1], frames); + for (jack_nframes_t i = 0; i < frames; i++) { + left[i] = 0.25f; + right[i] = -0.125f; + } + return 0; +} + +EXPORT int obs_fixture_capture_jack(void) +{ + struct capture_probe probe = {0}; + if (os_event_init(&probe.ready, OS_EVENT_TYPE_AUTO)) + return 90; + obs_source_t *source = obs_source_create_private("jack_output_capture", + "cc-build-jack-capture", NULL); + jack_client_t *writer = NULL; + int status = 91; + if (!source) + goto cleanup; + obs_source_add_audio_capture_callback(source, receive_audio, &probe); + writer = jack_client_open("cc-build-jack-writer", JackNoStartServer, NULL); + if (!writer) + goto cleanup; + for (unsigned i = 0; i < 2; i++) { + probe.ports[i] = jack_port_register(writer, i ? "right" : "left", + JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0); + if (!probe.ports[i]) + goto cleanup; + } + if (jack_set_process_callback(writer, send_jack_audio, &probe) || jack_activate(writer)) + goto cleanup; + if (jack_connect(writer, jack_port_name(probe.ports[0]), + "OBS Studio: cc-build-jack-capture:in_1") || + jack_connect(writer, jack_port_name(probe.ports[1]), + "OBS Studio: cc-build-jack-capture:in_2")) + goto cleanup; + status = os_event_timedwait(probe.ready, 5000) ? 92 : 0; + if (!status) + blog(LOG_INFO, "cc::Build JACK capture: %u packets with distinct stereo samples", + atomic_load(&probe.packets)); +cleanup: + if (writer) + jack_client_close(writer); + if (source) { + obs_source_remove_audio_capture_callback(source, receive_audio, &probe); + obs_source_release(source); + obs_wait_for_destroy_queue(); + } + os_event_destroy(probe.ready); + return status; +} +#endif + +#ifdef OBS_FIXTURE_SNDIO +struct sndio_writer { + struct sio_hdl *handle; + atomic_bool stop; +}; + +static void *send_sndio_audio(void *opaque) +{ + struct sndio_writer *writer = opaque; + int16_t samples[512 * 2]; + for (size_t i = 0; i < 512; i++) { + samples[2 * i] = 8192; + samples[2 * i + 1] = -4096; + } + unsigned nfds = sio_nfds(writer->handle); + struct pollfd *fds = calloc(nfds, sizeof(*fds)); + size_t offset = 0; + while (fds && !atomic_load(&writer->stop)) { + int count = sio_pollfd(writer->handle, fds, POLLOUT); + if (poll(fds, count, 100) < 0) + break; + int events = sio_revents(writer->handle, fds); + if (events & POLLHUP) + break; + if (events & POLLOUT) { + size_t written = sio_write(writer->handle, + (const uint8_t *)samples + offset, sizeof(samples) - offset); + offset = (offset + written) % sizeof(samples); + } + } + free(fds); + return NULL; +} + +EXPORT int obs_fixture_capture_sndio(const char *device) +{ + struct capture_probe probe = {0}; + struct sndio_writer writer = {0}; + pthread_t thread; + bool started = false; + if (os_event_init(&probe.ready, OS_EVENT_TYPE_AUTO)) + return 93; + obs_data_t *settings = obs_data_create(); + obs_data_set_string(settings, "device", device); + obs_source_t *source = obs_source_create_private("sndio_output_capture", + "cc-build-sndio-capture", settings); + obs_data_release(settings); + int status = 94; + if (!source) + goto cleanup; + obs_source_add_audio_capture_callback(source, receive_audio, &probe); + writer.handle = sio_open(device, SIO_PLAY, 1); + if (!writer.handle) + goto cleanup; + struct sio_par parameters; + sio_initpar(¶meters); + parameters.bits = 16; + parameters.bps = 2; + parameters.sig = 1; + parameters.le = 1; + parameters.rate = 48000; + parameters.pchan = 2; + if (!sio_setpar(writer.handle, ¶meters) || !sio_start(writer.handle)) + goto cleanup; + if (pthread_create(&thread, NULL, send_sndio_audio, &writer)) + goto cleanup; + started = true; + status = os_event_timedwait(probe.ready, 5000) ? 95 : 0; + if (!status) + blog(LOG_INFO, "cc::Build sndio capture: %u packets with distinct stereo samples", + atomic_load(&probe.packets)); +cleanup: + if (started) { + atomic_store(&writer.stop, true); + pthread_join(thread, NULL); + } + if (writer.handle) + sio_close(writer.handle); + if (source) { + obs_source_remove_audio_capture_callback(source, receive_audio, &probe); + obs_source_release(source); + obs_wait_for_destroy_queue(); + } + os_event_destroy(probe.ready); + return status; +} +#endif + +EXPORT bool obs_fixture_open_display(void) +{ + XInitThreads(); + test_display = XOpenDisplay(NULL); + if (!test_display) + return false; + obs_set_nix_platform(OBS_NIX_PLATFORM_X11_EGL); + obs_set_nix_platform_display(test_display); + return true; +} + +static void receive_frame(void *unused, struct video_data *frame) +{ + (void)unused; + if (frame->data[0] && atomic_load(&expected_y) == 235 && + atomic_load(&frames) == 0 && frame->data[0][0] == 16) + return; /* Drain black frames already in the video pipeline. */ + if (!frame->data[0] || frame->linesize[0] < fixture_width || frame->data[0][0] != atomic_load(&expected_y)) + atomic_fetch_add(&invalid_frames, 1); + atomic_fetch_add(&frames, 1); +} + +/* WHIP_PROBE */ + +static int record_clip(const char *path, const char *output_id) +{ + obs_data_t *settings = obs_data_create(); + obs_data_set_string(settings, "rate_control", "CBR"); + obs_data_set_int(settings, "bitrate", 500); + bool nvenc = getenv("OBS_BUILD_NVENC_ENCODE") != NULL; + if (!nvenc) { + obs_data_set_string(settings, "preset", "ultrafast"); + obs_data_set_string(settings, "tune", "zerolatency"); + } + obs_encoder_t *video = obs_video_encoder_create(nvenc ? "obs_nvenc_h264_soft" : "obs_x264", + "cc-build-video", settings, NULL); + obs_data_release(settings); + settings = obs_data_create(); + obs_data_set_int(settings, "bitrate", 128); + const char *audio_id = getenv("OBS_BUILD_FDK") ? "libfdk_aac" : "ffmpeg_aac"; + obs_encoder_t *audio = obs_audio_encoder_create(audio_id, "cc-build-audio", settings, 0, NULL); + if (audio) + blog(LOG_INFO, "cc::Build audio encoder: %s", obs_encoder_get_id(audio)); + obs_data_release(settings); + settings = obs_data_create(); + obs_data_set_string(settings, "path", path); + obs_output_t *output = obs_output_create(output_id, "cc-build-recording", settings, NULL); + obs_data_release(settings); + int status = 0; + if (!video || !audio || !output) { + status = 85; + goto cleanup; + } + obs_encoder_set_video(video, obs_get_video()); + obs_encoder_set_audio(audio, obs_get_audio()); + obs_output_set_video_encoder(output, video); + obs_output_set_audio_encoder(output, audio, 0); + if (!obs_output_start(output)) { + blog(LOG_ERROR, "cc::Build recording start failed: %s", obs_output_get_last_error(output)); + status = 86; + goto cleanup; + } + for (unsigned i = 0; i < 400 && obs_output_active(output) && obs_output_get_total_frames(output) < 15; ++i) + os_sleep_ms(10); + if (obs_output_get_total_frames(output) < 15) + status = 87; + obs_output_stop(output); + for (unsigned i = 0; i < 500 && obs_output_active(output); ++i) + os_sleep_ms(10); + if (obs_output_active(output)) { + obs_output_force_stop(output); + status = 88; + } + blog(LOG_INFO, "cc::Build recording: %s (status %d)", path, status); +cleanup: + obs_output_release(output); + obs_encoder_release(video); + obs_encoder_release(audio); + return status; +} + +EXPORT int obs_fixture_initialize(const char *renderer, const char *data_path, bool audio_enabled) +{ + // Hardware encoders have minimum dimensions above the tiny software probe. + if (getenv("OBS_BUILD_NVENC_ENCODE")) { + fixture_width = 640; + fixture_height = 360; + } + obs_add_data_path(data_path); + if (audio_enabled) { + struct obs_audio_info audio = { .samples_per_sec = 48000, .speakers = SPEAKERS_STEREO }; + if (!obs_reset_audio(&audio)) + return 84; + } + struct obs_video_info video = { + .graphics_module = renderer, + .fps_num = 30, .fps_den = 1, + .base_width = fixture_width, .base_height = fixture_height, + .output_width = fixture_width, .output_height = fixture_height, + .output_format = VIDEO_FORMAT_NV12, + .gpu_conversion = true, + .colorspace = VIDEO_CS_709, + .range = VIDEO_RANGE_PARTIAL, + .scale_type = OBS_SCALE_BICUBIC, + }; + int result = obs_reset_video(&video); + return result; +} + +EXPORT int obs_fixture_render(const char *record_path, const char *output_id) +{ + obs_enter_graphics(); + blog(LOG_INFO, "cc::Build graphics device: %s", gs_get_device_name()); + obs_leave_graphics(); + obs_scene_t *scene = obs_scene_create("cc-build-rendering"); + if (!scene) + return 81; + obs_set_output_source(0, obs_scene_get_source(scene)); + atomic_store(&frames, 0); + atomic_store(&invalid_frames, 0); + obs_add_raw_video_callback(NULL, receive_frame, NULL); + for (unsigned i = 0; i < 200 && atomic_load(&frames) < 3; ++i) + os_sleep_ms(10); + obs_remove_raw_video_callback(receive_frame, NULL); + int source_status = 0; + obs_source_t *color = NULL; + if (getenv("OBS_BUILD_SOURCES") || getenv("OBS_BUILD_APP_GUI")) { + obs_data_t *settings = obs_data_create(); + obs_data_set_int(settings, "width", fixture_width); + obs_data_set_int(settings, "height", fixture_height); + obs_data_set_int(settings, "color", 0xFFFFFFFF); + color = obs_source_create("color_source_v3", "cc-build-white", settings, NULL); + obs_data_release(settings); + if (!color || obs_source_get_width(color) != fixture_width || obs_source_get_height(color) != fixture_height) { + source_status = 89; + } else { + obs_scene_add(scene, color); + atomic_store(&frames, 0); + atomic_store(&expected_y, 235); + obs_add_raw_video_callback(NULL, receive_frame, NULL); + for (unsigned i = 0; i < 200 && atomic_load(&frames) < 3; ++i) + os_sleep_ms(10); + obs_remove_raw_video_callback(receive_frame, NULL); + blog(LOG_INFO, "cc::Build color source rendered %u white frames", atomic_load(&frames)); + } + } + int streaming_status = 0; +#ifdef OBS_FIXTURE_WHIP + if (getenv("OBS_BUILD_WHIP_ENDPOINT")) + streaming_status = stream_whip(getenv("OBS_BUILD_WHIP_ENDPOINT")); +#endif + int recording_status = record_path ? record_clip(record_path, output_id) : 0; + obs_set_output_source(0, NULL); + if (color) { + obs_source_remove(color); + obs_source_release(color); + } + // Public sources also belong to the main canvas until explicitly removed. + obs_source_remove(obs_scene_get_source(scene)); + obs_scene_release(scene); + // Match frontend scene teardown: queued scene destruction can release its + // child sources. Finish it before obs_shutdown force-frees remaining ones. + while (obs_wait_for_destroy_queue()) {} + /* The owning test calls obs_shutdown after this probe. */ + if (atomic_load(&frames) < 3) + return 82; + if (atomic_load(&invalid_frames)) + return 83; + return source_status ? source_status : (streaming_status ? streaming_status : recording_status); +} + +EXPORT void obs_fixture_close_display(void) +{ + obs_set_nix_platform_display(NULL); + XCloseDisplay(test_display); + test_display = NULL; +} +"#; diff --git a/rust/obs-build/tests/libobs/scripting.rs b/rust/obs-build/tests/libobs/scripting.rs new file mode 100644 index 0000000000..3977d7271e --- /dev/null +++ b/rust/obs-build/tests/libobs/scripting.rs @@ -0,0 +1,244 @@ +//! Real scripting lifecycle through the unchanged native API and bindings. +use obs_build::{NativeBuild, SharedLibrary, scripting}; +use std::path::Path; + +pub fn exercise( + build: &NativeBuild, + root: &Path, + artifacts: &scripting::Artifacts, + cores: &[&Path], + frontend: bool, +) { + let output = build.output.join("script-scenarios"); + std::fs::create_dir_all(&output).unwrap(); + let output = output.canonicalize().unwrap(); + let source = output.join("probe.c"); + std::fs::write(&source, PROBE).unwrap(); + let mut target = SharedLibrary { + name: "scripting-probe".into(), + sources: vec![source], + include_dirs: vec![ + root.into(), + root.join("libobs"), + root.join("shared/obs-scripting"), + build.output.join("config"), + ], + dependencies: vec![cores[0].into(), artifacts.library.clone()], + compile_options: vec!["-std=gnu17".into()], + ..SharedLibrary::default() + }; + target.include_dirs.extend( + pkg_config::Config::new() + .cargo_metadata(false) + .probe("simde") + .unwrap() + .include_paths, + ); + let executable = build.executable(&target).unwrap(); + let bin = artifacts.runtime.join("bin"); + std::fs::create_dir_all(&bin).unwrap(); + let runner = bin.join(executable.file_name().unwrap()); + std::fs::copy(&executable, &runner).unwrap(); + let lua = output.join("native_smoke.lua"); + let python = output.join("native_smoke.py"); + let lua_frontend = if frontend { + "\nassert(obs.obs_frontend_recording_active() == false)\n" + } else { + "\nassert(obs.obs_frontend_recording_active == nil)\n" + }; + let python_frontend = if frontend { + "\nassert obs.obs_frontend_recording_active() is False\n" + } else { + "\nassert not hasattr(obs, 'obs_frontend_recording_active')\n" + }; + std::fs::write(&lua, format!("{LUA}{lua_frontend}")).unwrap(); + std::fs::write(&python, format!("{PYTHON}{python_frontend}")).unwrap(); + for core in cores { + let config = tempfile::tempdir().unwrap(); + let mut paths = vec![ + core.parent().unwrap().to_owned(), + artifacts.library.parent().unwrap().to_owned(), + ]; + paths.extend(std::env::split_paths( + &std::env::var_os("LD_LIBRARY_PATH").unwrap_or_default(), + )); + let result = std::process::Command::new(&runner) + .arg(if artifacts.lua_module.is_some() { + lua.as_os_str() + } else { + std::ffi::OsStr::new("-") + }) + .arg(if artifacts.python_module.is_some() { + python.as_os_str() + } else { + std::ffi::OsStr::new("-") + }) + .arg(config.path()) + .arg(artifacts.lua_module.as_deref().unwrap_or(Path::new("-"))) + .arg(artifacts.python_module.as_deref().unwrap_or(Path::new("-"))) + .arg(core) + .current_dir(config.path()) + .env("LD_LIBRARY_PATH", std::env::join_paths(paths).unwrap()) + .env_remove("PYTHONHOME") + .env_remove("PYTHONPATH") + .env_remove("LUA_PATH") + .env_remove("LUA_CPATH") + .output() + .unwrap(); + let label = format!( + "{}-lua{}-python{}-frontend{}.log", + core.parent() + .unwrap() + .file_name() + .unwrap() + .to_string_lossy(), + u8::from(artifacts.lua_module.is_some()), + u8::from(artifacts.python_module.is_some()), + u8::from(frontend) + ); + std::fs::write( + output.join(label), + format!( + "{}\n{}", + String::from_utf8_lossy(&result.stdout), + String::from_utf8_lossy(&result.stderr) + ), + ) + .unwrap(); + assert!( + result.status.success(), + "scripting {}: {}\n{}\n{}", + core.display(), + result.status, + String::from_utf8_lossy(&result.stdout), + String::from_utf8_lossy(&result.stderr) + ); + println!( + "cc::Build scripting defaults/update/properties/save/reload/unload passed: {}", + core.display() + ); + } +} + +const LUA: &str = r#" +obs = obslua +function script_description() return 'native-lua' end +function script_defaults(settings) obs.obs_data_set_default_int(settings, 'seed', 41) end +function script_update(settings) + obs.obs_data_set_int(settings, 'updated', obs.obs_data_get_int(settings, 'seed') + 1) +end +function script_save(settings) + obs.obs_data_set_int(settings, 'saved', obs.obs_data_get_int(settings, 'updated') + 1) +end +function script_properties() + local props = obs.obs_properties_create() + obs.obs_properties_add_int(props, 'gain', 'Gain', -100, 100, 1) + return props +end +function script_unload() obs.script_log(obs.LOG_INFO, 'native-unload') end +"#; + +const PYTHON: &str = r#" +import obspython as obs +def script_description(): + return 'native-python' +def script_defaults(settings): + obs.obs_data_set_default_int(settings, 'seed', 41) +def script_update(settings): + obs.obs_data_set_int(settings, 'updated', obs.obs_data_get_int(settings, 'seed') + 1) +def script_save(settings): + obs.obs_data_set_int(settings, 'saved', obs.obs_data_get_int(settings, 'updated') + 1) +def script_properties(): + props = obs.obs_properties_create() + obs.obs_properties_add_int(props, 'gain', 'Gain', -100, 100, 1) + return props +def script_unload(): + obs.script_log(obs.LOG_INFO, 'native-unload') +"#; + +const PROBE: &str = r#" +#include +#include +#include +#include +#include +#define CHECK(value) do { if (!(value)) { fprintf(stderr, "scripting check line %d: %s\n", __LINE__, #value); return 1; } } while (0) +static unsigned errors, unloads; +static bool module_loaded(const char *path) +{ + FILE *maps = fopen("/proc/self/maps", "r"); + if (!maps) return false; + char line[8192]; + bool found = false; + while (fgets(line, sizeof(line), maps)) + if (strstr(line, path)) { found = true; break; } + fclose(maps); + return found; +} +static void log_script(void *unused, obs_script_t *script, int level, const char *message) +{ + (void)unused; (void)script; + if (level <= LOG_ERROR) ++errors; + if (strstr(message, "native-unload")) ++unloads; + fprintf(stderr, "script: %s\n", message); +} +static int exercise(const char *path, enum obs_script_lang language, const char *description, const char *module) +{ + obs_data_t *settings = obs_data_create(); + obs_script_t *script = obs_script_create(path, settings); + obs_data_release(settings); + CHECK(script && obs_script_loaded(script)); + CHECK(module_loaded(module)); + printf("cc::Build loaded scripting binding: %s\n", module); + CHECK(obs_script_get_lang(script) == language); + CHECK(strcmp(obs_script_get_description(script), description) == 0); + settings = obs_script_get_settings(script); + CHECK(obs_data_get_int(settings, "seed") == 41); + CHECK(obs_data_get_int(settings, "updated") == 42); + obs_data_release(settings); + obs_properties_t *properties = obs_script_get_properties(script); + CHECK(properties && obs_properties_get(properties, "gain")); + CHECK(obs_property_get_type(obs_properties_get(properties, "gain")) == OBS_PROPERTY_INT); + obs_properties_destroy(properties); + settings = obs_data_create(); + obs_data_set_int(settings, "seed", 100); + obs_script_update(script, settings); + obs_data_release(settings); + settings = obs_script_save(script); + CHECK(obs_data_get_int(settings, "updated") == 101 && obs_data_get_int(settings, "saved") == 102); + obs_data_release(settings); + CHECK(obs_script_reload(script) && obs_script_loaded(script)); + CHECK(strcmp(obs_script_get_description(script), description) == 0); + unsigned before = unloads; + obs_script_destroy(script); + CHECK(unloads == before + 1); + CHECK(errors == 0); + return 0; +} +int main(int argc, char **argv) +{ + CHECK(argc == 7); + CHECK(obs_startup("en-US", argv[3], NULL)); + CHECK(module_loaded(argv[6])); + obs_scripting_set_log_callback(log_script, NULL); + CHECK(obs_scripting_load()); + bool lua = strcmp(argv[1], "-") != 0, python = strcmp(argv[2], "-") != 0; + const char **formats = obs_scripting_supported_formats(); + unsigned count = 0; + bool has_lua = false, has_python = false; + while (formats[count]) { + has_lua |= strcmp(formats[count], "lua") == 0; + has_python |= strcmp(formats[count], "py") == 0; + ++count; + } + CHECK(count == (unsigned)lua + (unsigned)python); + CHECK(has_lua == lua && has_python == python); + CHECK(obs_scripting_python_loaded() == python); + if (lua) CHECK(exercise(argv[1], OBS_SCRIPT_LANG_LUA, "native-lua", argv[4]) == 0); + if (python) CHECK(exercise(argv[2], OBS_SCRIPT_LANG_PYTHON, "native-python", argv[5]) == 0); + obs_scripting_unload(); + obs_shutdown(); + puts("cc::Build scripting lifecycle complete"); + return 0; +} +"#; diff --git a/rust/obs-build/tests/libobs/tools.rs b/rust/obs-build/tests/libobs/tools.rs new file mode 100644 index 0000000000..5ea3fa3f22 --- /dev/null +++ b/rust/obs-build/tests/libobs/tools.rs @@ -0,0 +1,297 @@ +//! Test-only module that exercises the actual frontend Tools actions/dialogs. +use obs_build::{NativeBuild, SharedLibrary, plugins}; +use std::path::Path; + +pub fn build(build: &NativeBuild, root: &Path, core: &Path, api: &Path) -> plugins::Module { + let source = build.output.join("frontend-tools-probe.cpp"); + if std::fs::read_to_string(&source).ok().as_deref() != Some(SOURCE) { + std::fs::write(&source, SOURCE).unwrap(); + } + let mut target = SharedLibrary { + name: "native-frontend-probe".into(), + sources: vec![source], + file_name: Some("native-frontend-probe.so".into()), + include_dirs: vec![ + root.into(), + root.join("libobs"), + root.join("frontend/api"), + build.output.join("config"), + ], + dependencies: vec![core.into(), api.into()], + cpp_compile_options: vec![ + "-std=gnu++17".into(), + "-fvisibility=hidden".into(), + "-fvisibility-inlines-hidden".into(), + ], + ..SharedLibrary::default() + }; + for package in ["simde", "Qt6Widgets", "Qt6Test"] { + let dependency = pkg_config::Config::new() + .cargo_metadata(false) + .probe(package) + .unwrap(); + target.include_dirs.extend(dependency.include_paths); + let mut definitions: Vec<_> = dependency.defines.into_iter().collect(); + definitions.sort(); + target.definitions.extend(definitions); + for path in dependency.link_paths { + target.link_options.extend([ + format!("-L{}", path.display()), + format!("-Wl,-rpath,{}", path.display()), + ]); + } + target + .link_options + .extend(dependency.libs.iter().map(|name| format!("-l{name}"))); + } + let data = build.output.join("frontend-tools-probe-data"); + std::fs::create_dir_all(&data).unwrap(); + plugins::Module { + library: build.shared_library(&target).unwrap(), + data, + } +} + +const SOURCE: &str = r#" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +OBS_DECLARE_MODULE() + +static bool open_dialog(QMenu *menu, const char *label, const char *type, const char *image, int scripts = -1, bool websocket = false) +{ + QAction *selected = nullptr; + for (QAction *action : menu->actions()) { + QString text = action->text(); text.remove('&'); + if (text == label) { selected = action; break; } + } + if (!selected) { blog(LOG_ERROR, "cc::Build missing Tools action %s", label); return false; } + // SceneSwitcher runs a nested modal event loop and is destroyed before + // trigger() returns. OutputTimer instead queues its show() after 250 ms. + // Inspect and close both while their event loops are running. + QObject context; + QEventLoop loop; + bool completed = false; + bool passed = false; + QTimer::singleShot(400, &context, [&]() { + QPointer dialog; + for (QWidget *widget : QApplication::topLevelWidgets()) + if (widget->inherits(type) && widget->isVisible()) { dialog = widget; break; } + if (!dialog) { + blog(LOG_ERROR, "cc::Build Tools dialog %s did not open", type); + } else { + bool valid = true; + if (scripts >= 0) { + QListWidget *list = dialog->findChild("scripts"); + valid = list && list->count() == scripts; + if (!valid) blog(LOG_ERROR, "cc::Build incorrect saved script count"); + if (valid) { + for (int row = 0; row < scripts; ++row) { + list->setCurrentRow(row); + // OBSPropertiesView queues its initial property reload. + QApplication::processEvents(); + QLabel *description = dialog->findChild("description"); + const auto fields = dialog->findChildren(); + bool seed = false; + for (QSpinBox *field : fields) seed = seed || field->value() == 41; + if (!description || !description->text().startsWith("Native GUI ") || !seed) { + blog(LOG_ERROR, "cc::Build saved script properties were not displayed for row %d", row); + valid = false; + } + } + if (scripts) { + list->setCurrentRow(0); + QApplication::processEvents(); + } + } + } + if (websocket) { + QPushButton *button = dialog->findChild("showConnectInfoButton"); + if (!button || obs_video_active()) { + blog(LOG_ERROR, "cc::Build websocket connection dialog requires idle output and its button"); + valid = false; + } else { + button->click(); + QApplication::processEvents(); + QPointer info; + for (QWidget *widget : QApplication::topLevelWidgets()) + if (widget->inherits("ConnectInfo") && widget->isVisible()) { info = widget; break; } + QLabel *code = info ? info->findChild("qrCodeLabel") : nullptr; + const QImage qr = code ? code->pixmap().toImage() : QImage(); + bool black = false, white = false; + for (int y = 0; y < qr.height(); ++y) + for (int x = 0; x < qr.width(); ++x) { + int value = qr.pixelColor(x, y).lightness(); + black = black || value < 32; white = white || value > 223; + } + const char *directory = std::getenv("OBS_BUILD_GUI_EVIDENCE"); + valid = valid && info && black && white && directory && + info->grab().save(QString::fromUtf8(directory) + "/websocket-connect-info.png"); + if (info) info->close(); + if (!valid) blog(LOG_ERROR, "cc::Build websocket connection QR dialog failed"); + } + } + const char *directory = std::getenv("OBS_BUILD_GUI_EVIDENCE"); + bool saved = directory && dialog->grab().save(QString::fromUtf8(directory) + "/" + image); + bool closed = dialog->close(); + passed = valid && saved && closed && (!dialog || !dialog->isVisible()); + if (!passed) blog(LOG_ERROR, "cc::Build Tools inspection/screenshot/close failed"); + } + completed = true; + loop.quit(); + }); + selected->trigger(); + if (!completed) loop.exec(); + return passed; +} + +static bool verify_browser_panel(QMainWindow *main) +{ + QAction *action = nullptr; + for (QAction *candidate : main->findChildren()) { + QString text = candidate->text(); text.remove('&'); + if (text == "Custom Browser Docks") { action = candidate; break; } + } + const char *directory = std::getenv("OBS_BUILD_GUI_EVIDENCE"); + if (!action || !directory) { blog(LOG_ERROR, "cc::Build browser dock action missing"); return false; } + blog(LOG_INFO, "cc::Build opening browser dock editor"); + action->trigger(); + QPointer dialog; + for (QWidget *widget : QApplication::topLevelWidgets()) + if (widget->inherits("OBSExtraBrowsers") && widget->isVisible()) { dialog = widget; break; } + auto *table = dialog ? dialog->findChild("table") : nullptr; + auto *apply = dialog ? dialog->findChild("apply") : nullptr; + if (!table || !table->model() || !apply) { blog(LOG_ERROR, "cc::Build browser dock editor missing"); return false; } + auto *model = table->model(); + // This model commits through its line-edit delegate, not setData(). Drive + // the actual editor so validation and new-row insertion also run. + auto edit_cell = [&](int column, const QString &text) { + const auto index = model->index(0, column); + table->setCurrentIndex(index); + table->openPersistentEditor(index); + QApplication::processEvents(); + QLineEdit *editor = nullptr; + const auto center = table->viewport()->mapToGlobal(table->visualRect(index).center()); + for (auto *candidate : table->findChildren()) + if (candidate->isVisible() && candidate->rect().contains(candidate->mapFromGlobal(center))) editor = candidate; + if (!editor) { blog(LOG_ERROR, "cc::Build browser dock cell editor missing"); return false; } + editor->selectAll(); QTest::keyClicks(editor, text); QTest::keyClick(editor, Qt::Key_Return); + QApplication::processEvents(); + const bool committed = model->index(0, column).data().toString() == text; + table->closePersistentEditor(index); + if (!committed) blog(LOG_ERROR, "cc::Build browser dock cell %d edit was not committed", column); + return committed; + }; + if (!edit_cell(0, "Native CEF Panel") || !edit_cell(1, "about:blank")) return false; + blog(LOG_INFO, "cc::Build creating browser dock"); + apply->click(); + QDockWidget *dock = nullptr; + for (auto *candidate : main->findChildren()) + if (candidate->windowTitle() == "Native CEF Panel") { dock = candidate; break; } + if (!dock || !dock->widget()) { blog(LOG_ERROR, "cc::Build browser dock was not created"); return false; } + QSignalSpy titles(dock->widget(), SIGNAL(titleChanged(QString))); + if (!titles.isValid()) { blog(LOG_ERROR, "cc::Build browser title signal missing"); return false; } + const QString url = QUrl::fromLocalFile(QString::fromUtf8(directory) + "/browser-panel.html").toString(); + if (!edit_cell(1, url)) return false; + blog(LOG_INFO, "cc::Build navigating browser dock"); + apply->click(); + bool loaded = false; + QElapsedTimer timer; timer.start(); + while (!loaded && timer.elapsed() < 20000) { + for (const auto &signal : titles) + if (!signal.isEmpty() && signal.front().toString() == "Native CEF Panel Ready") loaded = true; + if (!loaded) { + const auto remaining = 20000 - timer.elapsed(); + if (remaining <= 0 || !titles.wait(static_cast(remaining))) break; + } + } + bool saved = dialog->grab().save(QString::fromUtf8(directory) + "/browser-dock-editor.png"); + // CEF uses a native child window, which QWidget::grab() cannot capture. + dialog->hide(); dock->raise(); dock->activateWindow(); + QImage pixels; + bool rendered = false; + timer.restart(); + while (!rendered && timer.elapsed() < 5000) { + QTest::qWait(50); + pixels = dock->screen()->grabWindow(dock->winId()).toImage(); + if (!pixels.isNull()) { + const auto color = pixels.pixelColor(pixels.width() / 2, pixels.height() / 2); + rendered = std::abs(color.red() - 17) <= 4 && std::abs(color.green() - 203) <= 4 && std::abs(color.blue() - 77) <= 4; + } + } + saved = !pixels.isNull() && pixels.save(QString::fromUtf8(directory) + "/browser-panel.png") && saved; + dialog->close(); dock->hide(); + if (!loaded || !rendered || !saved) { blog(LOG_ERROR, "cc::Build browser dock page readiness or rendered pixels failed"); return false; } + blog(LOG_INFO, "cc::Build browser dock creation, URL update, CEF JavaScript title and rendered pixels verified"); + return true; +} + +static void verify_dialogs() +{ + auto *main = static_cast(obs_frontend_get_main_window()); + if (!main) { blog(LOG_ERROR, "cc::Build main window missing"); return; } + QMenu *tools = nullptr; + for (QAction *action : main->menuBar()->actions()) { + QString text = action->text(); text.remove('&'); + if (text == "Tools") tools = action->menu(); + } + if (!tools) { blog(LOG_ERROR, "cc::Build Tools menu missing"); return; } + if (std::getenv("OBS_BUILD_FRONTEND_TOOLS")) { + if (!open_dialog(tools, "Automatic Scene Switcher", "SceneSwitcher", "tools-scene-switcher.png")) return; + if (!open_dialog(tools, "Output Timer", "OutputTimer", "tools-output-timer.png")) return; + const char *count = std::getenv("OBS_BUILD_GUI_SCRIPT_COUNT"); + if (count && std::atoi(count) >= 0 && !open_dialog(tools, "Scripts", "ScriptsTool", "tools-scripts.png", std::atoi(count))) return; + if (!count || std::atoi(count) < 0) { + for (QAction *action : tools->actions()) { + QString text = action->text(); text.remove('&'); + if (text == "Scripts") { blog(LOG_ERROR, "cc::Build disabled Scripts action is present"); return; } + } + } + } + if (std::getenv("OBS_BUILD_WEBSOCKET") && + !open_dialog(tools, "WebSocket Server Settings", "SettingsDialog", "websocket-settings.png", -1, true)) return; + if (std::getenv("OBS_BUILD_BROWSER") && !std::getenv("OBS_BUILD_DISABLE_BROWSER_PANELS") && + !verify_browser_panel(main)) return; + blog(LOG_INFO, "cc::Build frontend Tools dialogs verified"); +} + +static bool frontend_exited = false; + +static void frontend_event(enum obs_frontend_event event, void *) +{ + if (event == OBS_FRONTEND_EVENT_EXIT) frontend_exited = true; + if (event == OBS_FRONTEND_EVENT_FINISHED_LOADING) + QTimer::singleShot(0, verify_dialogs); +} + +bool obs_module_load(void) +{ + obs_frontend_add_event_callback(frontend_event, nullptr); + return true; +} +void obs_module_unload(void) { if (!frontend_exited) obs_frontend_remove_event_callback(frontend_event, nullptr); } +"#; diff --git a/rust/obs-build/tests/libobs/vlc.rs b/rust/obs-build/tests/libobs/vlc.rs new file mode 100644 index 0000000000..281a08fdee --- /dev/null +++ b/rust/obs-build/tests/libobs/vlc.rs @@ -0,0 +1,20 @@ +//! Runs the unchanged VLC C tests with the selected native artifacts. +use obs_build::{NativeBuild, plugins::Module, validation}; +use std::path::Path; + +pub fn exercise( + build: &NativeBuild, + root: &Path, + core: &Path, + rust_core: &Path, + vlc: &Module, + graphics: &Path, +) { + let tests = validation::build_vlc_tests(build, root, core, vlc, graphics).unwrap(); + assert_eq!( + tests.len(), + 6, + "all original Linux VLC test targets are required" + ); + super::native_tests::exercise(build, root, core, rust_core, &tests, "vlc"); +} diff --git a/rust/obs-build/tests/libobs/webrtc.rs b/rust/obs-build/tests/libobs/webrtc.rs new file mode 100644 index 0000000000..42a0d74e4f --- /dev/null +++ b/rust/obs-build/tests/libobs/webrtc.rs @@ -0,0 +1,41 @@ +//! Original WHIP helper tests: real sources, no libobs or transport stubs. +use obs_build::{NativeBuild, validation}; +use std::{path::PathBuf, process::Command}; + +#[test] +fn original_whip_clock_and_host_tests_pass_without_a_core_or_sdk() { + let root = PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("../.."); + let directory = tempfile::tempdir().unwrap(); + let build = NativeBuild { + host: env!("OBS_BUILD_HOST").into(), + target: env!("OBS_BUILD_TARGET").into(), + output: directory.path().join("native"), + }; + let tests = validation::build_webrtc_tests(&build, &root).unwrap(); + assert_eq!(tests.len(), 2); + for test in tests { + let output = Command::new("timeout") + .args(["--kill-after=5s", "60s"]) + .arg(&test.path) + .current_dir(directory.path()) + .env("CMOCKA_MESSAGE_OUTPUT", "STDOUT") + .env_remove("CMOCKA_TEST_FILTER") + .env_remove("CMOCKA_SKIP_FILTER") + .output() + .unwrap(); + let stdout = String::from_utf8_lossy(&output.stdout); + let stderr = String::from_utf8_lossy(&output.stderr); + println!("{}\n{stdout}\n{stderr}", test.name); + assert!(output.status.success(), "{}: {}", test.name, output.status); + assert!(!stdout.contains("SKIPPED") && !stderr.contains("SKIPPED")); + let cases = match test.name.as_str() { + "test_whip_rtp_timestamp" => 6, + "test_whip_host_os_name" => 2, + other => panic!("unexpected WHIP target {other}"), + }; + assert!( + stderr.contains(&format!("{cases} test(s).")) + || stdout.contains(&format!("{cases} test(s).")) + ); + } +} diff --git a/rust/obs-build/tests/libobs/websocket_probe.py b/rust/obs-build/tests/libobs/websocket_probe.py new file mode 100644 index 0000000000..840e7e23a4 --- /dev/null +++ b/rust/obs-build/tests/libobs/websocket_probe.py @@ -0,0 +1,215 @@ +#!/usr/bin/env -S uv run --script +# /// script +# dependencies = ["websockets==13.1"] +# /// +"""Exercise the staged plugin using the unchanged Tier 4 wire client.""" +from __future__ import annotations + +import argparse +import asyncio +import base64 +import json +import os +from pathlib import Path +import subprocess +import sys + +sys.path.insert(0, str(Path(__file__).resolve().parents[4] / "test/websocket-tier4")) +from obsws import ObsWsClient, SUB_SCENES # noqa: E402 + + +async def verify(runtime: Path, recording: bool) -> None: + manifest = json.loads((runtime / "expected-websocket.json").read_text()) + uri = f"ws://127.0.0.1:{manifest['port']}" + bad = ObsWsClient(uri) + try: + hello = await bad.connect() + assert hello and hello["d"]["rpcVersion"] == 1 + challenge = hello["d"]["authentication"] + await bad.identify(password="incorrect-fixture-password", auth_challenge=challenge) + await asyncio.wait_for(bad.ws.wait_closed(), 5) + assert bad.ws.close_code == 4009, "server accepted incorrect password" + finally: + await bad.close_conn() + + client = ObsWsClient(uri) + evidence = {} + try: + hello = await client.connect() + assert hello and "authentication" in hello["d"] + await client.identify(password=manifest["password"], + auth_challenge=hello["d"]["authentication"], + event_subscriptions=SUB_SCENES) + assert await client.wait_op(2), "authenticated Identify failed" + + async def request(name: str, data=None): + reply = await client.request(name, data) + assert reply["d"]["requestStatus"]["code"] == 100, reply + result = reply["d"].get("responseData", {}) + evidence[name] = result + return result + + version = await request("GetVersion") + assert version["obsWebSocketVersion"] == "5.7.5" + scenes = await request("GetSceneList") + assert scenes["currentProgramSceneName"] == "Native scene" + inputs = await request("GetInputList") + assert any(item["inputName"] == "Native white" for item in inputs["inputs"]) + settings = await request("GetInputSettings", {"inputName": "Native white"}) + assert settings["inputSettings"]["color"] == 0xFFFFFFFF + status = await request("GetRecordStatus") + assert status["outputActive"] is False, "fixture unexpectedly started recording" + image = await request("GetSourceScreenshot", { + "sourceName": "Native white", "imageFormat": "png", + "imageWidth": 64, "imageHeight": 64, + }) + prefix, encoded = image["imageData"].split(",", 1) + assert prefix == "data:image/png;base64" + screenshot = runtime / "websocket-white.png" + screenshot.write_bytes(base64.b64decode(encoded, validate=True)) + decoded = subprocess.run([ + "ffmpeg", "-v", "error", "-i", str(screenshot), "-frames:v", "1", + "-f", "rawvideo", "-pix_fmt", "rgb24", "-", + ], check=True, capture_output=True, timeout=15).stdout + assert len(decoded) == 64 * 64 * 3 and min(decoded) >= 240, "wire screenshot is not white" + await request("CreateScene", {"sceneName": "Native wire temporary"}) + event = await client.wait_for_event("SceneCreated", timeout=5) + assert event and event["d"]["eventData"]["sceneName"] == "Native wire temporary" + await request("RemoveScene", {"sceneName": "Native wire temporary"}) + batch = await client.request_batch([{"requestType": "GetVersion"}, {"requestType": "GetSceneList"}]) + assert all(item["requestStatus"]["code"] == 100 for item in batch["d"]["results"]) + unknown = await client.request("NativeMissingRequest") + assert unknown["d"]["requestStatus"]["code"] == 204 + if os.environ.get("OBS_BUILD_VLC"): + kinds = await request("GetInputKindList") + if os.environ.get("OBS_BUILD_VLC_ABSENT"): + assert "vlc_source" not in kinds["inputKinds"], "VLC source registered without its runtime" + else: + assert "vlc_source" in kinds["inputKinds"], "VLC runtime did not register its source" + await verify_vlc(runtime, request) + if os.environ.get("OBS_BUILD_BROWSER"): + evidence["browser"] = await verify_browser(runtime, request) + if recording: + await request("StartRecord") + deadline = asyncio.get_running_loop().time() + 5 + while True: + status = await request("GetRecordStatus") + if status["outputActive"]: + break + assert asyncio.get_running_loop().time() < deadline, "wire recording did not start" + await asyncio.sleep(0.05) + evidence["authentication"] = "wrong password rejected; correct password accepted" + evidence["scene_event_and_batch"] = True + (runtime / "websocket-evidence.json").write_text(json.dumps(evidence, indent=2)) + print("Staged obs-websocket auth, requests, event, batch, recording status and white screenshot passed") + finally: + await client.close_conn() + + +async def verify_browser(runtime: Path, request) -> dict: + page = runtime / "browser-source.html" + page.write_text(''' +''') + kinds = await request("GetInputKindList") + assert "browser_source" in kinds["inputKinds"], "browser source was not registered" + await request("CreateInput", { + "sceneName": "Native scene", "inputName": "Native browser", "inputKind": "browser_source", + "sceneItemEnabled": True, + "inputSettings": {"is_local_file": True, "local_file": str(page), "width": 128, + "height": 72, "webpage_control_level": 2, "shutdown": False}, + }) + item = await request("GetSceneItemId", {"sceneName": "Native scene", "sourceName": "Native browser"}) + deadline = asyncio.get_running_loop().time() + 20 + expected = (17, 203, 77) + while True: + image = await request("GetSourceScreenshot", { + "sourceName": "Native browser", "imageFormat": "png", "imageWidth": 64, "imageHeight": 36, + }) + screenshot = runtime / "browser-bridge.png" + screenshot.write_bytes(base64.b64decode(image["imageData"].split(",", 1)[1], validate=True)) + frame = subprocess.run([ + "ffmpeg", "-v", "error", "-i", str(screenshot), "-frames:v", "1", + "-f", "rawvideo", "-pix_fmt", "rgb24", "-", + ], capture_output=True, check=True, timeout=15).stdout + if len(frame) == 64 * 36 * 3 and all(abs(value - expected[index % 3]) <= 4 for index, value in enumerate(frame)): + break + if asyncio.get_running_loop().time() >= deadline: + state = { + "active": await request("GetSourceActive", {"sourceName": "Native browser"}), + "settings": await request("GetInputSettings", {"inputName": "Native browser"}), + "transform": await request("GetSceneItemTransform", {"sceneName": "Native scene", "sceneItemId": item["sceneItemId"]}), + } + (runtime / "browser-failure.json").write_text(json.dumps(state, indent=2)) + raise AssertionError(f"browser did not render the JavaScript API success color; see {screenshot}") + await asyncio.sleep(0.1) + await request("SetSceneItemEnabled", {"sceneName": "Native scene", "sceneItemId": item["sceneItemId"], "sceneItemEnabled": False}) + print("Native browser rendered local HTML and window.obsstudio.getCurrentScene callback passed") + return {"local_file": str(page), "bridge_scene": "Native scene", "rendered_rgb": list(frame[:3])} + + +async def verify_vlc(runtime: Path, request) -> None: + clip = runtime / "vlc-white.mkv" + subprocess.run([ + "ffmpeg", "-v", "error", "-y", "-f", "lavfi", "-i", "color=white:s=320x180:r=30", + "-t", "6", "-c:v", "libx264", "-preset", "ultrafast", "-pix_fmt", "yuv420p", str(clip), + ], check=True, capture_output=True, timeout=20) + await request("CreateInput", { + "sceneName": "Native scene", "inputName": "Native VLC", "inputKind": "vlc_source", + "sceneItemEnabled": True, + "inputSettings": {"playlist": [{"value": str(clip)}], "loop": True, + "playback_behavior": "always_play"}, + }) + deadline = asyncio.get_running_loop().time() + 15 + while True: + status = await request("GetMediaInputStatus", {"inputName": "Native VLC"}) + if status["mediaState"] == "OBS_MEDIA_STATE_PLAYING" and status["mediaDuration"] > 0: + break + assert asyncio.get_running_loop().time() < deadline, status + await asyncio.sleep(0.1) + assert 5000 <= status["mediaDuration"] <= 6500, status + while True: + image = await request("GetSourceScreenshot", { + "sourceName": "Native VLC", "imageFormat": "png", "imageWidth": 64, "imageHeight": 36, + }) + screenshot = runtime / "vlc-white.png" + screenshot.write_bytes(base64.b64decode(image["imageData"].split(",", 1)[1], validate=True)) + decoded = subprocess.run([ + "ffmpeg", "-v", "error", "-i", str(screenshot), "-frames:v", "1", + "-f", "rawvideo", "-pix_fmt", "rgb24", "-", + ], check=True, capture_output=True, timeout=15).stdout + if len(decoded) == 64 * 36 * 3 and min(decoded) >= 240: + break + assert asyncio.get_running_loop().time() < deadline, "VLC did not decode a white frame" + await asyncio.sleep(0.1) + for action, expected in [("PAUSE", "PAUSED"), ("PLAY", "PLAYING"), ("RESTART", "PLAYING")]: + await request("TriggerMediaInputAction", { + "inputName": "Native VLC", "mediaAction": f"OBS_WEBSOCKET_MEDIA_INPUT_ACTION_{action}", + }) + deadline = asyncio.get_running_loop().time() + 5 + while True: + status = await request("GetMediaInputStatus", {"inputName": "Native VLC"}) + if status["mediaState"] == f"OBS_MEDIA_STATE_{expected}": + break + assert asyncio.get_running_loop().time() < deadline, status + await asyncio.sleep(0.05) + print("Native VLC playlist decoded white video; pause/play/restart passed") + + +if __name__ == "__main__": + parser = argparse.ArgumentParser() + parser.add_argument("--runtime", type=Path, required=True) + parser.add_argument("--recording", action="store_true") + arguments = parser.parse_args() + asyncio.run(verify(arguments.runtime.resolve(), arguments.recording)) diff --git a/rust/obs-build/tests/libobs/whip-probe.c b/rust/obs-build/tests/libobs/whip-probe.c new file mode 100644 index 0000000000..9d3ad61b8e --- /dev/null +++ b/rust/obs-build/tests/libobs/whip-probe.c @@ -0,0 +1,167 @@ +/* Native fixture extension; the public OBS API drives the real WHIP module. */ +#ifdef OBS_FIXTURE_WHIP +#include +#include +#include + +struct whip_tone { + obs_source_t *source; + os_event_t *stop; + pthread_t thread; +}; + +static void *whip_tone_thread(void *opaque) +{ + struct whip_tone *tone = opaque; + float samples[2][480]; + for (unsigned i = 0; i < 480; ++i) { + float wave = sinf(6.28318530718f * (float)(i % 48) / 48.0f); + samples[0][i] = 0.25f * wave; + samples[1][i] = -0.125f * wave; + } + uint64_t next = os_gettime_ns(); + while (os_event_try(tone->stop) == EAGAIN) { + struct obs_source_audio audio = { + .data = {(uint8_t *)samples[0], (uint8_t *)samples[1]}, + .frames = 480, + .speakers = SPEAKERS_STEREO, + .format = AUDIO_FORMAT_FLOAT_PLANAR, + .samples_per_sec = 48000, + .timestamp = next, + }; + obs_source_output_audio(tone->source, &audio); + next += 10000000ULL; + os_sleepto_ns(next); + } + return NULL; +} + +static const char *whip_tone_name(void *unused) +{ + (void)unused; + return "WHIP integration tone"; +} + +static void *whip_tone_create(obs_data_t *settings, obs_source_t *source) +{ + (void)settings; + struct whip_tone *tone = bzalloc(sizeof(*tone)); + tone->source = source; + if (os_event_init(&tone->stop, OS_EVENT_TYPE_MANUAL)) { + bfree(tone); + return NULL; + } + if (pthread_create(&tone->thread, NULL, whip_tone_thread, tone)) { + os_event_destroy(tone->stop); + bfree(tone); + return NULL; + } + return tone; +} + +static void whip_tone_destroy(void *opaque) +{ + struct whip_tone *tone = opaque; + os_event_signal(tone->stop); + pthread_join(tone->thread, NULL); + os_event_destroy(tone->stop); + bfree(tone); +} + +struct whip_stop { + os_event_t *event; + int code; +}; + +static void whip_stopped(void *opaque, calldata_t *data) +{ + struct whip_stop *stopped = opaque; + stopped->code = (int)calldata_int(data, "code"); + os_event_signal(stopped->event); +} + +static int stream_whip(const char *endpoint) +{ + struct obs_source_info info = { + .id = "cc_build_whip_tone", + .type = OBS_SOURCE_TYPE_INPUT, + .output_flags = OBS_SOURCE_AUDIO, + .get_name = whip_tone_name, + .create = whip_tone_create, + .destroy = whip_tone_destroy, + }; + obs_register_source(&info); + obs_source_t *tone = obs_source_create(info.id, "whip tone", NULL, NULL); + obs_set_output_source(1, tone); + obs_data_t *settings = obs_data_create(); + obs_data_set_string(settings, "server", endpoint); + obs_data_set_string(settings, "bearer_token", "cc-build-whip-token"); + obs_service_t *service = obs_service_create("whip_custom", "whip service", settings, NULL); + obs_data_release(settings); + settings = obs_data_create(); + obs_data_set_string(settings, "rate_control", "CBR"); + obs_data_set_string(settings, "preset", "ultrafast"); + obs_data_set_string(settings, "tune", "zerolatency"); + obs_data_set_int(settings, "bitrate", 500); + obs_data_set_int(settings, "keyint_sec", 1); + obs_data_set_int(settings, "bf", 0); + obs_data_set_bool(settings, "repeat_headers", true); + obs_encoder_t *video = obs_video_encoder_create("obs_x264", "whip video", settings, NULL); + obs_data_release(settings); + settings = obs_data_create(); + obs_data_set_int(settings, "bitrate", 128); + obs_encoder_t *audio = obs_audio_encoder_create("ffmpeg_opus", "whip audio", settings, 0, NULL); + obs_data_release(settings); + obs_output_t *output = obs_output_create("whip_output", "whip stream", NULL, NULL); + struct whip_stop stopped = {0}; + int status = 0; + if (!tone || !service || !video || !audio || !output || os_event_init(&stopped.event, OS_EVENT_TYPE_MANUAL)) { + status = 100; + goto cleanup; + } + signal_handler_connect(obs_output_get_signal_handler(output), "stop", whip_stopped, &stopped); + obs_encoder_set_video(video, obs_get_video()); + obs_encoder_set_audio(audio, obs_get_audio()); + obs_output_set_service(output, service); + obs_output_set_video_encoder(output, video); + obs_output_set_audio_encoder(output, audio, 0); + if (!obs_output_start(output)) { + status = 101; + goto disconnect; + } + for (unsigned i = 0; + i < 1500 && obs_output_get_total_frames(output) < 90 && os_event_try(stopped.event) == EAGAIN; ++i) + os_sleep_ms(10); + uint32_t sent_frames = obs_output_get_total_frames(output); + uint64_t bytes = obs_output_get_total_bytes(output); + if (sent_frames < 90 || !bytes) + status = 102; + obs_output_stop(output); + if (os_event_timedwait(stopped.event, 10000)) { + obs_output_force_stop(output); + status = 103; + os_event_timedwait(stopped.event, 10000); + } + if (stopped.code != OBS_OUTPUT_SUCCESS) + status = 104; + blog(LOG_INFO, "cc::Build WHIP transmitted frames=%u bytes=%" PRIu64 " status=%d", sent_frames, bytes, status); +disconnect: + signal_handler_disconnect(obs_output_get_signal_handler(output), "stop", whip_stopped, &stopped); +cleanup: + if (status && output) + blog(LOG_ERROR, "WHIP fixture failed: %d, %s", status, obs_output_get_last_error(output)); + obs_output_release(output); + obs_encoder_release(video); + obs_encoder_release(audio); + obs_service_release(service); + if (stopped.event) + os_event_destroy(stopped.event); + obs_set_output_source(1, NULL); + if (tone) + obs_source_remove(tone); + obs_source_release(tone); + while (obs_wait_for_destroy_queue()) { + } + return status; +} +#endif diff --git a/rust/obs-build/tests/libobs/whip_receiver.py b/rust/obs-build/tests/libobs/whip_receiver.py new file mode 100644 index 0000000000..99c8964759 --- /dev/null +++ b/rust/obs-build/tests/libobs/whip_receiver.py @@ -0,0 +1,196 @@ +#!/usr/bin/env -S uv run --script +# /// script +# requires-python = ">=3.12" +# dependencies = ["aiortc==1.15.0", "aiohttp==3.14.5", "numpy==2.5.4"] +# /// +"""Receive and decode the real native WHIP fixture while running its command.""" + +import argparse +import asyncio +import json +import os +from pathlib import Path +import signal +import uuid + +from aiohttp import web +from aiortc import RTCConfiguration, RTCPeerConnection, RTCSessionDescription +from aiortc.mediastreams import MediaStreamError +import numpy as np + + +async def exercise(args): + sessions = {} + peers = {} + consumers = [] + args.output.parent.mkdir(parents=True, exist_ok=True) + + def save(): + args.output.write_text(json.dumps(list(sessions.values()), indent=2) + "\n") + + def authorize(request): + if request.headers.get("Authorization") != "Bearer cc-build-whip-token": + raise web.HTTPUnauthorized() + + async def consume(track, state): + previous = None + try: + while True: + frame = await track.recv() + if frame.pts is None or ( + previous is not None and frame.pts <= previous + ): + raise AssertionError(f"{track.kind} timestamp did not advance") + previous = frame.pts + if track.kind == "video": + if (frame.width, frame.height) != (64, 64): + raise AssertionError("unexpected decoded video geometry") + rgb = frame.to_ndarray(format="rgb24") + expected = 255 if args.color == "white" else 0 + if np.max(np.abs(rgb.astype(float) - expected)) > 8: + raise AssertionError("decoded video differs from fixture scene") + state["video_frames"] += 1 + else: + if frame.sample_rate != 48000 or len(frame.layout.channels) != 2: + raise AssertionError("expected 48 kHz stereo Opus audio") + raw = frame.to_ndarray() + samples = raw.T if frame.format.is_planar else raw.reshape(-1, 2) + samples = samples.astype(float) / ( + np.iinfo(raw.dtype).max if raw.dtype.kind in "iu" else 1 + ) + rms = float(np.sqrt(np.mean(samples**2))) + frequencies = np.fft.rfftfreq(len(samples), 1 / 48000) + dominant = float( + frequencies[np.argmax(np.abs(np.fft.rfft(samples[:, 0])))] + ) + state["audio_frames"] += 1 + if 0.10 < rms < 0.18 and 950 <= dominant <= 1050: + state["tone_frames"] += 1 + state["tone_rms"] = rms + state["tone_frequency"] = dominant + save() + except MediaStreamError: + pass # The sender closes its real peer before deleting the resource. + except Exception as error: + state["errors"].append(f"{type(error).__name__}: {error}") + save() + + async def offer(request): + authorize(request) + if request.content_type != "application/sdp": + raise web.HTTPUnsupportedMediaType() + identifier = uuid.uuid4().hex + peer = RTCPeerConnection(RTCConfiguration(iceServers=[])) + peers[identifier] = peer + state = { + "id": identifier, + "states": [], + "video_frames": 0, + "audio_frames": 0, + "tone_frames": 0, + "deleted": False, + "errors": [], + } + sessions[identifier] = state + + @peer.on("connectionstatechange") + async def changed(): + state["states"].append(peer.connectionState) + save() + + @peer.on("track") + def track_received(track): + consumers.append(asyncio.create_task(consume(track, state))) + + try: + sdp = await request.text() + args.output.with_name( + f"{args.output.stem}-{identifier}-offer.sdp" + ).write_text(sdp) + await peer.setRemoteDescription( + RTCSessionDescription(sdp=sdp, type="offer") + ) + await peer.setLocalDescription(await peer.createAnswer()) + answer = peer.localDescription.sdp + args.output.with_name( + f"{args.output.stem}-{identifier}-answer.sdp" + ).write_text(answer) + save() + return web.Response( + status=201, + text=answer, + content_type="application/sdp", + headers={"Location": f"/resource/{identifier}"}, + ) + except Exception as error: + state["errors"].append(f"offer: {type(error).__name__}: {error}") + save() + raise + + async def delete(request): + authorize(request) + identifier = request.match_info["identifier"] + if identifier not in peers: + raise web.HTTPNotFound() + sessions[identifier]["deleted"] = True + await peers[identifier].close() + save() + return web.Response(status=200) + + app = web.Application() + app.router.add_post("/whip", offer) + app.router.add_delete("/resource/{identifier}", delete) + runner = web.AppRunner(app) + await runner.setup() + await web.TCPSite(runner, "127.0.0.1", 0).start() + port = runner.addresses[0][1] + env = dict(os.environ, OBS_BUILD_WHIP_ENDPOINT=f"http://127.0.0.1:{port}/whip") + process = None + try: + process = await asyncio.create_subprocess_exec( + *args.command, env=env, start_new_session=True + ) + result = await asyncio.wait_for(process.wait(), timeout=args.timeout) + if result: + raise AssertionError(f"native command failed: {result}") + finally: + if process is not None and process.returncode is None: + os.killpg(process.pid, signal.SIGTERM) + try: + await asyncio.wait_for(process.wait(), timeout=5) + except asyncio.TimeoutError: + os.killpg(process.pid, signal.SIGKILL) + await process.wait() + for peer in peers.values(): + await peer.close() + await asyncio.gather(*consumers) + await runner.cleanup() + save() + assert len(sessions) == args.sessions, ( + f"expected {args.sessions} streams: {sessions}" + ) + for state in sessions.values(): + assert not state["errors"], state + assert "connected" in state["states"] and state["deleted"], state + assert state["video_frames"] >= 12, state + assert state["audio_frames"] >= 20 and state["tone_frames"] >= 10, state + print( + f"Validated {len(sessions)} real WHIP streams: decoded video, Opus tone, timestamps and DELETE" + ) + + +if __name__ == "__main__": + parser = argparse.ArgumentParser(description=__doc__) + parser.add_argument("--output", type=Path, required=True) + parser.add_argument("--color", choices=["black", "white"], default="black") + parser.add_argument("--sessions", type=int, default=2) + parser.add_argument("--timeout", type=float, default=300) + parser.add_argument("command", nargs=argparse.REMAINDER) + options = parser.parse_args() + if options.command and options.command[0] == "--": + options.command.pop(0) + if options.timeout <= 0: + parser.error("--timeout must be positive") + if not options.command: + parser.error("provide the native test command after --") + asyncio.run(exercise(options)) diff --git a/rust/obs-build/tests/native.rs b/rust/obs-build/tests/native.rs new file mode 100644 index 0000000000..b12d6d5d38 --- /dev/null +++ b/rust/obs-build/tests/native.rs @@ -0,0 +1,389 @@ +//! Build-system integration contracts; these compile and load actual C artifacts. +use obs_build::{NativeBuild, SharedLibrary}; +use std::{fs, path::Path}; + +fn target(name: &str, source: &Path, dependencies: Vec) -> SharedLibrary { + SharedLibrary { + name: name.into(), + sources: vec![source.into()], + include_dirs: vec![], + dependencies, + unity: true, + ..SharedLibrary::default() + } +} + +unsafe fn answer(library: &Path, symbol: &[u8], dependencies: &[&Path]) -> i32 { + // SAFETY: the fixture below defines this symbol with the C ABI and no args; + // its owning library stays loaded for the entire call. + unsafe { + // Load dependencies explicitly as well: Windows does not search sibling + // target directories for DLLs. Keep their handles alive through the call. + let _dependencies: Vec<_> = dependencies + .iter() + .map(|path| libloading::Library::new(path).unwrap()) + .collect(); + let lib = libloading::Library::new(library).unwrap(); + let function = lib.get:: i32>(symbol).unwrap(); + function() + } +} + +#[test] +fn native_plugin_links_shared_core_and_observes_rebuilt_dependency() { + let dir = tempfile::tempdir().unwrap(); + let core_source = dir.path().join("core.c"); + let plugin_source = dir.path().join("plugin.c"); + fs::write( + &core_source, + "__declspec_placeholder__ int obs_fixture_answer(void) { return 42; }" + .replace("__declspec_placeholder__", EXPORT), + ) + .unwrap(); + fs::write(&plugin_source, format!("extern int obs_fixture_answer(void); {EXPORT} int obs_fixture_plugin(void) {{ return obs_fixture_answer() + 1; }}")).unwrap(); + let build = NativeBuild { + host: env!("OBS_BUILD_HOST").into(), + target: env!("OBS_BUILD_TARGET").into(), + output: dir.path().join("artifacts"), + }; + let core = build + .shared_library(&target("fixture-core", &core_source, vec![])) + .unwrap(); + let plugin = build + .shared_library(&target( + "fixture-plugin", + &plugin_source, + vec![core.clone()], + )) + .unwrap(); + // SAFETY: both sources above define the expected no-argument C functions. + assert_eq!( + unsafe { answer(&plugin, b"obs_fixture_plugin", &[&core]) }, + 43 + ); + fs::write( + &core_source, + format!("{EXPORT} int obs_fixture_answer(void) {{ return 84; }}"), + ) + .unwrap(); + build + .shared_library(&target("fixture-core", &core_source, vec![])) + .unwrap(); + // SAFETY: the rebuilt core preserves the function ABI; it changes its result. + assert_eq!( + unsafe { answer(&plugin, b"obs_fixture_plugin", &[&core]) }, + 85 + ); +} + +#[test] +fn unity_toggle_preserves_exports_and_explicit_generated_source_wins() { + let dir = tempfile::tempdir().unwrap(); + let source_dir = dir.path().join("source"); + let generated_dir = dir.path().join("generated"); + fs::create_dir_all(&source_dir).unwrap(); + fs::create_dir_all(&generated_dir).unwrap(); + fs::write( + source_dir.join("manifest.c"), + "#error stale source tree manifest selected\n", + ) + .unwrap(); + let generated = generated_dir.join("manifest.c"); + fs::write( + &generated, + format!("{EXPORT} int obs_fixture_count(void) {{ return 17; }}"), + ) + .unwrap(); + let extra = source_dir.join("extra.c"); + fs::write(&extra, "int obs_fixture_other(void) { return 23; }").unwrap(); + for unity in [false, true] { + let build = NativeBuild { + host: env!("OBS_BUILD_HOST").into(), + target: env!("OBS_BUILD_TARGET").into(), + output: dir.path().join(format!("output-{unity}")), + }; + let mut library = target("fixture-manifest", &generated, vec![]); + library.sources.push(extra.clone()); + library.include_dirs.push(source_dir.clone()); + library.unity = unity; + let artifact = build.shared_library(&library).unwrap(); + // SAFETY: the generated fixture defines this no-argument C function. + assert_eq!(unsafe { answer(&artifact, b"obs_fixture_count", &[]) }, 17); + } +} + +#[test] +fn executable_runs_against_its_shared_core_dependency() { + let dir = tempfile::tempdir().unwrap(); + let core_source = dir.path().join("core.c"); + let executable_source = dir.path().join("main.c"); + let helper_source = dir.path().join("helper.c"); + fs::write( + &helper_source, + "int fixture_private_value(void) { return 42; }", + ) + .unwrap(); + fs::write( + &core_source, + format!("extern int fixture_private_value(void); {EXPORT} int fixture_value(void) {{ return fixture_private_value(); }}"), + ) + .unwrap(); + fs::write( + &executable_source, + "extern int fixture_value(void); int main(void) { return fixture_value() == 42 ? 0 : 7; }", + ) + .unwrap(); + let build = NativeBuild { + host: env!("OBS_BUILD_HOST").into(), + target: env!("OBS_BUILD_TARGET").into(), + output: dir.path().join("artifacts"), + }; + let helper = build + .static_library(&target("fixture-helper", &helper_source, vec![])) + .unwrap(); + let core = build + .shared_library(&target("fixture-core", &core_source, vec![helper])) + .unwrap(); + let executable = build + .executable(&target( + "fixture-app", + &executable_source, + vec![core.clone()], + )) + .unwrap(); + let old_path = std::env::var_os("PATH").unwrap_or_default(); + let search = std::env::join_paths( + std::iter::once(core.parent().unwrap().to_path_buf()) + .chain(std::env::split_paths(&old_path)), + ) + .unwrap(); + assert!( + std::process::Command::new(executable) + .env("PATH", search) + .status() + .unwrap() + .success() + ); +} + +const EXPORT: &str = "\n#if defined(_WIN32)\n__declspec(dllexport)\n#endif\n"; + +#[test] +fn pch_preserves_mixed_languages_unity_and_header_flag_invalidation() { + if !env!("OBS_BUILD_TARGET").contains("linux") { + eprintln!("compiled PCH integration currently covers Linux GCC and Clang"); + return; + } + let directory = tempfile::tempdir().unwrap(); + let root = directory.path(); + let header = root.join("common.h"); + let transitive = root.join("value.h"); + let write_header = |value| { + fs::write(&header, format!("#pragma once\n#include \"value.h\"\n#define HEADER_VALUE {value}\n#ifdef __cplusplus\n#include \n#else\n#include \n#endif\n")).unwrap() + }; + let c = root.join("part.c"); + let cpp = root.join("part.cpp"); + fs::write(&c, "#include \"common.h\"\n#ifdef FIXTURE_CPP\n#error C++ flags leaked into C\n#endif\nint fixture_c(void) { return HEADER_VALUE + FIXTURE_C + TRANSITIVE_VALUE; }\n").unwrap(); + fs::write(&cpp, "#include \"common.h\"\n#ifdef FIXTURE_C\n#error C flags leaked into C++\n#endif\nextern \"C\" int fixture_c(void);\nextern \"C\" int obs_fixture_pch(void) { std::vector values{HEADER_VALUE + TRANSITIVE_VALUE, FIXTURE_CPP}; return fixture_c() + values[0] + values[1]; }\n").unwrap(); + for unity in [false, true] { + write_header(17); + fs::write(&transitive, "#define TRANSITIVE_VALUE 0\n").unwrap(); + let build = NativeBuild { + host: env!("OBS_BUILD_HOST").into(), + target: env!("OBS_BUILD_TARGET").into(), + output: root.join(format!("output-{unity}")), + }; + let mut library = target("fixture-pch", &c, vec![]); + library.sources.push(cpp.clone()); + library.include_dirs.push(root.into()); + library.unity = unity; + library.c_compile_options.push("-DFIXTURE_C=3".into()); + library.cpp_compile_options.push("-DFIXTURE_CPP=5".into()); + library + .precompiled_headers + .push(obs_build::PrecompiledHeader { + header: header.clone(), + sources: vec![c.clone(), cpp.clone()], + }); + let artifact = build.shared_library(&library).unwrap(); + // SAFETY: the fixture defines this no-argument C ABI function. + assert_eq!(unsafe { answer(&artifact, b"obs_fixture_pch", &[]) }, 42); + write_header(37); + let artifact = build.shared_library(&library).unwrap(); + // SAFETY: the edited header preserves the function ABI. + assert_eq!(unsafe { answer(&artifact, b"obs_fixture_pch", &[]) }, 82); + fs::write(&transitive, "#define TRANSITIVE_VALUE 11\n").unwrap(); + let artifact = build.shared_library(&library).unwrap(); + // SAFETY: the edited transitive header preserves the function ABI. + assert_eq!(unsafe { answer(&artifact, b"obs_fixture_pch", &[]) }, 104); + library.c_compile_options = vec!["-DFIXTURE_C=7".into()]; + let artifact = build.shared_library(&library).unwrap(); + // SAFETY: changing the compiler macro preserves the function ABI. + assert_eq!(unsafe { answer(&artifact, b"obs_fixture_pch", &[]) }, 108); + } +} + +#[test] +fn explicit_groups_compile_as_individual_sources_and_observe_member_edits() { + let directory = tempfile::tempdir().unwrap(); + let root = directory.path(); + fs::create_dir(root.join("build")).unwrap(); + fs::write(root.join("build/fixture.pch.h"), "#define VALUE 17\n").unwrap(); + let first = root.join("first.c.h"); + fs::write( + &first, + "#include \"build/fixture.pch.h\"\nint first(void) { return VALUE; }\n", + ) + .unwrap(); + fs::write(root.join("second.c.h"), format!("#include \"build/fixture.pch.h\"\nextern int first(void); {EXPORT} int obs_fixture_separate(void) {{ return first() + VALUE; }}\n")).unwrap(); + let group = root.join("build/fixture+.h.c"); + fs::write(&group, "/* explicit group */\n#include \"build/fixture.pch.h\"\n#include \"first.c.h\"\n#include \"second.c.h\"\n").unwrap(); + let build = NativeBuild { + host: env!("OBS_BUILD_HOST").into(), + target: env!("OBS_BUILD_TARGET").into(), + output: root.join("artifacts"), + }; + let mut library = target("fixture-separate", &group, vec![]); + library.unity = false; + library.include_dirs.push(root.into()); + library.sources = build + .separate_group_sources(root, &library.sources) + .unwrap(); + assert_eq!(library.sources.len(), 2); + assert!(!library.sources.contains(&group)); + let artifact = build.shared_library(&library).unwrap(); + // SAFETY: the fixture defines this no-argument C function. + assert_eq!( + unsafe { answer(&artifact, b"obs_fixture_separate", &[]) }, + 34 + ); + fs::write( + &first, + "#include \"build/fixture.pch.h\"\nint first(void) { return VALUE + 1; }\n", + ) + .unwrap(); + fs::write(root.join("build/fixture.pch.h"), "#define VALUE 21\n").unwrap(); + let artifact = build.shared_library(&library).unwrap(); + // SAFETY: the rebuilt fixture preserves its function ABI. + assert_eq!( + unsafe { answer(&artifact, b"obs_fixture_separate", &[]) }, + 43 + ); +} + +#[test] +fn individual_compilation_rejects_conditional_group_selection() { + let directory = tempfile::tempdir().unwrap(); + let group = directory.path().join("conditional+.h.c"); + fs::write( + &group, + "#if ENABLE_OPTION\n#include \"optional.c.h\"\n#endif\n", + ) + .unwrap(); + let build = NativeBuild { + host: env!("OBS_BUILD_HOST").into(), + target: env!("OBS_BUILD_TARGET").into(), + output: directory.path().join("artifacts"), + }; + let error = build + .separate_group_sources(directory.path(), &[group]) + .unwrap_err(); + assert!(error.contains("non-include group line"), "{error}"); +} + +#[test] +fn deploying_mux_helper_in_place_preserves_its_contents() { + let directory = tempfile::tempdir().unwrap(); + let helper = directory.path().join("obs-ffmpeg-mux"); + std::fs::write(&helper, b"existing executable").unwrap(); + let artifacts = obs_build::plugins::FfmpegArtifacts { + module: obs_build::plugins::Module { + library: std::path::PathBuf::new(), + data: std::path::PathBuf::new(), + }, + muxer: helper.clone(), + }; + assert_eq!(artifacts.deploy_muxer(directory.path()).unwrap(), helper); + assert_eq!(std::fs::read(helper).unwrap(), b"existing executable"); +} + +#[test] +fn mixed_c_and_cpp_use_independent_flags_and_the_cpp_linker() { + let directory = tempfile::tempdir().unwrap(); + let c_source = directory.path().join("helper.c"); + let cpp_source = directory.path().join("main.cpp"); + std::fs::write(&c_source, "#if !defined(C_ONLY) || defined(CPP_ONLY)\n#error wrong C flags\n#endif\nint helper(void) { return 42; }\n").unwrap(); + std::fs::write(&cpp_source, "#include \n#if !defined(CPP_ONLY) || defined(C_ONLY)\n#error wrong C++ flags\n#endif\nextern \"C\" int helper(void);\nint main() { std::vector values{helper()}; return values.at(0) == 42 ? 0 : 1; }\n").unwrap(); + let target = SharedLibrary { + name: "mixed-native".into(), + sources: vec![c_source, cpp_source], + c_compile_options: vec!["-DC_ONLY".into()], + cpp_compile_options: vec!["-DCPP_ONLY".into()], + ..SharedLibrary::default() + }; + let build = NativeBuild { + host: env!("OBS_BUILD_HOST").into(), + target: env!("OBS_BUILD_TARGET").into(), + output: directory.path().join("out"), + }; + let artifact = build.executable(&target).unwrap(); + assert!( + std::process::Command::new(artifact) + .status() + .unwrap() + .success() + ); +} + +#[test] +fn pch_batches_preserve_constructor_order_with_interleaved_headers() { + if !env!("OBS_BUILD_TARGET").contains("linux") { + eprintln!("compiled PCH integration currently covers Linux GCC and Clang"); + return; + } + let directory = tempfile::tempdir().unwrap(); + let root = directory.path(); + let a = root.join("a-header.h"); + let z = root.join("z-header.h"); + for header in [&a, &z] { + fs::write(header, "#pragma once\nextern int fixture_order;\n").unwrap(); + } + let mut sources = Vec::new(); + for index in 1..=3 { + let path = root.join(format!("part-{index}.cpp")); + let header = if index == 2 { + "a-header.h" + } else { + "z-header.h" + }; + fs::write(&path, format!("#include \"{header}\"\nstruct Init{index} {{ Init{index}() {{ fixture_order = fixture_order * 10 + {index}; }} }};\nstatic Init{index} init{index};\n")).unwrap(); + sources.push(path); + } + let entry = root.join("entry.cpp"); + fs::write(&entry, "int fixture_order = 0;\nextern \"C\" int obs_fixture_order(void) { return fixture_order; }\n").unwrap(); + for unity in [false, true] { + let build = NativeBuild { + host: env!("OBS_BUILD_HOST").into(), + target: env!("OBS_BUILD_TARGET").into(), + output: root.join(format!("artifacts-{unity}")), + }; + let mut library = target("fixture-order", &entry, vec![]); + library.sources = sources.clone(); + library.sources.push(entry.clone()); + library.include_dirs.push(root.into()); + library.unity = unity; + library.precompiled_headers = vec![ + obs_build::PrecompiledHeader { + header: a.clone(), + sources: vec![sources[1].clone()], + }, + obs_build::PrecompiledHeader { + header: z.clone(), + sources: vec![sources[0].clone(), sources[2].clone()], + }, + ]; + let artifact = build.shared_library(&library).unwrap(); + // SAFETY: the fixture defines this no-argument C ABI function. + assert_eq!(unsafe { answer(&artifact, b"obs_fixture_order", &[]) }, 123); + } +} diff --git a/rust/obs-sys/Cargo.toml b/rust/obs-sys/Cargo.toml new file mode 100644 index 0000000000..c1389274dc --- /dev/null +++ b/rust/obs-sys/Cargo.toml @@ -0,0 +1,20 @@ +[package] +name = "obs-sys" +version = "0.1.0" +description = "Native libobs C ABI with an optional cc::Build source build" +edition.workspace = true +rust-version.workspace = true +license.workspace = true +publish.workspace = true +links = "obs" + +[features] +default = [] +bundled = ["dep:obs-build"] + +[build-dependencies] +obs-build = { path = "../obs-build", optional = true } + +[[test]] +name = "native" +required-features = ["bundled"] diff --git a/rust/obs-sys/build-options.rs b/rust/obs-sys/build-options.rs new file mode 100644 index 0000000000..f5a153fe97 --- /dev/null +++ b/rust/obs-sys/build-options.rs @@ -0,0 +1,28 @@ +//! Options shared by the build script and its configuration contracts. +use std::ffi::OsString; + +pub const VARIABLES: [&str; 2] = ["OBS_SYS_UNITY", "OBS_SYS_PCH"]; + +#[derive(Debug, PartialEq, Eq)] +pub struct BuildModes { + pub unity: bool, + pub pch: bool, +} + +impl BuildModes { + pub fn from_lookup(mut lookup: impl FnMut(&str) -> Option) -> Result { + Ok(Self { + unity: flag(VARIABLES[0], lookup(VARIABLES[0]), true)?, + pch: flag(VARIABLES[1], lookup(VARIABLES[1]), false)?, + }) + } +} + +fn flag(name: &str, value: Option, default: bool) -> Result { + match value.as_ref().map(|value| value.to_str()) { + None => Ok(default), + Some(Some("0")) => Ok(false), + Some(Some("1")) => Ok(true), + _ => Err(format!("{name} must be 0 or 1")), + } +} diff --git a/rust/obs-sys/build.rs b/rust/obs-sys/build.rs new file mode 100644 index 0000000000..ac40ab4345 --- /dev/null +++ b/rust/obs-sys/build.rs @@ -0,0 +1,58 @@ +#[cfg(feature = "bundled")] +#[path = "build-options.rs"] +mod build_options; + +fn main() { + println!("cargo:rerun-if-changed=build.rs"); + println!("cargo:rerun-if-changed=build-options.rs"); + #[cfg(feature = "bundled")] + { + for variable in build_options::VARIABLES { + println!("cargo:rerun-if-env-changed={variable}"); + } + let modes = build_options::BuildModes::from_lookup(|name| std::env::var_os(name)) + .unwrap_or_else(|error| panic!("configure bundled libobs: {error}")); + let root = std::path::Path::new(env!("CARGO_MANIFEST_DIR")).join("../.."); + for directory in ["libobs", "deps/libcaption"] { + println!("cargo:rerun-if-changed={}", root.join(directory).display()); + } + for variable in [ + "CPATH", + "C_INCLUDE_PATH", + "CPLUS_INCLUDE_PATH", + "LIBRARY_PATH", + "CFLAGS", + "CXXFLAGS", + "CC", + "CXX", + "PKG_CONFIG_PATH", + ] { + println!("cargo:rerun-if-env-changed={variable}"); + } + let build = obs_build::NativeBuild { + host: std::env::var("HOST").unwrap(), + target: std::env::var("TARGET").unwrap(), + output: std::path::PathBuf::from(std::env::var_os("OUT_DIR").unwrap()).join("native"), + }; + let options = obs_build::libobs::Options { + unity: modes.unity, + pch: modes.pch, + ..obs_build::libobs::Options::default() + }; + let library = obs_build::libobs::build_with_options(&build, &root, &options) + .unwrap_or_else(|error| panic!("build bundled libobs: {error}")); + for (name, enabled) in [("UNITY", modes.unity), ("PCH", modes.pch)] { + println!( + "cargo:rustc-env=OBS_SYS_NATIVE_{name}={}", + u8::from(enabled) + ); + } + println!( + "cargo:rustc-link-search=native={}", + library.parent().unwrap().display() + ); + println!("cargo:rustc-link-lib=dylib=obs"); + println!("cargo:rustc-env=OBS_SYS_LIBRARY={}", library.display()); + println!("cargo:library={}", library.display()); + } +} diff --git a/rust/obs-sys/src/ffi/mod.rs b/rust/obs-sys/src/ffi/mod.rs new file mode 100644 index 0000000000..9ccccacbf3 --- /dev/null +++ b/rust/obs-sys/src/ffi/mod.rs @@ -0,0 +1,13 @@ +//! Declarations from the unchanged libobs public headers. +unsafe extern "C" { + /// Returns the libobs C API version from `libobs/obs-config.h`. + pub fn obs_get_version() -> u32; + /// Initializes libobs; a null name store asks libobs to create its own. + pub fn obs_startup( + locale: *const std::ffi::c_char, + module_config_path: *const std::ffi::c_char, + store: *mut std::ffi::c_void, + ) -> bool; + pub fn obs_initialized() -> bool; + pub fn obs_shutdown(); +} diff --git a/rust/obs-sys/src/lib.rs b/rust/obs-sys/src/lib.rs new file mode 100644 index 0000000000..4fa9c7d5be --- /dev/null +++ b/rust/obs-sys/src/lib.rs @@ -0,0 +1,12 @@ +//! Low-level bindings to the original libobs C ABI. +//! +//! `bundled` builds the native library through obs-build and cc::Build. Without +//! it the declarations can be used by a parent supplying its own libobs linkage. +//! +//! Bundled builds accept `OBS_SYS_UNITY=0|1` (default `1`) and +//! `OBS_SYS_PCH=0|1` (default `0`). PCH currently requires Linux GCC or Clang. +//! Cargo tracks both options and rebuilds the native library when they change. +#![deny(unsafe_code)] + +#[allow(unsafe_code)] +pub mod ffi; diff --git a/rust/obs-sys/tests/native.rs b/rust/obs-sys/tests/native.rs new file mode 100644 index 0000000000..c169fd2d15 --- /dev/null +++ b/rust/obs-sys/tests/native.rs @@ -0,0 +1,71 @@ +#[path = "../build-options.rs"] +mod build_options; + +#[test] +fn bundled_native_build_modes_are_independent_and_validate_inputs() { + use build_options::BuildModes; + for (unity, pch, expected) in [ + (None, None, (true, false)), + (Some("0"), None, (false, false)), + (None, Some("1"), (true, true)), + (Some("0"), Some("1"), (false, true)), + (Some("1"), Some("0"), (true, false)), + ] { + let modes = BuildModes::from_lookup(|name| match name { + "OBS_SYS_UNITY" => unity.map(Into::into), + "OBS_SYS_PCH" => pch.map(Into::into), + _ => panic!("unexpected native build variable: {name}"), + }) + .unwrap(); + assert_eq!((modes.unity, modes.pch), expected); + } + for variable in build_options::VARIABLES { + for value in ["", "yes", "2", "-1"] { + let error = BuildModes::from_lookup(|name| { + (name == variable).then(|| std::ffi::OsString::from(value)) + }) + .unwrap_err(); + assert!(error.contains(variable), "{error}"); + assert!(error.contains("0 or 1"), "{error}"); + } + } +} + +#[test] +fn bundled_native_build_uses_requested_modes() { + let modes = build_options::BuildModes::from_lookup(|name| std::env::var_os(name)).unwrap(); + assert_eq!( + option_env!("OBS_SYS_NATIVE_UNITY"), + Some(if modes.unity { "1" } else { "0" }) + ); + assert_eq!( + option_env!("OBS_SYS_NATIVE_PCH"), + Some(if modes.pch { "1" } else { "0" }) + ); +} + +#[test] +fn bundled_libobs_reports_the_public_c_api_version() { + // SAFETY: the bundled build links the original no-argument C API function. + let version = unsafe { obs_sys::ffi::obs_get_version() }; + assert_eq!(version >> 24, 33); + assert!(std::path::Path::new(env!("OBS_SYS_LIBRARY")).is_file()); +} + +#[test] +fn bundled_libobs_starts_and_shuts_down_without_a_frontend() { + // SAFETY: the locale is a NUL-terminated static string. Null optional paths + // and profiler store are explicitly supported by obs_startup in obs.h. + // This is the only test that owns the process-global OBS lifecycle. + unsafe { + assert!(!obs_sys::ffi::obs_initialized()); + assert!(obs_sys::ffi::obs_startup( + c"en-US".as_ptr(), + std::ptr::null(), + std::ptr::null_mut(), + )); + assert!(obs_sys::ffi::obs_initialized()); + obs_sys::ffi::obs_shutdown(); + assert!(!obs_sys::ffi::obs_initialized()); + } +} diff --git a/rust/tools/linux-validate/Dockerfile b/rust/tools/linux-validate/Dockerfile index 4487602d47..05ccf7f27e 100644 --- a/rust/tools/linux-validate/Dockerfile +++ b/rust/tools/linux-validate/Dockerfile @@ -1,10 +1,13 @@ # Linux build environment for Tier 2 validation (docs/rust-port/testing-policy.md). FROM ubuntu:26.04 +# The source-manifest validator runs Python through uv in local containers too. +COPY --from=ghcr.io/astral-sh/uv:0.13.1 /uv /uvx /usr/local/bin/ ENV DEBIAN_FRONTEND=noninteractive COPY apt-packages.txt /tmp/apt-packages.txt RUN apt-get update && grep -v '^#' /tmp/apt-packages.txt | xargs apt-get install -y --no-install-recommends \ && if apt-cache show libvpl-dev >/dev/null 2>&1; then apt-get install -y --no-install-recommends libvpl-dev; fi # libvpl-dev is amd64-only. validate.sh leaves QSV off, so an arm64 image skips it. +RUN uv run --no-project --offline --python /usr/bin/python3 python -c 'import json, pathlib, re' # Install exactly the toolchain pinned in rust-toolchain.toml (run.sh passes it) # so corrosion/CMake finds it; rustup must not have to fetch it at run time. # Compiler launcher for the CMake builds: zccache, pinned with its checksum. diff --git a/rust/tools/linux-validate/validate.sh b/rust/tools/linux-validate/validate.sh index 5700c11442..3a4c087b12 100755 --- a/rust/tools/linux-validate/validate.sh +++ b/rust/tools/linux-validate/validate.sh @@ -117,20 +117,13 @@ done export ZCCACHE_CACHE_DIR="${ZCCACHE_CACHE_DIR:-$BUILD/zccache}" trap 'zccache stop >/dev/null 2>&1 || true' EXIT -# Every libobs C file the Rust build replaces: the implementation files of -# the unity groups (BUILD.md) in LIBOBS_PORTED_SOURCES and -# LIBOBS_LINUX_PORTED_SOURCES in libobs/cmake/sources.cmake, instead of a -# hand-kept list (obs-rust/obs-studio#137). Paths stay relative to libobs/ and -# are matched under libobs.dir/, because libobs also links same-named files -# from deps (deps/libcaption/src/utf8.c). -ported_groups=$(awk '/^set\($/ { getline name; inlist = (name ~ /^ *LIBOBS_(LINUX_)?PORTED_SOURCES$/); next } - /^set\(LIBOBS_(LINUX_)?PORTED_SOURCES / { for (i = 2; i <= NF; i++) print $i; next } - inlist && /^\)/ { inlist = 0 } inlist { print $1 } - /list\(APPEND LIBOBS_PORTED_SOURCES / { print $3 }' "$SRC"/libobs/cmake/sources.cmake | - tr -d ')' | grep -E '^build/.*\+\.h\.c$' | sort -u) -ported_objs=$(cd "$SRC/libobs" && sed -n 's|^#include "libobs/\(.*\.c\.h\)"$|\1.o|p' $ported_groups | sort -u) +# Read the same canonical source sets as CMake and obs-build, then expand the +# selected ported groups into implementation object names. Scraping sources.cmake +# misses groups now that it imports the JSON manifest instead of listing them. +ported_objs=$(uv run --no-project python "$SRC/rust/tools/ported_sources.py" --root "$SRC" --host linux) + if [ "$(wc -w <<<"$ported_objs")" -lt 20 ]; then - echo "FAIL: derived only $(wc -w <<<"$ported_objs") ported objects from libobs/cmake/sources.cmake" + echo "FAIL: derived only $(wc -w <<<"$ported_objs") ported objects from libobs/build/source-sets.json" exit 1 fi echo "== ported objects checked out of libobs-with-rust: $(wc -w <<<"$ported_objs")" diff --git a/rust/tools/ported_sources.py b/rust/tools/ported_sources.py new file mode 100644 index 0000000000..3fd5b65668 --- /dev/null +++ b/rust/tools/ported_sources.py @@ -0,0 +1,35 @@ +#!/usr/bin/env -S uv run --script +"""Read the canonical native source inventory for Tier 2 graph validation.""" +import argparse +import json +from pathlib import Path +import re + +MEMBER = re.compile(r'^\s*#include\s+"libobs/([^"\n]+\.(?:c|m)\.h)"\s*$', re.MULTILINE) + + +def ported_objects(root: Path, host: str, hevc: bool = True) -> list[str]: + if host not in {"linux", "windows", "macos"}: + raise ValueError(f"unknown native host: {host}") + libobs = root / "libobs" + sets = json.loads((libobs / "build/source-sets.json").read_text()) + names = ["LIBOBS_PORTED_SOURCES", f"LIBOBS_{host.upper()}_PORTED_SOURCES"] + if hevc: + names.append("LIBOBS_HEVC_PORTED_SOURCES") + objects = set() + for name in names: + for group in sets[name]: + members = MEMBER.findall((libobs / group).read_text()) + if not members: + raise ValueError(f"ported group contains no implementation members: {group}") + objects.update(member + ".o" for member in members) + return sorted(objects) + + +if __name__ == "__main__": + parser = argparse.ArgumentParser(description=__doc__) + parser.add_argument("--root", type=Path, default=Path(__file__).resolve().parents[2]) + parser.add_argument("--host", required=True, choices=["linux", "windows", "macos"]) + parser.add_argument("--without-hevc", action="store_true") + arguments = parser.parse_args() + print("\n".join(ported_objects(arguments.root, arguments.host, not arguments.without_hevc))) diff --git a/test/cmocka/test_audio_buffering_subsample.c b/test/cmocka/test_audio_buffering_subsample.c new file mode 100644 index 0000000000..926351987c --- /dev/null +++ b/test/cmocka/test_audio_buffering_subsample.c @@ -0,0 +1,120 @@ +/* Regression for the uninitialized interval in add_audio_buffering (#838). + * Compile the original private implementation directly: this checks the C + * buffering algorithm, rather than the Rust swap or real-time scheduling. + * Unused core functions are discarded at link time. */ +#include +#include +#include +#include + +#include "libobs/obs-audio.c.h" + +static const uint64_t start = 1000000000ULL; + +static void subsample_delay_preserves_interval(void **state) +{ + (void)state; + const size_t rates[] = {44100, 48000, 96000}; + for (size_t i = 0; i < sizeof(rates) / sizeof(rates[0]); i++) { + const uint64_t offsets[] = {1, 10000, (1000000000ULL - 1) / rates[i]}; + for (size_t j = 0; j < sizeof(offsets) / sizeof(offsets[0]); j++) { + struct obs_core_audio audio = {.max_buffering_ticks = 45}; + const struct ts_info original = {start, + start + audio_frames_to_ns(rates[i], AUDIO_OUTPUT_FRAMES)}; + struct ts_info ts = original; + assert_int_equal(ns_to_audio_frames(rates[i], offsets[j]), 0); + add_audio_buffering(&audio, rates[i], &ts, start - offsets[j], "subsample"); + assert_int_equal(ts.start, original.start); + assert_int_equal(ts.end, original.end); + assert_int_equal(audio.total_buffering_ticks, 0); + assert_int_equal(audio.buffering_wait_ticks, 0); + assert_int_equal(audio.buffered_timestamps.size, 0); + deque_free(&audio.buffered_timestamps); + } + } +} + +static void subsample_delay_preserves_pending_interval(void **state) +{ + (void)state; + const uint64_t tick = audio_frames_to_ns(48000, AUDIO_OUTPUT_FRAMES); + struct obs_core_audio audio = {.max_buffering_ticks = 45, + .total_buffering_ticks = 1, + .buffering_wait_ticks = 1, + .buffered_ts = start + tick}; + const struct ts_info original = {start, start + tick}; + struct ts_info ts = original; + deque_push_front(&audio.buffered_timestamps, &original, sizeof(original)); + add_audio_buffering(&audio, 48000, &ts, start - 1, "pending"); + struct ts_info queued; + deque_peek_front(&audio.buffered_timestamps, &queued, sizeof(queued)); + deque_free(&audio.buffered_timestamps); + assert_int_equal(ts.start, original.start); + assert_int_equal(ts.end, original.end); + assert_int_equal(queued.start, original.start); + assert_int_equal(queued.end, original.end); + assert_int_equal(audio.total_buffering_ticks, 1); + assert_int_equal(audio.buffering_wait_ticks, 1); +} + +static void first_sample_adds_one_tick(void **state) +{ + (void)state; + struct obs_core_audio audio = {.max_buffering_ticks = 45}; + struct ts_info ts = {start, start + audio_frames_to_ns(48000, AUDIO_OUTPUT_FRAMES)}; + assert_int_equal(ns_to_audio_frames(48000, 20834), 1); + add_audio_buffering(&audio, 48000, &ts, start - 20834, "one sample"); + struct ts_info queued; + deque_peek_front(&audio.buffered_timestamps, &queued, sizeof(queued)); + deque_free(&audio.buffered_timestamps); + assert_int_equal(audio.total_buffering_ticks, 1); + assert_int_equal(audio.buffering_wait_ticks, 1); + assert_int_equal(ts.start, start - audio_frames_to_ns(48000, AUDIO_OUTPUT_FRAMES)); + assert_int_equal(ts.end, start); + assert_int_equal(queued.start, ts.start); + assert_int_equal(queued.end, ts.end); +} + +static void larger_delay_adds_two_ticks(void **state) +{ + (void)state; + struct obs_core_audio audio = {.max_buffering_ticks = 45}; + struct ts_info ts = {start, start + audio_frames_to_ns(48000, AUDIO_OUTPUT_FRAMES)}; + add_audio_buffering(&audio, 48000, &ts, start - 22000000, "two ticks"); + struct ts_info queued; + deque_peek_front(&audio.buffered_timestamps, &queued, sizeof(queued)); + assert_int_equal(audio.buffered_timestamps.size, 2 * sizeof(queued)); + deque_free(&audio.buffered_timestamps); + assert_int_equal(audio.total_buffering_ticks, 2); + assert_int_equal(audio.buffering_wait_ticks, 2); + assert_int_equal(ts.start, start - audio_frames_to_ns(48000, 2 * AUDIO_OUTPUT_FRAMES)); + assert_int_equal(ts.end, start - audio_frames_to_ns(48000, AUDIO_OUTPUT_FRAMES)); + assert_int_equal(queued.start, ts.start); + assert_int_equal(queued.end, ts.end); +} + +static void full_buffer_preserves_interval(void **state) +{ + (void)state; + struct obs_core_audio audio = {.max_buffering_ticks = 45, .total_buffering_ticks = 45}; + const struct ts_info original = {start, start + audio_frames_to_ns(48000, AUDIO_OUTPUT_FRAMES)}; + struct ts_info ts = original; + add_audio_buffering(&audio, 48000, &ts, start - 1, "full"); + assert_int_equal(ts.start, original.start); + assert_int_equal(ts.end, original.end); + assert_int_equal(audio.total_buffering_ticks, 45); + assert_int_equal(audio.buffering_wait_ticks, 0); + assert_int_equal(audio.buffered_timestamps.size, 0); +} + +int main(void) +{ + const struct CMUnitTest tests[] = { + cmocka_unit_test(subsample_delay_preserves_interval), + cmocka_unit_test(subsample_delay_preserves_pending_interval), + cmocka_unit_test(first_sample_adds_one_tick), + cmocka_unit_test(larger_delay_adds_two_ticks), + cmocka_unit_test(full_buffer_preserves_interval), + }; + return cmocka_run_group_tests(tests, NULL, NULL); +} diff --git a/test/cmocka/tests.d/test_audio_buffering_subsample.cmake b/test/cmocka/tests.d/test_audio_buffering_subsample.cmake new file mode 100644 index 0000000000..6022f4ea28 --- /dev/null +++ b/test/cmocka/tests.d/test_audio_buffering_subsample.cmake @@ -0,0 +1,19 @@ +# Exercise the original private buffering helper without a display or clocks. +# Linux section GC discards unrelated functions from the included core source. +if(OS_LINUX) + add_executable(test_audio_buffering_subsample test_audio_buffering_subsample.c) + target_include_directories(test_audio_buffering_subsample PRIVATE ${CMOCKA_INCLUDE_DIR} "${CMAKE_SOURCE_DIR}") + target_link_libraries( + test_audio_buffering_subsample + PRIVATE OBS::libobs OBS::caption Uthash::Uthash ZLIB::ZLIB ${CMOCKA_LIBRARIES} m + ) + target_compile_options(test_audio_buffering_subsample PRIVATE -ffunction-sections -fdata-sections) + target_link_options(test_audio_buffering_subsample PRIVATE -Wl,--gc-sections) + include(CheckCCompilerFlag) + check_c_compiler_flag(-ftrivial-auto-var-init=pattern HAVE_C_TRIVIAL_AUTO_VAR_INIT_PATTERN) + if(HAVE_C_TRIVIAL_AUTO_VAR_INIT_PATTERN) + target_compile_options(test_audio_buffering_subsample PRIVATE -ftrivial-auto-var-init=pattern) + endif() + add_dependencies(cmocka-tests test_audio_buffering_subsample) + add_test(NAME test_audio_buffering_subsample COMMAND test_audio_buffering_subsample) +endif()