From ca2536af6667f85a3009065699e421b34cf9d515 Mon Sep 17 00:00:00 2001 From: Zach Vorhies Date: Sat, 17 Oct 2026 13:04:05 -0700 Subject: [PATCH 01/88] test(build): define shared native build and plugin contracts (RED) Refs #1332. Both integration contracts fail because the shared-library backend is not implemented. Preserve the full application conversion and performance requirements in the build plan. --- Cargo.lock | 21 +++++++ docs/rust-port/cc-build.md | 44 ++++++++++++++ rust/obs-build/Cargo.toml | 15 +++++ rust/obs-build/build.rs | 10 ++++ rust/obs-build/src/lib.rs | 30 ++++++++++ rust/obs-build/tests/native.rs | 102 +++++++++++++++++++++++++++++++++ 6 files changed, 222 insertions(+) create mode 100644 docs/rust-port/cc-build.md create mode 100644 rust/obs-build/Cargo.toml create mode 100644 rust/obs-build/build.rs create mode 100644 rust/obs-build/src/lib.rs create mode 100644 rust/obs-build/tests/native.rs diff --git a/Cargo.lock b/Cargo.lock index 37d2b25ea8..20addd8f85 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", ] @@ -354,6 +356,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 +422,15 @@ dependencies = [ "autocfg", ] +[[package]] +name = "obs-build" +version = "0.1.0" +dependencies = [ + "cc", + "libloading", + "tempfile", +] + [[package]] name = "obs-c-oracle" version = "0.1.0" diff --git a/docs/rust-port/cc-build.md b/docs/rust-port/cc-build.md new file mode 100644 index 0000000000..f0a69d6a49 --- /dev/null +++ b/docs/rust-port/cc-build.md @@ -0,0 +1,44 @@ +# 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. + +## 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. diff --git a/rust/obs-build/Cargo.toml b/rust/obs-build/Cargo.toml new file mode 100644 index 0000000000..449dfa7395 --- /dev/null +++ b/rust/obs-build/Cargo.toml @@ -0,0 +1,15 @@ +[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 + +[dependencies] +cc = { version = "=1.6.0", features = ["parallel"] } + +[dev-dependencies] +libloading.workspace = true +tempfile = "=3.27.0" 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/src/lib.rs b/rust/obs-build/src/lib.rs new file mode 100644 index 0000000000..d1fd0d0cde --- /dev/null +++ b/rust/obs-build/src/lib.rs @@ -0,0 +1,30 @@ +//! 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::path::PathBuf; + +#[derive(Clone, Debug)] +pub struct SharedLibrary { + pub name: String, + pub sources: Vec, + pub include_dirs: Vec, + pub dependencies: Vec, + pub unity: bool, +} + +#[derive(Clone, Debug)] +pub struct NativeBuild { + pub host: String, + pub target: String, + pub output: PathBuf, +} + +impl NativeBuild { + /// Compile through cc::Build, then link a native shared library. + pub fn shared_library(&self, _library: &SharedLibrary) -> Result { + Err("native shared-library compilation is not implemented".into()) + } +} diff --git a/rust/obs-build/tests/native.rs b/rust/obs-build/tests/native.rs new file mode 100644 index 0000000000..63b310d085 --- /dev/null +++ b/rust/obs-build/tests/native.rs @@ -0,0 +1,102 @@ +//! 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, + } +} + +unsafe fn answer(library: &Path, symbol: &[u8]) -> 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 { + 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") }, 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") }, 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); + } +} + +const EXPORT: &str = "\n#if defined(_WIN32)\n__declspec(dllexport)\n#endif\n"; From b49c92520949b969501ccf82aa94bcb8df341c14 Mon Sep 17 00:00:00 2001 From: Zach Vorhies Date: Sat, 17 Oct 2026 13:06:52 -0700 Subject: [PATCH 02/88] build: compile and dynamically link native targets with cc::Build (GREEN) Refs #1332. Compile separate or unity C/C++ sources with cc::Build, link shared libraries with target-specific conventions and keep generated source paths explicit. Both native integration contracts and all-target clippy pass on Linux. Full libobs/application conversion remains in progress. --- rust/obs-build/src/lib.rs | 110 ++++++++++++++++++++++++++++- rust/obs-build/src/platform/mod.rs | 77 ++++++++++++++++++++ rust/obs-build/tests/native.rs | 20 ++++-- 3 files changed, 200 insertions(+), 7 deletions(-) create mode 100644 rust/obs-build/src/platform/mod.rs diff --git a/rust/obs-build/src/lib.rs b/rust/obs-build/src/lib.rs index d1fd0d0cde..0bd4339137 100644 --- a/rust/obs-build/src/lib.rs +++ b/rust/obs-build/src/lib.rs @@ -4,7 +4,9 @@ //! Rust crates; native compiles go through cc::Build and inherit soldr's tools. #![forbid(unsafe_code)] -use std::path::PathBuf; +use std::{fs, path::PathBuf}; + +mod platform; #[derive(Clone, Debug)] pub struct SharedLibrary { @@ -24,7 +26,109 @@ pub struct NativeBuild { impl NativeBuild { /// Compile through cc::Build, then link a native shared library. - pub fn shared_library(&self, _library: &SharedLibrary) -> Result { - Err("native shared-library compilation is not implemented".into()) + pub fn shared_library(&self, library: &SharedLibrary) -> Result { + 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 = output.canonicalize().map_err(|e| e.to_string())?; + let mut c_sources = Vec::new(); + let mut cpp_sources = Vec::new(); + for source in &library.sources { + let absolute = source + .canonicalize() + .map_err(|e| format!("{}: {e}", source.display()))?; + match source.extension().and_then(|e| e.to_str()) { + Some("c") => c_sources.push(absolute), + Some("cpp" | "cc" | "cxx") => cpp_sources.push(absolute), + other => { + return Err(format!( + "unsupported native source language {other:?}: {}", + source.display() + )); + } + } + } + let cpp_link = !cpp_sources.is_empty(); + let mut objects = Vec::new(); + for (cpp, sources) in [(false, c_sources), (true, cpp_sources)] { + if sources.is_empty() { + continue; + } + let mut compiler = self.compiler(library, &output, cpp); + if library.unity { + let group = output.join(if cpp { "unity.cpp" } else { "unity.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())?, + ); + } + let artifact = output.join(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(), + )?; + 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) + } + + 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) + .cargo_metadata(false) + .includes(&library.include_dirs); + compiler } } diff --git a/rust/obs-build/src/platform/mod.rs b/rust/obs-build/src/platform/mod.rs new file mode 100644 index 0000000000..291c84a956 --- /dev/null +++ b/rust/obs-build/src/platform/mod.rs @@ -0,0 +1,77 @@ +//! 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, +}; + +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| p.with_extension("lib"))); + 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| p.with_extension("dll.a"))); + 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(()) +} diff --git a/rust/obs-build/tests/native.rs b/rust/obs-build/tests/native.rs index 63b310d085..d3c943fef2 100644 --- a/rust/obs-build/tests/native.rs +++ b/rust/obs-build/tests/native.rs @@ -12,10 +12,16 @@ fn target(name: &str, source: &Path, dependencies: Vec) -> S } } -unsafe fn answer(library: &Path, symbol: &[u8]) -> i32 { +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() @@ -50,7 +56,10 @@ fn native_plugin_links_shared_core_and_observes_rebuilt_dependency() { )) .unwrap(); // SAFETY: both sources above define the expected no-argument C functions. - assert_eq!(unsafe { answer(&plugin, b"obs_fixture_plugin") }, 43); + assert_eq!( + unsafe { answer(&plugin, b"obs_fixture_plugin", &[&core]) }, + 43 + ); fs::write( &core_source, format!("{EXPORT} int obs_fixture_answer(void) {{ return 84; }}"), @@ -60,7 +69,10 @@ fn native_plugin_links_shared_core_and_observes_rebuilt_dependency() { .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") }, 85); + assert_eq!( + unsafe { answer(&plugin, b"obs_fixture_plugin", &[&core]) }, + 85 + ); } #[test] @@ -95,7 +107,7 @@ fn unity_toggle_preserves_exports_and_explicit_generated_source_wins() { 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); + assert_eq!(unsafe { answer(&artifact, b"obs_fixture_count", &[]) }, 17); } } From 55a40e9a29f0e23ef4cced0cb75a01545df41df1 Mon Sep 17 00:00:00 2001 From: Zach Vorhies Date: Sat, 17 Oct 2026 13:09:27 -0700 Subject: [PATCH 03/88] test(build): require the bundled obs-sys crate to build real libobs (RED) Refs #1332. The bundled C API test fails at the explicitly unimplemented libobs backend. Move the existing source sets into a manifest shared with the CMake reference so the new native build does not maintain a divergent source list. --- Cargo.lock | 15 +++ libobs/build/source-sets.json | 167 +++++++++++++++++++++++++++++ libobs/cmake/sources.cmake | 190 +++------------------------------ rust/obs-build/Cargo.toml | 2 + rust/obs-build/src/lib.rs | 19 +++- rust/obs-build/src/libobs.rs | 9 ++ rust/obs-build/tests/native.rs | 1 + rust/obs-sys/Cargo.toml | 20 ++++ rust/obs-sys/build.rs | 21 ++++ rust/obs-sys/src/ffi/mod.rs | 5 + rust/obs-sys/src/lib.rs | 8 ++ rust/obs-sys/tests/native.rs | 7 ++ 12 files changed, 288 insertions(+), 176 deletions(-) create mode 100644 libobs/build/source-sets.json create mode 100644 rust/obs-build/src/libobs.rs create mode 100644 rust/obs-sys/Cargo.toml create mode 100644 rust/obs-sys/build.rs create mode 100644 rust/obs-sys/src/ffi/mod.rs create mode 100644 rust/obs-sys/src/lib.rs create mode 100644 rust/obs-sys/tests/native.rs diff --git a/Cargo.lock b/Cargo.lock index 20addd8f85..631c31d177 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -428,6 +428,8 @@ version = "0.1.0" dependencies = [ "cc", "libloading", + "pkg-config", + "serde_json", "tempfile", ] @@ -557,6 +559,13 @@ dependencies = [ "tungstenite", ] +[[package]] +name = "obs-sys" +version = "0.1.0" +dependencies = [ + "obs-build", +] + [[package]] name = "obs-util" version = "0.1.0" @@ -589,6 +598,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/libobs/build/source-sets.json b/libobs/build/source-sets.json new file mode 100644 index 0000000000..cf611f0535 --- /dev/null +++ b/libobs/build/source-sets.json @@ -0,0 +1,167 @@ +{ + "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" + ] +} diff --git a/libobs/cmake/sources.cmake b/libobs/cmake/sources.cmake index c1ac28b1a9..5b867b1116 100644 --- a/libobs/cmake/sources.cmake +++ b/libobs/cmake/sources.cmake @@ -17,186 +17,28 @@ # 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. +file(READ "${CMAKE_CURRENT_LIST_DIR}/../build/source-sets.json" _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) 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/rust/obs-build/Cargo.toml b/rust/obs-build/Cargo.toml index 449dfa7395..521fa42230 100644 --- a/rust/obs-build/Cargo.toml +++ b/rust/obs-build/Cargo.toml @@ -9,6 +9,8 @@ publish.workspace = true [dependencies] cc = { version = "=1.6.0", features = ["parallel"] } +pkg-config = "=0.3.34" +serde_json = "=1.0.151" [dev-dependencies] libloading.workspace = true diff --git a/rust/obs-build/src/lib.rs b/rust/obs-build/src/lib.rs index 0bd4339137..cfc5fc6aa9 100644 --- a/rust/obs-build/src/lib.rs +++ b/rust/obs-build/src/lib.rs @@ -6,15 +6,20 @@ use std::{fs, path::PathBuf}; +pub mod libobs; mod platform; -#[derive(Clone, Debug)] +#[derive(Clone, Debug, Default)] pub struct SharedLibrary { pub name: String, pub sources: Vec, pub include_dirs: Vec, pub dependencies: Vec, pub unity: bool, + pub definitions: Vec<(String, Option)>, + pub compile_options: Vec, + pub link_options: Vec, + pub file_name: Option, } #[derive(Clone, Debug)] @@ -91,7 +96,12 @@ impl NativeBuild { .map_err(|e| e.to_string())?, ); } - let artifact = output.join(platform::shared_filename(&self.target, &library.name)); + 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( @@ -102,6 +112,7 @@ impl NativeBuild { &library.dependencies, compiler.is_like_msvc(), )?; + command.args(&library.link_options); let result = command .output() .map_err(|e| format!("execute linker {command:?}: {e}"))?; @@ -129,6 +140,10 @@ impl NativeBuild { .cpp(cpp) .cargo_metadata(false) .includes(&library.include_dirs); + for (name, value) in &library.definitions { + compiler.define(name, value.as_deref()); + } + compiler.flags(&library.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..978bf6fdf9 --- /dev/null +++ b/rust/obs-build/src/libobs.rs @@ -0,0 +1,9 @@ +//! The native libobs graph, shared by bundled obs-sys and the application build. +use crate::NativeBuild; +use std::path::{Path, PathBuf}; + +/// Build the real C libobs, including generated configuration and native dependencies. +pub fn build(build: &NativeBuild, root: &Path) -> Result { + let _ = (build, root); + Err("the real libobs native build is not implemented".into()) +} diff --git a/rust/obs-build/tests/native.rs b/rust/obs-build/tests/native.rs index d3c943fef2..02a0f44c98 100644 --- a/rust/obs-build/tests/native.rs +++ b/rust/obs-build/tests/native.rs @@ -9,6 +9,7 @@ fn target(name: &str, source: &Path, dependencies: Vec) -> S include_dirs: vec![], dependencies, unity: true, + ..SharedLibrary::default() } } 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.rs b/rust/obs-sys/build.rs new file mode 100644 index 0000000000..6acecd65d5 --- /dev/null +++ b/rust/obs-sys/build.rs @@ -0,0 +1,21 @@ +fn main() { + println!("cargo:rerun-if-changed=build.rs"); + #[cfg(feature = "bundled")] + { + let root = std::path::Path::new(env!("CARGO_MANIFEST_DIR")).join("../.."); + 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 library = obs_build::libobs::build(&build, &root) + .unwrap_or_else(|error| panic!("build bundled libobs: {error}")); + 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..6fee62ee4e --- /dev/null +++ b/rust/obs-sys/src/ffi/mod.rs @@ -0,0 +1,5 @@ +//! 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; +} diff --git a/rust/obs-sys/src/lib.rs b/rust/obs-sys/src/lib.rs new file mode 100644 index 0000000000..777ea1b59f --- /dev/null +++ b/rust/obs-sys/src/lib.rs @@ -0,0 +1,8 @@ +//! 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. +#![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..6ebca9fa0c --- /dev/null +++ b/rust/obs-sys/tests/native.rs @@ -0,0 +1,7 @@ +#[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()); +} From 1c41ad018c28a861b962df62481b5963741476ea Mon Sep 17 00:00:00 2001 From: Zach Vorhies Date: Sat, 17 Oct 2026 13:17:32 -0700 Subject: [PATCH 04/88] feat(build): compile bundled Linux libobs through cc::Build --- docs/rust-port/cc-build.md | 30 +++ libobs/cmake/sources.cmake | 4 +- rust/obs-build/src/lib.rs | 78 ++++--- rust/obs-build/src/libobs.rs | 221 +++++++++++++++++++- rust/obs-build/src/platform/libobs_linux.rs | 71 +++++++ rust/obs-build/src/platform/mod.rs | 64 ++++++ rust/obs-sys/build.rs | 16 ++ rust/obs-sys/src/ffi/mod.rs | 8 + rust/obs-sys/tests/native.rs | 18 ++ 9 files changed, 474 insertions(+), 36 deletions(-) create mode 100644 rust/obs-build/src/platform/libobs_linux.rs diff --git a/docs/rust-port/cc-build.md b/docs/rust-port/cc-build.md index f0a69d6a49..11aef9d076 100644 --- a/docs/rust-port/cc-build.md +++ b/docs/rust-port/cc-build.md @@ -42,3 +42,33 @@ does not complete the conversion. 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 Rust twin, 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. diff --git a/libobs/cmake/sources.cmake b/libobs/cmake/sources.cmake index 5b867b1116..8a40e137f2 100644 --- a/libobs/cmake/sources.cmake +++ b/libobs/cmake/sources.cmake @@ -18,7 +18,9 @@ # which build obs-nix.c the same way. # Canonical source lists are shared with obs-build and bundled obs-sys. -file(READ "${CMAKE_CURRENT_LIST_DIR}/../build/source-sets.json" _libobs_source_sets) +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}) diff --git a/rust/obs-build/src/lib.rs b/rust/obs-build/src/lib.rs index cfc5fc6aa9..501e7e1784 100644 --- a/rust/obs-build/src/lib.rs +++ b/rust/obs-build/src/lib.rs @@ -32,6 +32,48 @@ pub struct NativeBuild { impl NativeBuild { /// Compile through cc::Build, then link a native shared library. pub fn shared_library(&self, library: &SharedLibrary) -> Result { + let (output, cpp_link, objects) = self.objects(library)?; + 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) + } + + /// 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 @@ -96,36 +138,7 @@ impl NativeBuild { .map_err(|e| e.to_string())?, ); } - 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) + Ok((output, cpp_link, objects)) } fn compiler(&self, library: &SharedLibrary, output: &std::path::Path, cpp: bool) -> cc::Build { @@ -138,7 +151,10 @@ impl NativeBuild { .debug(true) .pic(true) .cpp(cpp) - .cargo_metadata(false) + // 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) .includes(&library.include_dirs); for (name, value) in &library.definitions { compiler.define(name, value.as_deref()); diff --git a/rust/obs-build/src/libobs.rs b/rust/obs-build/src/libobs.rs index 978bf6fdf9..3b851f3ed4 100644 --- a/rust/obs-build/src/libobs.rs +++ b/rust/obs-build/src/libobs.rs @@ -1,9 +1,222 @@ //! The native libobs graph, shared by bundled obs-sys and the application build. -use crate::NativeBuild; -use std::path::{Path, PathBuf}; +use crate::{NativeBuild, SharedLibrary}; +use std::{ + collections::BTreeMap, + fs, + path::{Path, PathBuf}, +}; + +#[derive(Clone, Debug)] +pub struct Options { + pub hevc: bool, + pub wayland: bool, + pub pulseaudio: bool, + pub gio: bool, + pub core_modules: Vec, +} + +impl Default for Options { + fn default() -> Self { + Self { + 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 { - let _ = (build, root); - Err("the real libobs native build is not implemented".into()) + build_with_options(build, root, &Options::default()) +} + +pub fn build_with_options( + 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() + }; + for key in ["LIBOBS_SOURCES", "LIBOBS_PORTED_SOURCES"] { + append_sources(&sets, key, &root, &mut library)?; + } + if options.hevc { + library + .sources + .push(root.join("libobs/build/libobs.ported-hevc+.h.c")); + 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)?; + } + let mut caption = SharedLibrary { + name: "caption".into(), + include_dirs: vec![ + root.join("deps/libcaption"), + root.join("deps/libcaption/caption"), + ], + compile_options: library.compile_options.clone(), + definitions: vec![("__STDC_CONSTANT_MACROS".into(), None)], + ..SharedLibrary::default() + }; + 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"))); + } + library.dependencies.push(build.static_library(&caption)?); + 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); + 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) +} + +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); + for (name, value) in dependency.defines { + library.definitions.push((name, value)); + } + 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(()) +} + +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(()) } 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..5fb64de6be --- /dev/null +++ b/rust/obs-build/src/platform/libobs_linux.rs @@ -0,0 +1,71 @@ +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)?; + append_sources(sets, "LIBOBS_LINUX_PORTED_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(()) +} diff --git a/rust/obs-build/src/platform/mod.rs b/rust/obs-build/src/platform/mod.rs index 291c84a956..7f1e5fba62 100644 --- a/rust/obs-build/src/platform/mod.rs +++ b/rust/obs-build/src/platform/mod.rs @@ -6,6 +6,24 @@ use std::{ process::Command, }; +mod libobs_linux; + +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") @@ -75,3 +93,49 @@ pub fn configure_shared_link( } 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()) +} + +#[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-sys/build.rs b/rust/obs-sys/build.rs index 6acecd65d5..1158d0cc2a 100644 --- a/rust/obs-sys/build.rs +++ b/rust/obs-sys/build.rs @@ -3,6 +3,22 @@ fn main() { #[cfg(feature = "bundled")] { 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(), diff --git a/rust/obs-sys/src/ffi/mod.rs b/rust/obs-sys/src/ffi/mod.rs index 6fee62ee4e..9ccccacbf3 100644 --- a/rust/obs-sys/src/ffi/mod.rs +++ b/rust/obs-sys/src/ffi/mod.rs @@ -2,4 +2,12 @@ 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/tests/native.rs b/rust/obs-sys/tests/native.rs index 6ebca9fa0c..17a1050981 100644 --- a/rust/obs-sys/tests/native.rs +++ b/rust/obs-sys/tests/native.rs @@ -5,3 +5,21 @@ fn bundled_libobs_reports_the_public_c_api_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()); + } +} From 9c25cc16dd6b27dff4e23b4c70da54573e5c51c5 Mon Sep 17 00:00:00 2001 From: Zach Vorhies Date: Sat, 17 Oct 2026 13:18:35 -0700 Subject: [PATCH 05/88] test(build): require native C and Rust libobs twins --- rust/obs-build/Cargo.toml | 7 ++++ rust/obs-build/src/libobs.rs | 17 +++++++++ rust/obs-build/tests/libobs.rs | 66 ++++++++++++++++++++++++++++++++++ 3 files changed, 90 insertions(+) create mode 100644 rust/obs-build/tests/libobs.rs diff --git a/rust/obs-build/Cargo.toml b/rust/obs-build/Cargo.toml index 521fa42230..87d1a93092 100644 --- a/rust/obs-build/Cargo.toml +++ b/rust/obs-build/Cargo.toml @@ -7,6 +7,9 @@ rust-version.workspace = true license.workspace = true publish.workspace = true +[features] +libobs-integration = [] + [dependencies] cc = { version = "=1.6.0", features = ["parallel"] } pkg-config = "=0.3.34" @@ -15,3 +18,7 @@ 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/src/libobs.rs b/rust/obs-build/src/libobs.rs index 3b851f3ed4..d324777e69 100644 --- a/rust/obs-build/src/libobs.rs +++ b/rust/obs-build/src/libobs.rs @@ -220,3 +220,20 @@ fn write_if_changed(path: &Path, text: &str) -> Result<(), String> { } 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 { + Err("the native Rust implementation twin is not implemented".into()) +} diff --git a/rust/obs-build/tests/libobs.rs b/rust/obs-build/tests/libobs.rs new file mode 100644 index 0000000000..c82b9393d8 --- /dev/null +++ b/rust/obs-build/tests/libobs.rs @@ -0,0 +1,66 @@ +//! Opt-in integration against real native dependencies and libobs-rust. +use obs_build::{NativeBuild, libobs}; +use std::{ffi::c_void, path::PathBuf}; + +#[test] +fn c_and_rust_twins_preserve_the_public_data_and_lifecycle_apis() { + 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: output.path().into(), + }; + let libraries = + libobs::build_pair(&build, &root, &libobs::Options::default(), &archive).unwrap(); + assert_ne!(libraries.reference, libraries.with_rust); + for path in [&libraries.reference, &libraries.with_rust] { + // 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(); + 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(), + std::ptr::null(), + std::ptr::null_mut() + )); + 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(); + } + } +} From eb05fe084b5735402502072d02e01b5b0e35dafb Mon Sep 17 00:00:00 2001 From: Zach Vorhies Date: Sat, 17 Oct 2026 13:23:28 -0700 Subject: [PATCH 06/88] feat(build): reuse common objects for the Rust libobs twin --- docs/rust-port/cc-build.md | 28 ++++++- rust/obs-build/src/lib.rs | 5 +- rust/obs-build/src/libobs.rs | 91 ++++++++++++++++++--- rust/obs-build/src/platform/libobs_linux.rs | 42 +++++++++- rust/obs-build/src/platform/mod.rs | 25 ++++++ rust/obs-build/tests/libobs.rs | 43 +++++++++- 6 files changed, 216 insertions(+), 18 deletions(-) diff --git a/docs/rust-port/cc-build.md b/docs/rust-port/cc-build.md index 11aef9d076..80c4c00fb1 100644 --- a/docs/rust-port/cc-build.md +++ b/docs/rust-port/cc-build.md @@ -66,9 +66,35 @@ Local evidence for this checkpoint: 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 Rust twin, application and plugins, +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. diff --git a/rust/obs-build/src/lib.rs b/rust/obs-build/src/lib.rs index 501e7e1784..922a79c74a 100644 --- a/rust/obs-build/src/lib.rs +++ b/rust/obs-build/src/lib.rs @@ -13,6 +13,8 @@ mod platform; 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, @@ -32,7 +34,8 @@ pub struct NativeBuild { impl NativeBuild { /// Compile through cc::Build, then link a native shared library. pub fn shared_library(&self, library: &SharedLibrary) -> Result { - let (output, cpp_link, objects) = self.objects(library)?; + let (output, cpp_link, mut objects) = self.objects(library)?; + objects.extend(library.precompiled_objects.iter().cloned()); let artifact = output.join( library .file_name diff --git a/rust/obs-build/src/libobs.rs b/rust/obs-build/src/libobs.rs index d324777e69..9907fd6603 100644 --- a/rust/obs-build/src/libobs.rs +++ b/rust/obs-build/src/libobs.rs @@ -37,6 +37,19 @@ pub fn build_with_options( 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> = @@ -63,13 +76,8 @@ pub fn build_with_options( unity: false, ..SharedLibrary::default() }; - for key in ["LIBOBS_SOURCES", "LIBOBS_PORTED_SOURCES"] { - append_sources(&sets, key, &root, &mut library)?; - } + append_sources(&sets, "LIBOBS_SOURCES", &root, &mut library)?; if options.hevc { - library - .sources - .push(root.join("libobs/build/libobs.ported-hevc+.h.c")); library.definitions.push(("ENABLE_HEVC".into(), None)); } crate::platform::configure_libobs(&build.target, &root, options, &sets, &mut library)?; @@ -150,7 +158,15 @@ pub fn build_with_options( let module_source = config.join("obs-core-modules.c"); write_if_changed(&module_source, &modules)?; library.sources.push(module_source); - let artifact = build.shared_library(&library)?; + 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 { @@ -160,6 +176,27 @@ pub fn build_with_options( 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 { + library + .sources + .push(root.join("libobs/build/libobs.ported-hevc+.h.c")); + } + } + crate::platform::configure_libobs_variant(build, root, options, sets, library, rust_archive) +} + pub(crate) fn append_sources( sets: &BTreeMap>, name: &str, @@ -230,10 +267,40 @@ pub struct Libraries { /// 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, + build: &NativeBuild, + root: &Path, + options: &Options, + rust_archive: &Path, ) -> Result { - Err("the native Rust implementation twin is not implemented".into()) + // 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_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/platform/libobs_linux.rs b/rust/obs-build/src/platform/libobs_linux.rs index 5fb64de6be..8400c917a1 100644 --- a/rust/obs-build/src/platform/libobs_linux.rs +++ b/rust/obs-build/src/platform/libobs_linux.rs @@ -12,7 +12,6 @@ pub fn configure( library: &mut SharedLibrary, ) -> Result<(), String> { append_sources(sets, "LIBOBS_LINUX_SOURCES", root, library)?; - append_sources(sets, "LIBOBS_LINUX_PORTED_SOURCES", root, library)?; library.file_name = Some("libobs.so.30".into()); library .definitions @@ -69,3 +68,44 @@ pub fn configure( } 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 index 7f1e5fba62..707e15d1fa 100644 --- a/rust/obs-build/src/platform/mod.rs +++ b/rust/obs-build/src/platform/mod.rs @@ -114,6 +114,31 @@ pub fn package_shared_library(target: &str, paths: &[PathBuf], name: &str) -> Op .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 + )) + } +} + #[cfg(test)] mod tests { use super::*; diff --git a/rust/obs-build/tests/libobs.rs b/rust/obs-build/tests/libobs.rs index c82b9393d8..0e6abd01bc 100644 --- a/rust/obs-build/tests/libobs.rs +++ b/rust/obs-build/tests/libobs.rs @@ -13,17 +13,34 @@ fn c_and_rust_twins_preserve_the_public_data_and_lifecycle_apis() { let build = NativeBuild { host: env!("OBS_BUILD_HOST").into(), target: env!("OBS_BUILD_TARGET").into(), - output: output.path().into(), + output: std::env::var_os("OBS_BUILD_TEST_OUTPUT") + .map(PathBuf::from) + .unwrap_or_else(|| output.path().into()), }; - let libraries = - libobs::build_pair(&build, &root, &libobs::Options::default(), &archive).unwrap(); + let options = libobs::Options { + hevc: std::env::var_os("OBS_BUILD_DISABLE_HEVC").is_none(), + ..libobs::Options::default() + }; + let libraries = libobs::build_pair(&build, &root, &options, &archive).unwrap(); assert_ne!(libraries.reference, libraries.with_rust); + assert_eq!(exports(&libraries.reference), exports(&libraries.with_rust)); for path in [&libraries.reference, &libraries.with_rust] { // 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(), + options.hevc + ); + } let startup = library .get:: 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() +} From 936ead70e8c6b9daf052f03f2a9e734039b361fa Mon Sep 17 00:00:00 2001 From: Zach Vorhies Date: Sat, 17 Oct 2026 13:25:18 -0700 Subject: [PATCH 07/88] test(build): require real OBS filter and transition module loading --- rust/obs-build/src/lib.rs | 1 + rust/obs-build/src/plugins.rs | 41 ++++++++++++++++++++++++++++ rust/obs-build/tests/libobs.rs | 50 +++++++++++++++++++++++++++++++++- 3 files changed, 91 insertions(+), 1 deletion(-) create mode 100644 rust/obs-build/src/plugins.rs diff --git a/rust/obs-build/src/lib.rs b/rust/obs-build/src/lib.rs index 922a79c74a..1d00dcc8bb 100644 --- a/rust/obs-build/src/lib.rs +++ b/rust/obs-build/src/lib.rs @@ -8,6 +8,7 @@ use std::{fs, path::PathBuf}; pub mod libobs; mod platform; +pub mod plugins; #[derive(Clone, Debug, Default)] pub struct SharedLibrary { diff --git a/rust/obs-build/src/plugins.rs b/rust/obs-build/src/plugins.rs new file mode 100644 index 0000000000..894657c9a4 --- /dev/null +++ b/rust/obs-build/src/plugins.rs @@ -0,0 +1,41 @@ +//! Native OBS module builds using the same engine as bundled libobs. +use crate::NativeBuild; +use std::path::{Path, PathBuf}; + +#[derive(Debug)] +pub struct Module { + pub library: PathBuf, + pub data: PathBuf, +} + +#[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 { + Err("real OBS transition module build is not implemented".into()) +} + +pub fn build_filters( + _build: &NativeBuild, + _root: &Path, + _core: &Path, + _options: &FiltersOptions, +) -> Result { + Err("real OBS filter module build is not implemented".into()) +} diff --git a/rust/obs-build/tests/libobs.rs b/rust/obs-build/tests/libobs.rs index 0e6abd01bc..8e5c119ac6 100644 --- a/rust/obs-build/tests/libobs.rs +++ b/rust/obs-build/tests/libobs.rs @@ -1,5 +1,5 @@ //! Opt-in integration against real native dependencies and libobs-rust. -use obs_build::{NativeBuild, libobs}; +use obs_build::{NativeBuild, libobs, plugins}; use std::{ffi::c_void, path::PathBuf}; #[test] @@ -24,6 +24,16 @@ fn c_and_rust_twins_preserve_the_public_data_and_lifecycle_apis() { let libraries = libobs::build_pair(&build, &root, &options, &archive).unwrap(); assert_ne!(libraries.reference, libraries.with_rust); assert_eq!(exports(&libraries.reference), exports(&libraries.with_rust)); + let modules = [ + plugins::build_transitions(&build, &root, &libraries.reference).unwrap(), + plugins::build_filters( + &build, + &root, + &libraries.reference, + &plugins::FiltersOptions::default(), + ) + .unwrap(), + ]; for path in [&libraries.reference, &libraries.with_rust] { // SAFETY: these signatures come from the unchanged obs.h/obs-data.h. // Symbols are called only while their library is loaded, data handles @@ -72,6 +82,44 @@ fn c_and_rust_twins_preserve_the_public_data_and_lifecycle_apis() { std::ptr::null(), std::ptr::null_mut() )); + 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)); + } + for (symbol, expected) in [ + (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"), + ] { + 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; + } + assert!(found, "{expected} was not registered"); + } let data = create(); assert!(!data.is_null()); set(data, c"value".as_ptr(), -9223372036854775807); From 05f7ed8b954064b7bbc77c351817999dfd944a6d Mon Sep 17 00:00:00 2001 From: Zach Vorhies Date: Sat, 17 Oct 2026 13:31:08 -0700 Subject: [PATCH 08/88] feat(build): compile and load OBS filter and transition modules --- docs/rust-port/cc-build.md | 23 ++ .../obs-filters/build/rnnoise-sources.json | 9 + plugins/obs-filters/cmake/rnnoise.cmake | 20 +- rust/obs-build/src/platform/mod.rs | 17 ++ rust/obs-build/src/plugins.rs | 96 +++++++- rust/obs-build/tests/libobs.rs | 229 ++++++++++-------- 6 files changed, 279 insertions(+), 115 deletions(-) create mode 100644 plugins/obs-filters/build/rnnoise-sources.json diff --git a/docs/rust-port/cc-build.md b/docs/rust-port/cc-build.md index 80c4c00fb1..e072423d35 100644 --- a/docs/rust-port/cc-build.md +++ b/docs/rust-port/cc-build.md @@ -98,3 +98,26 @@ 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. 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/rust/obs-build/src/platform/mod.rs b/rust/obs-build/src/platform/mod.rs index 707e15d1fa..1a31e8fb97 100644 --- a/rust/obs-build/src/platform/mod.rs +++ b/rust/obs-build/src/platform/mod.rs @@ -139,6 +139,23 @@ pub fn configure_libobs_variant( } } +pub fn configure_module(target: &str, library: &mut crate::SharedLibrary) -> Result<(), String> { + if target.contains("linux") { + library.file_name = Some(format!("{}.so", library.name)); + library.compile_options.extend( + ["-std=gnu17", "-fno-strict-aliasing", "-fvisibility=hidden"].map(String::from), + ); + library + .link_options + .extend(["-lm", "-pthread"].map(String::from)); + Ok(()) + } else { + Err(format!( + "native OBS module graph for {target} is not implemented yet" + )) + } +} + #[cfg(test)] mod tests { use super::*; diff --git a/rust/obs-build/src/plugins.rs b/rust/obs-build/src/plugins.rs index 894657c9a4..e257f0f9e4 100644 --- a/rust/obs-build/src/plugins.rs +++ b/rust/obs-build/src/plugins.rs @@ -1,5 +1,5 @@ //! Native OBS module builds using the same engine as bundled libobs. -use crate::NativeBuild; +use crate::{NativeBuild, SharedLibrary, libobs::add_package}; use std::path::{Path, PathBuf}; #[derive(Debug)] @@ -23,19 +23,91 @@ impl Default for FiltersOptions { } } -pub fn build_transitions( - _build: &NativeBuild, - _root: &Path, - _core: &Path, -) -> Result { - Err("real OBS transition module build is not implemented".into()) +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, + build: &NativeBuild, + root: &Path, + core: &Path, + options: &FiltersOptions, ) -> Result { - Err("real OBS filter module build is not implemented".into()) + 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)?, + }) } diff --git a/rust/obs-build/tests/libobs.rs b/rust/obs-build/tests/libobs.rs index 8e5c119ac6..d2999c8236 100644 --- a/rust/obs-build/tests/libobs.rs +++ b/rust/obs-build/tests/libobs.rs @@ -3,7 +3,21 @@ use obs_build::{NativeBuild, libobs, plugins}; use std::{ffi::c_void, path::PathBuf}; #[test] -fn c_and_rust_twins_preserve_the_public_data_and_lifecycle_apis() { +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") @@ -24,109 +38,132 @@ fn c_and_rust_twins_preserve_the_public_data_and_lifecycle_apis() { let libraries = libobs::build_pair(&build, &root, &options, &archive).unwrap(); assert_ne!(libraries.reference, libraries.with_rust); assert_eq!(exports(&libraries.reference), exports(&libraries.with_rust)); + 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 modules = [ plugins::build_transitions(&build, &root, &libraries.reference).unwrap(), - plugins::build_filters( - &build, - &root, - &libraries.reference, - &plugins::FiltersOptions::default(), - ) - .unwrap(), + plugins::build_filters(&build, &root, &libraries.reference, &filters).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 serialized = serde_json::to_string(&modules).unwrap(); for path in [&libraries.reference, &libraries.with_rust] { - // 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(), - options.hevc - ); - } - 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(), - std::ptr::null(), - std::ptr::null_mut() - )); - let open = library - .get:: i32>(b"obs_open_module") - .unwrap(); - let init = library - .get:: bool>(b"obs_init_module") + let run = std::process::Command::new(std::env::current_exe().unwrap()) + .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(); + assert!( + run.status.success(), + "{}\n{}", + String::from_utf8_lossy(&run.stdout), + String::from_utf8_lossy(&run.stderr) + ); + } +} + +fn exercise(path: &std::path::Path, modules: &[plugins::Module], hevc: bool) { + // 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 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(), + std::ptr::null(), + std::ptr::null_mut() + )); + 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)); + } + for (symbol, expected) in [ + (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"), + ] { + let enumerate = library + .get:: bool>(symbol) .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)); - } - for (symbol, expected) in [ - (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"), - ] { - 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 mut found = false; + for index in 0..1024 { + let mut name = std::ptr::null(); + if !enumerate(index, &mut name) { + break; } - assert!(found, "{expected} was not registered"); + assert!(!name.is_null()); + found |= std::ffi::CStr::from_ptr(name).to_str().unwrap() == expected; } - 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(); + 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(); + assert_eq!(found, enabled, "unexpected registration of {expected}"); } + 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(); } } From f5e845f4b644086fa6a47ec1672c1883694d8f5b Mon Sep 17 00:00:00 2001 From: Zach Vorhies Date: Sat, 17 Oct 2026 13:33:28 -0700 Subject: [PATCH 09/88] test(build): require the real native OpenGL renderer --- rust/obs-build/src/graphics.rs | 12 ++++++++++++ rust/obs-build/src/lib.rs | 1 + rust/obs-build/tests/libobs.rs | 10 ++++++++-- 3 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 rust/obs-build/src/graphics.rs diff --git a/rust/obs-build/src/graphics.rs b/rust/obs-build/src/graphics.rs new file mode 100644 index 0000000000..e9ca2486c9 --- /dev/null +++ b/rust/obs-build/src/graphics.rs @@ -0,0 +1,12 @@ +//! Graphics backends built from the shared native OBS configuration. +use crate::{NativeBuild, libobs::Options}; +use std::path::{Path, PathBuf}; + +pub fn build_opengl( + _build: &NativeBuild, + _root: &Path, + _core: &Path, + _options: &Options, +) -> Result { + Err("real OBS OpenGL backend build is not implemented".into()) +} diff --git a/rust/obs-build/src/lib.rs b/rust/obs-build/src/lib.rs index 1d00dcc8bb..422017dfcd 100644 --- a/rust/obs-build/src/lib.rs +++ b/rust/obs-build/src/lib.rs @@ -6,6 +6,7 @@ use std::{fs, path::PathBuf}; +pub mod graphics; pub mod libobs; mod platform; pub mod plugins; diff --git a/rust/obs-build/tests/libobs.rs b/rust/obs-build/tests/libobs.rs index d2999c8236..907d9ca5f7 100644 --- a/rust/obs-build/tests/libobs.rs +++ b/rust/obs-build/tests/libobs.rs @@ -1,5 +1,5 @@ //! Opt-in integration against real native dependencies and libobs-rust. -use obs_build::{NativeBuild, libobs, plugins}; +use obs_build::{NativeBuild, graphics, libobs, plugins}; use std::{ffi::c_void, path::PathBuf}; #[test] @@ -46,6 +46,8 @@ fn c_and_rust_twins_preserve_public_data_lifecycle_and_module_apis() { plugins::build_transitions(&build, &root, &libraries.reference).unwrap(), plugins::build_filters(&build, &root, &libraries.reference, &filters).unwrap(), ]; + let renderer = std::env::var_os("OBS_BUILD_RENDER") + .map(|_| graphics::build_opengl(&build, &root, &libraries.reference, &options).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. @@ -55,7 +57,11 @@ fn c_and_rust_twins_preserve_public_data_lifecycle_and_module_apis() { .collect(); let serialized = serde_json::to_string(&modules).unwrap(); for path in [&libraries.reference, &libraries.with_rust] { - let run = std::process::Command::new(std::env::current_exe().unwrap()) + let mut command = std::process::Command::new(std::env::current_exe().unwrap()); + if let Some(renderer) = &renderer { + command.env("OBS_BUILD_TEST_RENDERER", renderer); + } + let run = command .args([ "--exact", "c_and_rust_twins_preserve_public_data_lifecycle_and_module_apis", From 35b366d78013ed318b43ffd528c6fc6cdd68021f Mon Sep 17 00:00:00 2001 From: Zach Vorhies Date: Sat, 17 Oct 2026 13:39:57 -0700 Subject: [PATCH 10/88] feat(build): compile OpenGL and render frames with both libobs variants --- docs/rust-port/cc-build.md | 22 +++++ rust/obs-build/src/graphics.rs | 44 ++++++++-- rust/obs-build/src/platform/mod.rs | 46 +++++++++++ rust/obs-build/tests/libobs.rs | 42 +++++++++- rust/obs-build/tests/libobs/render.rs | 113 ++++++++++++++++++++++++++ 5 files changed, 260 insertions(+), 7 deletions(-) create mode 100644 rust/obs-build/tests/libobs/render.rs diff --git a/docs/rust-port/cc-build.md b/docs/rust-port/cc-build.md index e072423d35..ec29e0bfb3 100644 --- a/docs/rust-port/cc-build.md +++ b/docs/rust-port/cc-build.md @@ -121,3 +121,25 @@ 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. diff --git a/rust/obs-build/src/graphics.rs b/rust/obs-build/src/graphics.rs index e9ca2486c9..9f675dfb3d 100644 --- a/rust/obs-build/src/graphics.rs +++ b/rust/obs-build/src/graphics.rs @@ -1,12 +1,44 @@ //! Graphics backends built from the shared native OBS configuration. -use crate::{NativeBuild, libobs::Options}; +use crate::{NativeBuild, SharedLibrary, libobs::Options}; use std::path::{Path, PathBuf}; pub fn build_opengl( - _build: &NativeBuild, - _root: &Path, - _core: &Path, - _options: &Options, + build: &NativeBuild, + root: &Path, + core: &Path, + options: &Options, ) -> Result { - Err("real OBS OpenGL backend build is not implemented".into()) + 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)?; + let mut glad = SharedLibrary { + name: "obsglad".into(), + sources: vec![root.join("deps/glad/src/glad.c")], + include_dirs: vec![root.join("deps/glad/include")], + compile_options: library.compile_options.clone(), + ..SharedLibrary::default() + }; + crate::platform::configure_glad(&build.target, &root, &mut glad)?; + library.dependencies.push(build.static_library(&glad)?); + 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) } diff --git a/rust/obs-build/src/platform/mod.rs b/rust/obs-build/src/platform/mod.rs index 1a31e8fb97..45317b8c3f 100644 --- a/rust/obs-build/src/platform/mod.rs +++ b/rust/obs-build/src/platform/mod.rs @@ -156,6 +156,52 @@ pub fn configure_module(target: &str, library: &mut crate::SharedLibrary) -> Res } } +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" + )) + } +} + #[cfg(test)] mod tests { use super::*; diff --git a/rust/obs-build/tests/libobs.rs b/rust/obs-build/tests/libobs.rs index 907d9ca5f7..04654c085e 100644 --- a/rust/obs-build/tests/libobs.rs +++ b/rust/obs-build/tests/libobs.rs @@ -1,6 +1,8 @@ //! Opt-in integration against real native dependencies and libobs-rust. use obs_build::{NativeBuild, graphics, libobs, plugins}; use std::{ffi::c_void, path::PathBuf}; +#[path = "libobs/render.rs"] +mod render; #[test] fn c_and_rust_twins_preserve_public_data_lifecycle_and_module_apis() { @@ -48,6 +50,9 @@ fn c_and_rust_twins_preserve_public_data_lifecycle_and_module_apis() { ]; let renderer = std::env::var_os("OBS_BUILD_RENDER") .map(|_| graphics::build_opengl(&build, &root, &libraries.reference, &options).unwrap()); + let probe = renderer + .as_ref() + .map(|_| render::build(&build, &root, &libraries.reference)); // 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. @@ -60,6 +65,7 @@ fn c_and_rust_twins_preserve_public_data_lifecycle_and_module_apis() { let mut command = std::process::Command::new(std::env::current_exe().unwrap()); if let Some(renderer) = &renderer { command.env("OBS_BUILD_TEST_RENDERER", renderer); + command.env("OBS_BUILD_TEST_PROBE", probe.as_ref().unwrap()); } let run = command .args([ @@ -71,9 +77,15 @@ fn c_and_rust_twins_preserve_public_data_lifecycle_and_module_apis() { .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") + }) { + println!("{}: {line}", path.display()); + } assert!( run.status.success(), - "{}\n{}", + "{}\n{}\n{}", + run.status, String::from_utf8_lossy(&run.stdout), String::from_utf8_lossy(&run.stderr) ); @@ -94,6 +106,14 @@ fn exercise(path: &std::path::Path, modules: &[plugins::Module], hevc: bool) { ] { assert_eq!(library.get::(symbol).is_ok(), hevc); } + 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:: i32>(b"obs_fixture_render").unwrap(); + assert_eq!( + render(renderer.as_ptr(), data_path.as_ptr()), + 0, + "graphics/frame rendering failed" + ); + } 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()(); + } } } diff --git a/rust/obs-build/tests/libobs/render.rs b/rust/obs-build/tests/libobs/render.rs new file mode 100644 index 0000000000..8f00099620 --- /dev/null +++ b/rust/obs-build/tests/libobs/render.rs @@ -0,0 +1,113 @@ +//! 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"); + if std::fs::read_to_string(&source).ok().as_deref() != Some(SOURCE) { + std::fs::write(&source, SOURCE).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() + }; + for package in ["simde", "x11"] { + 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 + +static Display *test_display; +static atomic_uint frames; +static atomic_uint invalid_frames; + +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] || frame->linesize[0] < 64 || frame->data[0][0] != 16) + atomic_fetch_add(&invalid_frames, 1); + atomic_fetch_add(&frames, 1); +} + +EXPORT int obs_fixture_render(const char *renderer, const char *data_path) +{ + obs_add_data_path(data_path); + struct obs_video_info video = { + .graphics_module = renderer, + .fps_num = 30, .fps_den = 1, + .base_width = 64, .base_height = 64, + .output_width = 64, .output_height = 64, + .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); + if (result != OBS_VIDEO_SUCCESS) + return result; + 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); + obs_set_output_source(0, NULL); + obs_scene_release(scene); + /* The owning test calls obs_shutdown after this probe. */ + if (atomic_load(&frames) < 3) + return 82; + return atomic_load(&invalid_frames) ? 83 : 0; +} + +EXPORT void obs_fixture_close_display(void) +{ + obs_set_nix_platform_display(NULL); + XCloseDisplay(test_display); + test_display = NULL; +} +"#; From 06042de9cb69c6b5aaf605368a84084d778b9907 Mon Sep 17 00:00:00 2001 From: Zach Vorhies Date: Sat, 17 Oct 2026 13:42:55 -0700 Subject: [PATCH 11/88] test(build): require native executables linked to shared libraries --- rust/obs-build/src/lib.rs | 5 ++++ rust/obs-build/tests/native.rs | 45 ++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+) diff --git a/rust/obs-build/src/lib.rs b/rust/obs-build/src/lib.rs index 422017dfcd..7f602ec069 100644 --- a/rust/obs-build/src/lib.rs +++ b/rust/obs-build/src/lib.rs @@ -70,6 +70,11 @@ impl NativeBuild { Ok(artifact) } + /// Compile and link an executable with the native shared dependencies. + pub fn executable(&self, _target: &SharedLibrary) -> Result { + Err("native executable linking is not implemented".into()) + } + /// 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)?; diff --git a/rust/obs-build/tests/native.rs b/rust/obs-build/tests/native.rs index 02a0f44c98..bb0605af93 100644 --- a/rust/obs-build/tests/native.rs +++ b/rust/obs-build/tests/native.rs @@ -112,4 +112,49 @@ fn unity_toggle_preserves_exports_and_explicit_generated_source_wins() { } } +#[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"); + fs::write( + &core_source, + format!("{EXPORT} int fixture_value(void) {{ return 42; }}"), + ) + .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 core = build + .shared_library(&target("fixture-core", &core_source, vec![])) + .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"; From 6cd81dbe0491871261015f3ead602b5dbb811690 Mon Sep 17 00:00:00 2001 From: Zach Vorhies Date: Sat, 17 Oct 2026 13:43:17 -0700 Subject: [PATCH 12/88] feat(build): link native executables and preserve static archive inputs --- rust/obs-build/src/lib.rs | 35 +++++++++++++++- rust/obs-build/src/platform/mod.rs | 64 +++++++++++++++++++++++++++++- rust/obs-build/tests/native.rs | 13 +++++- 3 files changed, 106 insertions(+), 6 deletions(-) diff --git a/rust/obs-build/src/lib.rs b/rust/obs-build/src/lib.rs index 7f602ec069..80a37b1f4e 100644 --- a/rust/obs-build/src/lib.rs +++ b/rust/obs-build/src/lib.rs @@ -71,8 +71,39 @@ impl NativeBuild { } /// Compile and link an executable with the native shared dependencies. - pub fn executable(&self, _target: &SharedLibrary) -> Result { - Err("native executable linking is not implemented".into()) + 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. diff --git a/rust/obs-build/src/platform/mod.rs b/rust/obs-build/src/platform/mod.rs index 45317b8c3f..3220955ddb 100644 --- a/rust/obs-build/src/platform/mod.rs +++ b/rust/obs-build/src/platform/mod.rs @@ -45,7 +45,7 @@ pub fn configure_shared_link( if target.contains("windows") { if msvc { command.arg("/LD").args(objects); - command.args(dependencies.iter().map(|p| p.with_extension("lib"))); + command.args(dependencies.iter().map(|p| dependency_link_name(p, true))); command .arg("/link") .arg(format!("/OUT:{}", artifact.display())) @@ -55,7 +55,7 @@ pub fn configure_shared_link( )); } else { command.arg("-shared").args(objects); - command.args(dependencies.iter().map(|p| p.with_extension("dll.a"))); + 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() @@ -202,6 +202,66 @@ pub fn configure_glad( } } +fn dependency_link_name(path: &Path, msvc: bool) -> PathBuf { + 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(()) +} + #[cfg(test)] mod tests { use super::*; diff --git a/rust/obs-build/tests/native.rs b/rust/obs-build/tests/native.rs index bb0605af93..7d1f7a1c3f 100644 --- a/rust/obs-build/tests/native.rs +++ b/rust/obs-build/tests/native.rs @@ -117,9 +117,15 @@ 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!("{EXPORT} int fixture_value(void) {{ return 42; }}"), + format!("extern int fixture_private_value(void); {EXPORT} int fixture_value(void) {{ return fixture_private_value(); }}"), ) .unwrap(); fs::write( @@ -132,8 +138,11 @@ fn executable_runs_against_its_shared_core_dependency() { 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![])) + .shared_library(&target("fixture-core", &core_source, vec![helper])) .unwrap(); let executable = build .executable(&target( From 9bfa984efab52f4295adad138a5a894f49f80043 Mon Sep 17 00:00:00 2001 From: Zach Vorhies Date: Sat, 17 Oct 2026 13:45:53 -0700 Subject: [PATCH 13/88] test(build): require x264, FFmpeg, and recording output modules --- rust/obs-build/src/plugins.rs | 48 ++++++++++++++++++++++++++++++++++ rust/obs-build/tests/libobs.rs | 18 ++++++++++++- 2 files changed, 65 insertions(+), 1 deletion(-) diff --git a/rust/obs-build/src/plugins.rs b/rust/obs-build/src/plugins.rs index e257f0f9e4..5293390581 100644 --- a/rust/obs-build/src/plugins.rs +++ b/rust/obs-build/src/plugins.rs @@ -111,3 +111,51 @@ fn finish(build: &NativeBuild, root: &Path, library: SharedLibrary) -> Result Self { + Self { + logging: false, + mpegts: true, + nvenc: false, + mux_debug: false, + } + } +} + +#[derive(Debug)] +pub struct FfmpegArtifacts { + pub module: Module, + pub muxer: PathBuf, +} + +pub fn build_x264(_build: &NativeBuild, _root: &Path, _core: &Path) -> Result { + Err("real x264 module build is not implemented".into()) +} + +pub fn build_outputs( + _build: &NativeBuild, + _root: &Path, + _core: &Path, + _options: &crate::libobs::Options, +) -> Result { + Err("real outputs module build is not implemented".into()) +} + +pub fn build_ffmpeg( + _build: &NativeBuild, + _root: &Path, + _core: &Path, + _options: &crate::libobs::Options, + _features: &FfmpegOptions, +) -> Result { + Err("real FFmpeg module and muxer build is not implemented".into()) +} diff --git a/rust/obs-build/tests/libobs.rs b/rust/obs-build/tests/libobs.rs index 04654c085e..5a222f17e8 100644 --- a/rust/obs-build/tests/libobs.rs +++ b/rust/obs-build/tests/libobs.rs @@ -44,10 +44,26 @@ fn c_and_rust_twins_preserve_public_data_lifecycle_and_module_apis() { speexdsp: std::env::var_os("OBS_BUILD_DISABLE_SPEEXDSP").is_none(), rnnoise: std::env::var_os("OBS_BUILD_DISABLE_RNNOISE").is_none(), }; - let modules = [ + let mut modules = vec![ plugins::build_transitions(&build, &root, &libraries.reference).unwrap(), plugins::build_filters(&build, &root, &libraries.reference, &filters).unwrap(), ]; + if std::env::var_os("OBS_BUILD_RECORD").is_some() { + modules.push(plugins::build_x264(&build, &root, &libraries.reference).unwrap()); + modules + .push(plugins::build_outputs(&build, &root, &libraries.reference, &options).unwrap()); + modules.push( + plugins::build_ffmpeg( + &build, + &root, + &libraries.reference, + &options, + &plugins::FfmpegOptions::default(), + ) + .unwrap() + .module, + ); + } let renderer = std::env::var_os("OBS_BUILD_RENDER") .map(|_| graphics::build_opengl(&build, &root, &libraries.reference, &options).unwrap()); let probe = renderer From e3d4904cef4bc35673042f3d2282adf2cb3e90cc Mon Sep 17 00:00:00 2001 From: Zach Vorhies Date: Sat, 17 Oct 2026 13:52:28 -0700 Subject: [PATCH 14/88] feat(build): build recording modules and validate H264 AAC output --- docs/rust-port/cc-build.md | 30 +++++ rust/obs-build/src/libobs.rs | 59 ++++----- rust/obs-build/src/platform/mod.rs | 58 +++++++++ rust/obs-build/src/plugins.rs | 165 ++++++++++++++++++++++++-- rust/obs-build/tests/libobs.rs | 126 ++++++++++++++++++-- rust/obs-build/tests/libobs/render.rs | 62 +++++++++- 6 files changed, 451 insertions(+), 49 deletions(-) diff --git a/docs/rust-port/cc-build.md b/docs/rust-port/cc-build.md index ec29e0bfb3..c328c9d5df 100644 --- a/docs/rust-port/cc-build.md +++ b/docs/rust-port/cc-build.md @@ -143,3 +143,33 @@ 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. + +This checkpoint exercises mp4_output. `ffmpeg_muxer` requires its helper beside +the running app; the returned helper artifact still needs deployment and runtime +validation through that output. 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. diff --git a/rust/obs-build/src/libobs.rs b/rust/obs-build/src/libobs.rs index 9907fd6603..4e58ac87fd 100644 --- a/rust/obs-build/src/libobs.rs +++ b/rust/obs-build/src/libobs.rs @@ -93,33 +93,7 @@ fn prepare(build: &NativeBuild, root: &Path, options: &Options) -> Result 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()))?; diff --git a/rust/obs-build/src/platform/mod.rs b/rust/obs-build/src/platform/mod.rs index 3220955ddb..a8c463a92d 100644 --- a/rust/obs-build/src/platform/mod.rs +++ b/rust/obs-build/src/platform/mod.rs @@ -262,6 +262,64 @@ pub fn configure_executable_link( 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(()) +} + #[cfg(test)] mod tests { use super::*; diff --git a/rust/obs-build/src/plugins.rs b/rust/obs-build/src/plugins.rs index 5293390581..6f2a175f47 100644 --- a/rust/obs-build/src/plugins.rs +++ b/rust/obs-build/src/plugins.rs @@ -137,25 +137,164 @@ pub struct FfmpegArtifacts { pub muxer: PathBuf, } -pub fn build_x264(_build: &NativeBuild, _root: &Path, _core: &Path) -> Result { - Err("real x264 module build is not implemented".into()) +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, + build: &NativeBuild, + root: &Path, + core: &Path, + options: &crate::libobs::Options, ) -> Result { - Err("real outputs module build is not implemented".into()) + 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, + build: &NativeBuild, + root: &Path, + core: &Path, + options: &crate::libobs::Options, + features: &FfmpegOptions, ) -> Result { - Err("real FFmpeg module and muxer build is not implemented".into()) + 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)?, + }) +} + +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/tests/libobs.rs b/rust/obs-build/tests/libobs.rs index 5a222f17e8..db9796fa59 100644 --- a/rust/obs-build/tests/libobs.rs +++ b/rust/obs-build/tests/libobs.rs @@ -64,8 +64,10 @@ fn c_and_rust_twins_preserve_public_data_lifecycle_and_module_apis() { .module, ); } - let renderer = std::env::var_os("OBS_BUILD_RENDER") - .map(|_| graphics::build_opengl(&build, &root, &libraries.reference, &options).unwrap()); + let wants_graphics = std::env::var_os("OBS_BUILD_RENDER").is_some() + || std::env::var_os("OBS_BUILD_RECORD").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)); @@ -83,6 +85,19 @@ fn c_and_rust_twins_preserve_public_data_lifecycle_and_module_apis() { command.env("OBS_BUILD_TEST_RENDERER", renderer); command.env("OBS_BUILD_TEST_PROBE", probe.as_ref().unwrap()); } + let recording = std::env::var_os("OBS_BUILD_RECORD").map(|_| { + let variant = path + .parent() + .unwrap() + .file_name() + .unwrap() + .to_str() + .unwrap(); + build.output.join(format!("recording-{variant}.mp4")) + }); + if let Some(recording) = &recording { + command.env("OBS_BUILD_TEST_RECORDING", recording); + } let run = command .args([ "--exact", @@ -94,7 +109,9 @@ fn c_and_rust_twins_preserve_public_data_lifecycle_and_module_apis() { .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("Loading up OpenGL") + || line.contains("cc::Build graphics device") + || line.contains("cc::Build recording") }) { println!("{}: {line}", path.display()); } @@ -105,6 +122,9 @@ fn c_and_rust_twins_preserve_public_data_lifecycle_and_module_apis() { String::from_utf8_lossy(&run.stdout), String::from_utf8_lossy(&run.stderr) ); + if let Some(recording) = recording { + verify_recording(&recording); + } } } @@ -178,11 +198,30 @@ fn exercise(path: &std::path::Path, modules: &[plugins::Module], hevc: bool) { assert_eq!(open(&mut handle, binary.as_ptr(), data_path.as_ptr()), 0); assert!(init(handle)); } - for (symbol, expected) in [ + 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"), - ] { + ]; + if std::env::var_os("OBS_BUILD_RECORD").is_some() { + 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"), + ]); + 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" + ); + } + for (symbol, expected) in expected_types { let enumerate = library .get:: bool>(symbol) .unwrap(); @@ -208,9 +247,24 @@ fn exercise(path: &std::path::Path, modules: &[plugins::Module], hevc: bool) { .canonicalize() .unwrap(); let data_path = std::ffi::CString::new(format!("{}/", data_path.display())).unwrap(); - let render = probe.get:: i32>(b"obs_fixture_render").unwrap(); + 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()); assert_eq!( - render(renderer.as_ptr(), data_path.as_ptr()), + render( + renderer.as_ptr(), + data_path.as_ptr(), + recording + .as_ref() + .map_or(std::ptr::null(), |path| path.as_ptr()) + ), 0, "graphics/frame rendering failed" ); @@ -248,3 +302,61 @@ fn exports(path: &std::path::Path) -> std::collections::BTreeSet { .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,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"); + assert_eq!(video["width"], 64); + assert_eq!(video["height"], 64); + 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"); + 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()); +} diff --git a/rust/obs-build/tests/libobs/render.rs b/rust/obs-build/tests/libobs/render.rs index 8f00099620..0fed177129 100644 --- a/rust/obs-build/tests/libobs/render.rs +++ b/rust/obs-build/tests/libobs/render.rs @@ -66,9 +66,64 @@ static void receive_frame(void *unused, struct video_data *frame) atomic_fetch_add(&frames, 1); } -EXPORT int obs_fixture_render(const char *renderer, const char *data_path) +static int record_clip(const char *path) +{ + obs_data_t *settings = obs_data_create(); + obs_data_set_string(settings, "rate_control", "CBR"); + obs_data_set_int(settings, "bitrate", 500); + obs_data_set_string(settings, "preset", "ultrafast"); + obs_data_set_string(settings, "tune", "zerolatency"); + obs_encoder_t *video = obs_video_encoder_create("obs_x264", "cc-build-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_aac", "cc-build-audio", settings, 0, NULL); + obs_data_release(settings); + settings = obs_data_create(); + obs_data_set_string(settings, "path", path); + obs_output_t *output = obs_output_create("mp4_output", "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_render(const char *renderer, const char *data_path, const char *record_path) { obs_add_data_path(data_path); + if (record_path) { + 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, @@ -96,12 +151,15 @@ EXPORT int obs_fixture_render(const char *renderer, const char *data_path) for (unsigned i = 0; i < 200 && atomic_load(&frames) < 3; ++i) os_sleep_ms(10); obs_remove_raw_video_callback(receive_frame, NULL); + int recording_status = record_path ? record_clip(record_path) : 0; obs_set_output_source(0, NULL); obs_scene_release(scene); /* The owning test calls obs_shutdown after this probe. */ if (atomic_load(&frames) < 3) return 82; - return atomic_load(&invalid_frames) ? 83 : 0; + if (atomic_load(&invalid_frames)) + return 83; + return recording_status; } EXPORT void obs_fixture_close_display(void) From 334a1a6b1e67096821d290b669f6184b89205c85 Mon Sep 17 00:00:00 2001 From: Zach Vorhies Date: Sat, 17 Oct 2026 13:55:21 -0700 Subject: [PATCH 15/88] test(build): require deployed FFmpeg mux helper and Matroska recording --- rust/obs-build/src/plugins.rs | 7 +++ rust/obs-build/tests/libobs.rs | 68 +++++++++++++++++++++------ rust/obs-build/tests/libobs/render.rs | 8 ++-- 3 files changed, 64 insertions(+), 19 deletions(-) diff --git a/rust/obs-build/src/plugins.rs b/rust/obs-build/src/plugins.rs index 6f2a175f47..fc81482c6d 100644 --- a/rust/obs-build/src/plugins.rs +++ b/rust/obs-build/src/plugins.rs @@ -137,6 +137,13 @@ pub struct FfmpegArtifacts { 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 { + Err("FFmpeg helper deployment is not implemented".into()) + } +} + 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")?; diff --git a/rust/obs-build/tests/libobs.rs b/rust/obs-build/tests/libobs.rs index db9796fa59..941f5559ef 100644 --- a/rust/obs-build/tests/libobs.rs +++ b/rust/obs-build/tests/libobs.rs @@ -48,22 +48,36 @@ fn c_and_rust_twins_preserve_public_data_lifecycle_and_module_apis() { plugins::build_transitions(&build, &root, &libraries.reference).unwrap(), plugins::build_filters(&build, &root, &libraries.reference, &filters).unwrap(), ]; + let mut ffmpeg = None; if std::env::var_os("OBS_BUILD_RECORD").is_some() { modules.push(plugins::build_x264(&build, &root, &libraries.reference).unwrap()); modules .push(plugins::build_outputs(&build, &root, &libraries.reference, &options).unwrap()); - modules.push( - plugins::build_ffmpeg( - &build, - &root, - &libraries.reference, - &options, - &plugins::FfmpegOptions::default(), - ) - .unwrap() - .module, - ); + 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. + let runner = if let Some(ffmpeg) = &ffmpeg { + let bin = build.output.join("test-bin"); + let helper = ffmpeg.deploy_muxer(&bin).unwrap(); + assert!(helper.is_file()); + let runner = bin.join("obs-native-integration"); + std::fs::copy(std::env::current_exe().unwrap(), &runner).unwrap(); + runner + } else { + std::env::current_exe().unwrap() + }; let wants_graphics = std::env::var_os("OBS_BUILD_RENDER").is_some() || std::env::var_os("OBS_BUILD_RECORD").is_some(); let renderer = wants_graphics @@ -79,8 +93,23 @@ fn c_and_rust_twins_preserve_public_data_lifecycle_and_module_apis() { .map(|module| (&module.library, &module.data)) .collect(); let serialized = serde_json::to_string(&modules).unwrap(); - for path in [&libraries.reference, &libraries.with_rust] { - let mut command = std::process::Command::new(std::env::current_exe().unwrap()); + let outputs: &[(&str, &str)] = if ffmpeg.is_some() { + &[("mp4_output", "mp4"), ("ffmpeg_muxer", "mkv")] + } else { + &[("mp4_output", "mp4")] + }; + 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 command = std::process::Command::new(&runner); + command.env("OBS_BUILD_TEST_OUTPUT_ID", output_id); + // 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()); @@ -93,7 +122,9 @@ fn c_and_rust_twins_preserve_public_data_lifecycle_and_module_apis() { .unwrap() .to_str() .unwrap(); - build.output.join(format!("recording-{variant}.mp4")) + build + .output + .join(format!("recording-{variant}.{extension}")) }); if let Some(recording) = &recording { command.env("OBS_BUILD_TEST_RECORDING", recording); @@ -208,6 +239,7 @@ fn exercise(path: &std::path::Path, modules: &[plugins::Module], hevc: bool) { (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 @@ -252,18 +284,24 @@ fn exercise(path: &std::path::Path, modules: &[plugins::Module], hevc: bool) { *const std::ffi::c_char, *const std::ffi::c_char, *const std::ffi::c_char, + *const std::ffi::c_char, ) -> 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( renderer.as_ptr(), data_path.as_ptr(), recording .as_ref() - .map_or(std::ptr::null(), |path| path.as_ptr()) + .map_or(std::ptr::null(), |path| path.as_ptr()), + output_id.as_ptr() ), 0, "graphics/frame rendering failed" diff --git a/rust/obs-build/tests/libobs/render.rs b/rust/obs-build/tests/libobs/render.rs index 0fed177129..bda9f64521 100644 --- a/rust/obs-build/tests/libobs/render.rs +++ b/rust/obs-build/tests/libobs/render.rs @@ -66,7 +66,7 @@ static void receive_frame(void *unused, struct video_data *frame) atomic_fetch_add(&frames, 1); } -static int record_clip(const char *path) +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"); @@ -81,7 +81,7 @@ static int record_clip(const char *path) obs_data_release(settings); settings = obs_data_create(); obs_data_set_string(settings, "path", path); - obs_output_t *output = obs_output_create("mp4_output", "cc-build-recording", settings, NULL); + 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) { @@ -116,7 +116,7 @@ cleanup: return status; } -EXPORT int obs_fixture_render(const char *renderer, const char *data_path, const char *record_path) +EXPORT int obs_fixture_render(const char *renderer, const char *data_path, const char *record_path, const char *output_id) { obs_add_data_path(data_path); if (record_path) { @@ -151,7 +151,7 @@ EXPORT int obs_fixture_render(const char *renderer, const char *data_path, const for (unsigned i = 0; i < 200 && atomic_load(&frames) < 3; ++i) os_sleep_ms(10); obs_remove_raw_video_callback(receive_frame, NULL); - int recording_status = record_path ? record_clip(record_path) : 0; + int recording_status = record_path ? record_clip(record_path, output_id) : 0; obs_set_output_source(0, NULL); obs_scene_release(scene); /* The owning test calls obs_shutdown after this probe. */ From f5fd0a440a977a5f79f41d8f275f2e870f6a2db2 Mon Sep 17 00:00:00 2001 From: Zach Vorhies Date: Sat, 17 Oct 2026 13:56:43 -0700 Subject: [PATCH 16/88] feat(build): deploy and exercise FFmpeg recording helper --- docs/rust-port/cc-build.md | 7 ++++--- rust/obs-build/src/plugins.rs | 22 ++++++++++++++++++++-- rust/obs-build/tests/native.rs | 16 ++++++++++++++++ 3 files changed, 40 insertions(+), 5 deletions(-) diff --git a/docs/rust-port/cc-build.md b/docs/rust-port/cc-build.md index c328c9d5df..9469aa5fc3 100644 --- a/docs/rust-port/cc-build.md +++ b/docs/rust-port/cc-build.md @@ -168,8 +168,9 @@ 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. -This checkpoint exercises mp4_output. `ffmpeg_muxer` requires its helper beside -the running app; the returned helper artifact still needs deployment and runtime -validation through that output. The full Qt application, capture sources, other +`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. diff --git a/rust/obs-build/src/plugins.rs b/rust/obs-build/src/plugins.rs index fc81482c6d..3f194f77a2 100644 --- a/rust/obs-build/src/plugins.rs +++ b/rust/obs-build/src/plugins.rs @@ -139,8 +139,26 @@ pub struct FfmpegArtifacts { impl FfmpegArtifacts { /// Deploy the mux helper beside the executable that loads the module. - pub fn deploy_muxer(&self, _bin_dir: &Path) -> Result { - Err("FFmpeg helper deployment is not implemented".into()) + 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) } } diff --git a/rust/obs-build/tests/native.rs b/rust/obs-build/tests/native.rs index 7d1f7a1c3f..12ff0cc9c2 100644 --- a/rust/obs-build/tests/native.rs +++ b/rust/obs-build/tests/native.rs @@ -167,3 +167,19 @@ fn executable_runs_against_its_shared_core_dependency() { } const EXPORT: &str = "\n#if defined(_WIN32)\n__declspec(dllexport)\n#endif\n"; + +#[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"); +} From 38de64c6b568d2368bc55ffedc933431c121155b Mon Sep 17 00:00:00 2001 From: Zach Vorhies Date: Sat, 17 Oct 2026 13:57:21 -0700 Subject: [PATCH 17/88] test(build): require image text capture audio and service modules --- rust/obs-build/src/plugins.rs | 21 +++++++++++++++++++ rust/obs-build/tests/libobs.rs | 37 +++++++++++++++++++++++++++++++++- 2 files changed, 57 insertions(+), 1 deletion(-) diff --git a/rust/obs-build/src/plugins.rs b/rust/obs-build/src/plugins.rs index 3f194f77a2..9cbbdc275f 100644 --- a/rust/obs-build/src/plugins.rs +++ b/rust/obs-build/src/plugins.rs @@ -323,3 +323,24 @@ fn shared_archive(build: &NativeBuild, root: &Path, name: &str) -> Result Result { + Err("source module graph is not implemented".into()) +} diff --git a/rust/obs-build/tests/libobs.rs b/rust/obs-build/tests/libobs.rs index 941f5559ef..0cb0fb61ed 100644 --- a/rust/obs-build/tests/libobs.rs +++ b/rust/obs-build/tests/libobs.rs @@ -48,6 +48,23 @@ fn c_and_rust_twins_preserve_public_data_lifecycle_and_module_apis() { plugins::build_transitions(&build, &root, &libraries.reference).unwrap(), plugins::build_filters(&build, &root, &libraries.reference, &filters).unwrap(), ]; + if std::env::var_os("OBS_BUILD_SOURCES").is_some() { + 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()); + } + } let mut ffmpeg = None; if std::env::var_os("OBS_BUILD_RECORD").is_some() { modules.push(plugins::build_x264(&build, &root, &libraries.reference).unwrap()); @@ -79,7 +96,8 @@ fn c_and_rust_twins_preserve_public_data_lifecycle_and_module_apis() { std::env::current_exe().unwrap() }; let wants_graphics = std::env::var_os("OBS_BUILD_RENDER").is_some() - || std::env::var_os("OBS_BUILD_RECORD").is_some(); + || std::env::var_os("OBS_BUILD_RECORD").is_some() + || std::env::var_os("OBS_BUILD_SOURCES").is_some(); let renderer = wants_graphics .then(|| graphics::build_opengl(&build, &root, &libraries.reference, &options).unwrap()); let probe = renderer @@ -253,6 +271,23 @@ fn exercise(path: &std::path::Path, modules: &[plugins::Module], hevc: bool) { "exactly one SRT shared library must be loaded" ); } + if std::env::var_os("OBS_BUILD_SOURCES").is_some() { + 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"), + ]); + } for (symbol, expected) in expected_types { let enumerate = library .get:: bool>(symbol) From 035130916f9f31fb8e259ab18fdd9006447c5b21 Mon Sep 17 00:00:00 2001 From: Zach Vorhies Date: Sat, 17 Oct 2026 13:59:21 -0700 Subject: [PATCH 18/88] feat(build): build common source and service modules with cc --- docs/rust-port/cc-build.md | 21 ++++++++ rust/obs-build/src/graphics.rs | 22 ++++---- rust/obs-build/src/platform/mod.rs | 74 +++++++++++++++++++++++++++ rust/obs-build/src/plugins.rs | 33 ++++++++++-- rust/obs-build/tests/libobs.rs | 1 + rust/obs-build/tests/libobs/render.rs | 31 ++++++++++- 6 files changed, 166 insertions(+), 16 deletions(-) diff --git a/docs/rust-port/cc-build.md b/docs/rust-port/cc-build.md index 9469aa5fc3..1d6f789dd1 100644 --- a/docs/rust-port/cc-build.md +++ b/docs/rust-port/cc-build.md @@ -174,3 +174,24 @@ 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. diff --git a/rust/obs-build/src/graphics.rs b/rust/obs-build/src/graphics.rs index 9f675dfb3d..bcaeef707e 100644 --- a/rust/obs-build/src/graphics.rs +++ b/rust/obs-build/src/graphics.rs @@ -23,15 +23,7 @@ pub fn build_opengl( ..SharedLibrary::default() }; crate::platform::configure_opengl(&build.target, &root, options, &mut library)?; - let mut glad = SharedLibrary { - name: "obsglad".into(), - sources: vec![root.join("deps/glad/src/glad.c")], - include_dirs: vec![root.join("deps/glad/include")], - compile_options: library.compile_options.clone(), - ..SharedLibrary::default() - }; - crate::platform::configure_glad(&build.target, &root, &mut glad)?; - library.dependencies.push(build.static_library(&glad)?); + 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, @@ -42,3 +34,15 @@ pub fn build_opengl( } 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/platform/mod.rs b/rust/obs-build/src/platform/mod.rs index a8c463a92d..ded4bb8dff 100644 --- a/rust/obs-build/src/platform/mod.rs +++ b/rust/obs-build/src/platform/mod.rs @@ -345,3 +345,77 @@ mod tests { ); } } + +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::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::Image => &[], + SourceModule::Text => &["freetype2", "fontconfig"], + SourceModule::PulseAudio => &["libpulse"], + 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::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(()) +} diff --git a/rust/obs-build/src/plugins.rs b/rust/obs-build/src/plugins.rs index 9cbbdc275f..a5e1a399cd 100644 --- a/rust/obs-build/src/plugins.rs +++ b/rust/obs-build/src/plugins.rs @@ -336,11 +336,34 @@ pub enum SourceModule { RtmpServices { updates: bool }, } +impl SourceModule { + pub fn name(self) -> &'static str { + match self { + Self::Image => "image-source", + Self::Text => "text-freetype2", + Self::PulseAudio => "linux-pulseaudio", + 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, + build: &NativeBuild, + root: &Path, + core: &Path, + source: SourceModule, ) -> Result { - Err("source module graph is not implemented".into()) + 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::X11Capture) { + library + .dependencies + .push(crate::graphics::build_glad(build, &root)?); + } + finish(build, &root, library) } diff --git a/rust/obs-build/tests/libobs.rs b/rust/obs-build/tests/libobs.rs index 0cb0fb61ed..c212192c2f 100644 --- a/rust/obs-build/tests/libobs.rs +++ b/rust/obs-build/tests/libobs.rs @@ -161,6 +161,7 @@ fn c_and_rust_twins_preserve_public_data_lifecycle_and_module_apis() { line.contains("Loading up OpenGL") || line.contains("cc::Build graphics device") || line.contains("cc::Build recording") + || line.contains("cc::Build color source") }) { println!("{}: {line}", path.display()); } diff --git a/rust/obs-build/tests/libobs/render.rs b/rust/obs-build/tests/libobs/render.rs index bda9f64521..838356ba89 100644 --- a/rust/obs-build/tests/libobs/render.rs +++ b/rust/obs-build/tests/libobs/render.rs @@ -39,6 +39,7 @@ pub fn build(build: &NativeBuild, root: &Path, core: &Path) -> PathBuf { const SOURCE: &str = r#" #include #include +#include #include #include #include @@ -46,6 +47,7 @@ const SOURCE: &str = r#" static Display *test_display; static atomic_uint frames; static atomic_uint invalid_frames; +static atomic_uint expected_y = 16; EXPORT bool obs_fixture_open_display(void) { @@ -61,7 +63,10 @@ EXPORT bool obs_fixture_open_display(void) static void receive_frame(void *unused, struct video_data *frame) { (void)unused; - if (!frame->data[0] || frame->linesize[0] < 64 || frame->data[0][0] != 16) + 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] < 64 || frame->data[0][0] != atomic_load(&expected_y)) atomic_fetch_add(&invalid_frames, 1); atomic_fetch_add(&frames, 1); } @@ -151,6 +156,28 @@ EXPORT int obs_fixture_render(const char *renderer, const char *data_path, const 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; + if (getenv("OBS_BUILD_SOURCES")) { + obs_data_t *settings = obs_data_create(); + obs_data_set_int(settings, "width", 64); + obs_data_set_int(settings, "height", 64); + obs_data_set_int(settings, "color", 0xFFFFFFFF); + obs_source_t *color = obs_source_create("color_source_v3", "cc-build-white", settings, NULL); + obs_data_release(settings); + if (!color || obs_source_get_width(color) != 64 || obs_source_get_height(color) != 64) { + 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)); + } + obs_source_release(color); + } int recording_status = record_path ? record_clip(record_path, output_id) : 0; obs_set_output_source(0, NULL); obs_scene_release(scene); @@ -159,7 +186,7 @@ EXPORT int obs_fixture_render(const char *renderer, const char *data_path, const return 82; if (atomic_load(&invalid_frames)) return 83; - return recording_status; + return source_status ? source_status : recording_status; } EXPORT void obs_fixture_close_display(void) From 94572988567025adff79c13593a102839f515017 Mon Sep 17 00:00:00 2001 From: Zach Vorhies Date: Sat, 17 Oct 2026 14:00:51 -0700 Subject: [PATCH 19/88] test(build): require native PipeWire module support --- rust/obs-build/src/platform/mod.rs | 5 +++++ rust/obs-build/src/plugins.rs | 5 +++++ rust/obs-build/tests/libobs.rs | 14 +++++++++++++- 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/rust/obs-build/src/platform/mod.rs b/rust/obs-build/src/platform/mod.rs index ded4bb8dff..85412cf96c 100644 --- a/rust/obs-build/src/platform/mod.rs +++ b/rust/obs-build/src/platform/mod.rs @@ -353,12 +353,16 @@ pub fn configure_source( library: &mut crate::SharedLibrary, ) -> Result<(), String> { use crate::{libobs::add_package, plugins::SourceModule}; + if matches!(source, SourceModule::PipeWire) { + return Err("PipeWire module graph is not implemented".into()); + } if !target.contains("linux") { return Err(format!( "source module graph for {target} is not implemented yet" )); } let groups: &[&str] = match source { + SourceModule::PipeWire => unreachable!(), SourceModule::Image => &["core", "slideshow", "posix"], SourceModule::Text => &["core", "nix"], SourceModule::PulseAudio | SourceModule::Alsa | SourceModule::X11Capture => &["nix"], @@ -372,6 +376,7 @@ pub fn configure_source( .map(|group| root.join(format!("plugins/{0}/build/{0}.{group}+.h.c", source.name()))), ); let packages: &[&str] = match source { + SourceModule::PipeWire => unreachable!(), SourceModule::Image => &[], SourceModule::Text => &["freetype2", "fontconfig"], SourceModule::PulseAudio => &["libpulse"], diff --git a/rust/obs-build/src/plugins.rs b/rust/obs-build/src/plugins.rs index a5e1a399cd..3eb792b6d1 100644 --- a/rust/obs-build/src/plugins.rs +++ b/rust/obs-build/src/plugins.rs @@ -330,6 +330,7 @@ pub enum SourceModule { Image, Text, PulseAudio, + PipeWire, Alsa, V4l2 { udev: bool }, X11Capture, @@ -342,6 +343,7 @@ impl SourceModule { Self::Image => "image-source", Self::Text => "text-freetype2", Self::PulseAudio => "linux-pulseaudio", + Self::PipeWire => "linux-pipewire", Self::Alsa => "linux-alsa", Self::V4l2 { .. } => "linux-v4l2", Self::X11Capture => "linux-capture", @@ -356,6 +358,9 @@ pub fn build_source( core: &Path, source: SourceModule, ) -> Result { + if matches!(source, SourceModule::PipeWire) { + return Err("PipeWire module graph is not implemented".into()); + } let root = root.canonicalize().map_err(|e| e.to_string())?; let mut library = module(build, &root, core, source.name())?; library.sources.clear(); diff --git a/rust/obs-build/tests/libobs.rs b/rust/obs-build/tests/libobs.rs index c212192c2f..59a9ca87da 100644 --- a/rust/obs-build/tests/libobs.rs +++ b/rust/obs-build/tests/libobs.rs @@ -65,6 +65,17 @@ fn c_and_rust_twins_preserve_public_data_lifecycle_and_module_apis() { .push(plugins::build_source(&build, &root, &libraries.reference, source).unwrap()); } } + if std::env::var_os("OBS_BUILD_PIPEWIRE").is_some() { + modules.push( + plugins::build_source( + &build, + &root, + &libraries.reference, + plugins::SourceModule::PipeWire, + ) + .unwrap(), + ); + } let mut ffmpeg = None; if std::env::var_os("OBS_BUILD_RECORD").is_some() { modules.push(plugins::build_x264(&build, &root, &libraries.reference).unwrap()); @@ -97,7 +108,8 @@ fn c_and_rust_twins_preserve_public_data_lifecycle_and_module_apis() { }; let wants_graphics = std::env::var_os("OBS_BUILD_RENDER").is_some() || std::env::var_os("OBS_BUILD_RECORD").is_some() - || std::env::var_os("OBS_BUILD_SOURCES").is_some(); + || std::env::var_os("OBS_BUILD_SOURCES").is_some() + || std::env::var_os("OBS_BUILD_PIPEWIRE").is_some(); let renderer = wants_graphics .then(|| graphics::build_opengl(&build, &root, &libraries.reference, &options).unwrap()); let probe = renderer From 6cb1452b019df697008bc6d7d1ae7c917219cb29 Mon Sep 17 00:00:00 2001 From: Zach Vorhies Date: Sat, 17 Oct 2026 14:02:09 -0700 Subject: [PATCH 20/88] feat(build): compile and load PipeWire with native graphics initialized --- docs/rust-port/cc-build.md | 11 ++++ rust/obs-build/src/platform/mod.rs | 82 +++++++++++++++++---------- rust/obs-build/src/plugins.rs | 5 +- rust/obs-build/tests/libobs.rs | 36 ++++++++---- rust/obs-build/tests/libobs/render.rs | 11 ++-- 5 files changed, 95 insertions(+), 50 deletions(-) diff --git a/docs/rust-port/cc-build.md b/docs/rust-port/cc-build.md index 1d6f789dd1..ab95eaea75 100644 --- a/docs/rust-port/cc-build.md +++ b/docs/rust-port/cc-build.md @@ -195,3 +195,14 @@ 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. diff --git a/rust/obs-build/src/platform/mod.rs b/rust/obs-build/src/platform/mod.rs index 85412cf96c..d001eb7e2e 100644 --- a/rust/obs-build/src/platform/mod.rs +++ b/rust/obs-build/src/platform/mod.rs @@ -320,32 +320,6 @@ pub fn configure_ffmpeg( 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 - ); - } -} - pub fn configure_source( target: &str, root: &Path, @@ -353,16 +327,13 @@ pub fn configure_source( library: &mut crate::SharedLibrary, ) -> Result<(), String> { use crate::{libobs::add_package, plugins::SourceModule}; - if matches!(source, SourceModule::PipeWire) { - return Err("PipeWire module graph is not implemented".into()); - } if !target.contains("linux") { return Err(format!( "source module graph for {target} is not implemented yet" )); } let groups: &[&str] = match source { - SourceModule::PipeWire => unreachable!(), + SourceModule::PipeWire => &["nix"], SourceModule::Image => &["core", "slideshow", "posix"], SourceModule::Text => &["core", "nix"], SourceModule::PulseAudio | SourceModule::Alsa | SourceModule::X11Capture => &["nix"], @@ -376,7 +347,7 @@ pub fn configure_source( .map(|group| root.join(format!("plugins/{0}/build/{0}.{group}+.h.c", source.name()))), ); let packages: &[&str] = match source { - SourceModule::PipeWire => unreachable!(), + SourceModule::PipeWire => &["libpipewire-0.3", "gio-unix-2.0", "libdrm"], SourceModule::Image => &[], SourceModule::Text => &["freetype2", "fontconfig"], SourceModule::PulseAudio => &["libpulse"], @@ -398,6 +369,29 @@ pub fn configure_source( add_package(library, target, package)?; } match source { + 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)); @@ -424,3 +418,29 @@ pub fn configure_source( } 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 index 3eb792b6d1..e4bec71df1 100644 --- a/rust/obs-build/src/plugins.rs +++ b/rust/obs-build/src/plugins.rs @@ -358,14 +358,11 @@ pub fn build_source( core: &Path, source: SourceModule, ) -> Result { - if matches!(source, SourceModule::PipeWire) { - return Err("PipeWire module graph is not implemented".into()); - } 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::X11Capture) { + if matches!(source, SourceModule::X11Capture | SourceModule::PipeWire) { library .dependencies .push(crate::graphics::build_glad(build, &root)?); diff --git a/rust/obs-build/tests/libobs.rs b/rust/obs-build/tests/libobs.rs index 59a9ca87da..cf0819021b 100644 --- a/rust/obs-build/tests/libobs.rs +++ b/rust/obs-build/tests/libobs.rs @@ -243,6 +243,31 @@ fn exercise(path: &std::path::Path, modules: &[plugins::Module], hevc: bool) { std::ptr::null(), 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(), + std::env::var_os("OBS_BUILD_RECORD").is_some() + ), + 0 + ); + } let open = library .get:: i32>(b"obs_fixture_render") .unwrap(); let recording = std::env::var("OBS_BUILD_TEST_RECORDING") @@ -344,8 +360,6 @@ fn exercise(path: &std::path::Path, modules: &[plugins::Module], hevc: bool) { .unwrap(); assert_eq!( render( - renderer.as_ptr(), - data_path.as_ptr(), recording .as_ref() .map_or(std::ptr::null(), |path| path.as_ptr()), diff --git a/rust/obs-build/tests/libobs/render.rs b/rust/obs-build/tests/libobs/render.rs index 838356ba89..a9c85c0892 100644 --- a/rust/obs-build/tests/libobs/render.rs +++ b/rust/obs-build/tests/libobs/render.rs @@ -121,10 +121,10 @@ cleanup: return status; } -EXPORT int obs_fixture_render(const char *renderer, const char *data_path, const char *record_path, const char *output_id) +EXPORT int obs_fixture_initialize(const char *renderer, const char *data_path, bool audio_enabled) { obs_add_data_path(data_path); - if (record_path) { + if (audio_enabled) { struct obs_audio_info audio = { .samples_per_sec = 48000, .speakers = SPEAKERS_STEREO }; if (!obs_reset_audio(&audio)) return 84; @@ -141,8 +141,11 @@ EXPORT int obs_fixture_render(const char *renderer, const char *data_path, const .scale_type = OBS_SCALE_BICUBIC, }; int result = obs_reset_video(&video); - if (result != OBS_VIDEO_SUCCESS) - return result; + 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(); From 2ee0c673e0e95c874a7d86d8cbcde5525d288bbd Mon Sep 17 00:00:00 2001 From: Zach Vorhies Date: Sat, 17 Oct 2026 14:03:07 -0700 Subject: [PATCH 21/88] test(build): require frontend API and Qt VST module --- rust/obs-build/src/frontend.rs | 7 +++++++ rust/obs-build/src/lib.rs | 1 + rust/obs-build/src/plugins.rs | 4 ++++ rust/obs-build/tests/libobs.rs | 25 ++++++++++++++++++++++++- 4 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 rust/obs-build/src/frontend.rs diff --git a/rust/obs-build/src/frontend.rs b/rust/obs-build/src/frontend.rs new file mode 100644 index 0000000000..6bf7434570 --- /dev/null +++ b/rust/obs-build/src/frontend.rs @@ -0,0 +1,7 @@ +//! Native frontend support libraries and application build graph. +use crate::NativeBuild; +use std::path::{Path, PathBuf}; + +pub fn build_api(_build: &NativeBuild, _root: &Path, _core: &Path) -> Result { + Err("frontend API build is not implemented".into()) +} diff --git a/rust/obs-build/src/lib.rs b/rust/obs-build/src/lib.rs index 80a37b1f4e..35667995c2 100644 --- a/rust/obs-build/src/lib.rs +++ b/rust/obs-build/src/lib.rs @@ -6,6 +6,7 @@ use std::{fs, path::PathBuf}; +pub mod frontend; pub mod graphics; pub mod libobs; mod platform; diff --git a/rust/obs-build/src/plugins.rs b/rust/obs-build/src/plugins.rs index e4bec71df1..aaf4ea4f35 100644 --- a/rust/obs-build/src/plugins.rs +++ b/rust/obs-build/src/plugins.rs @@ -369,3 +369,7 @@ pub fn build_source( } finish(build, &root, library) } + +pub fn build_vst(_build: &NativeBuild, _root: &Path, _core: &Path) -> Result { + Err("Qt VST module build is not implemented".into()) +} diff --git a/rust/obs-build/tests/libobs.rs b/rust/obs-build/tests/libobs.rs index cf0819021b..a590670675 100644 --- a/rust/obs-build/tests/libobs.rs +++ b/rust/obs-build/tests/libobs.rs @@ -1,5 +1,5 @@ //! Opt-in integration against real native dependencies and libobs-rust. -use obs_build::{NativeBuild, graphics, libobs, plugins}; +use obs_build::{NativeBuild, frontend, graphics, libobs, plugins}; use std::{ffi::c_void, path::PathBuf}; #[path = "libobs/render.rs"] mod render; @@ -76,6 +76,10 @@ fn c_and_rust_twins_preserve_public_data_lifecycle_and_module_apis() { .unwrap(), ); } + let frontend = std::env::var_os("OBS_BUILD_QT").map(|_| { + modules.push(plugins::build_vst(&build, &root, &libraries.reference).unwrap()); + frontend::build_api(&build, &root, &libraries.reference).unwrap() + }); let mut ffmpeg = None; if std::env::var_os("OBS_BUILD_RECORD").is_some() { modules.push(plugins::build_x264(&build, &root, &libraries.reference).unwrap()); @@ -134,6 +138,9 @@ fn c_and_rust_twins_preserve_public_data_lifecycle_and_module_apis() { { let mut command = std::process::Command::new(&runner); 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( @@ -204,6 +211,19 @@ fn exercise(path: &std::path::Path, modules: &[plugins::Module], hevc: bool) { ] { 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 { @@ -326,6 +346,9 @@ fn exercise(path: &std::path::Path, modules: &[plugins::Module], hevc: bool) { (b"obs_enum_service_types".as_slice(), "rtmp_custom"), ]); } + if std::env::var_os("OBS_BUILD_QT").is_some() { + expected_types.push((b"obs_enum_filter_types".as_slice(), "vst_filter")); + } for (symbol, expected) in expected_types { let enumerate = library .get:: bool>(symbol) From 74a822adf6fa74c0a92f8167a60d815e1e8445c2 Mon Sep 17 00:00:00 2001 From: Zach Vorhies Date: Sat, 17 Oct 2026 14:05:44 -0700 Subject: [PATCH 22/88] feat(build): compile frontend API and Qt VST with explicit moc generation --- docs/rust-port/cc-build.md | 20 ++++++++++++ rust/obs-build/src/frontend.rs | 29 +++++++++++++++-- rust/obs-build/src/lib.rs | 1 + rust/obs-build/src/platform/mod.rs | 52 ++++++++++++++++++++++++++---- rust/obs-build/src/plugins.rs | 17 ++++++++-- rust/obs-build/src/qt.rs | 52 ++++++++++++++++++++++++++++++ rust/obs-build/tests/libobs.rs | 5 +++ 7 files changed, 165 insertions(+), 11 deletions(-) create mode 100644 rust/obs-build/src/qt.rs diff --git a/docs/rust-port/cc-build.md b/docs/rust-port/cc-build.md index ab95eaea75..8263b9378f 100644 --- a/docs/rust-port/cc-build.md +++ b/docs/rust-port/cc-build.md @@ -206,3 +206,23 @@ shared GLAD archive. Enable its opt-in build/load check with 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. diff --git a/rust/obs-build/src/frontend.rs b/rust/obs-build/src/frontend.rs index 6bf7434570..dc4c7b3f74 100644 --- a/rust/obs-build/src/frontend.rs +++ b/rust/obs-build/src/frontend.rs @@ -1,7 +1,30 @@ //! Native frontend support libraries and application build graph. -use crate::NativeBuild; +use crate::{NativeBuild, SharedLibrary, libobs::add_package}; use std::path::{Path, PathBuf}; -pub fn build_api(_build: &NativeBuild, _root: &Path, _core: &Path) -> Result { - Err("frontend API build is not implemented".into()) +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) } diff --git a/rust/obs-build/src/lib.rs b/rust/obs-build/src/lib.rs index 35667995c2..e4106beff1 100644 --- a/rust/obs-build/src/lib.rs +++ b/rust/obs-build/src/lib.rs @@ -11,6 +11,7 @@ pub mod graphics; pub mod libobs; mod platform; pub mod plugins; +pub mod qt; #[derive(Clone, Debug, Default)] pub struct SharedLibrary { diff --git a/rust/obs-build/src/platform/mod.rs b/rust/obs-build/src/platform/mod.rs index d001eb7e2e..85e54138c9 100644 --- a/rust/obs-build/src/platform/mod.rs +++ b/rust/obs-build/src/platform/mod.rs @@ -142,12 +142,16 @@ pub fn configure_libobs_variant( pub fn configure_module(target: &str, library: &mut crate::SharedLibrary) -> Result<(), String> { if target.contains("linux") { library.file_name = Some(format!("{}.so", library.name)); - library.compile_options.extend( - ["-std=gnu17", "-fno-strict-aliasing", "-fvisibility=hidden"].map(String::from), - ); - library - .link_options - .extend(["-lm", "-pthread"].map(String::from)); + for flag in ["-std=gnu17", "-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!( @@ -419,6 +423,42 @@ pub fn configure_source( Ok(()) } +pub fn configure_cpp_module( + target: &str, + library: &mut crate::SharedLibrary, +) -> Result<(), String> { + configure_module(target, library)?; + library + .compile_options + .retain(|flag| !flag.starts_with("-std=")); + library + .compile_options + .extend(["-std=gnu++17", "-fvisibility-inlines-hidden"].map(String::from)); + 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(()) +} + #[cfg(test)] mod tests { use super::*; diff --git a/rust/obs-build/src/plugins.rs b/rust/obs-build/src/plugins.rs index aaf4ea4f35..83ef904219 100644 --- a/rust/obs-build/src/plugins.rs +++ b/rust/obs-build/src/plugins.rs @@ -370,6 +370,19 @@ pub fn build_source( finish(build, &root, library) } -pub fn build_vst(_build: &NativeBuild, _root: &Path, _core: &Path) -> Result { - Err("Qt VST module build is not implemented".into()) +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/qt.rs b/rust/obs-build/src/qt.rs new file mode 100644 index 0000000000..66d116ef1a --- /dev/null +++ b/rust/obs-build/src/qt.rs @@ -0,0 +1,52 @@ +//! 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 { + println!("cargo:rerun-if-env-changed=OBS_QT_MOC"); + println!("cargo:rerun-if-changed={}", header.display()); + let tool = if let Some(path) = std::env::var_os("OBS_QT_MOC") { + PathBuf::from(path) + } else { + PathBuf::from(pkg_config::get_variable("Qt6Core", "libexecdir").map_err(|e| e.to_string())?) + .join("moc") + }; + let header = header.canonicalize().map_err(|e| e.to_string())?; + let mut command = Command::new(tool); + 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}"), + }); + } + let result = command + .arg(&header) + .output() + .map_err(|e| format!("execute Qt moc: {e}"))?; + if !result.status.success() { + return Err(format!( + "Qt moc {} failed: {}", + header.display(), + String::from_utf8_lossy(&result.stderr) + )); + } + if result.stdout.is_empty() { + return Err(format!("Qt moc produced no code for {}", header.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(result.stdout.as_slice()) { + std::fs::write(output, result.stdout).map_err(|e| e.to_string())?; + } + library.sources.push(output.into()); + Ok(output.into()) +} diff --git a/rust/obs-build/tests/libobs.rs b/rust/obs-build/tests/libobs.rs index a590670675..bb6aae8ef2 100644 --- a/rust/obs-build/tests/libobs.rs +++ b/rust/obs-build/tests/libobs.rs @@ -80,6 +80,11 @@ fn c_and_rust_twins_preserve_public_data_lifecycle_and_module_apis() { modules.push(plugins::build_vst(&build, &root, &libraries.reference).unwrap()); frontend::build_api(&build, &root, &libraries.reference).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 ffmpeg = None; if std::env::var_os("OBS_BUILD_RECORD").is_some() { modules.push(plugins::build_x264(&build, &root, &libraries.reference).unwrap()); From bb27ac1b92b3a843fbf41b05a3b00f02965e4118 Mon Sep 17 00:00:00 2001 From: Zach Vorhies Date: Sat, 17 Oct 2026 14:06:23 -0700 Subject: [PATCH 23/88] test(build): require separate C and C++ target flags --- rust/obs-build/src/lib.rs | 2 ++ rust/obs-build/tests/native.rs | 28 ++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/rust/obs-build/src/lib.rs b/rust/obs-build/src/lib.rs index e4106beff1..1c3c31de3e 100644 --- a/rust/obs-build/src/lib.rs +++ b/rust/obs-build/src/lib.rs @@ -24,6 +24,8 @@ pub struct SharedLibrary { pub unity: bool, 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, } diff --git a/rust/obs-build/tests/native.rs b/rust/obs-build/tests/native.rs index 12ff0cc9c2..bbe70ff055 100644 --- a/rust/obs-build/tests/native.rs +++ b/rust/obs-build/tests/native.rs @@ -183,3 +183,31 @@ fn deploying_mux_helper_in_place_preserves_its_contents() { 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() + ); +} From 0b1720284504d3b9de72825dace3286e33ce7bf8 Mon Sep 17 00:00:00 2001 From: Zach Vorhies Date: Sat, 17 Oct 2026 14:07:28 -0700 Subject: [PATCH 24/88] feat(build): isolate C and C++ compiler options for mixed targets --- docs/rust-port/cc-build.md | 10 ++++++++++ rust/obs-build/src/lib.rs | 5 +++++ rust/obs-build/src/platform/mod.rs | 14 +++++++++----- 3 files changed, 24 insertions(+), 5 deletions(-) diff --git a/docs/rust-port/cc-build.md b/docs/rust-port/cc-build.md index 8263b9378f..e792ae37bd 100644 --- a/docs/rust-port/cc-build.md +++ b/docs/rust-port/cc-build.md @@ -226,3 +226,13 @@ Enable `OBS_BUILD_QT=1` to build the real VST module and frontend API. Both core 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. diff --git a/rust/obs-build/src/lib.rs b/rust/obs-build/src/lib.rs index 1c3c31de3e..1911412d35 100644 --- a/rust/obs-build/src/lib.rs +++ b/rust/obs-build/src/lib.rs @@ -205,6 +205,11 @@ impl NativeBuild { 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/platform/mod.rs b/rust/obs-build/src/platform/mod.rs index 85e54138c9..2f9fba0066 100644 --- a/rust/obs-build/src/platform/mod.rs +++ b/rust/obs-build/src/platform/mod.rs @@ -142,7 +142,14 @@ pub fn configure_libobs_variant( pub fn configure_module(target: &str, library: &mut crate::SharedLibrary) -> Result<(), String> { if target.contains("linux") { library.file_name = Some(format!("{}.so", library.name)); - for flag in ["-std=gnu17", "-fno-strict-aliasing", "-fvisibility=hidden"] { + 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()); } @@ -429,10 +436,7 @@ pub fn configure_cpp_module( ) -> Result<(), String> { configure_module(target, library)?; library - .compile_options - .retain(|flag| !flag.starts_with("-std=")); - library - .compile_options + .cpp_compile_options .extend(["-std=gnu++17", "-fvisibility-inlines-hidden"].map(String::from)); Ok(()) } From 7617797692b9c74045655c1911cb5952a0c36615 Mon Sep 17 00:00:00 2001 From: Zach Vorhies Date: Sat, 17 Oct 2026 14:08:14 -0700 Subject: [PATCH 25/88] test(build): require Qt UI resources and real spinbox widgets --- rust/obs-build/src/frontend.rs | 8 +++ rust/obs-build/src/qt.rs | 12 +++++ rust/obs-build/tests/libobs.rs | 3 ++ rust/obs-build/tests/libobs/qt.rs | 81 +++++++++++++++++++++++++++++++ 4 files changed, 104 insertions(+) create mode 100644 rust/obs-build/tests/libobs/qt.rs diff --git a/rust/obs-build/src/frontend.rs b/rust/obs-build/src/frontend.rs index dc4c7b3f74..a39426e875 100644 --- a/rust/obs-build/src/frontend.rs +++ b/rust/obs-build/src/frontend.rs @@ -28,3 +28,11 @@ pub fn build_api(build: &NativeBuild, root: &Path, core: &Path) -> Result Result<(), String> { + Err("Qt spinbox build is not implemented".into()) +} diff --git a/rust/obs-build/src/qt.rs b/rust/obs-build/src/qt.rs index 66d116ef1a..ddeac1c7ce 100644 --- a/rust/obs-build/src/qt.rs +++ b/rust/obs-build/src/qt.rs @@ -50,3 +50,15 @@ pub fn moc(library: &mut SharedLibrary, header: &Path, output: &Path) -> Result< library.sources.push(output.into()); Ok(output.into()) } + +pub fn uic(_library: &mut SharedLibrary, _form: &Path, _output: &Path) -> Result { + Err("Qt UI generation is not implemented".into()) +} + +pub fn rcc( + _library: &mut SharedLibrary, + _resources: &Path, + _output: &Path, +) -> Result { + Err("Qt resource generation is not implemented".into()) +} diff --git a/rust/obs-build/tests/libobs.rs b/rust/obs-build/tests/libobs.rs index bb6aae8ef2..391e01f415 100644 --- a/rust/obs-build/tests/libobs.rs +++ b/rust/obs-build/tests/libobs.rs @@ -1,6 +1,8 @@ //! Opt-in integration against real native dependencies and libobs-rust. use obs_build::{NativeBuild, frontend, graphics, libobs, plugins}; use std::{ffi::c_void, path::PathBuf}; +#[path = "libobs/qt.rs"] +mod qt; #[path = "libobs/render.rs"] mod render; @@ -77,6 +79,7 @@ fn c_and_rust_twins_preserve_public_data_lifecycle_and_module_apis() { ); } let frontend = std::env::var_os("OBS_BUILD_QT").map(|_| { + qt::exercise(&build, &root); modules.push(plugins::build_vst(&build, &root, &libraries.reference).unwrap()); frontend::build_api(&build, &root, &libraries.reference).unwrap() }); 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; +} +"#; From d523550754f9cf06c94985cce0f1da867c62035a Mon Sep 17 00:00:00 2001 From: Zach Vorhies Date: Sat, 17 Oct 2026 14:11:05 -0700 Subject: [PATCH 26/88] feat(build): generate Qt UI resources and compile shared widgets --- docs/rust-port/cc-build.md | 16 +++++ rust/obs-build/src/frontend.rs | 27 +++++-- rust/obs-build/src/platform/mod.rs | 18 ++++- rust/obs-build/src/qt.rs | 109 ++++++++++++++++++++--------- 4 files changed, 133 insertions(+), 37 deletions(-) diff --git a/docs/rust-port/cc-build.md b/docs/rust-port/cc-build.md index e792ae37bd..92df52e05c 100644 --- a/docs/rust-port/cc-build.md +++ b/docs/rust-port/cc-build.md @@ -236,3 +236,19 @@ 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. diff --git a/rust/obs-build/src/frontend.rs b/rust/obs-build/src/frontend.rs index a39426e875..9acf5a2273 100644 --- a/rust/obs-build/src/frontend.rs +++ b/rust/obs-build/src/frontend.rs @@ -29,10 +29,29 @@ pub fn build_api(build: &NativeBuild, root: &Path, core: &Path) -> Result Result<(), String> { - Err("Qt spinbox build is not implemented".into()) + 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(()) } diff --git a/rust/obs-build/src/platform/mod.rs b/rust/obs-build/src/platform/mod.rs index 2f9fba0066..627e235fec 100644 --- a/rust/obs-build/src/platform/mod.rs +++ b/rust/obs-build/src/platform/mod.rs @@ -430,14 +430,30 @@ pub fn configure_source( 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_cpp_module( target: &str, library: &mut crate::SharedLibrary, ) -> Result<(), String> { configure_module(target, library)?; + configure_cpp17(target, library); library .cpp_compile_options - .extend(["-std=gnu++17", "-fvisibility-inlines-hidden"].map(String::from)); + .push("-fvisibility-inlines-hidden".into()); Ok(()) } diff --git a/rust/obs-build/src/qt.rs b/rust/obs-build/src/qt.rs index ddeac1c7ce..1a61839e67 100644 --- a/rust/obs-build/src/qt.rs +++ b/rust/obs-build/src/qt.rs @@ -8,16 +8,7 @@ use std::{ /// 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 { - println!("cargo:rerun-if-env-changed=OBS_QT_MOC"); - println!("cargo:rerun-if-changed={}", header.display()); - let tool = if let Some(path) = std::env::var_os("OBS_QT_MOC") { - PathBuf::from(path) - } else { - PathBuf::from(pkg_config::get_variable("Qt6Core", "libexecdir").map_err(|e| e.to_string())?) - .join("moc") - }; - let header = header.canonicalize().map_err(|e| e.to_string())?; - let mut command = Command::new(tool); + let mut command = command("moc")?; for directory in &library.include_dirs { command.arg("-I").arg(directory); } @@ -27,38 +18,92 @@ pub fn moc(library: &mut SharedLibrary, header: &Path, output: &Path) -> Result< 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.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(&header) + .arg(&input) .output() - .map_err(|e| format!("execute Qt moc: {e}"))?; + .map_err(|e| format!("execute Qt tool: {e}"))?; if !result.status.success() { return Err(format!( - "Qt moc {} failed: {}", - header.display(), + "Qt tool {command:?} failed: {}", String::from_utf8_lossy(&result.stderr) )); } - if result.stdout.is_empty() { - return Err(format!("Qt moc produced no code for {}", header.display())); + 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(result.stdout.as_slice()) { - std::fs::write(output, result.stdout).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())?; } - library.sources.push(output.into()); - Ok(output.into()) -} - -pub fn uic(_library: &mut SharedLibrary, _form: &Path, _output: &Path) -> Result { - Err("Qt UI generation is not implemented".into()) -} - -pub fn rcc( - _library: &mut SharedLibrary, - _resources: &Path, - _output: &Path, -) -> Result { - Err("Qt resource generation is not implemented".into()) + Ok(()) } From b207b1fd3f2673154c3561e5968d477175cfec79 Mon Sep 17 00:00:00 2001 From: Zach Vorhies Date: Sat, 17 Oct 2026 14:15:10 -0700 Subject: [PATCH 27/88] test(build): require a Cargo-built OBS frontend executable --- frontend/build/cargo-sources.json | 343 ++++++++++++++++++++++++++++++ rust/obs-build/src/frontend.rs | 10 + rust/obs-build/tests/libobs.rs | 33 ++- 3 files changed, 385 insertions(+), 1 deletion(-) create mode 100644 frontend/build/cargo-sources.json diff --git a/frontend/build/cargo-sources.json b/frontend/build/cargo-sources.json new file mode 100644 index 0000000000..0dbb9a348e --- /dev/null +++ b/frontend/build/cargo-sources.json @@ -0,0 +1,343 @@ +{ + "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" + ], + "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/rust/obs-build/src/frontend.rs b/rust/obs-build/src/frontend.rs index 9acf5a2273..dfaf204c92 100644 --- a/rust/obs-build/src/frontend.rs +++ b/rust/obs-build/src/frontend.rs @@ -55,3 +55,13 @@ pub fn add_spinbox( } Ok(()) } + +pub fn build_application( + _build: &NativeBuild, + _root: &Path, + _core: &Path, + _api: &Path, + _gpu_status_archive: &Path, +) -> Result { + Err("full frontend application build is not implemented".into()) +} diff --git a/rust/obs-build/tests/libobs.rs b/rust/obs-build/tests/libobs.rs index 391e01f415..8cd5fd7ef1 100644 --- a/rust/obs-build/tests/libobs.rs +++ b/rust/obs-build/tests/libobs.rs @@ -78,7 +78,9 @@ fn c_and_rust_twins_preserve_public_data_lifecycle_and_module_apis() { .unwrap(), ); } - let frontend = std::env::var_os("OBS_BUILD_QT").map(|_| { + let frontend = (std::env::var_os("OBS_BUILD_QT").is_some() + || std::env::var_os("OBS_BUILD_APP").is_some()) + .then(|| { qt::exercise(&build, &root); modules.push(plugins::build_vst(&build, &root, &libraries.reference).unwrap()); frontend::build_api(&build, &root, &libraries.reference).unwrap() @@ -88,6 +90,35 @@ fn c_and_rust_twins_preserve_public_data_lifecycle_and_module_apis() { { assert_eq!(exports(frontend), exports(&PathBuf::from(reference))); } + if std::env::var_os("OBS_BUILD_APP").is_some() { + 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( + &build, + &root, + &libraries.reference, + frontend.as_ref().unwrap(), + &gpu_archive, + ) + .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() + ); + } let mut ffmpeg = None; if std::env::var_os("OBS_BUILD_RECORD").is_some() { modules.push(plugins::build_x264(&build, &root, &libraries.reference).unwrap()); From a1fccfd22d788cf2815b4a5f52654b954b4deac4 Mon Sep 17 00:00:00 2001 From: Zach Vorhies Date: Sat, 17 Oct 2026 14:27:33 -0700 Subject: [PATCH 28/88] feat(build): compile and link the Linux OBS frontend through cc --- docs/rust-port/cc-build.md | 25 ++++ frontend/build/cargo-sources.json | 4 +- rust/obs-build/src/deps.rs | 26 ++++ rust/obs-build/src/frontend.rs | 202 ++++++++++++++++++++++++++++- rust/obs-build/src/lib.rs | 15 ++- rust/obs-build/src/platform/mod.rs | 56 ++++++++ rust/obs-build/src/plugins.rs | 21 +-- rust/obs-build/src/qt.rs | 45 +++++++ 8 files changed, 364 insertions(+), 30 deletions(-) create mode 100644 rust/obs-build/src/deps.rs diff --git a/docs/rust-port/cc-build.md b/docs/rust-port/cc-build.md index 92df52e05c..daad64fed0 100644 --- a/docs/rust-port/cc-build.md +++ b/docs/rust-port/cc-build.md @@ -252,3 +252,28 @@ 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 +`OBS-Studio-Rust 0.1.0 (based on OBS 33.0.0-cc-build)` through `--version`. +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. diff --git a/frontend/build/cargo-sources.json b/frontend/build/cargo-sources.json index 0dbb9a348e..76f2fecfbf 100644 --- a/frontend/build/cargo-sources.json +++ b/frontend/build/cargo-sources.json @@ -285,7 +285,9 @@ "frontend/plugin-manager/PluginManager.hpp", "frontend/build/frontend.plugin-manager-pluginmanagerwindow+.hpp.cpp", "frontend/plugin-manager/PluginManagerWindow.hpp", - "frontend/plugin-manager/PluginModuleLoader.hpp" + "frontend/plugin-manager/PluginModuleLoader.hpp", + "frontend/forms/OBSBasicTransform.ui", + "frontend/forms/OBSLogViewer.ui" ], "linux": [ "frontend/build/frontend.linux+.hpp.cpp", 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 index dfaf204c92..70ff7cb54c 100644 --- a/rust/obs-build/src/frontend.rs +++ b/rust/obs-build/src/frontend.rs @@ -56,12 +56,202 @@ pub fn add_spinbox( Ok(()) } +/// Build the Linux frontend graph without browser panels; broader platform and +/// feature configurations remain under conversion. pub fn build_application( - _build: &NativeBuild, - _root: &Path, - _core: &Path, - _api: &Path, - _gpu_status_archive: &Path, + build: &NativeBuild, + root: &Path, + core: &Path, + api: &Path, + gpu_status_archive: &Path, ) -> Result { - Err("full frontend application build is not implemented".into()) + 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 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)?; + 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) +} + +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(()) +} + +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/lib.rs b/rust/obs-build/src/lib.rs index 1911412d35..bdd814650a 100644 --- a/rust/obs-build/src/lib.rs +++ b/rust/obs-build/src/lib.rs @@ -6,6 +6,7 @@ use std::{fs, path::PathBuf}; +mod deps; pub mod frontend; pub mod graphics; pub mod libobs; @@ -199,10 +200,18 @@ impl NativeBuild { // 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) - .includes(&library.include_dirs); + .cargo_metadata(true); + let mut includes = std::collections::HashSet::new(); + for directory in &library.include_dirs { + if includes.insert(directory) { + compiler.include(directory); + } + } + let mut definitions = std::collections::HashSet::new(); for (name, value) in &library.definitions { - compiler.define(name, value.as_deref()); + if definitions.insert((name, value)) { + compiler.define(name, value.as_deref()); + } } compiler.flags(&library.compile_options); compiler.flags(if cpp { diff --git a/rust/obs-build/src/platform/mod.rs b/rust/obs-build/src/platform/mod.rs index 627e235fec..c57aee8635 100644 --- a/rust/obs-build/src/platform/mod.rs +++ b/rust/obs-build/src/platform/mod.rs @@ -479,6 +479,62 @@ pub fn configure_vst( 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-plugins/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(()) +} + #[cfg(test)] mod tests { use super::*; diff --git a/rust/obs-build/src/plugins.rs b/rust/obs-build/src/plugins.rs index 83ef904219..978112ee2e 100644 --- a/rust/obs-build/src/plugins.rs +++ b/rust/obs-build/src/plugins.rs @@ -1,5 +1,5 @@ //! Native OBS module builds using the same engine as bundled libobs. -use crate::{NativeBuild, SharedLibrary, libobs::add_package}; +use crate::{NativeBuild, SharedLibrary, deps::shared_archive, libobs::add_package}; use std::path::{Path, PathBuf}; #[derive(Debug)] @@ -305,25 +305,6 @@ pub fn build_ffmpeg( }) } -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) -} - /// Built-in source and service modules with independent optional features. #[derive(Clone, Copy, Debug)] pub enum SourceModule { diff --git a/rust/obs-build/src/qt.rs b/rust/obs-build/src/qt.rs index 1a61839e67..b2c7eb664d 100644 --- a/rust/obs-build/src/qt.rs +++ b/rust/obs-build/src/qt.rs @@ -31,6 +31,7 @@ pub fn uic(library: &mut SharedLibrary, form: &Path, output: &Path) -> Result Result<(), 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(()) +} From 3b07ce787f69cad6db235d67d9e1815bc8be18cf Mon Sep 17 00:00:00 2001 From: Zach Vorhies Date: Sat, 17 Oct 2026 14:30:37 -0700 Subject: [PATCH 29/88] test(build): require the real frontend GUI to start and close --- rust/obs-build/tests/libobs.rs | 5 +++++ rust/obs-build/tests/libobs/application.rs | 6 ++++++ 2 files changed, 11 insertions(+) create mode 100644 rust/obs-build/tests/libobs/application.rs diff --git a/rust/obs-build/tests/libobs.rs b/rust/obs-build/tests/libobs.rs index 8cd5fd7ef1..90622bbb86 100644 --- a/rust/obs-build/tests/libobs.rs +++ b/rust/obs-build/tests/libobs.rs @@ -3,6 +3,8 @@ use obs_build::{NativeBuild, frontend, graphics, libobs, plugins}; use std::{ffi::c_void, path::PathBuf}; #[path = "libobs/qt.rs"] mod qt; +#[path = "libobs/application.rs"] +mod application; #[path = "libobs/render.rs"] mod render; @@ -23,6 +25,9 @@ fn c_and_rust_twins_preserve_public_data_lifecycle_and_module_apis() { return; } let root = PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("../.."); + if std::env::var_os("OBS_BUILD_APP_GUI").is_some() { + application::exercise(&root).unwrap(); + } 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"), diff --git a/rust/obs-build/tests/libobs/application.rs b/rust/obs-build/tests/libobs/application.rs new file mode 100644 index 0000000000..0bc4e8431a --- /dev/null +++ b/rust/obs-build/tests/libobs/application.rs @@ -0,0 +1,6 @@ +//! Full frontend runtime validation with an isolated profile and display. +use std::path::Path; + +pub fn exercise(_root: &Path) -> Result<(), String> { + Err("frontend GUI runtime harness is not implemented".into()) +} From 9d694ab7207f5656e56d30bd277bae377ef70366 Mon Sep 17 00:00:00 2001 From: Zach Vorhies Date: Sat, 17 Oct 2026 14:42:15 -0700 Subject: [PATCH 30/88] test(build): run the staged OBS GUI with both native cores --- docs/rust-port/cc-build.md | 27 ++ rust/obs-build/src/libobs.rs | 8 +- rust/obs-build/src/platform/mod.rs | 2 +- rust/obs-build/tests/libobs.rs | 81 ++++-- rust/obs-build/tests/libobs/application.rs | 240 +++++++++++++++++- .../tests/libobs/application_probe.py | 118 +++++++++ rust/obs-build/tests/libobs/render.rs | 2 +- 7 files changed, 449 insertions(+), 29 deletions(-) create mode 100644 rust/obs-build/tests/libobs/application_probe.py diff --git a/docs/rust-port/cc-build.md b/docs/rust-port/cc-build.md index daad64fed0..cd0dda8086 100644 --- a/docs/rust-port/cc-build.md +++ b/docs/rust-port/cc-build.md @@ -277,3 +277,30 @@ 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, GUI recording, browser/websocket features, remaining modules/platforms, +full test tiers and controlled performance measurements are still required. diff --git a/rust/obs-build/src/libobs.rs b/rust/obs-build/src/libobs.rs index 4e58ac87fd..397c046eb0 100644 --- a/rust/obs-build/src/libobs.rs +++ b/rust/obs-build/src/libobs.rs @@ -201,9 +201,11 @@ pub(crate) fn add_package( .probe(package) .map_err(|e| format!("native dependency {package}: {e}"))?; library.include_dirs.extend(dependency.include_paths); - for (name, value) in dependency.defines { - library.definitions.push((name, value)); - } + // 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 diff --git a/rust/obs-build/src/platform/mod.rs b/rust/obs-build/src/platform/mod.rs index c57aee8635..0c840c91c3 100644 --- a/rust/obs-build/src/platform/mod.rs +++ b/rust/obs-build/src/platform/mod.rs @@ -519,7 +519,7 @@ pub fn configure_application( ("OBS_PLATFORM_DATA_PATH", "share/"), ( "OBS_PLATFORM_PLUGIN_MODULE_PATH", - "/usr/local/lib64/obs-plugins/plugins", + "/usr/local/lib64/obs-modules/plugins", ), ( "OBS_PLATFORM_PLUGIN_DATA_PATH", diff --git a/rust/obs-build/tests/libobs.rs b/rust/obs-build/tests/libobs.rs index 90622bbb86..83d8cd9d1a 100644 --- a/rust/obs-build/tests/libobs.rs +++ b/rust/obs-build/tests/libobs.rs @@ -1,10 +1,10 @@ //! Opt-in integration against real native dependencies and libobs-rust. use obs_build::{NativeBuild, frontend, graphics, libobs, plugins}; use std::{ffi::c_void, path::PathBuf}; -#[path = "libobs/qt.rs"] -mod qt; #[path = "libobs/application.rs"] mod application; +#[path = "libobs/qt.rs"] +mod qt; #[path = "libobs/render.rs"] mod render; @@ -25,9 +25,6 @@ fn c_and_rust_twins_preserve_public_data_lifecycle_and_module_apis() { return; } let root = PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("../.."); - if std::env::var_os("OBS_BUILD_APP_GUI").is_some() { - application::exercise(&root).unwrap(); - } 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"), @@ -42,6 +39,29 @@ fn c_and_rust_twins_preserve_public_data_lifecycle_and_module_apis() { }; let options = libobs::Options { 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() }; let libraries = libobs::build_pair(&build, &root, &options, &archive).unwrap(); @@ -55,7 +75,7 @@ fn c_and_rust_twins_preserve_public_data_lifecycle_and_module_apis() { plugins::build_transitions(&build, &root, &libraries.reference).unwrap(), plugins::build_filters(&build, &root, &libraries.reference, &filters).unwrap(), ]; - if std::env::var_os("OBS_BUILD_SOURCES").is_some() { + if enabled("OBS_BUILD_SOURCES") { for source in [ plugins::SourceModule::Image, plugins::SourceModule::Text, @@ -72,7 +92,7 @@ fn c_and_rust_twins_preserve_public_data_lifecycle_and_module_apis() { .push(plugins::build_source(&build, &root, &libraries.reference, source).unwrap()); } } - if std::env::var_os("OBS_BUILD_PIPEWIRE").is_some() { + if enabled("OBS_BUILD_PIPEWIRE") { modules.push( plugins::build_source( &build, @@ -83,9 +103,7 @@ fn c_and_rust_twins_preserve_public_data_lifecycle_and_module_apis() { .unwrap(), ); } - let frontend = (std::env::var_os("OBS_BUILD_QT").is_some() - || std::env::var_os("OBS_BUILD_APP").is_some()) - .then(|| { + let frontend = (enabled("OBS_BUILD_QT") || enabled("OBS_BUILD_APP")).then(|| { qt::exercise(&build, &root); modules.push(plugins::build_vst(&build, &root, &libraries.reference).unwrap()); frontend::build_api(&build, &root, &libraries.reference).unwrap() @@ -95,7 +113,8 @@ fn c_and_rust_twins_preserve_public_data_lifecycle_and_module_apis() { { assert_eq!(exports(frontend), exports(&PathBuf::from(reference))); } - if std::env::var_os("OBS_BUILD_APP").is_some() { + 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"), @@ -123,9 +142,10 @@ fn c_and_rust_twins_preserve_public_data_lifecycle_and_module_apis() { "OBS application version: {}", String::from_utf8_lossy(&output.stdout).trim() ); + application = Some(executable); } let mut ffmpeg = None; - if std::env::var_os("OBS_BUILD_RECORD").is_some() { + 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()); @@ -154,15 +174,30 @@ fn c_and_rust_twins_preserve_public_data_lifecycle_and_module_apis() { } else { std::env::current_exe().unwrap() }; - let wants_graphics = std::env::var_os("OBS_BUILD_RENDER").is_some() - || std::env::var_os("OBS_BUILD_RECORD").is_some() - || std::env::var_os("OBS_BUILD_SOURCES").is_some() - || std::env::var_os("OBS_BUILD_PIPEWIRE").is_some(); + let wants_graphics = enabled("OBS_BUILD_RENDER") + || enabled("OBS_BUILD_RECORD") + || enabled("OBS_BUILD_SOURCES") + || enabled("OBS_BUILD_PIPEWIRE"); 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 enabled("OBS_BUILD_APP_GUI") { + 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(), + modules: &modules, + }, + &[&libraries.reference, &libraries.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. @@ -195,7 +230,7 @@ fn c_and_rust_twins_preserve_public_data_lifecycle_and_module_apis() { command.env("OBS_BUILD_TEST_RENDERER", renderer); command.env("OBS_BUILD_TEST_PROBE", probe.as_ref().unwrap()); } - let recording = std::env::var_os("OBS_BUILD_RECORD").map(|_| { + let recording = enabled("OBS_BUILD_RECORD").then(|| { let variant = path .parent() .unwrap() @@ -327,7 +362,7 @@ fn exercise(path: &std::path::Path, modules: &[plugins::Module], hevc: bool) { initialize( renderer.as_ptr(), data_path.as_ptr(), - std::env::var_os("OBS_BUILD_RECORD").is_some() + enabled("OBS_BUILD_RECORD") ), 0 ); @@ -354,7 +389,7 @@ fn exercise(path: &std::path::Path, modules: &[plugins::Module], hevc: bool) { (b"obs_enum_filter_types".as_slice(), "noise_suppress_filter"), (b"obs_enum_filter_types".as_slice(), "gain_filter"), ]; - if std::env::var_os("OBS_BUILD_RECORD").is_some() { + if enabled("OBS_BUILD_RECORD") { expected_types.extend([ (b"obs_enum_encoder_types".as_slice(), "obs_x264"), (b"obs_enum_encoder_types".as_slice(), "ffmpeg_aac"), @@ -373,7 +408,7 @@ fn exercise(path: &std::path::Path, modules: &[plugins::Module], hevc: bool) { "exactly one SRT shared library must be loaded" ); } - if std::env::var_os("OBS_BUILD_SOURCES").is_some() { + 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"), @@ -390,7 +425,7 @@ fn exercise(path: &std::path::Path, modules: &[plugins::Module], hevc: bool) { (b"obs_enum_service_types".as_slice(), "rtmp_custom"), ]); } - if std::env::var_os("OBS_BUILD_QT").is_some() { + if enabled("OBS_BUILD_QT") { expected_types.push((b"obs_enum_filter_types".as_slice(), "vst_filter")); } for (symbol, expected) in expected_types { @@ -527,3 +562,7 @@ fn verify_recording(path: &std::path::Path) { ); 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() +} diff --git a/rust/obs-build/tests/libobs/application.rs b/rust/obs-build/tests/libobs/application.rs index 0bc4e8431a..6a56b99c0c 100644 --- a/rust/obs-build/tests/libobs/application.rs +++ b/rust/obs-build/tests/libobs/application.rs @@ -1,6 +1,240 @@ //! Full frontend runtime validation with an isolated profile and display. -use std::path::Path; +use obs_build::{NativeBuild, SharedLibrary, plugins}; +use std::path::{Path, PathBuf}; -pub fn exercise(_root: &Path) -> Result<(), String> { - Err("frontend GUI runtime harness is not implemented".into()) +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 modules: &'a [plugins::Module], } + +pub fn exercise(inputs: Inputs<'_>, cores: &[&Path]) -> Result<(), String> { + let inspector = inspector(inputs.build)?; + for core in cores { + // 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)?; + 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 { + 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())?; + // 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> { + std::fs::copy(source, target) + .map(|_| ()) + .map_err(|e| format!("copy {} to {}: {e}", source.display(), target.display())) +} + +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..26a918460d --- /dev/null +++ b/rust/obs-build/tests/libobs/application_probe.py @@ -0,0 +1,118 @@ +#!/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 json +import os +from pathlib import Path +import select +import subprocess +import time +import uuid + + +def profile(runtime: Path) -> Path: + config = runtime / "user-config/obs-studio-rust" + config.mkdir(parents=True) + (config / "global.ini").write_text("[General]\nLastVersion=4294967295\n") + (config / "user.ini").write_text( + "[General]\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" + ) + 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) + (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], + })) + 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) + 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) + app = subprocess.Popen([str(runtime / "bin/obs-studio-rust"), "--multi", "--only-bundled-plugins", + "--disable-shutdown-check", "--disable-updater", "--disable-missing-files-check", + "--unfiltered_log"], 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"==== Startup complete" 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" + assert b"Native white" in log, "saved color source was not restored" + 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" + 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) + + +if __name__ == "__main__": + main() diff --git a/rust/obs-build/tests/libobs/render.rs b/rust/obs-build/tests/libobs/render.rs index a9c85c0892..c39fd944be 100644 --- a/rust/obs-build/tests/libobs/render.rs +++ b/rust/obs-build/tests/libobs/render.rs @@ -160,7 +160,7 @@ EXPORT int obs_fixture_render(const char *record_path, const char *output_id) os_sleep_ms(10); obs_remove_raw_video_callback(receive_frame, NULL); int source_status = 0; - if (getenv("OBS_BUILD_SOURCES")) { + if (getenv("OBS_BUILD_SOURCES") || getenv("OBS_BUILD_APP_GUI")) { obs_data_t *settings = obs_data_create(); obs_data_set_int(settings, "width", 64); obs_data_set_int(settings, "height", 64); From 4766a0e97136eac21e6ef9ae606f3d75bb05e38d Mon Sep 17 00:00:00 2001 From: Zach Vorhies Date: Sat, 17 Oct 2026 14:42:51 -0700 Subject: [PATCH 31/88] test(build): require an actual frontend recording --- rust/obs-build/tests/libobs/application_probe.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/rust/obs-build/tests/libobs/application_probe.py b/rust/obs-build/tests/libobs/application_probe.py index 26a918460d..35f90a6e67 100644 --- a/rust/obs-build/tests/libobs/application_probe.py +++ b/rust/obs-build/tests/libobs/application_probe.py @@ -100,6 +100,9 @@ def main() -> None: 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_APP_RECORD"): + recordings = list((runtime / "recordings").glob("*.mkv")) + assert len(recordings) == 1, "frontend did not create the requested recording" print(f"OBS normal window, staged libraries/modules, saved scene, screenshot and clean shutdown: {runtime}") finally: if not drained: From 74486171e1c789517a315c1c8b84b822543c8666 Mon Sep 17 00:00:00 2001 From: Zach Vorhies Date: Sat, 17 Oct 2026 14:44:44 -0700 Subject: [PATCH 32/88] test(build): validate recording through the real OBS frontend --- docs/rust-port/cc-build.md | 15 +++++- .../tests/libobs/application_probe.py | 50 +++++++++++++++++-- 2 files changed, 59 insertions(+), 6 deletions(-) diff --git a/docs/rust-port/cc-build.md b/docs/rust-port/cc-build.md index cd0dda8086..2e3c5fae7a 100644 --- a/docs/rust-port/cc-build.md +++ b/docs/rust-port/cc-build.md @@ -302,5 +302,18 @@ 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, GUI recording, browser/websocket features, remaining modules/platforms, +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. diff --git a/rust/obs-build/tests/libobs/application_probe.py b/rust/obs-build/tests/libobs/application_probe.py index 35f90a6e67..53c8a3af41 100644 --- a/rust/obs-build/tests/libobs/application_probe.py +++ b/rust/obs-build/tests/libobs/application_probe.py @@ -28,6 +28,16 @@ def profile(runtime: Path) -> Path: "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() + with (selected / "basic.ini").open("a") as output: + output.write( + "[Output]\nMode=Simple\n[SimpleOutput]\n" + f"FilePath={recordings}\nRecFormat2=mkv\nRecQuality=Small\n" + "RecEncoder=x264\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()), @@ -59,9 +69,12 @@ def main() -> None: 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) - app = subprocess.Popen([str(runtime / "bin/obs-studio-rust"), "--multi", "--only-bundled-plugins", - "--disable-shutdown-check", "--disable-updater", "--disable-missing-files-check", - "--unfiltered_log"], env=env, cwd=runtime, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) + recording = bool(os.environ.get("OBS_BUILD_APP_RECORD")) + command = [str(runtime / "bin/obs-studio-rust"), "--multi", "--only-bundled-plugins", + "--disable-shutdown-check", "--disable-updater", "--disable-missing-files-check", "--unfiltered_log"] + if recording: + command.append("--startrecording") + app = subprocess.Popen(command, env=env, cwd=runtime, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) log = bytearray() drained = False try: @@ -74,7 +87,7 @@ def main() -> None: chunk = os.read(app.stdout.fileno(), 65536) log.extend(chunk) (runtime / "application.log").write_bytes(log) - if b"==== Startup complete" in log: + if b"==== Startup complete" in log and (not 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 @@ -88,6 +101,10 @@ def main() -> None: 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" 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) @@ -100,9 +117,10 @@ def main() -> None: 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_APP_RECORD"): + if recording: 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: @@ -117,5 +135,27 @@ def main() -> None: (runtime / "application.log").write_bytes(log) +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}") + + if __name__ == "__main__": main() From 056b73db0da9cce01c126405018d2e1d735b8df1 Mon Sep 17 00:00:00 2001 From: Zach Vorhies Date: Sat, 17 Oct 2026 14:46:02 -0700 Subject: [PATCH 33/88] test(build): require NVENC plugin twins and capability helper --- rust/obs-build/src/plugins.rs | 17 +++++++++++++++++ rust/obs-build/tests/libobs.rs | 18 ++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/rust/obs-build/src/plugins.rs b/rust/obs-build/src/plugins.rs index 978112ee2e..07e8238cca 100644 --- a/rust/obs-build/src/plugins.rs +++ b/rust/obs-build/src/plugins.rs @@ -8,6 +8,23 @@ pub struct Module { 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 { + Err("NVENC native graph is not implemented".into()) +} + #[derive(Clone, Debug)] pub struct FiltersOptions { pub speexdsp: bool, diff --git a/rust/obs-build/tests/libobs.rs b/rust/obs-build/tests/libobs.rs index 83d8cd9d1a..888c5aed16 100644 --- a/rust/obs-build/tests/libobs.rs +++ b/rust/obs-build/tests/libobs.rs @@ -67,6 +67,24 @@ fn c_and_rust_twins_preserve_public_data_lifecycle_and_module_apis() { let libraries = libobs::build_pair(&build, &root, &options, &archive).unwrap(); assert_ne!(libraries.reference, libraries.with_rust); assert_eq!(exports(&libraries.reference), exports(&libraries.with_rust)); + if std::env::var_os("OBS_BUILD_NVENC").is_some() { + let archive = 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")); + } 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(), From b5078f37de88bb463353abf43537ca65a59544b7 Mon Sep 17 00:00:00 2001 From: Zach Vorhies Date: Sat, 17 Oct 2026 14:53:49 -0700 Subject: [PATCH 34/88] feat(build): build and exercise NVENC plugin twins through cc --- docs/rust-port/cc-build.md | 31 ++++++++++++ rust/obs-build/src/platform/mod.rs | 46 +++++++++++++++++ rust/obs-build/src/plugins.rs | 71 ++++++++++++++++++++++++--- rust/obs-build/tests/libobs.rs | 68 ++++++++++++++++++++----- rust/obs-build/tests/libobs/render.rs | 41 +++++++++++----- 5 files changed, 229 insertions(+), 28 deletions(-) diff --git a/docs/rust-port/cc-build.md b/docs/rust-port/cc-build.md index 2e3c5fae7a..3235bd6d95 100644 --- a/docs/rust-port/cc-build.md +++ b/docs/rust-port/cc-build.md @@ -317,3 +317,34 @@ 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. NVENC discovery/encoding in the staged +GUI, OpenGL texture interoperability, HEVC/AV1 encoding and other platforms still +need validation. diff --git a/rust/obs-build/src/platform/mod.rs b/rust/obs-build/src/platform/mod.rs index 0c840c91c3..e9f3b1caa9 100644 --- a/rust/obs-build/src/platform/mod.rs +++ b/rust/obs-build/src/platform/mod.rs @@ -445,6 +445,52 @@ pub fn configure_cpp17(target: &str, library: &mut crate::SharedLibrary) { } } +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, diff --git a/rust/obs-build/src/plugins.rs b/rust/obs-build/src/plugins.rs index 07e8238cca..764acb542c 100644 --- a/rust/obs-build/src/plugins.rs +++ b/rust/obs-build/src/plugins.rs @@ -16,13 +16,72 @@ pub struct NvencArtifacts { } pub fn build_nvenc_pair( - _build: &NativeBuild, - _root: &Path, - _core: &Path, - _rust_archive: &Path, - _ffmpeg_ids: bool, + build: &NativeBuild, + root: &Path, + core: &Path, + rust_archive: &Path, + ffmpeg_ids: bool, ) -> Result { - Err("NVENC native graph is not implemented".into()) + 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)] diff --git a/rust/obs-build/tests/libobs.rs b/rust/obs-build/tests/libobs.rs index 888c5aed16..c5a85b2162 100644 --- a/rust/obs-build/tests/libobs.rs +++ b/rust/obs-build/tests/libobs.rs @@ -67,8 +67,10 @@ fn c_and_rust_twins_preserve_public_data_lifecycle_and_module_apis() { let libraries = libobs::build_pair(&build, &root, &options, &archive).unwrap(); assert_ne!(libraries.reference, libraries.with_rust); assert_eq!(exports(&libraries.reference), exports(&libraries.with_rust)); - if std::env::var_os("OBS_BUILD_NVENC").is_some() { - let archive = root.join("target/release/libobs_nvenc_plugin.a"); + 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, @@ -84,7 +86,17 @@ fn c_and_rust_twins_preserve_public_data_lifecycle_and_module_apis() { 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(), @@ -182,10 +194,16 @@ fn c_and_rust_twins_preserve_public_data_lifecycle_and_module_apis() { ffmpeg = Some(artifacts); } // Mirror the app layout: the module launches its helper beside the process. - let runner = if let Some(ffmpeg) = &ffmpeg { + let runner = if ffmpeg.is_some() || nvenc.is_some() { let bin = build.output.join("test-bin"); - let helper = ffmpeg.deploy_muxer(&bin).unwrap(); - assert!(helper.is_file()); + std::fs::create_dir_all(&bin).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 runner = bin.join("obs-native-integration"); std::fs::copy(std::env::current_exe().unwrap(), &runner).unwrap(); runner @@ -195,7 +213,8 @@ fn c_and_rust_twins_preserve_public_data_lifecycle_and_module_apis() { let wants_graphics = enabled("OBS_BUILD_RENDER") || enabled("OBS_BUILD_RECORD") || enabled("OBS_BUILD_SOURCES") - || enabled("OBS_BUILD_PIPEWIRE"); + || enabled("OBS_BUILD_PIPEWIRE") + || nvenc.is_some(); let renderer = wants_graphics .then(|| graphics::build_opengl(&build, &root, &libraries.reference, &options).unwrap()); let probe = renderer @@ -223,7 +242,6 @@ fn c_and_rust_twins_preserve_public_data_lifecycle_and_module_apis() { .iter() .map(|module| (&module.library, &module.data)) .collect(); - let serialized = serde_json::to_string(&modules).unwrap(); let outputs: &[(&str, &str)] = if ffmpeg.is_some() { &[("mp4_output", "mp4"), ("ffmpeg_muxer", "mkv")] } else { @@ -233,6 +251,16 @@ fn c_and_rust_twins_preserve_public_data_lifecycle_and_module_apis() { .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); command.env("OBS_BUILD_TEST_OUTPUT_ID", output_id); if let Some(frontend) = &frontend { @@ -295,6 +323,9 @@ fn c_and_rust_twins_preserve_public_data_lifecycle_and_module_apis() { } 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. @@ -357,7 +388,7 @@ fn exercise(path: &std::path::Path, modules: &[plugins::Module], hevc: bool) { .unwrap(); assert!(startup( c"en-US".as_ptr(), - std::ptr::null(), + module_config_path.as_ptr(), std::ptr::null_mut() )); if let Some(probe) = &probe { @@ -407,6 +438,13 @@ fn exercise(path: &std::path::Path, modules: &[plugins::Module], hevc: bool) { (b"obs_enum_filter_types".as_slice(), "noise_suppress_filter"), (b"obs_enum_filter_types".as_slice(), "gain_filter"), ]; + 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") { expected_types.extend([ (b"obs_enum_encoder_types".as_slice(), "obs_x264"), @@ -462,6 +500,9 @@ fn exercise(path: &std::path::Path, modules: &[plugins::Module], hevc: bool) { 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 let Some(probe) = &probe { @@ -548,8 +589,13 @@ fn verify_recording(path: &std::path::Path) { .iter() .find(|stream| stream["codec_name"] == "h264") .expect("missing H.264 track"); - assert_eq!(video["width"], 64); - assert_eq!(video["height"], 64); + 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() diff --git a/rust/obs-build/tests/libobs/render.rs b/rust/obs-build/tests/libobs/render.rs index c39fd944be..9db51c8b12 100644 --- a/rust/obs-build/tests/libobs/render.rs +++ b/rust/obs-build/tests/libobs/render.rs @@ -48,6 +48,7 @@ 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; EXPORT bool obs_fixture_open_display(void) { @@ -66,7 +67,7 @@ static void receive_frame(void *unused, struct video_data *frame) 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] < 64 || frame->data[0][0] != atomic_load(&expected_y)) + 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); } @@ -76,9 +77,13 @@ 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); - obs_data_set_string(settings, "preset", "ultrafast"); - obs_data_set_string(settings, "tune", "zerolatency"); - obs_encoder_t *video = obs_video_encoder_create("obs_x264", "cc-build-video", settings, NULL); + 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); @@ -123,6 +128,11 @@ cleanup: 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 }; @@ -132,8 +142,8 @@ EXPORT int obs_fixture_initialize(const char *renderer, const char *data_path, b struct obs_video_info video = { .graphics_module = renderer, .fps_num = 30, .fps_den = 1, - .base_width = 64, .base_height = 64, - .output_width = 64, .output_height = 64, + .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, @@ -160,14 +170,15 @@ EXPORT int obs_fixture_render(const char *record_path, const char *output_id) 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", 64); - obs_data_set_int(settings, "height", 64); + obs_data_set_int(settings, "width", fixture_width); + obs_data_set_int(settings, "height", fixture_height); obs_data_set_int(settings, "color", 0xFFFFFFFF); - obs_source_t *color = obs_source_create("color_source_v3", "cc-build-white", settings, NULL); + color = obs_source_create("color_source_v3", "cc-build-white", settings, NULL); obs_data_release(settings); - if (!color || obs_source_get_width(color) != 64 || obs_source_get_height(color) != 64) { + 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); @@ -179,11 +190,19 @@ EXPORT int obs_fixture_render(const char *record_path, const char *output_id) obs_remove_raw_video_callback(receive_frame, NULL); blog(LOG_INFO, "cc::Build color source rendered %u white frames", atomic_load(&frames)); } - obs_source_release(color); } 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; From d326a3fe9d03bb0e2d0ea92af4bc549f47b9df18 Mon Sep 17 00:00:00 2001 From: Zach Vorhies Date: Sat, 17 Oct 2026 14:55:15 -0700 Subject: [PATCH 35/88] test(build): require NVENC in the staged GUI runtime --- rust/obs-build/tests/libobs/application_probe.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/rust/obs-build/tests/libobs/application_probe.py b/rust/obs-build/tests/libobs/application_probe.py index 53c8a3af41..7d8ad3a60f 100644 --- a/rust/obs-build/tests/libobs/application_probe.py +++ b/rust/obs-build/tests/libobs/application_probe.py @@ -100,6 +100,8 @@ def main() -> None: 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_NVENC"): + assert str(runtime / "lib64/obs-modules/core/obs-nvenc.so") in maps, "staged NVENC was not loaded" 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 From 58b46a7967500cce05ff6a1ee6736f284b6e9a6f Mon Sep 17 00:00:00 2001 From: Zach Vorhies Date: Sat, 17 Oct 2026 14:57:59 -0700 Subject: [PATCH 36/88] test(build): exercise NVENC through the staged OBS frontend --- docs/rust-port/cc-build.md | 21 +++++++++++++++++-- rust/obs-build/tests/libobs.rs | 17 +++++++++++++-- rust/obs-build/tests/libobs/application.rs | 21 +++++++++++++++---- .../tests/libobs/application_probe.py | 7 ++++++- 4 files changed, 57 insertions(+), 9 deletions(-) diff --git a/docs/rust-port/cc-build.md b/docs/rust-port/cc-build.md index 3235bd6d95..0be7adf73e 100644 --- a/docs/rust-port/cc-build.md +++ b/docs/rust-port/cc-build.md @@ -345,6 +345,23 @@ 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. NVENC discovery/encoding in the staged -GUI, OpenGL texture interoperability, HEVC/AV1 encoding and other platforms still +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. diff --git a/rust/obs-build/tests/libobs.rs b/rust/obs-build/tests/libobs.rs index c5a85b2162..0ead81e7dc 100644 --- a/rust/obs-build/tests/libobs.rs +++ b/rust/obs-build/tests/libobs.rs @@ -37,7 +37,7 @@ fn c_and_rust_twins_preserve_public_data_lifecycle_and_module_apis() { .map(PathBuf::from) .unwrap_or_else(|| output.path().into()), }; - let options = libobs::Options { + let mut options = libobs::Options { hevc: std::env::var_os("OBS_BUILD_DISABLE_HEVC").is_none(), core_modules: if enabled("OBS_BUILD_APP_GUI") { [ @@ -64,6 +64,9 @@ fn c_and_rust_twins_preserve_public_data_lifecycle_and_module_apis() { }, ..libobs::Options::default() }; + if enabled("OBS_BUILD_APP_GUI") && std::env::var_os("OBS_BUILD_NVENC").is_some() { + options.core_modules.push("obs-nvenc".into()); + } let libraries = libobs::build_pair(&build, &root, &options, &archive).unwrap(); assert_ne!(libraries.reference, libraries.with_rust); assert_eq!(exports(&libraries.reference), exports(&libraries.with_rust)); @@ -229,9 +232,19 @@ fn c_and_rust_twins_preserve_public_data_lifecycle_and_module_apis() { 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, }, - &[&libraries.reference, &libraries.with_rust], + &[ + 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(); } diff --git a/rust/obs-build/tests/libobs/application.rs b/rust/obs-build/tests/libobs/application.rs index 6a56b99c0c..c6eac0a0c3 100644 --- a/rust/obs-build/tests/libobs/application.rs +++ b/rust/obs-build/tests/libobs/application.rs @@ -9,12 +9,19 @@ pub struct Inputs<'a> { 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 fn exercise(inputs: Inputs<'_>, cores: &[&Path]) -> Result<(), String> { +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 core in cores { + 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-") @@ -26,7 +33,7 @@ pub fn exercise(inputs: Inputs<'_>, cores: &[&Path]) -> Result<(), String> { 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] { + for library in [core, inputs.api, inputs.renderer] { copy( library, &libraries.join( @@ -37,6 +44,12 @@ pub fn exercise(inputs: Inputs<'_>, cores: &[&Path]) -> Result<(), String> { )?; } inputs.ffmpeg.deploy_muxer(&bin)?; + 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"), @@ -50,7 +63,7 @@ pub fn exercise(inputs: Inputs<'_>, cores: &[&Path]) -> Result<(), String> { &runtime.join("share/obs/obs-studio/authors"), )?; let mut names = Vec::new(); - for module in inputs.modules { + for module in inputs.modules.iter().chain(variant.nvenc) { let name = module .library .file_stem() diff --git a/rust/obs-build/tests/libobs/application_probe.py b/rust/obs-build/tests/libobs/application_probe.py index 7d8ad3a60f..15e6922ba8 100644 --- a/rust/obs-build/tests/libobs/application_probe.py +++ b/rust/obs-build/tests/libobs/application_probe.py @@ -31,11 +31,12 @@ def profile(runtime: Path) -> Path: 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" - "RecEncoder=x264\nRecAudioEncoder=aac\nRecTracks=1\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()), @@ -70,6 +71,8 @@ def main() -> None: 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 recording: @@ -120,6 +123,8 @@ def main() -> None: 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 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) From 428d40228f5dbde5441e618d70c791b6afc5f20a Mon Sep 17 00:00:00 2001 From: Zach Vorhies Date: Sat, 17 Oct 2026 14:59:23 -0700 Subject: [PATCH 37/88] test(build): require the native OBS scripting graph --- rust/obs-build/src/lib.rs | 1 + rust/obs-build/src/scripting.rs | 36 +++++++++++++++++++++++++++++++++ rust/obs-build/tests/libobs.rs | 12 ++++++++++- 3 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 rust/obs-build/src/scripting.rs diff --git a/rust/obs-build/src/lib.rs b/rust/obs-build/src/lib.rs index bdd814650a..2b5281339d 100644 --- a/rust/obs-build/src/lib.rs +++ b/rust/obs-build/src/lib.rs @@ -13,6 +13,7 @@ pub mod libobs; mod platform; pub mod plugins; pub mod qt; +pub mod scripting; #[derive(Clone, Debug, Default)] pub struct SharedLibrary { diff --git a/rust/obs-build/src/scripting.rs b/rust/obs-build/src/scripting.rs new file mode 100644 index 0000000000..acf9d4a897 --- /dev/null +++ b/rust/obs-build/src/scripting.rs @@ -0,0 +1,36 @@ +//! Native scripting library and generated language bindings. +use crate::NativeBuild; +use std::path::{Path, PathBuf}; + +#[derive(Clone, Debug)] +pub struct Options { + pub lua: bool, + pub python: bool, +} + +impl Default for Options { + fn default() -> Self { + Self { + lua: true, + python: true, + } + } +} + +#[derive(Debug)] +pub struct Artifacts { + pub library: 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 { + Err("scripting native graph is not implemented".into()) +} diff --git a/rust/obs-build/tests/libobs.rs b/rust/obs-build/tests/libobs.rs index 0ead81e7dc..c9b6aa0e88 100644 --- a/rust/obs-build/tests/libobs.rs +++ b/rust/obs-build/tests/libobs.rs @@ -1,5 +1,5 @@ //! Opt-in integration against real native dependencies and libobs-rust. -use obs_build::{NativeBuild, frontend, graphics, libobs, plugins}; +use obs_build::{NativeBuild, frontend, graphics, libobs, plugins, scripting}; use std::{ffi::c_void, path::PathBuf}; #[path = "libobs/application.rs"] mod application; @@ -104,6 +104,16 @@ fn c_and_rust_twins_preserve_public_data_lifecycle_and_module_apis() { speexdsp: std::env::var_os("OBS_BUILD_DISABLE_SPEEXDSP").is_none(), rnnoise: std::env::var_os("OBS_BUILD_DISABLE_RNNOISE").is_none(), }; + if std::env::var_os("OBS_BUILD_SCRIPTING").is_some() { + scripting::build( + &build, + &root, + &libraries.reference, + None, + &scripting::Options::default(), + ) + .unwrap(); + } let mut modules = vec![ plugins::build_transitions(&build, &root, &libraries.reference).unwrap(), plugins::build_filters(&build, &root, &libraries.reference, &filters).unwrap(), From 30a74bded5baa228000259e85a23d846b33a895a Mon Sep 17 00:00:00 2001 From: Zach Vorhies Date: Sat, 17 Oct 2026 15:08:49 -0700 Subject: [PATCH 38/88] feat(build): compile Lua and Python scripting with native runtime checks --- docs/rust-port/cc-build.md | 36 +++ rust/obs-build/src/platform/mod.rs | 32 +++ rust/obs-build/src/scripting.rs | 275 ++++++++++++++++++++++- rust/obs-build/tests/libobs.rs | 21 +- rust/obs-build/tests/libobs/scripting.rs | 244 ++++++++++++++++++++ 5 files changed, 598 insertions(+), 10 deletions(-) create mode 100644 rust/obs-build/tests/libobs/scripting.rs diff --git a/docs/rust-port/cc-build.md b/docs/rust-port/cc-build.md index 0be7adf73e..f55f6a0147 100644 --- a/docs/rust-port/cc-build.md +++ b/docs/rust-port/cc-build.md @@ -365,3 +365,39 @@ 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 frontend Tools plugin, scripting UI/application staging, other platforms +and release packaging still require conversion and validation. This shared +library checkpoint does not complete those application features. diff --git a/rust/obs-build/src/platform/mod.rs b/rust/obs-build/src/platform/mod.rs index e9f3b1caa9..e490f24887 100644 --- a/rust/obs-build/src/platform/mod.rs +++ b/rust/obs-build/src/platform/mod.rs @@ -445,6 +445,38 @@ pub fn configure_cpp17(target: &str, library: &mut crate::SharedLibrary) { } } +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 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, diff --git a/rust/obs-build/src/scripting.rs b/rust/obs-build/src/scripting.rs index acf9d4a897..c2902acb96 100644 --- a/rust/obs-build/src/scripting.rs +++ b/rust/obs-build/src/scripting.rs @@ -1,11 +1,13 @@ //! Native scripting library and generated language bindings. -use crate::NativeBuild; +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 { @@ -13,6 +15,7 @@ impl Default for Options { Self { lua: true, python: true, + module_dir: "lib64/obs-scripting".into(), } } } @@ -20,17 +23,275 @@ impl Default for Options { #[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, + build: &NativeBuild, + root: &Path, + core: &Path, + frontend: Option<&Path>, + options: &Options, ) -> Result { - Err("scripting native graph is not implemented".into()) + 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/tests/libobs.rs b/rust/obs-build/tests/libobs.rs index c9b6aa0e88..7a8725fe17 100644 --- a/rust/obs-build/tests/libobs.rs +++ b/rust/obs-build/tests/libobs.rs @@ -7,6 +7,8 @@ mod application; mod qt; #[path = "libobs/render.rs"] mod render; +#[path = "libobs/scripting.rs"] +mod script_tests; #[test] fn c_and_rust_twins_preserve_public_data_lifecycle_and_module_apis() { @@ -105,14 +107,27 @@ fn c_and_rust_twins_preserve_public_data_lifecycle_and_module_apis() { rnnoise: std::env::var_os("OBS_BUILD_DISABLE_RNNOISE").is_none(), }; if std::env::var_os("OBS_BUILD_SCRIPTING").is_some() { - scripting::build( + let api = std::env::var_os("OBS_BUILD_SCRIPTING_FRONTEND") + .map(|_| frontend::build_api(&build, &root, &libraries.reference).unwrap()); + let artifacts = scripting::build( &build, &root, &libraries.reference, - None, - &scripting::Options::default(), + 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], + api.is_some(), + ); } let mut modules = vec![ plugins::build_transitions(&build, &root, &libraries.reference).unwrap(), 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; +} +"#; From 863ba5ac94c4d7ad99dd39e6cf952807f0b35c01 Mon Sep 17 00:00:00 2001 From: Zach Vorhies Date: Sat, 17 Oct 2026 15:12:29 -0700 Subject: [PATCH 39/88] test(build): require the frontend Tools plugin graph --- rust/obs-build/src/plugins.rs | 10 ++++++++++ rust/obs-build/tests/libobs.rs | 35 +++++++++++++++++++++++++++------- 2 files changed, 38 insertions(+), 7 deletions(-) diff --git a/rust/obs-build/src/plugins.rs b/rust/obs-build/src/plugins.rs index 764acb542c..bb0b8d7a04 100644 --- a/rust/obs-build/src/plugins.rs +++ b/rust/obs-build/src/plugins.rs @@ -8,6 +8,16 @@ pub struct Module { pub data: PathBuf, } +pub fn build_frontend_tools( + _build: &NativeBuild, + _root: &Path, + _core: &Path, + _api: &Path, + _scripting: Option<&crate::scripting::Artifacts>, +) -> Result { + Err("frontend Tools native graph is not implemented".into()) +} + #[derive(Debug)] pub struct NvencArtifacts { pub reference: Module, diff --git a/rust/obs-build/tests/libobs.rs b/rust/obs-build/tests/libobs.rs index 7a8725fe17..e402be193c 100644 --- a/rust/obs-build/tests/libobs.rs +++ b/rust/obs-build/tests/libobs.rs @@ -106,14 +106,18 @@ fn c_and_rust_twins_preserve_public_data_lifecycle_and_module_apis() { speexdsp: std::env::var_os("OBS_BUILD_DISABLE_SPEEXDSP").is_none(), rnnoise: std::env::var_os("OBS_BUILD_DISABLE_RNNOISE").is_none(), }; - if std::env::var_os("OBS_BUILD_SCRIPTING").is_some() { - let api = std::env::var_os("OBS_BUILD_SCRIPTING_FRONTEND") - .map(|_| frontend::build_api(&build, &root, &libraries.reference).unwrap()); + 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, - api.as_deref(), + 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(), @@ -126,9 +130,12 @@ fn c_and_rust_twins_preserve_public_data_lifecycle_and_module_apis() { &root, &artifacts, &[&libraries.reference, &libraries.with_rust], - api.is_some(), + 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(), @@ -164,7 +171,21 @@ fn c_and_rust_twins_preserve_public_data_lifecycle_and_module_apis() { let frontend = (enabled("OBS_BUILD_QT") || enabled("OBS_BUILD_APP")).then(|| { qt::exercise(&build, &root); modules.push(plugins::build_vst(&build, &root, &libraries.reference).unwrap()); - frontend::build_api(&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() }); if let (Some(frontend), Some(reference)) = (&frontend, std::env::var_os("OBS_BUILD_FRONTEND_REFERENCE")) From 710089d3d4acc3174ac7af74b7a5dcb1a60a3307 Mon Sep 17 00:00:00 2001 From: Zach Vorhies Date: Sat, 17 Oct 2026 15:28:11 -0700 Subject: [PATCH 40/88] feat(build): compile frontend Tools and exercise saved GUI scripts --- docs/rust-port/cc-build.md | 51 ++++- rust/obs-build/src/frontend.rs | 4 +- rust/obs-build/src/platform/mod.rs | 19 ++ rust/obs-build/src/plugins.rs | 12 +- rust/obs-build/src/plugins/frontend_tools.rs | 95 ++++++++++ rust/obs-build/tests/libobs.rs | 28 ++- rust/obs-build/tests/libobs/application.rs | 54 +++++- .../tests/libobs/application_probe.py | 68 ++++++- rust/obs-build/tests/libobs/tools.rs | 174 ++++++++++++++++++ 9 files changed, 483 insertions(+), 22 deletions(-) create mode 100644 rust/obs-build/src/plugins/frontend_tools.rs create mode 100644 rust/obs-build/tests/libobs/tools.rs diff --git a/docs/rust-port/cc-build.md b/docs/rust-port/cc-build.md index f55f6a0147..a149591895 100644 --- a/docs/rust-port/cc-build.md +++ b/docs/rust-port/cc-build.md @@ -266,7 +266,8 @@ 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 -`OBS-Studio-Rust 0.1.0 (based on OBS 33.0.0-cc-build)` through `--version`. +`--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. @@ -398,6 +399,48 @@ 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 frontend Tools plugin, scripting UI/application staging, other platforms -and release packaging still require conversion and validation. This shared -library checkpoint does not complete those application features. +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. diff --git a/rust/obs-build/src/frontend.rs b/rust/obs-build/src/frontend.rs index 70ff7cb54c..e9b954bab9 100644 --- a/rust/obs-build/src/frontend.rs +++ b/rust/obs-build/src/frontend.rs @@ -206,7 +206,7 @@ pub fn build_application( build.executable(&library) } -fn add_inputs( +pub(crate) fn add_inputs( build: &NativeBuild, root: &Path, library: &mut SharedLibrary, @@ -249,7 +249,7 @@ fn add_inputs( Ok(()) } -fn write(path: &Path, content: &str) -> Result<(), String> { +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())?; } diff --git a/rust/obs-build/src/platform/mod.rs b/rust/obs-build/src/platform/mod.rs index e490f24887..8ee34f86fa 100644 --- a/rust/obs-build/src/platform/mod.rs +++ b/rust/obs-build/src/platform/mod.rs @@ -455,6 +455,25 @@ pub fn configure_scripting(target: &str, library: &mut crate::SharedLibrary) -> 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()); diff --git a/rust/obs-build/src/plugins.rs b/rust/obs-build/src/plugins.rs index bb0b8d7a04..308ab23be6 100644 --- a/rust/obs-build/src/plugins.rs +++ b/rust/obs-build/src/plugins.rs @@ -1,6 +1,8 @@ //! 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 frontend_tools; +pub use frontend_tools::build as build_frontend_tools; #[derive(Debug)] pub struct Module { @@ -8,16 +10,6 @@ pub struct Module { pub data: PathBuf, } -pub fn build_frontend_tools( - _build: &NativeBuild, - _root: &Path, - _core: &Path, - _api: &Path, - _scripting: Option<&crate::scripting::Artifacts>, -) -> Result { - Err("frontend Tools native graph is not implemented".into()) -} - #[derive(Debug)] pub struct NvencArtifacts { pub reference: Module, 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/tests/libobs.rs b/rust/obs-build/tests/libobs.rs index e402be193c..fc510a5be0 100644 --- a/rust/obs-build/tests/libobs.rs +++ b/rust/obs-build/tests/libobs.rs @@ -9,6 +9,8 @@ mod qt; mod render; #[path = "libobs/scripting.rs"] mod script_tests; +#[path = "libobs/tools.rs"] +mod tools; #[test] fn c_and_rust_twins_preserve_public_data_lifecycle_and_module_apis() { @@ -69,6 +71,15 @@ fn c_and_rust_twins_preserve_public_data_lifecycle_and_module_apis() { 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 + .extend(["frontend-tools".into(), "native-frontend-probe".into()]); + } let libraries = libobs::build_pair(&build, &root, &options, &archive).unwrap(); assert_ne!(libraries.reference, libraries.with_rust); assert_eq!(exports(&libraries.reference), exports(&libraries.with_rust)); @@ -175,7 +186,7 @@ fn c_and_rust_twins_preserve_public_data_lifecycle_and_module_apis() { .clone() .unwrap_or_else(|| frontend::build_api(&build, &root, &libraries.reference).unwrap()) }); - let _frontend_tools = tools_enabled.then(|| { + let frontend_tools = tools_enabled.then(|| { plugins::build_frontend_tools( &build, &root, @@ -270,6 +281,14 @@ fn c_and_rust_twins_preserve_public_data_lifecycle_and_module_apis() { .as_ref() .map(|_| render::build(&build, &root, &libraries.reference)); if enabled("OBS_BUILD_APP_GUI") { + let gui_probe = frontend_tools.as_ref().map(|_| { + tools::build( + &build, + &root, + &libraries.reference, + frontend.as_ref().unwrap(), + ) + }); application::exercise( application::Inputs { root: &root, @@ -280,6 +299,13 @@ fn c_and_rust_twins_preserve_public_data_lifecycle_and_module_apis() { ffmpeg: ffmpeg.as_ref().unwrap(), nvenc_helper: nvenc.as_ref().map(|nvenc| nvenc.helper.as_path()), modules: &modules, + frontend_tools: frontend_tools.as_ref(), + script_artifacts: if tools_enabled { + script_artifacts.as_ref() + } else { + None + }, + gui_probe: gui_probe.as_ref(), }, &[ application::Variant { diff --git a/rust/obs-build/tests/libobs/application.rs b/rust/obs-build/tests/libobs/application.rs index c6eac0a0c3..cfd6e5906f 100644 --- a/rust/obs-build/tests/libobs/application.rs +++ b/rust/obs-build/tests/libobs/application.rs @@ -1,5 +1,5 @@ //! Full frontend runtime validation with an isolated profile and display. -use obs_build::{NativeBuild, SharedLibrary, plugins}; +use obs_build::{NativeBuild, SharedLibrary, plugins, scripting}; use std::path::{Path, PathBuf}; pub struct Inputs<'a> { @@ -11,6 +11,9 @@ pub struct Inputs<'a> { pub ffmpeg: &'a plugins::FfmpegArtifacts, pub nvenc_helper: Option<&'a Path>, pub modules: &'a [plugins::Module], + 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> { @@ -44,6 +47,44 @@ pub fn exercise(inputs: Inputs<'_>, variants: &[Variant<'_>]) -> Result<(), Stri )?; } 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, @@ -63,7 +104,13 @@ pub fn exercise(inputs: Inputs<'_>, variants: &[Variant<'_>]) -> Result<(), Stri &runtime.join("share/obs/obs-studio/authors"), )?; let mut names = Vec::new(); - for module in inputs.modules.iter().chain(variant.nvenc) { + for module in inputs + .modules + .iter() + .chain(variant.nvenc) + .chain(inputs.frontend_tools) + .chain(inputs.gui_probe) + { let name = module .library .file_stem() @@ -126,6 +173,9 @@ pub fn exercise(inputs: Inputs<'_>, variants: &[Variant<'_>]) -> Result<(), Stri } 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())) diff --git a/rust/obs-build/tests/libobs/application_probe.py b/rust/obs-build/tests/libobs/application_probe.py index 15e6922ba8..6179df5767 100644 --- a/rust/obs-build/tests/libobs/application_probe.py +++ b/rust/obs-build/tests/libobs/application_probe.py @@ -17,7 +17,7 @@ def profile(runtime: Path) -> Path: config.mkdir(parents=True) (config / "global.ini").write_text("[General]\nLastVersion=4294967295\n") (config / "user.ini").write_text( - "[General]\nFirstRun=true\nConfirmOnExit=false\n" + "[General]\nLanguage=en-US\nFirstRun=true\nConfirmOnExit=false\n" "[Basic]\nProfile=NativeSmoke\nProfileDir=NativeSmoke\n" "SceneCollection=NativeSmoke\nSceneCollectionFile=NativeSmoke\n" ) @@ -45,9 +45,19 @@ def profile(runtime: Path) -> Path: "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], + "scene_order": [{"name": "Native scene"}], "sources": [color, scene], "modules": modules, })) return config @@ -67,6 +77,12 @@ def main() -> None: # 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) @@ -90,7 +106,8 @@ def main() -> None: chunk = os.read(app.stdout.fileno(), 65536) log.extend(chunk) (runtime / "application.log").write_bytes(log) - if b"==== Startup complete" in log and (not recording or b"==== Recording Start" in log): + tools_ready = not os.environ.get("OBS_BUILD_FRONTEND_TOOLS") or b"cc::Build frontend Tools dialogs verified" in log + if b"==== Startup complete" in log and tools_ready and (not 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 @@ -105,6 +122,14 @@ def main() -> None: assert str(runtime / "lib64/obs-modules/core" / (name + ".so")) in maps, f"module {name} was not loaded" 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}" 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 @@ -122,6 +147,13 @@ def main() -> None: 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 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" @@ -164,5 +196,35 @@ def verify_recording(path: Path, env: dict[str, str]) -> None: 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/tools.rs b/rust/obs-build/tests/libobs/tools.rs new file mode 100644 index 0000000000..ca2c23574d --- /dev/null +++ b/rust/obs-build/tests/libobs/tools.rs @@ -0,0 +1,174 @@ +//! 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"] { + 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 + +OBS_DECLARE_MODULE() + +static bool open_dialog(QMenu *menu, const char *label, const char *type, const char *image, int scripts = -1) +{ + 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(); + } + } + } + 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 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 (!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; } + } + } + 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); } +"#; From 192d2de2437f62cb06f749c4ea5fa2fc56c02780 Mon Sep 17 00:00:00 2001 From: Zach Vorhies Date: Sat, 17 Oct 2026 15:29:16 -0700 Subject: [PATCH 41/88] fix(build): normalize compiler paths and account for native test targets --- Cargo.lock | 7 +++++++ ci/test_binary_cap.py | 5 +++-- rust/obs-build/Cargo.toml | 1 + rust/obs-build/src/lib.rs | 9 ++++----- rust/obs-build/src/platform/mod.rs | 1 + 5 files changed, 16 insertions(+), 7 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 631c31d177..af343a2dfa 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -247,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" @@ -427,6 +433,7 @@ name = "obs-build" version = "0.1.0" dependencies = [ "cc", + "dunce", "libloading", "pkg-config", "serde_json", 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/rust/obs-build/Cargo.toml b/rust/obs-build/Cargo.toml index 87d1a93092..ec0dac525d 100644 --- a/rust/obs-build/Cargo.toml +++ b/rust/obs-build/Cargo.toml @@ -11,6 +11,7 @@ publish.workspace = true libobs-integration = [] [dependencies] +dunce = "=1.0.5" cc = { version = "=1.6.0", features = ["parallel"] } pkg-config = "=0.3.34" serde_json = "=1.0.151" diff --git a/rust/obs-build/src/lib.rs b/rust/obs-build/src/lib.rs index 2b5281339d..1179b0c4cc 100644 --- a/rust/obs-build/src/lib.rs +++ b/rust/obs-build/src/lib.rs @@ -134,13 +134,12 @@ impl NativeBuild { } let output = self.output.join(&library.name); fs::create_dir_all(&output).map_err(|e| format!("create {}: {e}", output.display()))?; - let output = output.canonicalize().map_err(|e| e.to_string())?; + let output = dunce::canonicalize(&output).map_err(|e| e.to_string())?; let mut c_sources = Vec::new(); let mut cpp_sources = Vec::new(); for source in &library.sources { - let absolute = source - .canonicalize() - .map_err(|e| format!("{}: {e}", source.display()))?; + let absolute = + dunce::canonicalize(source).map_err(|e| format!("{}: {e}", source.display()))?; match source.extension().and_then(|e| e.to_str()) { Some("c") => c_sources.push(absolute), Some("cpp" | "cc" | "cxx") => cpp_sources.push(absolute), @@ -205,7 +204,7 @@ impl NativeBuild { let mut includes = std::collections::HashSet::new(); for directory in &library.include_dirs { if includes.insert(directory) { - compiler.include(directory); + compiler.include(dunce::simplified(directory)); } } let mut definitions = std::collections::HashSet::new(); diff --git a/rust/obs-build/src/platform/mod.rs b/rust/obs-build/src/platform/mod.rs index 8ee34f86fa..0956fc9184 100644 --- a/rust/obs-build/src/platform/mod.rs +++ b/rust/obs-build/src/platform/mod.rs @@ -214,6 +214,7 @@ pub fn configure_glad( } fn dependency_link_name(path: &Path, msvc: bool) -> PathBuf { + let path = dunce::simplified(path); if path .extension() .and_then(|s| s.to_str()) From 173e098cf5e07888f86fc8b526bc6a75482d2a1a Mon Sep 17 00:00:00 2001 From: Zach Vorhies Date: Sat, 17 Oct 2026 15:35:02 -0700 Subject: [PATCH 42/88] test(build): require the native websocket plugin and real wire behavior --- rust/obs-build/src/plugins.rs | 11 +++ rust/obs-build/tests/libobs.rs | 13 +++ rust/obs-build/tests/libobs/application.rs | 2 + .../tests/libobs/application_probe.py | 20 ++++ .../obs-build/tests/libobs/websocket_probe.py | 95 +++++++++++++++++++ 5 files changed, 141 insertions(+) create mode 100644 rust/obs-build/tests/libobs/websocket_probe.py diff --git a/rust/obs-build/src/plugins.rs b/rust/obs-build/src/plugins.rs index 308ab23be6..f249e64bcb 100644 --- a/rust/obs-build/src/plugins.rs +++ b/rust/obs-build/src/plugins.rs @@ -445,3 +445,14 @@ pub fn build_vst(build: &NativeBuild, root: &Path, core: &Path) -> Result Result { + Err("obs-websocket native graph is not implemented".into()) +} diff --git a/rust/obs-build/tests/libobs.rs b/rust/obs-build/tests/libobs.rs index fc510a5be0..efef5a6262 100644 --- a/rust/obs-build/tests/libobs.rs +++ b/rust/obs-build/tests/libobs.rs @@ -80,6 +80,10 @@ fn c_and_rust_twins_preserve_public_data_lifecycle_and_module_apis() { .core_modules .extend(["frontend-tools".into(), "native-frontend-probe".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()); + } let libraries = libobs::build_pair(&build, &root, &options, &archive).unwrap(); assert_ne!(libraries.reference, libraries.with_rust); assert_eq!(exports(&libraries.reference), exports(&libraries.with_rust)); @@ -198,6 +202,14 @@ fn c_and_rust_twins_preserve_public_data_lifecycle_and_module_apis() { ) .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"), + ).unwrap() + }); if let (Some(frontend), Some(reference)) = (&frontend, std::env::var_os("OBS_BUILD_FRONTEND_REFERENCE")) { @@ -300,6 +312,7 @@ fn c_and_rust_twins_preserve_public_data_lifecycle_and_module_apis() { nvenc_helper: nvenc.as_ref().map(|nvenc| nvenc.helper.as_path()), modules: &modules, frontend_tools: frontend_tools.as_ref(), + websocket: websocket.as_ref(), script_artifacts: if tools_enabled { script_artifacts.as_ref() } else { diff --git a/rust/obs-build/tests/libobs/application.rs b/rust/obs-build/tests/libobs/application.rs index cfd6e5906f..d9b5f640a7 100644 --- a/rust/obs-build/tests/libobs/application.rs +++ b/rust/obs-build/tests/libobs/application.rs @@ -11,6 +11,7 @@ pub struct Inputs<'a> { pub ffmpeg: &'a plugins::FfmpegArtifacts, pub nvenc_helper: Option<&'a Path>, pub modules: &'a [plugins::Module], + pub websocket: Option<&'a plugins::Module>, pub frontend_tools: Option<&'a plugins::Module>, pub script_artifacts: Option<&'a scripting::Artifacts>, pub gui_probe: Option<&'a plugins::Module>, @@ -109,6 +110,7 @@ pub fn exercise(inputs: Inputs<'_>, variants: &[Variant<'_>]) -> Result<(), Stri .iter() .chain(variant.nvenc) .chain(inputs.frontend_tools) + .chain(inputs.websocket) .chain(inputs.gui_probe) { let name = module diff --git a/rust/obs-build/tests/libobs/application_probe.py b/rust/obs-build/tests/libobs/application_probe.py index 6179df5767..b188fb3649 100644 --- a/rust/obs-build/tests/libobs/application_probe.py +++ b/rust/obs-build/tests/libobs/application_probe.py @@ -7,6 +7,8 @@ import os from pathlib import Path import select +import secrets +import socket import subprocess import time import uuid @@ -59,6 +61,18 @@ def profile(runtime: Path) -> Path: "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 @@ -130,6 +144,12 @@ def main() -> None: 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"): + 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) 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 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..91b5d0ef3d --- /dev/null +++ b/rust/obs-build/tests/libobs/websocket_probe.py @@ -0,0 +1,95 @@ +#!/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 +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 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 + 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() + + +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)) From ff5cce4039ca029f03947fd95eba7008769c88e2 Mon Sep 17 00:00:00 2001 From: Zach Vorhies Date: Sat, 17 Oct 2026 15:49:00 -0700 Subject: [PATCH 43/88] test(build): require Tier 2 to read canonical native source sets --- ci/test_ported_sources.py | 45 ++++++++++++++++++++++++++++++++++++ rust/tools/ported_sources.py | 7 ++++++ 2 files changed, 52 insertions(+) create mode 100644 ci/test_ported_sources.py create mode 100644 rust/tools/ported_sources.py 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/rust/tools/ported_sources.py b/rust/tools/ported_sources.py new file mode 100644 index 0000000000..c8250db5ca --- /dev/null +++ b/rust/tools/ported_sources.py @@ -0,0 +1,7 @@ +#!/usr/bin/env -S uv run --script +"""Read the canonical native source inventory for Tier 2 graph validation.""" +from pathlib import Path + + +def ported_objects(root: Path, host: str, hevc: bool = True) -> list[str]: + return [] From ef832a97cc65eba51b44f1c11b4e03cab1f0285c Mon Sep 17 00:00:00 2001 From: Zach Vorhies Date: Sat, 17 Oct 2026 15:55:09 -0700 Subject: [PATCH 44/88] fix(build): derive Tier 2 exclusions from the shared source manifest --- libobs/build/source-sets.json | 3 +++ libobs/cmake/sources.cmake | 2 +- rust/obs-build/src/libobs.rs | 4 +--- rust/tools/linux-validate/Dockerfile | 3 +++ rust/tools/linux-validate/validate.sh | 19 ++++++----------- rust/tools/ported_sources.py | 30 ++++++++++++++++++++++++++- 6 files changed, 43 insertions(+), 18 deletions(-) diff --git a/libobs/build/source-sets.json b/libobs/build/source-sets.json index cf611f0535..ecaf25a03b 100644 --- a/libobs/build/source-sets.json +++ b/libobs/build/source-sets.json @@ -163,5 +163,8 @@ "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 8a40e137f2..3c24ab9290 100644 --- a/libobs/cmake/sources.cmake +++ b/libobs/cmake/sources.cmake @@ -38,7 +38,7 @@ 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() # Adds a host's lists (libobs/CMakeLists.txt): its sources to the diff --git a/rust/obs-build/src/libobs.rs b/rust/obs-build/src/libobs.rs index 397c046eb0..b414943e98 100644 --- a/rust/obs-build/src/libobs.rs +++ b/rust/obs-build/src/libobs.rs @@ -163,9 +163,7 @@ fn add_variant( } else { append_sources(sets, "LIBOBS_PORTED_SOURCES", root, library)?; if options.hevc { - library - .sources - .push(root.join("libobs/build/libobs.ported-hevc+.h.c")); + append_sources(sets, "LIBOBS_HEVC_PORTED_SOURCES", root, library)?; } } crate::platform::configure_libobs_variant(build, root, options, sets, library, rust_archive) 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 index c8250db5ca..3fd5b65668 100644 --- a/rust/tools/ported_sources.py +++ b/rust/tools/ported_sources.py @@ -1,7 +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]: - return [] + 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))) From 8355990bbfc6a2abfbdf0a9df466cc39eb264c4c Mon Sep 17 00:00:00 2001 From: Zach Vorhies Date: Sat, 17 Oct 2026 15:55:11 -0700 Subject: [PATCH 45/88] feat(build): compile and exercise the native websocket server with cc --- docs/rust-port/cc-build.md | 49 ++++++++++ rust/obs-build/manifests/obs-websocket.json | 90 +++++++++++++++++++ rust/obs-build/src/platform/mod.rs | 52 +++++++++++ rust/obs-build/src/plugins.rs | 13 +-- rust/obs-build/src/plugins/websocket.rs | 79 ++++++++++++++++ rust/obs-build/tests/libobs.rs | 26 ++++-- .../tests/libobs/application_probe.py | 11 ++- rust/obs-build/tests/libobs/tools.rs | 50 +++++++++-- .../obs-build/tests/libobs/websocket_probe.py | 11 ++- 9 files changed, 350 insertions(+), 31 deletions(-) create mode 100644 rust/obs-build/manifests/obs-websocket.json create mode 100644 rust/obs-build/src/plugins/websocket.rs diff --git a/docs/rust-port/cc-build.md b/docs/rust-port/cc-build.md index a149591895..faa1a72292 100644 --- a/docs/rust-port/cc-build.md +++ b/docs/rust-port/cc-build.md @@ -444,3 +444,52 @@ 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. This toggle does not yet expand the core's explicit unity +groups into individual sources. + +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 the full configurable unity/PCH path 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. The complete Linux Tier 2 CI result still needs verification +on the updated branch; local source parity and HEVC on/off lifecycle/symbol +checks pass (1766/1762 exports respectively, identical between cores). 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/platform/mod.rs b/rust/obs-build/src/platform/mod.rs index 0956fc9184..63478f49ac 100644 --- a/rust/obs-build/src/platform/mod.rs +++ b/rust/obs-build/src/platform/mod.rs @@ -633,6 +633,58 @@ pub fn configure_application( 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::*; diff --git a/rust/obs-build/src/plugins.rs b/rust/obs-build/src/plugins.rs index f249e64bcb..e8e4446a8b 100644 --- a/rust/obs-build/src/plugins.rs +++ b/rust/obs-build/src/plugins.rs @@ -2,7 +2,9 @@ use crate::{NativeBuild, SharedLibrary, deps::shared_archive, libobs::add_package}; use std::path::{Path, PathBuf}; mod frontend_tools; +mod websocket; pub use frontend_tools::build as build_frontend_tools; +pub use websocket::{Options as WebsocketOptions, build as build_websocket}; #[derive(Debug)] pub struct Module { @@ -445,14 +447,3 @@ pub fn build_vst(build: &NativeBuild, root: &Path, core: &Path) -> Result Result { - Err("obs-websocket native graph is not implemented".into()) -} 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/tests/libobs.rs b/rust/obs-build/tests/libobs.rs index efef5a6262..fb39e66ae7 100644 --- a/rust/obs-build/tests/libobs.rs +++ b/rust/obs-build/tests/libobs.rs @@ -76,14 +76,20 @@ fn c_and_rust_twins_preserve_public_data_lifecycle_and_module_apis() { std::env::var_os("OBS_BUILD_APP_GUI").is_some(), "frontend Tools test requires OBS_BUILD_APP_GUI=1" ); - options - .core_modules - .extend(["frontend-tools".into(), "native-frontend-probe".into()]); + 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"); + 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_FRONTEND_TOOLS").is_some() + || std::env::var_os("OBS_BUILD_WEBSOCKET").is_some() + { + options.core_modules.push("native-frontend-probe".into()); + } let libraries = libobs::build_pair(&build, &root, &options, &archive).unwrap(); assert_ne!(libraries.reference, libraries.with_rust); assert_eq!(exports(&libraries.reference), exports(&libraries.with_rust)); @@ -207,8 +213,14 @@ fn c_and_rust_twins_preserve_public_data_lifecycle_and_module_apis() { &build, &root, &libraries.reference, - frontend.as_deref().expect("websocket requires the frontend API"), - ).unwrap() + frontend + .as_deref() + .expect("websocket requires the frontend API"), + &plugins::WebsocketOptions { + unity: std::env::var_os("OBS_BUILD_DISABLE_WEBSOCKET_UNITY").is_none(), + }, + ) + .unwrap() }); if let (Some(frontend), Some(reference)) = (&frontend, std::env::var_os("OBS_BUILD_FRONTEND_REFERENCE")) @@ -293,7 +305,7 @@ fn c_and_rust_twins_preserve_public_data_lifecycle_and_module_apis() { .as_ref() .map(|_| render::build(&build, &root, &libraries.reference)); if enabled("OBS_BUILD_APP_GUI") { - let gui_probe = frontend_tools.as_ref().map(|_| { + let gui_probe = (frontend_tools.is_some() || websocket.is_some()).then(|| { tools::build( &build, &root, diff --git a/rust/obs-build/tests/libobs/application_probe.py b/rust/obs-build/tests/libobs/application_probe.py index b188fb3649..017cf5b6c9 100644 --- a/rust/obs-build/tests/libobs/application_probe.py +++ b/rust/obs-build/tests/libobs/application_probe.py @@ -105,7 +105,10 @@ def main() -> None: 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 recording: + # 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() @@ -120,8 +123,8 @@ def main() -> None: chunk = os.read(app.stdout.fileno(), 65536) log.extend(chunk) (runtime / "application.log").write_bytes(log) - tools_ready = not os.environ.get("OBS_BUILD_FRONTEND_TOOLS") or b"cc::Build frontend Tools dialogs verified" in log - if b"==== Startup complete" in log and tools_ready and (not recording or b"==== Recording Start" in 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 @@ -145,6 +148,8 @@ def main() -> None: 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: diff --git a/rust/obs-build/tests/libobs/tools.rs b/rust/obs-build/tests/libobs/tools.rs index ca2c23574d..44cf6de90e 100644 --- a/rust/obs-build/tests/libobs/tools.rs +++ b/rust/obs-build/tests/libobs/tools.rs @@ -64,6 +64,8 @@ const SOURCE: &str = r#" #include #include #include +#include +#include #include #include #include @@ -72,7 +74,7 @@ const SOURCE: &str = r#" OBS_DECLARE_MODULE() -static bool open_dialog(QMenu *menu, const char *label, const char *type, const char *image, int scripts = -1) +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()) { @@ -119,6 +121,32 @@ static bool open_dialog(QMenu *menu, const char *label, const char *type, const } } } + 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(); @@ -143,16 +171,20 @@ static void verify_dialogs() if (text == "Tools") tools = action->menu(); } if (!tools) { blog(LOG_ERROR, "cc::Build Tools menu missing"); return; } - 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_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; blog(LOG_INFO, "cc::Build frontend Tools dialogs verified"); } diff --git a/rust/obs-build/tests/libobs/websocket_probe.py b/rust/obs-build/tests/libobs/websocket_probe.py index 91b5d0ef3d..5f417cc1aa 100644 --- a/rust/obs-build/tests/libobs/websocket_probe.py +++ b/rust/obs-build/tests/libobs/websocket_probe.py @@ -57,7 +57,7 @@ async def request(name: str, data=None): settings = await request("GetInputSettings", {"inputName": "Native white"}) assert settings["inputSettings"]["color"] == 0xFFFFFFFF status = await request("GetRecordStatus") - assert status["outputActive"] is recording + assert status["outputActive"] is False, "fixture unexpectedly started recording" image = await request("GetSourceScreenshot", { "sourceName": "Native white", "imageFormat": "png", "imageWidth": 64, "imageHeight": 64, @@ -79,6 +79,15 @@ async def request(name: str, data=None): assert all(item["requestStatus"]["code"] == 100 for item in batch["d"]["results"]) unknown = await client.request("NativeMissingRequest") assert unknown["d"]["requestStatus"]["code"] == 204 + 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)) From face3753a5f9b001f5b5cb538125be143773b6ad Mon Sep 17 00:00:00 2001 From: Zach Vorhies Date: Sat, 17 Oct 2026 15:56:42 -0700 Subject: [PATCH 46/88] test(build): require individual compilation of explicit unity groups --- rust/obs-build/src/lib.rs | 9 +++++++++ rust/obs-build/tests/native.rs | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/rust/obs-build/src/lib.rs b/rust/obs-build/src/lib.rs index 1179b0c4cc..a863244d97 100644 --- a/rust/obs-build/src/lib.rs +++ b/rust/obs-build/src/lib.rs @@ -40,6 +40,15 @@ pub struct NativeBuild { } 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> { + Err("individual BUILD.md source compilation is not implemented".into()) + } + /// 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)?; diff --git a/rust/obs-build/tests/native.rs b/rust/obs-build/tests/native.rs index bbe70ff055..029a696627 100644 --- a/rust/obs-build/tests/native.rs +++ b/rust/obs-build/tests/native.rs @@ -168,6 +168,38 @@ fn executable_runs_against_its_shared_core_dependency() { const EXPORT: &str = "\n#if defined(_WIN32)\n__declspec(dllexport)\n#endif\n"; +#[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 deploying_mux_helper_in_place_preserves_its_contents() { let directory = tempfile::tempdir().unwrap(); From 3ad39846fc40059ead1ae4bc0ba69b7b0bf98f3d Mon Sep 17 00:00:00 2001 From: Zach Vorhies Date: Sat, 17 Oct 2026 15:59:06 -0700 Subject: [PATCH 47/88] test(ci): require uv before the Tier 2 manifest reader --- ci/test_tier2_apt_cache.py | 6 ++++++ 1 file changed, 6 insertions(+) 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) From 8c8ff7029c3d9965a382cfc3733e8aec94eccc09 Mon Sep 17 00:00:00 2001 From: Zach Vorhies Date: Sat, 17 Oct 2026 15:59:46 -0700 Subject: [PATCH 48/88] fix(ci): install uv in the stock Tier 2 job containers --- .github/workflows/build-project.yaml | 12 ++++++++++++ 1 file changed, 12 insertions(+) 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. From ca331a93d751b9fa1a55b2997ca74616afaa63cc Mon Sep 17 00:00:00 2001 From: Zach Vorhies Date: Sat, 17 Oct 2026 16:00:35 -0700 Subject: [PATCH 49/88] feat(build): compile libobs unity members as separate translation units --- docs/rust-port/cc-build.md | 43 ++++++++++++- rust/obs-build/src/groups.rs | 108 +++++++++++++++++++++++++++++++++ rust/obs-build/src/lib.rs | 7 ++- rust/obs-build/src/libobs.rs | 12 +++- rust/obs-build/tests/libobs.rs | 1 + rust/obs-build/tests/native.rs | 46 ++++++++++++-- 6 files changed, 205 insertions(+), 12 deletions(-) create mode 100644 rust/obs-build/src/groups.rs diff --git a/docs/rust-port/cc-build.md b/docs/rust-port/cc-build.md index faa1a72292..9099bc38fd 100644 --- a/docs/rust-port/cc-build.md +++ b/docs/rust-port/cc-build.md @@ -464,8 +464,7 @@ 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. This toggle does not yet expand the core's explicit unity -groups into individual sources. +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 @@ -477,7 +476,8 @@ 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 the full configurable unity/PCH path remain required. +production packaging and configurable unity/PCH across the remaining graph +remain required. ## Shared source inventory and Linux Tier 2 @@ -493,3 +493,40 @@ This fixes the CI reader that found only one object after the source lists moved out of CMake. The complete Linux Tier 2 CI result still needs verification on the updated branch; local source parity and HEVC on/off lifecycle/symbol checks 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. diff --git a/rust/obs-build/src/groups.rs b/rust/obs-build/src/groups.rs new file mode 100644 index 0000000000..c4adcb90f9 --- /dev/null +++ b/rust/obs-build/src/groups.rs @@ -0,0 +1,108 @@ +//! Preserve explicit source inventories while compiling each member separately. +use std::{ + collections::HashSet, + fs, + path::{Path, PathBuf}, +}; + +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 index a863244d97..b86c01b196 100644 --- a/rust/obs-build/src/lib.rs +++ b/rust/obs-build/src/lib.rs @@ -9,6 +9,7 @@ use std::{fs, path::PathBuf}; mod deps; pub mod frontend; pub mod graphics; +mod groups; pub mod libobs; mod platform; pub mod plugins; @@ -43,10 +44,10 @@ impl NativeBuild { /// Expand explicit BUILD.md groups into individual translation units. pub fn separate_group_sources( &self, - _root: &std::path::Path, - _sources: &[PathBuf], + root: &std::path::Path, + sources: &[PathBuf], ) -> Result, String> { - Err("individual BUILD.md source compilation is not implemented".into()) + groups::separate(root, &self.output.join("individual-sources"), sources) } /// Compile through cc::Build, then link a native shared library. diff --git a/rust/obs-build/src/libobs.rs b/rust/obs-build/src/libobs.rs index b414943e98..e57c871a2d 100644 --- a/rust/obs-build/src/libobs.rs +++ b/rust/obs-build/src/libobs.rs @@ -8,6 +8,8 @@ use std::{ #[derive(Clone, Debug)] pub struct Options { + /// Keep explicit BUILD.md unity groups; false compiles their members separately. + pub unity: bool, pub hevc: bool, pub wayland: bool, pub pulseaudio: bool, @@ -18,6 +20,7 @@ pub struct Options { impl Default for Options { fn default() -> Self { Self { + unity: true, hevc: true, wayland: true, pulseaudio: true, @@ -132,6 +135,9 @@ fn prepare(build: &NativeBuild, root: &Path, options: &Options) -> Result Date: Sat, 17 Oct 2026 16:03:00 -0700 Subject: [PATCH 50/88] test(build): require native VLC playlist playback in the staged app --- rust/obs-build/src/platform/mod.rs | 2 + rust/obs-build/src/plugins.rs | 5 ++ rust/obs-build/tests/libobs.rs | 8 +++ .../obs-build/tests/libobs/websocket_probe.py | 51 +++++++++++++++++++ 4 files changed, 66 insertions(+) diff --git a/rust/obs-build/src/platform/mod.rs b/rust/obs-build/src/platform/mod.rs index 63478f49ac..34804c41dd 100644 --- a/rust/obs-build/src/platform/mod.rs +++ b/rust/obs-build/src/platform/mod.rs @@ -345,6 +345,7 @@ pub fn configure_source( )); } let groups: &[&str] = match source { + SourceModule::Vlc => &[], SourceModule::PipeWire => &["nix"], SourceModule::Image => &["core", "slideshow", "posix"], SourceModule::Text => &["core", "nix"], @@ -359,6 +360,7 @@ pub fn configure_source( .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"], diff --git a/rust/obs-build/src/plugins.rs b/rust/obs-build/src/plugins.rs index e8e4446a8b..ccc9066ec7 100644 --- a/rust/obs-build/src/plugins.rs +++ b/rust/obs-build/src/plugins.rs @@ -388,6 +388,7 @@ pub fn build_ffmpeg( /// Built-in source and service modules with independent optional features. #[derive(Clone, Copy, Debug)] pub enum SourceModule { + Vlc, Image, Text, PulseAudio, @@ -401,6 +402,7 @@ pub enum SourceModule { 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", @@ -420,6 +422,9 @@ pub fn build_source( source: SourceModule, ) -> Result { let root = root.canonicalize().map_err(|e| e.to_string())?; + if matches!(source, SourceModule::Vlc) { + return Err("native VLC graph is not implemented".into()); + } let mut library = module(build, &root, core, source.name())?; library.sources.clear(); crate::platform::configure_source(&build.target, &root, source, &mut library)?; diff --git a/rust/obs-build/tests/libobs.rs b/rust/obs-build/tests/libobs.rs index 183535f2ac..b63f4fc2c4 100644 --- a/rust/obs-build/tests/libobs.rs +++ b/rust/obs-build/tests/libobs.rs @@ -86,6 +86,11 @@ fn c_and_rust_twins_preserve_public_data_lifecycle_and_module_apis() { ); options.core_modules.push("obs-websocket".into()); } + if std::env::var_os("OBS_BUILD_VLC").is_some() { + assert!(enabled("OBS_BUILD_APP_GUI") && std::env::var_os("OBS_BUILD_WEBSOCKET").is_some(), + "VLC integration requires the staged GUI and 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() { @@ -162,6 +167,9 @@ fn c_and_rust_twins_preserve_public_data_lifecycle_and_module_apis() { plugins::build_transitions(&build, &root, &libraries.reference).unwrap(), plugins::build_filters(&build, &root, &libraries.reference, &filters).unwrap(), ]; + if std::env::var_os("OBS_BUILD_VLC").is_some() { + modules.push(plugins::build_source(&build, &root, &libraries.reference, plugins::SourceModule::Vlc).unwrap()); + } if enabled("OBS_BUILD_SOURCES") { for source in [ plugins::SourceModule::Image, diff --git a/rust/obs-build/tests/libobs/websocket_probe.py b/rust/obs-build/tests/libobs/websocket_probe.py index 5f417cc1aa..ca03d4afb8 100644 --- a/rust/obs-build/tests/libobs/websocket_probe.py +++ b/rust/obs-build/tests/libobs/websocket_probe.py @@ -9,6 +9,7 @@ import asyncio import base64 import json +import os from pathlib import Path import subprocess import sys @@ -79,6 +80,8 @@ async def request(name: str, data=None): 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"): + await verify_vlc(runtime, request) if recording: await request("StartRecord") deadline = asyncio.get_running_loop().time() + 5 @@ -96,6 +99,54 @@ async def request(name: str, data=None): await client.close_conn() +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) From 2297dcf3cf545cd9ba531a8cdeaf88b92d9b202c Mon Sep 17 00:00:00 2001 From: Zach Vorhies Date: Sat, 17 Oct 2026 16:08:29 -0700 Subject: [PATCH 51/88] feat(build): compile VLC with optional runtime discovery and verify playback --- docs/rust-port/cc-build.md | 27 ++++++++++++++++ rust/obs-build/src/platform/mod.rs | 32 ++++++++++++++++++- rust/obs-build/src/plugins.rs | 3 -- rust/obs-build/tests/libobs.rs | 25 +++++++++++++-- .../tests/libobs/application_probe.py | 9 ++++++ .../obs-build/tests/libobs/websocket_probe.py | 7 +++- 6 files changed, 95 insertions(+), 8 deletions(-) diff --git a/docs/rust-port/cc-build.md b/docs/rust-port/cc-build.md index 9099bc38fd..fb7fefc41d 100644 --- a/docs/rust-port/cc-build.md +++ b/docs/rust-port/cc-build.md @@ -530,3 +530,30 @@ 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. + +## 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. diff --git a/rust/obs-build/src/platform/mod.rs b/rust/obs-build/src/platform/mod.rs index 34804c41dd..1dc1838e37 100644 --- a/rust/obs-build/src/platform/mod.rs +++ b/rust/obs-build/src/platform/mod.rs @@ -345,7 +345,7 @@ pub fn configure_source( )); } let groups: &[&str] = match source { - SourceModule::Vlc => &[], + SourceModule::Vlc => &["core", "posix"], SourceModule::PipeWire => &["nix"], SourceModule::Image => &["core", "slideshow", "posix"], SourceModule::Text => &["core", "nix"], @@ -383,6 +383,36 @@ pub fn configure_source( add_package(library, target, package)?; } match source { + 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); + library.definitions.extend(headers.defines); + } + 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) diff --git a/rust/obs-build/src/plugins.rs b/rust/obs-build/src/plugins.rs index ccc9066ec7..3591d2c7de 100644 --- a/rust/obs-build/src/plugins.rs +++ b/rust/obs-build/src/plugins.rs @@ -422,9 +422,6 @@ pub fn build_source( source: SourceModule, ) -> Result { let root = root.canonicalize().map_err(|e| e.to_string())?; - if matches!(source, SourceModule::Vlc) { - return Err("native VLC graph is not implemented".into()); - } let mut library = module(build, &root, core, source.name())?; library.sources.clear(); crate::platform::configure_source(&build.target, &root, source, &mut library)?; diff --git a/rust/obs-build/tests/libobs.rs b/rust/obs-build/tests/libobs.rs index b63f4fc2c4..1b8e1047b8 100644 --- a/rust/obs-build/tests/libobs.rs +++ b/rust/obs-build/tests/libobs.rs @@ -87,8 +87,10 @@ fn c_and_rust_twins_preserve_public_data_lifecycle_and_module_apis() { options.core_modules.push("obs-websocket".into()); } if std::env::var_os("OBS_BUILD_VLC").is_some() { - assert!(enabled("OBS_BUILD_APP_GUI") && std::env::var_os("OBS_BUILD_WEBSOCKET").is_some(), - "VLC integration requires the staged GUI and websocket client"); + assert!( + enabled("OBS_BUILD_APP_GUI") && std::env::var_os("OBS_BUILD_WEBSOCKET").is_some(), + "VLC integration requires the staged GUI and websocket client" + ); options.core_modules.push("vlc-video".into()); } if std::env::var_os("OBS_BUILD_FRONTEND_TOOLS").is_some() @@ -168,7 +170,24 @@ fn c_and_rust_twins_preserve_public_data_lifecycle_and_module_apis() { plugins::build_filters(&build, &root, &libraries.reference, &filters).unwrap(), ]; if std::env::var_os("OBS_BUILD_VLC").is_some() { - modules.push(plugins::build_source(&build, &root, &libraries.reference, plugins::SourceModule::Vlc).unwrap()); + 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 [ diff --git a/rust/obs-build/tests/libobs/application_probe.py b/rust/obs-build/tests/libobs/application_probe.py index 017cf5b6c9..acb019a015 100644 --- a/rust/obs-build/tests/libobs/application_probe.py +++ b/rust/obs-build/tests/libobs/application_probe.py @@ -137,6 +137,12 @@ def main() -> None: 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_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: @@ -172,6 +178,9 @@ def main() -> None: 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 scripting: scripts = saved["modules"]["scripts-tool"] assert len(scripts) == len(scripting["languages"]), "saved script list changed" diff --git a/rust/obs-build/tests/libobs/websocket_probe.py b/rust/obs-build/tests/libobs/websocket_probe.py index ca03d4afb8..c3f6e6157a 100644 --- a/rust/obs-build/tests/libobs/websocket_probe.py +++ b/rust/obs-build/tests/libobs/websocket_probe.py @@ -81,7 +81,12 @@ async def request(name: str, data=None): unknown = await client.request("NativeMissingRequest") assert unknown["d"]["requestStatus"]["code"] == 204 if os.environ.get("OBS_BUILD_VLC"): - await verify_vlc(runtime, request) + 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 recording: await request("StartRecord") deadline = asyncio.get_running_loop().time() + 5 From b2f9b9182b47908c9488e222341ce907b473a493 Mon Sep 17 00:00:00 2001 From: Zach Vorhies Date: Sat, 17 Oct 2026 16:09:41 -0700 Subject: [PATCH 52/88] test(build): require building the unchanged C tests through cc --- rust/obs-build/src/lib.rs | 1 + rust/obs-build/src/validation.rs | 17 +++++++++++++++++ rust/obs-build/tests/libobs.rs | 22 ++++++++++++++++++++++ 3 files changed, 40 insertions(+) create mode 100644 rust/obs-build/src/validation.rs diff --git a/rust/obs-build/src/lib.rs b/rust/obs-build/src/lib.rs index b86c01b196..6fd8138202 100644 --- a/rust/obs-build/src/lib.rs +++ b/rust/obs-build/src/lib.rs @@ -15,6 +15,7 @@ mod platform; pub mod plugins; pub mod qt; pub mod scripting; +pub mod validation; #[derive(Clone, Debug, Default)] pub struct SharedLibrary { diff --git a/rust/obs-build/src/validation.rs b/rust/obs-build/src/validation.rs new file mode 100644 index 0000000000..6ce37c3dd6 --- /dev/null +++ b/rust/obs-build/src/validation.rs @@ -0,0 +1,17 @@ +//! Build the unchanged native C tests through the Cargo native engine. +use crate::NativeBuild; +use std::path::{Path, PathBuf}; + +pub struct Executable { + pub name: String, + pub path: PathBuf, +} + +pub fn build_c_tests( + _build: &NativeBuild, + _root: &Path, + _core: &Path, + _hevc: bool, +) -> Result, String> { + Err("native C test compilation is not implemented".into()) +} diff --git a/rust/obs-build/tests/libobs.rs b/rust/obs-build/tests/libobs.rs index 1b8e1047b8..08c75d73db 100644 --- a/rust/obs-build/tests/libobs.rs +++ b/rust/obs-build/tests/libobs.rs @@ -101,6 +101,28 @@ fn c_and_rust_twins_preserve_public_data_lifecycle_and_module_apis() { let libraries = libobs::build_pair(&build, &root, &options, &archive).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, options.hevc).unwrap(); + assert_eq!(executables.len(), if options.hevc { 51 } else { 50 }); + 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 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 output = std::process::Command::new(&test.path).current_dir(&directory).env("LD_LIBRARY_PATH", paths).output().unwrap(); + std::fs::write(directory.join("stdout.log"), &output.stdout).unwrap(); + std::fs::write(directory.join("stderr.log"), &output.stderr).unwrap(); + assert!(output.status.success(), "{} against {variant} failed: {}", test.name, String::from_utf8_lossy(&output.stderr)); + results.push(serde_json::json!({"variant": variant, "test":test.name, "exit":output.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) From 4369949a7fd18888d6a4d2523d6029d8b5c7c633 Mon Sep 17 00:00:00 2001 From: Zach Vorhies Date: Sat, 17 Oct 2026 16:19:19 -0700 Subject: [PATCH 53/88] feat(build): compile and run the native C test inventory with cc --- docs/rust-port/cc-build.md | 44 +- rust/obs-build/manifests/c-tests-linux.json | 454 ++++++++++++++++++++ rust/obs-build/src/platform/mod.rs | 65 ++- rust/obs-build/src/validation.rs | 175 +++++++- rust/obs-build/tests/libobs.rs | 91 +++- 5 files changed, 805 insertions(+), 24 deletions(-) create mode 100644 rust/obs-build/manifests/c-tests-linux.json diff --git a/docs/rust-port/cc-build.md b/docs/rust-port/cc-build.md index fb7fefc41d..176207bdbb 100644 --- a/docs/rust-port/cc-build.md +++ b/docs/rust-port/cc-build.md @@ -490,9 +490,9 @@ 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. The complete Linux Tier 2 CI result still needs verification -on the updated branch; local source parity and HEVC on/off lifecycle/symbol -checks pass (1766/1762 exports respectively, identical between cores). +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 @@ -529,7 +529,43 @@ 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. +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. The subsequent VLC and native-test +builder commits require their own remote verification. ## Linux VLC media source 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..6f9cd40bf0 --- /dev/null +++ b/rust/obs-build/manifests/c-tests-linux.json @@ -0,0 +1,454 @@ +[ + { + "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" + ] + } +] diff --git a/rust/obs-build/src/platform/mod.rs b/rust/obs-build/src/platform/mod.rs index 1dc1838e37..62e8cf2c3a 100644 --- a/rust/obs-build/src/platform/mod.rs +++ b/rust/obs-build/src/platform/mod.rs @@ -402,7 +402,9 @@ pub fn configure_source( } if let Some(headers) = headers { includes.extend(headers.include_paths); - library.definitions.extend(headers.defines); + 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 @@ -463,6 +465,67 @@ pub fn configure_source( 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" diff --git a/rust/obs-build/src/validation.rs b/rust/obs-build/src/validation.rs index 6ce37c3dd6..0f6cd42cfb 100644 --- a/rust/obs-build/src/validation.rs +++ b/rust/obs-build/src/validation.rs @@ -1,17 +1,178 @@ //! Build the unchanged native C tests through the Cargo native engine. -use crate::NativeBuild; -use std::path::{Path, PathBuf}; +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, + } + } +} + pub fn build_c_tests( - _build: &NativeBuild, - _root: &Path, - _core: &Path, - _hevc: bool, + build: &NativeBuild, + root: &Path, + core: &Path, + options: &Options, ) -> Result, String> { - Err("native C test compilation is not implemented".into()) + 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 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 index 08c75d73db..dcf96516b2 100644 --- a/rust/obs-build/tests/libobs.rs +++ b/rust/obs-build/tests/libobs.rs @@ -102,26 +102,93 @@ fn c_and_rust_twins_preserve_public_data_lifecycle_and_module_apis() { 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, options.hevc).unwrap(); + 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 { 51 } else { 50 }); let mut results = Vec::new(); for core in [&libraries.reference, &libraries.with_rust] { - let variant = core.parent().unwrap().file_name().unwrap().to_string_lossy(); + 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); + let directory = build + .output + .join("c-test-runs") + .join(variant.as_ref()) + .join(&test.name); std::fs::create_dir_all(&directory).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(); + 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 output = std::process::Command::new(&test.path).current_dir(&directory).env("LD_LIBRARY_PATH", paths).output().unwrap(); - std::fs::write(directory.join("stdout.log"), &output.stdout).unwrap(); - std::fs::write(directory.join("stderr.log"), &output.stderr).unwrap(); - assert!(output.status.success(), "{} against {variant} failed: {}", test.name, String::from_utf8_lossy(&output.stderr)); - results.push(serde_json::json!({"variant": variant, "test":test.name, "exit":output.status.code()})); + 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(); + 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") From c70a07b01fabaf18ee67597d6387cea487dd2673 Mon Sep 17 00:00:00 2001 From: Zach Vorhies Date: Sat, 17 Oct 2026 16:23:01 -0700 Subject: [PATCH 54/88] test(build): require compiled PCH with language and invalidation parity --- rust/obs-build/src/lib.rs | 11 +++++++++ rust/obs-build/tests/native.rs | 44 ++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+) diff --git a/rust/obs-build/src/lib.rs b/rust/obs-build/src/lib.rs index 6fd8138202..c7747e1d1c 100644 --- a/rust/obs-build/src/lib.rs +++ b/rust/obs-build/src/lib.rs @@ -17,6 +17,12 @@ 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, @@ -26,6 +32,8 @@ pub struct SharedLibrary { 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, @@ -132,6 +140,9 @@ impl NativeBuild { } fn objects(&self, library: &SharedLibrary) -> Result<(PathBuf, bool, Vec), String> { + if !library.precompiled_headers.is_empty() { + return Err("compiled precompiled headers are not implemented".into()); + } if library.name.is_empty() || !library .name diff --git a/rust/obs-build/tests/native.rs b/rust/obs-build/tests/native.rs index a35216c6fa..f786e6bfa9 100644 --- a/rust/obs-build/tests/native.rs +++ b/rust/obs-build/tests/native.rs @@ -168,6 +168,50 @@ fn executable_runs_against_its_shared_core_dependency() { 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 write_header = |value| fs::write(&header, format!("#pragma once\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; }\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, FIXTURE_CPP}; return fixture_c() + values[0] + values[1]; }\n").unwrap(); + for unity in [false, true] { + write_header(17); + 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); + 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", &[]) }, 86); + } +} + #[test] fn explicit_groups_compile_as_individual_sources_and_observe_member_edits() { let directory = tempfile::tempdir().unwrap(); From 5f04b9f0a97de547049747bdec0435db31dae04f Mon Sep 17 00:00:00 2001 From: Zach Vorhies Date: Sat, 17 Oct 2026 16:47:07 -0700 Subject: [PATCH 55/88] build: add optional compiled PCH to native Linux cores --- docs/rust-port/cc-build.md | 75 +++++++++++++++++++++++++- rust/obs-build/src/groups.rs | 33 ++++++++++++ rust/obs-build/src/lib.rs | 66 ++++++++++++++++++----- rust/obs-build/src/libobs.rs | 10 ++++ rust/obs-build/src/pch.rs | 87 ++++++++++++++++++++++++++++++ rust/obs-build/src/platform/mod.rs | 18 +++++++ rust/obs-build/tests/libobs.rs | 12 +++++ rust/obs-build/tests/native.rs | 78 ++++++++++++++++++++++++--- 8 files changed, 356 insertions(+), 23 deletions(-) create mode 100644 rust/obs-build/src/pch.rs diff --git a/docs/rust-port/cc-build.md b/docs/rust-port/cc-build.md index 176207bdbb..d8f54d8afa 100644 --- a/docs/rust-port/cc-build.md +++ b/docs/rust-port/cc-build.md @@ -564,8 +564,10 @@ absent from the selected executable dependencies. This is the selected 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. The subsequent VLC and native-test -builder commits require their own remote verification. +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 @@ -593,3 +595,72 @@ 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. + +## 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 + +Local GCC measurements used four compilation jobs, 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 the table's order, so these observations are not an isolated benchmark. +The integration driver writes the interval and selected options to +`core-build-timing.json` under `OBS_BUILD_TEST_OUTPUT`; repeat the same invocation +with that output directory to collect additional samples. + +| Unity | Compiled PCH | Fresh output | Repeat median | Repeat range | +| --- | --- | ---: | ---: | ---: | +| On | Off | 15.65 s | 1.98 s | 1.91–2.08 s | +| On | On | 33.30 s | 6.90 s | 4.59–8.64 s | +| Off | Off | 11.66 s | 3.35 s | 3.28–4.56 s | +| Off | On | 25.62 s | 7.01 s | 6.81–8.71 s | + +The final repeat in each mode reported zero compiler-cache misses. Two earlier +repeat invocations lacked usable soldr summary statistics; their elapsed times +remain recorded, without an inferred hit count. Cache summaries cover the +whole integration invocation, not just the timed core pair. + +PCH does not improve these measured runs. Unity remains enabled and PCH disabled +by default. PCH preparation and its per-header compilation batches still need +performance work before recommending it. These results do not establish full +application build time, clean-cache performance, a CMake comparison or Cargo +no-op behavior. diff --git a/rust/obs-build/src/groups.rs b/rust/obs-build/src/groups.rs index c4adcb90f9..4c93ca7d22 100644 --- a/rust/obs-build/src/groups.rs +++ b/rust/obs-build/src/groups.rs @@ -5,6 +5,39 @@ use std::{ 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, diff --git a/rust/obs-build/src/lib.rs b/rust/obs-build/src/lib.rs index c7747e1d1c..aee4dac5ec 100644 --- a/rust/obs-build/src/lib.rs +++ b/rust/obs-build/src/lib.rs @@ -11,6 +11,7 @@ pub mod frontend; pub mod graphics; mod groups; pub mod libobs; +mod pch; mod platform; pub mod plugins; pub mod qt; @@ -49,6 +50,12 @@ pub struct NativeBuild { 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( @@ -140,9 +147,6 @@ impl NativeBuild { } fn objects(&self, library: &SharedLibrary) -> Result<(PathBuf, bool, Vec), String> { - if !library.precompiled_headers.is_empty() { - return Err("compiled precompiled headers are not implemented".into()); - } if library.name.is_empty() || !library .name @@ -157,31 +161,65 @@ impl NativeBuild { 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 c_sources = Vec::new(); - let mut cpp_sources = Vec::new(); + 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()))?; - match source.extension().and_then(|e| e.to_str()) { - Some("c") => c_sources.push(absolute), - Some("cpp" | "cc" | "cxx") => cpp_sources.push(absolute), + 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], + }), } } - let cpp_link = !cpp_sources.is_empty(); + 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 (cpp, sources) in [(false, c_sources), (true, cpp_sources)] { - if sources.is_empty() { - continue; - } + 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(if cpp { "unity.cpp" } else { "unity.c" }); + 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")?; diff --git a/rust/obs-build/src/libobs.rs b/rust/obs-build/src/libobs.rs index e57c871a2d..c232e47f38 100644 --- a/rust/obs-build/src/libobs.rs +++ b/rust/obs-build/src/libobs.rs @@ -10,6 +10,8 @@ use std::{ 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, @@ -21,6 +23,7 @@ impl Default for Options { fn default() -> Self { Self { unity: true, + pch: false, hevc: true, wayland: true, pulseaudio: true, @@ -138,6 +141,9 @@ fn prepare(build: &NativeBuild, root: &Path, options: &Options) -> Result 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/mod.rs b/rust/obs-build/src/platform/mod.rs index 62e8cf2c3a..4b0ae3aaa0 100644 --- a/rust/obs-build/src/platform/mod.rs +++ b/rust/obs-build/src/platform/mod.rs @@ -8,6 +8,24 @@ use std::{ 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, diff --git a/rust/obs-build/tests/libobs.rs b/rust/obs-build/tests/libobs.rs index dcf96516b2..0e14385bc7 100644 --- a/rust/obs-build/tests/libobs.rs +++ b/rust/obs-build/tests/libobs.rs @@ -42,6 +42,7 @@ fn c_and_rust_twins_preserve_public_data_lifecycle_and_module_apis() { .unwrap_or_else(|| output.path().into()), }; 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") { @@ -98,7 +99,18 @@ fn c_and_rust_twins_preserve_public_data_lifecycle_and_module_apis() { { 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() { diff --git a/rust/obs-build/tests/native.rs b/rust/obs-build/tests/native.rs index f786e6bfa9..b12d6d5d38 100644 --- a/rust/obs-build/tests/native.rs +++ b/rust/obs-build/tests/native.rs @@ -177,13 +177,17 @@ fn pch_preserves_mixed_languages_unity_and_header_flag_invalidation() { let directory = tempfile::tempdir().unwrap(); let root = directory.path(); let header = root.join("common.h"); - let write_header = |value| fs::write(&header, format!("#pragma once\n#define HEADER_VALUE {value}\n#ifdef __cplusplus\n#include \n#else\n#include \n#endif\n")).unwrap(); + 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; }\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, FIXTURE_CPP}; return fixture_c() + values[0] + values[1]; }\n").unwrap(); + 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(), @@ -195,9 +199,12 @@ fn pch_preserves_mixed_languages_unity_and_header_flag_invalidation() { 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()], - }); + 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); @@ -205,10 +212,14 @@ fn pch_preserves_mixed_languages_unity_and_header_flag_invalidation() { 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", &[]) }, 86); + assert_eq!(unsafe { answer(&artifact, b"obs_fixture_pch", &[]) }, 108); } } @@ -323,3 +334,56 @@ fn mixed_c_and_cpp_use_independent_flags_and_the_cpp_linker() { .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); + } +} From 777daa806472e3e26b1166de982a0014349232c9 Mon Sep 17 00:00:00 2001 From: Zach Vorhies Date: Sat, 17 Oct 2026 16:49:50 -0700 Subject: [PATCH 56/88] test(obs-sys): require configurable bundled native build modes --- rust/obs-sys/build-options.rs | 16 ++++++++++++ rust/obs-sys/tests/native.rs | 46 +++++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+) create mode 100644 rust/obs-sys/build-options.rs diff --git a/rust/obs-sys/build-options.rs b/rust/obs-sys/build-options.rs new file mode 100644 index 0000000000..6f50d68246 --- /dev/null +++ b/rust/obs-sys/build-options.rs @@ -0,0 +1,16 @@ +//! 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(_lookup: impl FnMut(&str) -> Option) -> Result { + Err("bundled native build modes are not implemented".into()) + } +} diff --git a/rust/obs-sys/tests/native.rs b/rust/obs-sys/tests/native.rs index 17a1050981..c169fd2d15 100644 --- a/rust/obs-sys/tests/native.rs +++ b/rust/obs-sys/tests/native.rs @@ -1,3 +1,49 @@ +#[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. From 352bac56d1b91d85a84eb9d8fe80df63010cf947 Mon Sep 17 00:00:00 2001 From: Zach Vorhies Date: Sat, 17 Oct 2026 16:58:09 -0700 Subject: [PATCH 57/88] build(obs-sys): configure bundled unity and PCH through Cargo --- docs/rust-port/cc-build.md | 52 +++++++++++++++++++++++++++++++++++ rust/obs-sys/build-options.rs | 16 +++++++++-- rust/obs-sys/build.rs | 23 +++++++++++++++- rust/obs-sys/src/lib.rs | 4 +++ 4 files changed, 92 insertions(+), 3 deletions(-) diff --git a/docs/rust-port/cc-build.md b/docs/rust-port/cc-build.md index d8f54d8afa..16f585aea2 100644 --- a/docs/rust-port/cc-build.md +++ b/docs/rust-port/cc-build.md @@ -664,3 +664,55 @@ by default. PCH preparation and its per-header compilation batches still need performance work before recommending it. These results do not establish full application build time, clean-cache performance, a CMake comparison or Cargo no-op behavior. + +## 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. The subsequent bundled-mode changes require their own remote run. diff --git a/rust/obs-sys/build-options.rs b/rust/obs-sys/build-options.rs index 6f50d68246..f5a153fe97 100644 --- a/rust/obs-sys/build-options.rs +++ b/rust/obs-sys/build-options.rs @@ -10,7 +10,19 @@ pub struct BuildModes { } impl BuildModes { - pub fn from_lookup(_lookup: impl FnMut(&str) -> Option) -> Result { - Err("bundled native build modes are not implemented".into()) + 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 index 1158d0cc2a..ac40ab4345 100644 --- a/rust/obs-sys/build.rs +++ b/rust/obs-sys/build.rs @@ -1,7 +1,17 @@ +#[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()); @@ -24,8 +34,19 @@ fn main() { target: std::env::var("TARGET").unwrap(), output: std::path::PathBuf::from(std::env::var_os("OUT_DIR").unwrap()).join("native"), }; - let library = obs_build::libobs::build(&build, &root) + 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() diff --git a/rust/obs-sys/src/lib.rs b/rust/obs-sys/src/lib.rs index 777ea1b59f..4fa9c7d5be 100644 --- a/rust/obs-sys/src/lib.rs +++ b/rust/obs-sys/src/lib.rs @@ -2,6 +2,10 @@ //! //! `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)] From ca7187b3215299e9bf9c671281bdc018c4d7a251 Mon Sep 17 00:00:00 2001 From: Zach Vorhies Date: Sat, 17 Oct 2026 17:07:44 -0700 Subject: [PATCH 58/88] test(build): require native browser module and CEF helper artifacts --- rust/obs-build/src/plugins.rs | 4 ++ rust/obs-build/src/plugins/browser.rs | 26 ++++++++++++ rust/obs-build/tests/libobs.rs | 58 +++++++++++++++++++++++---- 3 files changed, 81 insertions(+), 7 deletions(-) create mode 100644 rust/obs-build/src/plugins/browser.rs diff --git a/rust/obs-build/src/plugins.rs b/rust/obs-build/src/plugins.rs index 3591d2c7de..272bed9b72 100644 --- a/rust/obs-build/src/plugins.rs +++ b/rust/obs-build/src/plugins.rs @@ -1,8 +1,12 @@ //! 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}; diff --git a/rust/obs-build/src/plugins/browser.rs b/rust/obs-build/src/plugins/browser.rs new file mode 100644 index 0000000000..1c71d25fdb --- /dev/null +++ b/rust/obs-build/src/plugins/browser.rs @@ -0,0 +1,26 @@ +//! The original browser source, browser-panel interfaces and CEF helper. +use super::Module; +use crate::NativeBuild; +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, +} + +pub fn build( + _build: &NativeBuild, + _root: &Path, + _core: &Path, + _api: &Path, + _options: &Options, +) -> Result { + Err("native browser module and CEF helper are not implemented".into()) +} diff --git a/rust/obs-build/tests/libobs.rs b/rust/obs-build/tests/libobs.rs index 0e14385bc7..4c5d376457 100644 --- a/rust/obs-build/tests/libobs.rs +++ b/rust/obs-build/tests/libobs.rs @@ -318,13 +318,15 @@ fn c_and_rust_twins_preserve_public_data_lifecycle_and_module_apis() { .unwrap(), ); } - let frontend = (enabled("OBS_BUILD_QT") || enabled("OBS_BUILD_APP")).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 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, @@ -351,6 +353,48 @@ fn c_and_rust_twins_preserve_public_data_lifecycle_and_module_apis() { ) .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_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()); + assert!(String::from_utf8_lossy(&deps.stdout).contains("libcef.so")); + } + 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")) { From 25407c3a925efde8311f184a268b7ee0b75225f5 Mon Sep 17 00:00:00 2001 From: Zach Vorhies Date: Sat, 17 Oct 2026 18:35:19 -0700 Subject: [PATCH 59/88] build: enable Linux CEF browser module and docks with cc::Build Preserve the browser runtime and JavaScript bridge checks against both core variants. Use a disposable basic-store profile for isolated GUI validation; production credential storage is unchanged. Depends on obs-rust/obs-browser#1. Full platform and packaging conversion remains in progress. --- docs/features.md | 5 + docs/rust-port/cc-build.md | 109 ++++++++- plugins/obs-browser | 2 +- rust/obs-build/manifests/obs-browser.json | 29 +++ rust/obs-build/src/frontend.rs | 46 +++- rust/obs-build/src/platform/mod.rs | 35 +++ rust/obs-build/src/plugins/browser.rs | 216 +++++++++++++++++- rust/obs-build/tests/libobs.rs | 34 ++- rust/obs-build/tests/libobs/application.rs | 5 + .../tests/libobs/application_probe.py | 57 ++++- rust/obs-build/tests/libobs/tools.rs | 93 +++++++- .../obs-build/tests/libobs/websocket_probe.py | 55 +++++ 12 files changed, 667 insertions(+), 19 deletions(-) create mode 100644 rust/obs-build/manifests/obs-browser.json diff --git a/docs/features.md b/docs/features.md index 9eb2fa8074..c29eb38eee 100644 --- a/docs/features.md +++ b/docs/features.md @@ -1269,6 +1269,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 index 16f585aea2..2359ee411f 100644 --- a/docs/rust-port/cc-build.md +++ b/docs/rust-port/cc-build.md @@ -637,8 +637,13 @@ includes native compilation and runtime checks and is not a build benchmark. ### Scoped core build measurements -Local GCC measurements used four compilation jobs, fixed opt-level 2 with debug -information, one fresh output directory per mode and three repeated builds. +Local GCC measurements used fixed opt-level 2 with debug information, one fresh +output directory per mode and three repeated builds. The wrapper requested four +Cargo jobs, but did not set `NUM_JOBS` for the standalone native integration +process. That process has no inherited Cargo jobserver, so cc 1.6 falls back to +machine parallelism. The original claim of four native jobs is withdrawn; these +observations do not provide a controlled native concurrency comparison. Future +standalone runs must set `NUM_JOBS` explicitly as well as `CARGO_BUILD_JOBS`. 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 @@ -715,4 +720,102 @@ 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. The subsequent bundled-mode changes require their own remote run. +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. Its initialization-failure branch still +needs runtime coverage. Browser-source rendering is now 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 under an explicit native job limit +remains necessary for cache evidence. 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/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/src/frontend.rs b/rust/obs-build/src/frontend.rs index e9b954bab9..b41bddc4a0 100644 --- a/rust/obs-build/src/frontend.rs +++ b/rust/obs-build/src/frontend.rs @@ -56,21 +56,44 @@ pub fn add_spinbox( Ok(()) } -/// Build the Linux frontend graph without browser panels; broader platform and -/// feature configurations remain under conversion. +#[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 common: Vec = + 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())?; @@ -95,6 +118,23 @@ pub fn build_application( ..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", diff --git a/rust/obs-build/src/platform/mod.rs b/rust/obs-build/src/platform/mod.rs index 4b0ae3aaa0..a169b7644f 100644 --- a/rust/obs-build/src/platform/mod.rs +++ b/rust/obs-build/src/platform/mod.rs @@ -746,6 +746,41 @@ pub fn configure_application( 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 { diff --git a/rust/obs-build/src/plugins/browser.rs b/rust/obs-build/src/plugins/browser.rs index 1c71d25fdb..0b7dbaf181 100644 --- a/rust/obs-build/src/plugins/browser.rs +++ b/rust/obs-build/src/plugins/browser.rs @@ -1,6 +1,6 @@ //! The original browser source, browser-panel interfaces and CEF helper. -use super::Module; -use crate::NativeBuild; +use super::{Module, finish, module}; +use crate::{NativeBuild, SharedLibrary, frontend, libobs::add_package}; use std::path::{Path, PathBuf}; pub struct Options { @@ -15,12 +15,212 @@ pub struct Artifacts { 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, + build: &NativeBuild, + root: &Path, + core: &Path, + api: &Path, + options: &Options, ) -> Result { - Err("native browser module and CEF helper are not implemented".into()) + 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/tests/libobs.rs b/rust/obs-build/tests/libobs.rs index 4c5d376457..471a792b9e 100644 --- a/rust/obs-build/tests/libobs.rs +++ b/rust/obs-build/tests/libobs.rs @@ -70,6 +70,13 @@ fn c_and_rust_twins_preserve_public_data_lifecycle_and_module_apis() { }, ..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()); + } if enabled("OBS_BUILD_APP_GUI") && std::env::var_os("OBS_BUILD_NVENC").is_some() { options.core_modules.push("obs-nvenc".into()); } @@ -371,6 +378,12 @@ fn c_and_rust_twins_preserve_public_data_lifecycle_and_module_apis() { 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", @@ -388,8 +401,20 @@ fn c_and_rust_twins_preserve_public_data_lifecycle_and_module_apis() { .output() .unwrap(); assert!(deps.status.success()); - assert!(String::from_utf8_lossy(&deps.stdout).contains("libcef.so")); + 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 { @@ -406,12 +431,16 @@ fn c_and_rust_twins_preserve_public_data_lifecycle_and_module_apis() { std::env::var_os("OBS_BUILD_GPU_ARCHIVE") .expect("build obs-gpu-status-frontend in release mode first"), ); - let executable = frontend::build_application( + 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) @@ -498,6 +527,7 @@ fn c_and_rust_twins_preserve_public_data_lifecycle_and_module_apis() { 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 { diff --git a/rust/obs-build/tests/libobs/application.rs b/rust/obs-build/tests/libobs/application.rs index d9b5f640a7..fb87254553 100644 --- a/rust/obs-build/tests/libobs/application.rs +++ b/rust/obs-build/tests/libobs/application.rs @@ -12,6 +12,7 @@ pub struct Inputs<'a> { 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>, @@ -111,6 +112,7 @@ pub fn exercise(inputs: Inputs<'_>, variants: &[Variant<'_>]) -> Result<(), Stri .chain(variant.nvenc) .chain(inputs.frontend_tools) .chain(inputs.websocket) + .chain(inputs.browser.map(|browser| &browser.module)) .chain(inputs.gui_probe) { let name = module @@ -135,6 +137,9 @@ pub fn exercise(inputs: Inputs<'_>, variants: &[Variant<'_>]) -> Result<(), Stri 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. diff --git a/rust/obs-build/tests/libobs/application_probe.py b/rust/obs-build/tests/libobs/application_probe.py index acb019a015..eb11e39275 100644 --- a/rust/obs-build/tests/libobs/application_probe.py +++ b/rust/obs-build/tests/libobs/application_probe.py @@ -3,6 +3,7 @@ from __future__ import annotations import argparse +import configparser import json import os from pathlib import Path @@ -15,9 +16,15 @@ 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) - (config / "global.ini").write_text("[General]\nLastVersion=4294967295\n") + 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" @@ -105,6 +112,11 @@ def main() -> None: 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")) @@ -123,6 +135,8 @@ def main() -> None: 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) @@ -137,6 +151,8 @@ def main() -> None: 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" @@ -161,6 +177,8 @@ def main() -> None: 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 @@ -181,6 +199,14 @@ def main() -> None: 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" @@ -208,6 +234,35 @@ def main() -> None: (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)], diff --git a/rust/obs-build/tests/libobs/tools.rs b/rust/obs-build/tests/libobs/tools.rs index 44cf6de90e..5ea3fa3f22 100644 --- a/rust/obs-build/tests/libobs/tools.rs +++ b/rust/obs-build/tests/libobs/tools.rs @@ -25,7 +25,7 @@ pub fn build(build: &NativeBuild, root: &Path, core: &Path, api: &Path) -> plugi ], ..SharedLibrary::default() }; - for package in ["simde", "Qt6Widgets"] { + for package in ["simde", "Qt6Widgets", "Qt6Test"] { let dependency = pkg_config::Config::new() .cargo_metadata(false) .probe(package) @@ -70,6 +70,14 @@ const SOURCE: &str = r#" #include #include #include +#include +#include +#include +#include +#include +#include +#include +#include #include OBS_DECLARE_MODULE() @@ -161,6 +169,87 @@ static bool open_dialog(QMenu *menu, const char *label, const char *type, const 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()); @@ -185,6 +274,8 @@ static void verify_dialogs() } 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"); } diff --git a/rust/obs-build/tests/libobs/websocket_probe.py b/rust/obs-build/tests/libobs/websocket_probe.py index c3f6e6157a..840e7e23a4 100644 --- a/rust/obs-build/tests/libobs/websocket_probe.py +++ b/rust/obs-build/tests/libobs/websocket_probe.py @@ -87,6 +87,8 @@ async def request(name: str, data=None): 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 @@ -104,6 +106,59 @@ async def request(name: str, data=None): 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([ From 1edbac96e84a8eeae858dfc9fa62f4a67ad9953d Mon Sep 17 00:00:00 2001 From: Zach Vorhies Date: Sat, 17 Oct 2026 18:43:22 -0700 Subject: [PATCH 60/88] docs: record native build measurements with explicit job limits --- docs/rust-port/cc-build.md | 59 ++++++++++++++++++-------------------- 1 file changed, 28 insertions(+), 31 deletions(-) diff --git a/docs/rust-port/cc-build.md b/docs/rust-port/cc-build.md index 2359ee411f..73a08d4808 100644 --- a/docs/rust-port/cc-build.md +++ b/docs/rust-port/cc-build.md @@ -637,38 +637,34 @@ includes native compilation and runtime checks and is not a build benchmark. ### Scoped core build measurements -Local GCC measurements used fixed opt-level 2 with debug information, one fresh -output directory per mode and three repeated builds. The wrapper requested four -Cargo jobs, but did not set `NUM_JOBS` for the standalone native integration -process. That process has no inherited Cargo jobserver, so cc 1.6 falls back to -machine parallelism. The original claim of four native jobs is withdrawn; these -observations do not provide a controlled native concurrency comparison. Future -standalone runs must set `NUM_JOBS` explicitly as well as `CARGO_BUILD_JOBS`. -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 the table's order, so these observations are not an isolated benchmark. -The integration driver writes the interval and selected options to -`core-build-timing.json` under `OBS_BUILD_TEST_OUTPUT`; repeat the same invocation -with that output directory to collect additional samples. +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 | 15.65 s | 1.98 s | 1.91–2.08 s | -| On | On | 33.30 s | 6.90 s | 4.59–8.64 s | -| Off | Off | 11.66 s | 3.35 s | 3.28–4.56 s | -| Off | On | 25.62 s | 7.01 s | 6.81–8.71 s | - -The final repeat in each mode reported zero compiler-cache misses. Two earlier -repeat invocations lacked usable soldr summary statistics; their elapsed times -remain recorded, without an inferred hit count. Cache summaries cover the -whole integration invocation, not just the timed core pair. - -PCH does not improve these measured runs. Unity remains enabled and PCH disabled -by default. PCH preparation and its per-header compilation batches still need -performance work before recommending it. These results do not establish full -application build time, clean-cache performance, a CMake comparison or Cargo -no-op behavior. +| 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. ## Bundled obs-sys configuration and Cargo scheduling @@ -817,5 +813,6 @@ the original dock editor, actual native dock pixels, local source HTML/JavaScrip 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 under an explicit native job limit -remains necessary for cache evidence. +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. From 96a5e34fca836c85bb465152f3ef86656e81f266 Mon Sep 17 00:00:00 2001 From: Zach Vorhies Date: Sat, 17 Oct 2026 18:44:40 -0700 Subject: [PATCH 61/88] docs: record unity on and PCH off as the selected default --- docs/rust-port/cc-build.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/docs/rust-port/cc-build.md b/docs/rust-port/cc-build.md index 73a08d4808..cd78bdc904 100644 --- a/docs/rust-port/cc-build.md +++ b/docs/rust-port/cc-build.md @@ -7,6 +7,13 @@ 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. +## 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 From b384ee71fc6603ab87c4ae5eb6ecf49075a51ca0 Mon Sep 17 00:00:00 2001 From: Zach Vorhies Date: Sat, 17 Oct 2026 18:50:52 -0700 Subject: [PATCH 62/88] docs: audit PCH requests and actual warm compiler execution --- docs/rust-port/cc-build.md | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/docs/rust-port/cc-build.md b/docs/rust-port/cc-build.md index cd78bdc904..d32fd94141 100644 --- a/docs/rust-port/cc-build.md +++ b/docs/rust-port/cc-build.md @@ -673,6 +673,33 @@ 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: From a0bc156429a258db256918f50a30ba84565202d5 Mon Sep 17 00:00:00 2001 From: Zach Vorhies Date: Sat, 17 Oct 2026 18:55:52 -0700 Subject: [PATCH 63/88] test: require optional FDK AAC build and actual encoded recordings --- rust/obs-build/src/plugins.rs | 5 +++++ rust/obs-build/tests/libobs.rs | 23 ++++++++++++++++++++++- rust/obs-build/tests/libobs/render.rs | 5 ++++- 3 files changed, 31 insertions(+), 2 deletions(-) diff --git a/rust/obs-build/src/plugins.rs b/rust/obs-build/src/plugins.rs index 272bed9b72..3c9df8a81f 100644 --- a/rust/obs-build/src/plugins.rs +++ b/rust/obs-build/src/plugins.rs @@ -246,6 +246,11 @@ impl FfmpegArtifacts { } } +/// Build the optional original FDK AAC encoder module. +pub fn build_fdk(_build: &NativeBuild, _root: &Path, _core: &Path) -> Result { + Err("FDK AAC native build is not implemented".into()) +} + 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")?; diff --git a/rust/obs-build/tests/libobs.rs b/rust/obs-build/tests/libobs.rs index 471a792b9e..bf12bd54ae 100644 --- a/rust/obs-build/tests/libobs.rs +++ b/rust/obs-build/tests/libobs.rs @@ -77,6 +77,9 @@ fn c_and_rust_twins_preserve_public_data_lifecycle_and_module_apis() { ); options.core_modules.push("obs-browser".into()); } + if enabled("OBS_BUILD_APP_GUI") && enabled("OBS_BUILD_FDK") { + options.core_modules.push("obs-libfdk".into()); + } if enabled("OBS_BUILD_APP_GUI") && std::env::var_os("OBS_BUILD_NVENC").is_some() { options.core_modules.push("obs-nvenc".into()); } @@ -277,6 +280,9 @@ fn c_and_rust_twins_preserve_public_data_lifecycle_and_module_apis() { plugins::build_transitions(&build, &root, &libraries.reference).unwrap(), plugins::build_filters(&build, &root, &libraries.reference, &filters).unwrap(), ]; + if enabled("OBS_BUILD_FDK") { + modules.push(plugins::build_fdk(&build, &root, &libraries.reference).unwrap()); + } if std::env::var_os("OBS_BUILD_VLC").is_some() { let vlc = plugins::build_source( &build, @@ -619,6 +625,7 @@ fn c_and_rust_twins_preserve_public_data_lifecycle_and_module_apis() { || line.contains("cc::Build graphics device") || line.contains("cc::Build recording") || line.contains("cc::Build color source") + || line.contains("cc::Build audio encoder") }) { println!("{}: {line}", path.display()); } @@ -629,6 +636,12 @@ fn c_and_rust_twins_preserve_public_data_lifecycle_and_module_apis() { String::from_utf8_lossy(&run.stdout), String::from_utf8_lossy(&run.stderr) ); + if enabled("OBS_BUILD_FDK") && recording.is_some() { + assert!( + String::from_utf8_lossy(&run.stdout) + .contains("cc::Build audio encoder: libfdk_aac") + ); + } if let Some(recording) = recording { verify_recording(&recording); } @@ -751,6 +764,9 @@ fn exercise(path: &std::path::Path, modules: &[plugins::Module], hevc: bool) { (b"obs_enum_filter_types".as_slice(), "noise_suppress_filter"), (b"obs_enum_filter_types".as_slice(), "gain_filter"), ]; + if enabled("OBS_BUILD_FDK") { + 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"), @@ -884,7 +900,7 @@ fn verify_recording(path: &std::path::Path) { "error", "-count_frames", "-show_entries", - "stream=codec_name,width,height,nb_read_frames:format=duration", + "stream=codec_name,profile,sample_rate,channels,width,height,nb_read_frames:format=duration", "-of", "json", ]) @@ -921,6 +937,11 @@ fn verify_recording(path: &std::path::Path) { .iter() .find(|stream| stream["codec_name"] == "aac") .expect("missing AAC track"); + if enabled("OBS_BUILD_FDK") { + assert_eq!(audio["profile"], "LC"); + assert_eq!(audio["sample_rate"], "48000"); + assert_eq!(audio["channels"], 2); + } assert!( audio["nb_read_frames"] .as_str() diff --git a/rust/obs-build/tests/libobs/render.rs b/rust/obs-build/tests/libobs/render.rs index 9db51c8b12..41e97861cd 100644 --- a/rust/obs-build/tests/libobs/render.rs +++ b/rust/obs-build/tests/libobs/render.rs @@ -87,7 +87,10 @@ static int record_clip(const char *path, const char *output_id) obs_data_release(settings); settings = obs_data_create(); obs_data_set_int(settings, "bitrate", 128); - obs_encoder_t *audio = obs_audio_encoder_create("ffmpeg_aac", "cc-build-audio", settings, 0, NULL); + 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); From 7f74dbf22bec8cc5e5cc795a4ff6ab3cb3a37520 Mon Sep 17 00:00:00 2001 From: Zach Vorhies Date: Sat, 17 Oct 2026 19:03:08 -0700 Subject: [PATCH 64/88] build: compile optional FDK AAC module through cc::Build --- docs/rust-port/cc-build.md | 35 +++++++++++++++++++++++++++++++--- rust/obs-build/src/plugins.rs | 7 +++++-- rust/obs-build/tests/libobs.rs | 10 +++++----- 3 files changed, 42 insertions(+), 10 deletions(-) diff --git a/docs/rust-port/cc-build.md b/docs/rust-port/cc-build.md index d32fd94141..adaa07e513 100644 --- a/docs/rust-port/cc-build.md +++ b/docs/rust-port/cc-build.md @@ -827,9 +827,13 @@ 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. Its initialization-failure branch still -needs runtime coverage. Browser-source rendering is now verified in the -disposable Linux test profile described below. +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 @@ -850,3 +854,28 @@ 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. diff --git a/rust/obs-build/src/plugins.rs b/rust/obs-build/src/plugins.rs index 3c9df8a81f..26287d6d8c 100644 --- a/rust/obs-build/src/plugins.rs +++ b/rust/obs-build/src/plugins.rs @@ -247,8 +247,11 @@ impl FfmpegArtifacts { } /// Build the optional original FDK AAC encoder module. -pub fn build_fdk(_build: &NativeBuild, _root: &Path, _core: &Path) -> Result { - Err("FDK AAC native build is not implemented".into()) +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) } pub fn build_x264(build: &NativeBuild, root: &Path, core: &Path) -> Result { diff --git a/rust/obs-build/tests/libobs.rs b/rust/obs-build/tests/libobs.rs index bf12bd54ae..6978d4d05d 100644 --- a/rust/obs-build/tests/libobs.rs +++ b/rust/obs-build/tests/libobs.rs @@ -77,7 +77,7 @@ fn c_and_rust_twins_preserve_public_data_lifecycle_and_module_apis() { ); options.core_modules.push("obs-browser".into()); } - if enabled("OBS_BUILD_APP_GUI") && enabled("OBS_BUILD_FDK") { + 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_NVENC").is_some() { @@ -280,7 +280,7 @@ fn c_and_rust_twins_preserve_public_data_lifecycle_and_module_apis() { plugins::build_transitions(&build, &root, &libraries.reference).unwrap(), plugins::build_filters(&build, &root, &libraries.reference, &filters).unwrap(), ]; - if enabled("OBS_BUILD_FDK") { + if std::env::var_os("OBS_BUILD_FDK").is_some() { modules.push(plugins::build_fdk(&build, &root, &libraries.reference).unwrap()); } if std::env::var_os("OBS_BUILD_VLC").is_some() { @@ -636,7 +636,7 @@ fn c_and_rust_twins_preserve_public_data_lifecycle_and_module_apis() { String::from_utf8_lossy(&run.stdout), String::from_utf8_lossy(&run.stderr) ); - if enabled("OBS_BUILD_FDK") && recording.is_some() { + 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") @@ -764,7 +764,7 @@ fn exercise(path: &std::path::Path, modules: &[plugins::Module], hevc: bool) { (b"obs_enum_filter_types".as_slice(), "noise_suppress_filter"), (b"obs_enum_filter_types".as_slice(), "gain_filter"), ]; - if enabled("OBS_BUILD_FDK") { + 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() { @@ -937,7 +937,7 @@ fn verify_recording(path: &std::path::Path) { .iter() .find(|stream| stream["codec_name"] == "aac") .expect("missing AAC track"); - if enabled("OBS_BUILD_FDK") { + 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); From 452911b5ca179887336cc81b1b4990531716c4cd Mon Sep 17 00:00:00 2001 From: Zach Vorhies Date: Sat, 17 Oct 2026 19:11:14 -0700 Subject: [PATCH 65/88] test: require optional JACK and sndio native modules --- rust/obs-build/src/platform/mod.rs | 5 +++++ rust/obs-build/src/plugins.rs | 4 ++++ rust/obs-build/tests/libobs.rs | 25 +++++++++++++++++++++++++ 3 files changed, 34 insertions(+) diff --git a/rust/obs-build/src/platform/mod.rs b/rust/obs-build/src/platform/mod.rs index a169b7644f..5cb3fc45ca 100644 --- a/rust/obs-build/src/platform/mod.rs +++ b/rust/obs-build/src/platform/mod.rs @@ -363,6 +363,9 @@ pub fn configure_source( )); } let groups: &[&str] = match source { + SourceModule::Jack | SourceModule::Sndio => { + return Err("optional native audio source build is not implemented".into()); + } SourceModule::Vlc => &["core", "posix"], SourceModule::PipeWire => &["nix"], SourceModule::Image => &["core", "slideshow", "posix"], @@ -383,6 +386,8 @@ pub fn configure_source( 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 => &[ diff --git a/rust/obs-build/src/plugins.rs b/rust/obs-build/src/plugins.rs index 26287d6d8c..4fba09cf32 100644 --- a/rust/obs-build/src/plugins.rs +++ b/rust/obs-build/src/plugins.rs @@ -404,6 +404,8 @@ pub enum SourceModule { Image, Text, PulseAudio, + Jack, + Sndio, PipeWire, Alsa, V4l2 { udev: bool }, @@ -418,6 +420,8 @@ impl SourceModule { 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", diff --git a/rust/obs-build/tests/libobs.rs b/rust/obs-build/tests/libobs.rs index 6978d4d05d..d71dbb67dc 100644 --- a/rust/obs-build/tests/libobs.rs +++ b/rust/obs-build/tests/libobs.rs @@ -77,6 +77,14 @@ fn c_and_rust_twins_preserve_public_data_lifecycle_and_module_apis() { ); 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()); } @@ -280,6 +288,15 @@ fn c_and_rust_twins_preserve_public_data_lifecycle_and_module_apis() { 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()); } @@ -764,6 +781,14 @@ fn exercise(path: &std::path::Path, modules: &[plugins::Module], hevc: bool) { (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")); } From b4c7cdd2fbab30a13570b36deb8070141609eb3b Mon Sep 17 00:00:00 2001 From: Zach Vorhies Date: Sat, 17 Oct 2026 19:20:27 -0700 Subject: [PATCH 66/88] build: support JACK and sndio with real native audio capture checks --- docs/rust-port/cc-build.md | 54 ++++++++ rust/obs-build/src/platform/mod.rs | 7 +- rust/obs-build/src/plugins.rs | 10 ++ rust/obs-build/tests/libobs.rs | 41 +++++- rust/obs-build/tests/libobs/render.rs | 190 +++++++++++++++++++++++++- 5 files changed, 296 insertions(+), 6 deletions(-) diff --git a/docs/rust-port/cc-build.md b/docs/rust-port/cc-build.md index adaa07e513..ee803f30a2 100644 --- a/docs/rust-port/cc-build.md +++ b/docs/rust-port/cc-build.md @@ -879,3 +879,57 @@ 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. diff --git a/rust/obs-build/src/platform/mod.rs b/rust/obs-build/src/platform/mod.rs index 5cb3fc45ca..dd75232624 100644 --- a/rust/obs-build/src/platform/mod.rs +++ b/rust/obs-build/src/platform/mod.rs @@ -363,9 +363,7 @@ pub fn configure_source( )); } let groups: &[&str] = match source { - SourceModule::Jack | SourceModule::Sndio => { - return Err("optional native audio source build is not implemented".into()); - } + SourceModule::Jack | SourceModule::Sndio => &["nix"], SourceModule::Vlc => &["core", "posix"], SourceModule::PipeWire => &["nix"], SourceModule::Image => &["core", "slideshow", "posix"], @@ -406,6 +404,9 @@ pub fn configure_source( 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. diff --git a/rust/obs-build/src/plugins.rs b/rust/obs-build/src/plugins.rs index 4fba09cf32..7e834fb72b 100644 --- a/rust/obs-build/src/plugins.rs +++ b/rust/obs-build/src/plugins.rs @@ -441,6 +441,16 @@ pub fn build_source( 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 diff --git a/rust/obs-build/tests/libobs.rs b/rust/obs-build/tests/libobs.rs index d71dbb67dc..bab85fce01 100644 --- a/rust/obs-build/tests/libobs.rs +++ b/rust/obs-build/tests/libobs.rs @@ -523,7 +523,8 @@ fn c_and_rust_twins_preserve_public_data_lifecycle_and_module_apis() { || enabled("OBS_BUILD_RECORD") || enabled("OBS_BUILD_SOURCES") || enabled("OBS_BUILD_PIPEWIRE") - || nvenc.is_some(); + || nvenc.is_some() + || captures_audio(); let renderer = wants_graphics .then(|| graphics::build_opengl(&build, &root, &libraries.reference, &options).unwrap()); let probe = renderer @@ -643,6 +644,8 @@ fn c_and_rust_twins_preserve_public_data_lifecycle_and_module_apis() { || 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") }) { println!("{}: {line}", path.display()); } @@ -659,6 +662,12 @@ fn c_and_rust_twins_preserve_public_data_lifecycle_and_module_apis() { .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); } @@ -754,7 +763,7 @@ fn exercise(path: &std::path::Path, modules: &[plugins::Module], hevc: bool) { initialize( renderer.as_ptr(), data_path.as_ptr(), - enabled("OBS_BUILD_RECORD") + enabled("OBS_BUILD_RECORD") || captures_audio() ), 0 ); @@ -883,6 +892,29 @@ fn exercise(path: &std::path::Path, modules: &[plugins::Module], hevc: bool) { 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()); @@ -989,3 +1021,8 @@ fn verify_recording(path: &std::path::Path) { 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/render.rs b/rust/obs-build/tests/libobs/render.rs index 41e97861cd..a3ae2695fa 100644 --- a/rust/obs-build/tests/libobs/render.rs +++ b/rust/obs-build/tests/libobs/render.rs @@ -20,7 +20,16 @@ pub fn build(build: &NativeBuild, root: &Path, core: &Path) -> PathBuf { compile_options: vec!["-std=gnu17".into()], ..SharedLibrary::default() }; - for package in ["simde", "x11"] { + let mut packages = vec!["simde", "x11"]; + 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) @@ -43,6 +52,15 @@ const SOURCE: &str = r#" #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; @@ -50,6 +68,176 @@ 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(); From a2176d33381660302ab6d82903a4e415c686e500 Mon Sep 17 00:00:00 2001 From: Zach Vorhies Date: Sat, 17 Oct 2026 19:22:05 -0700 Subject: [PATCH 67/88] docs: record JACK and sndio staged GUI validation --- docs/rust-port/cc-build.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/docs/rust-port/cc-build.md b/docs/rust-port/cc-build.md index ee803f30a2..1d71159629 100644 --- a/docs/rust-port/cc-build.md +++ b/docs/rust-port/cc-build.md @@ -933,3 +933,11 @@ 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. From 3f0a49d4ff3cef7b842e90bbdcc8bd2832079af1 Mon Sep 17 00:00:00 2001 From: Zach Vorhies Date: Sat, 17 Oct 2026 19:24:54 -0700 Subject: [PATCH 68/88] test: require QSV native module and matching core capabilities --- rust/obs-build/src/plugins.rs | 27 +++++++++++++ rust/obs-build/tests/libobs.rs | 73 ++++++++++++++++++++++++++++++++++ 2 files changed, 100 insertions(+) diff --git a/rust/obs-build/src/plugins.rs b/rust/obs-build/src/plugins.rs index 7e834fb72b..7a7abee9e0 100644 --- a/rust/obs-build/src/plugins.rs +++ b/rust/obs-build/src/plugins.rs @@ -254,6 +254,33 @@ pub fn build_fdk(build: &NativeBuild, root: &Path, core: &Path) -> Result 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 { + Err("Intel QSV native module build is not implemented".into()) +} + 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")?; diff --git a/rust/obs-build/tests/libobs.rs b/rust/obs-build/tests/libobs.rs index bab85fce01..46b9337ac6 100644 --- a/rust/obs-build/tests/libobs.rs +++ b/rust/obs-build/tests/libobs.rs @@ -88,6 +88,9 @@ fn c_and_rust_twins_preserve_public_data_lifecycle_and_module_apis() { 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_NVENC").is_some() { options.core_modules.push("obs-nvenc".into()); } @@ -300,6 +303,24 @@ fn c_and_rust_twins_preserve_public_data_lifecycle_and_module_apis() { 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 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, @@ -524,6 +545,7 @@ fn c_and_rust_twins_preserve_public_data_lifecycle_and_module_apis() { || enabled("OBS_BUILD_SOURCES") || enabled("OBS_BUILD_PIPEWIRE") || nvenc.is_some() + || qsv_enabled || captures_audio(); let renderer = wants_graphics .then(|| graphics::build_opengl(&build, &root, &libraries.reference, &options).unwrap()); @@ -584,6 +606,7 @@ fn c_and_rust_twins_preserve_public_data_lifecycle_and_module_apis() { } 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))) @@ -646,6 +669,7 @@ fn c_and_rust_twins_preserve_public_data_lifecycle_and_module_apis() { || line.contains("cc::Build audio encoder") || line.contains("cc::Build JACK capture") || line.contains("cc::Build sndio capture") + || line.contains("cc::Build QSV encoders") }) { println!("{}: {line}", path.display()); } @@ -656,6 +680,31 @@ fn c_and_rust_twins_preserve_public_data_lifecycle_and_module_apis() { 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(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) @@ -868,6 +917,30 @@ fn exercise(path: &std::path::Path, modules: &[plugins::Module], hevc: bool) { || 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:: Date: Sat, 17 Oct 2026 19:31:22 -0700 Subject: [PATCH 69/88] build: add Linux QSV graph with unity PCH and CMake runtime parity --- rust/obs-build/src/platform/mod.rs | 39 +++++++++++++++++++++++ rust/obs-build/src/plugins.rs | 20 +++++++++--- rust/obs-build/tests/libobs.rs | 50 ++++++++++++++++++++++++++++++ 3 files changed, 104 insertions(+), 5 deletions(-) diff --git a/rust/obs-build/src/platform/mod.rs b/rust/obs-build/src/platform/mod.rs index dd75232624..de3c68247e 100644 --- a/rust/obs-build/src/platform/mod.rs +++ b/rust/obs-build/src/platform/mod.rs @@ -350,6 +350,45 @@ pub fn configure_ffmpeg( 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" + )); + } + 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_source( target: &str, root: &Path, diff --git a/rust/obs-build/src/plugins.rs b/rust/obs-build/src/plugins.rs index 7a7abee9e0..bdef5954db 100644 --- a/rust/obs-build/src/plugins.rs +++ b/rust/obs-build/src/plugins.rs @@ -273,12 +273,22 @@ impl Default for QsvOptions { /// Build the original Intel Quick Sync encoder module. pub fn build_qsv( - _build: &NativeBuild, - _root: &Path, - _core: &Path, - _options: &QsvOptions, + build: &NativeBuild, + root: &Path, + core: &Path, + options: &QsvOptions, ) -> Result { - Err("Intel QSV native module build is not implemented".into()) + 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 { diff --git a/rust/obs-build/tests/libobs.rs b/rust/obs-build/tests/libobs.rs index 46b9337ac6..43e899e97f 100644 --- a/rust/obs-build/tests/libobs.rs +++ b/rust/obs-build/tests/libobs.rs @@ -692,6 +692,56 @@ fn c_and_rust_twins_preserve_public_data_lifecycle_and_module_apis() { .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, From 0c73e4776656bf0bd67dc7aa076ca18d5b8bf5de Mon Sep 17 00:00:00 2001 From: Zach Vorhies Date: Sat, 17 Oct 2026 19:32:03 -0700 Subject: [PATCH 70/88] test: require MP4 and MOV to honor disabled HEVC support --- rust/obs-build/tests/libobs.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/rust/obs-build/tests/libobs.rs b/rust/obs-build/tests/libobs.rs index 43e899e97f..8f655964fd 100644 --- a/rust/obs-build/tests/libobs.rs +++ b/rust/obs-build/tests/libobs.rs @@ -908,6 +908,21 @@ fn exercise(path: &std::path::Path, modules: &[plugins::Module], hevc: bool) { ]); } 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"), From a3d2588368a1039432d8eef6a4e506dcb55f8890 Mon Sep 17 00:00:00 2001 From: Zach Vorhies Date: Sat, 17 Oct 2026 19:43:54 -0700 Subject: [PATCH 71/88] fix: preserve MP4 MOV and VAAPI builds with HEVC disabled --- docs/features.md | 4 ++ docs/rust-port/cc-build.md | 78 +++++++++++++++++++++++++ plugins/obs-ffmpeg/obs-ffmpeg-vaapi.c.h | 2 + plugins/obs-outputs/mp4-mux.c.h | 12 ++++ plugins/obs-outputs/mp4-output.c.h | 8 +++ rust/obs-build/src/platform/mod.rs | 3 + rust/obs-build/tests/libobs.rs | 12 +++- 7 files changed, 118 insertions(+), 1 deletion(-) diff --git a/docs/features.md b/docs/features.md index c29eb38eee..d1cb8c7af4 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 diff --git a/docs/rust-port/cc-build.md b/docs/rust-port/cc-build.md index 1d71159629..67af3cdf1d 100644 --- a/docs/rust-port/cc-build.md +++ b/docs/rust-port/cc-build.md @@ -941,3 +941,81 @@ 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. 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-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/src/platform/mod.rs b/rust/obs-build/src/platform/mod.rs index de3c68247e..791b430bca 100644 --- a/rust/obs-build/src/platform/mod.rs +++ b/rust/obs-build/src/platform/mod.rs @@ -361,6 +361,9 @@ pub fn configure_qsv( "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") diff --git a/rust/obs-build/tests/libobs.rs b/rust/obs-build/tests/libobs.rs index 8f655964fd..6a4c06bb3b 100644 --- a/rust/obs-build/tests/libobs.rs +++ b/rust/obs-build/tests/libobs.rs @@ -601,7 +601,17 @@ fn c_and_rust_twins_preserve_public_data_lifecycle_and_module_apis() { .iter() .map(|module| (&module.library, &module.data)) .collect(); - let outputs: &[(&str, &str)] = if ffmpeg.is_some() { + 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")] From a616f3c576bbaca2fa232221e5cd79d2222af4bc Mon Sep 17 00:00:00 2001 From: Zach Vorhies Date: Sat, 17 Oct 2026 19:49:18 -0700 Subject: [PATCH 72/88] test: require the unchanged VLC compatibility suite in the Cargo graph --- rust/obs-build/src/validation.rs | 11 ++++++++++ rust/obs-build/tests/libobs.rs | 32 ++++++++++++++++++++++++++---- rust/obs-build/tests/libobs/vlc.rs | 19 ++++++++++++++++++ 3 files changed, 58 insertions(+), 4 deletions(-) create mode 100644 rust/obs-build/tests/libobs/vlc.rs diff --git a/rust/obs-build/src/validation.rs b/rust/obs-build/src/validation.rs index 0f6cd42cfb..e9033c006d 100644 --- a/rust/obs-build/src/validation.rs +++ b/rust/obs-build/src/validation.rs @@ -24,6 +24,17 @@ impl Default for Options { } } +/// 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> { + Err("VLC compatibility test build is not implemented".into()) +} + pub fn build_c_tests( build: &NativeBuild, root: &Path, diff --git a/rust/obs-build/tests/libobs.rs b/rust/obs-build/tests/libobs.rs index 6a4c06bb3b..bf188437f1 100644 --- a/rust/obs-build/tests/libobs.rs +++ b/rust/obs-build/tests/libobs.rs @@ -11,6 +11,8 @@ mod render; mod script_tests; #[path = "libobs/tools.rs"] mod tools; +#[path = "libobs/vlc.rs"] +mod vlc_tests; #[test] fn c_and_rust_twins_preserve_public_data_lifecycle_and_module_apis() { @@ -110,10 +112,17 @@ fn c_and_rust_twins_preserve_public_data_lifecycle_and_module_apis() { } if std::env::var_os("OBS_BUILD_VLC").is_some() { assert!( - enabled("OBS_BUILD_APP_GUI") && std::env::var_os("OBS_BUILD_WEBSOCKET").is_some(), - "VLC integration requires the staged GUI and websocket client" + 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" ); - options.core_modules.push("vlc-video".into()); + 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() @@ -546,12 +555,27 @@ fn c_and_rust_twins_preserve_public_data_lifecycle_and_module_apis() { || enabled("OBS_BUILD_PIPEWIRE") || nvenc.is_some() || qsv_enabled - || captures_audio(); + || captures_audio() + || std::env::var_os("OBS_BUILD_VLC_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_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( diff --git a/rust/obs-build/tests/libobs/vlc.rs b/rust/obs-build/tests/libobs/vlc.rs new file mode 100644 index 0000000000..554e66ca9f --- /dev/null +++ b/rust/obs-build/tests/libobs/vlc.rs @@ -0,0 +1,19 @@ +//! 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" + ); +} From 64e17338cec2191b47ce06d29b01c85803731e57 Mon Sep 17 00:00:00 2001 From: Zach Vorhies Date: Sat, 17 Oct 2026 19:57:05 -0700 Subject: [PATCH 73/88] build: run unchanged VLC compatibility tests through Cargo --- docs/rust-port/cc-build.md | 26 ++++++ rust/obs-build/src/validation.rs | 65 ++++++++++++-- rust/obs-build/tests/libobs.rs | 3 +- rust/obs-build/tests/libobs/application.rs | 2 +- rust/obs-build/tests/libobs/vlc.rs | 99 +++++++++++++++++++++- 5 files changed, 185 insertions(+), 10 deletions(-) diff --git a/docs/rust-port/cc-build.md b/docs/rust-port/cc-build.md index 67af3cdf1d..a2a9dca146 100644 --- a/docs/rust-port/cc-build.md +++ b/docs/rust-port/cc-build.md @@ -603,6 +603,32 @@ 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. + ## Optional compiled PCH for Linux cores `libobs::Options::pch` defaults to false and is independent of `unity`. diff --git a/rust/obs-build/src/validation.rs b/rust/obs-build/src/validation.rs index e9033c006d..c1812e92cc 100644 --- a/rust/obs-build/src/validation.rs +++ b/rust/obs-build/src/validation.rs @@ -26,13 +26,66 @@ impl Default for Options { /// 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, + build: &NativeBuild, + root: &Path, + core: &Path, + vlc: &crate::plugins::Module, + graphics: &Path, ) -> Result, String> { - Err("VLC compatibility test build is not implemented".into()) + 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( diff --git a/rust/obs-build/tests/libobs.rs b/rust/obs-build/tests/libobs.rs index bf188437f1..d0456db131 100644 --- a/rust/obs-build/tests/libobs.rs +++ b/rust/obs-build/tests/libobs.rs @@ -112,8 +112,7 @@ fn c_and_rust_twins_preserve_public_data_lifecycle_and_module_apis() { } 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"), + 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") { diff --git a/rust/obs-build/tests/libobs/application.rs b/rust/obs-build/tests/libobs/application.rs index fb87254553..a2ab369d0b 100644 --- a/rust/obs-build/tests/libobs/application.rs +++ b/rust/obs-build/tests/libobs/application.rs @@ -188,7 +188,7 @@ fn copy(source: &Path, target: &Path) -> Result<(), String> { .map_err(|e| format!("copy {} to {}: {e}", source.display(), target.display())) } -fn copy_tree(source: &Path, target: &Path) -> Result<(), String> { +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())?; diff --git a/rust/obs-build/tests/libobs/vlc.rs b/rust/obs-build/tests/libobs/vlc.rs index 554e66ca9f..27608271de 100644 --- a/rust/obs-build/tests/libobs/vlc.rs +++ b/rust/obs-build/tests/libobs/vlc.rs @@ -6,7 +6,7 @@ pub fn exercise( build: &NativeBuild, root: &Path, core: &Path, - _rust_core: &Path, + rust_core: &Path, vlc: &Module, graphics: &Path, ) { @@ -16,4 +16,101 @@ pub fn exercise( 6, "all original Linux VLC test targets are required" ); + 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("vlc-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" => { + "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 VLC 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("vlc-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(), + "VLC compatibility failures or skips: {}", + failures.join(", ") + ); } From 60beca3994bb45ec01d9c5364389c2369dd885ad Mon Sep 17 00:00:00 2001 From: Zach Vorhies Date: Sat, 17 Oct 2026 20:00:17 -0700 Subject: [PATCH 74/88] test: require graphics cmocka coverage in the Cargo graph --- rust/obs-build/src/validation.rs | 10 ++++++++++ rust/obs-build/tests/libobs.rs | 13 ++++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/rust/obs-build/src/validation.rs b/rust/obs-build/src/validation.rs index c1812e92cc..d6d20ee6dc 100644 --- a/rust/obs-build/src/validation.rs +++ b/rust/obs-build/src/validation.rs @@ -24,6 +24,16 @@ impl Default for Options { } } +/// 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> { + Err("graphics compatibility test build is not implemented".into()) +} + /// Build the unchanged VLC compatibility tests against the real native modules. pub fn build_vlc_tests( build: &NativeBuild, diff --git a/rust/obs-build/tests/libobs.rs b/rust/obs-build/tests/libobs.rs index d0456db131..8a71def5c8 100644 --- a/rust/obs-build/tests/libobs.rs +++ b/rust/obs-build/tests/libobs.rs @@ -555,12 +555,23 @@ fn c_and_rust_twins_preserve_public_data_lifecycle_and_module_apis() { || nvenc.is_some() || qsv_enabled || captures_audio() - || std::env::var_os("OBS_BUILD_VLC_C_TESTS").is_some(); + || 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); + } if std::env::var_os("OBS_BUILD_VLC_C_TESTS").is_some() { let vlc = modules .iter() From 1748b1f03e8124c8bb0de4a84c3a74aa3b60fad3 Mon Sep 17 00:00:00 2001 From: Zach Vorhies Date: Sat, 17 Oct 2026 20:04:44 -0700 Subject: [PATCH 75/88] build: add unchanged graphics audio compatibility tests to Cargo --- docs/rust-port/cc-build.md | 37 +++++++ rust/obs-build/src/validation.rs | 39 ++++++- rust/obs-build/tests/libobs.rs | 10 ++ rust/obs-build/tests/libobs/native_tests.rs | 111 ++++++++++++++++++++ rust/obs-build/tests/libobs/vlc.rs | 98 +---------------- 5 files changed, 193 insertions(+), 102 deletions(-) create mode 100644 rust/obs-build/tests/libobs/native_tests.rs diff --git a/docs/rust-port/cc-build.md b/docs/rust-port/cc-build.md index a2a9dca146..6ac5ad09ca 100644 --- a/docs/rust-port/cc-build.md +++ b/docs/rust-port/cc-build.md @@ -629,6 +629,43 @@ 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 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. + ## Optional compiled PCH for Linux cores `libobs::Options::pch` defaults to false and is independent of `unity`. diff --git a/rust/obs-build/src/validation.rs b/rust/obs-build/src/validation.rs index d6d20ee6dc..cb919f3701 100644 --- a/rust/obs-build/src/validation.rs +++ b/rust/obs-build/src/validation.rs @@ -26,12 +26,41 @@ impl Default for Options { /// Build unchanged cmocka tests that require the native graphics module. pub fn build_graphics_tests( - _build: &NativeBuild, - _root: &Path, - _core: &Path, - _graphics: &Path, + build: &NativeBuild, + root: &Path, + core: &Path, + graphics: &Path, ) -> Result, String> { - Err("graphics compatibility test build is not implemented".into()) + 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. diff --git a/rust/obs-build/tests/libobs.rs b/rust/obs-build/tests/libobs.rs index 8a71def5c8..479fca3f6d 100644 --- a/rust/obs-build/tests/libobs.rs +++ b/rust/obs-build/tests/libobs.rs @@ -3,6 +3,8 @@ 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"] @@ -571,6 +573,14 @@ fn c_and_rust_twins_preserve_public_data_lifecycle_and_module_apis() { ) .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 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/vlc.rs b/rust/obs-build/tests/libobs/vlc.rs index 27608271de..281a08fdee 100644 --- a/rust/obs-build/tests/libobs/vlc.rs +++ b/rust/obs-build/tests/libobs/vlc.rs @@ -16,101 +16,5 @@ pub fn exercise( 6, "all original Linux VLC test targets are required" ); - 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("vlc-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" => { - "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 VLC 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("vlc-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(), - "VLC compatibility failures or skips: {}", - failures.join(", ") - ); + super::native_tests::exercise(build, root, core, rust_core, &tests, "vlc"); } From b547ea12152fc2d40133d87fa6a406351ecaed60 Mon Sep 17 00:00:00 2001 From: Zach Vorhies Date: Sat, 17 Oct 2026 20:06:14 -0700 Subject: [PATCH 76/88] docs: record combined native graphics and VLC compatibility evidence --- docs/rust-port/cc-build.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/docs/rust-port/cc-build.md b/docs/rust-port/cc-build.md index 6ac5ad09ca..d27eda841a 100644 --- a/docs/rust-port/cc-build.md +++ b/docs/rust-port/cc-build.md @@ -645,6 +645,12 @@ 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 From 7253d9a4d55bc0efab12df9deb63be5c65fce83e Mon Sep 17 00:00:00 2001 From: Zach Vorhies Date: Sat, 17 Oct 2026 20:09:21 -0700 Subject: [PATCH 77/88] test: expose uninitialized sub-sample audio buffering intervals --- test/cmocka/test_audio_buffering_subsample.c | 120 ++++++++++++++++++ .../test_audio_buffering_subsample.cmake | 19 +++ 2 files changed, 139 insertions(+) create mode 100644 test/cmocka/test_audio_buffering_subsample.c create mode 100644 test/cmocka/tests.d/test_audio_buffering_subsample.cmake 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() From 306e6aa67f6fd2256e407a20521084d31cf35b01 Mon Sep 17 00:00:00 2001 From: Zach Vorhies Date: Sat, 17 Oct 2026 20:10:53 -0700 Subject: [PATCH 78/88] fix: initialize audio interval before zero-tick buffering --- docs/features.md | 5 +++++ libobs/obs-audio.c.h | 3 ++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/docs/features.md b/docs/features.md index d1cb8c7af4..a9bd6cccda 100644 --- a/docs/features.md +++ b/docs/features.md @@ -150,6 +150,11 @@ not get a line. [#1103](https://github.com/obs-rust/obs-studio/issues/1103), PR [#1104](https://github.com/obs-rust/obs-studio/pull/1104). +- 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 - **Codec availability follows the build.** MP4 and MOV outputs do not advertise 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; From d6388ca8650751016147c05cd1db1a5a949b4b0d Mon Sep 17 00:00:00 2001 From: Zach Vorhies Date: Sat, 17 Oct 2026 20:12:25 -0700 Subject: [PATCH 79/88] test: require the audio interval regression in the Cargo battery --- rust/obs-build/tests/libobs.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rust/obs-build/tests/libobs.rs b/rust/obs-build/tests/libobs.rs index 479fca3f6d..4138440ae7 100644 --- a/rust/obs-build/tests/libobs.rs +++ b/rust/obs-build/tests/libobs.rs @@ -156,7 +156,7 @@ fn c_and_rust_twins_preserve_public_data_lifecycle_and_module_apis() { }, ) .unwrap(); - assert_eq!(executables.len(), if options.hevc { 51 } else { 50 }); + 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 From de7358442c328a825967673f8b3e77ff4611d503 Mon Sep 17 00:00:00 2001 From: Zach Vorhies Date: Sat, 17 Oct 2026 20:19:59 -0700 Subject: [PATCH 80/88] build: include the audio interval regression in the native Cargo battery --- docs/features.md | 10 ++++---- docs/rust-port/cc-build.md | 27 +++++++++++++++++++++ rust/obs-build/manifests/c-tests-linux.json | 18 ++++++++++++++ rust/obs-build/src/validation.rs | 14 +++++++++++ 4 files changed, 64 insertions(+), 5 deletions(-) diff --git a/docs/features.md b/docs/features.md index a9bd6cccda..e955b00ea9 100644 --- a/docs/features.md +++ b/docs/features.md @@ -150,11 +150,6 @@ not get a line. [#1103](https://github.com/obs-rust/obs-studio/issues/1103), PR [#1104](https://github.com/obs-rust/obs-studio/pull/1104). -- 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 - **Codec availability follows the build.** MP4 and MOV outputs do not advertise @@ -620,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 diff --git a/docs/rust-port/cc-build.md b/docs/rust-port/cc-build.md index d27eda841a..687ee642b9 100644 --- a/docs/rust-port/cc-build.md +++ b/docs/rust-port/cc-build.md @@ -672,6 +672,33 @@ 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. + ## Optional compiled PCH for Linux cores `libobs::Options::pch` defaults to false and is independent of `unity`. diff --git a/rust/obs-build/manifests/c-tests-linux.json b/rust/obs-build/manifests/c-tests-linux.json index 6f9cd40bf0..e51805e408 100644 --- a/rust/obs-build/manifests/c-tests-linux.json +++ b/rust/obs-build/manifests/c-tests-linux.json @@ -450,5 +450,23 @@ "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/src/validation.rs b/rust/obs-build/src/validation.rs index cb919f3701..d861fd0e7c 100644 --- a/rust/obs-build/src/validation.rs +++ b/rust/obs-build/src/validation.rs @@ -231,6 +231,20 @@ pub fn build_c_tests( .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" { From bfa65e0dd459a0fa265cc6c972c565a0c2e8da74 Mon Sep 17 00:00:00 2001 From: Zach Vorhies Date: Sat, 17 Oct 2026 20:25:41 -0700 Subject: [PATCH 81/88] docs: record fixed-core application and audio compatibility validation --- docs/rust-port/cc-build.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/docs/rust-port/cc-build.md b/docs/rust-port/cc-build.md index 687ee642b9..526b8992ba 100644 --- a/docs/rust-port/cc-build.md +++ b/docs/rust-port/cc-build.md @@ -699,6 +699,24 @@ 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. + ## Optional compiled PCH for Linux cores `libobs::Options::pch` defaults to false and is independent of `unity`. From 2923db820cce3895be92a4a86473a31f3b0c87f2 Mon Sep 17 00:00:00 2001 From: Zach Vorhies Date: Sat, 17 Oct 2026 20:28:26 -0700 Subject: [PATCH 82/88] test: require the native WebRTC WHIP module and registrations --- rust/obs-build/src/plugins.rs | 34 ++++++++++++++++++++++++++++++++++ rust/obs-build/tests/libobs.rs | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+) diff --git a/rust/obs-build/src/plugins.rs b/rust/obs-build/src/plugins.rs index bdef5954db..1779b61b3d 100644 --- a/rust/obs-build/src/plugins.rs +++ b/rust/obs-build/src/plugins.rs @@ -254,6 +254,40 @@ pub fn build_fdk(build: &NativeBuild, root: &Path, core: &Path) -> Result Self { + Self { + 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 { + Err("WebRTC module build is not implemented".into()) +} + #[derive(Clone, Copy, Debug)] pub struct QsvOptions { pub hevc: bool, diff --git a/rust/obs-build/tests/libobs.rs b/rust/obs-build/tests/libobs.rs index 4138440ae7..de61b8a535 100644 --- a/rust/obs-build/tests/libobs.rs +++ b/rust/obs-build/tests/libobs.rs @@ -95,6 +95,9 @@ fn c_and_rust_twins_preserve_public_data_lifecycle_and_module_apis() { 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()); } @@ -314,6 +317,30 @@ fn c_and_rust_twins_preserve_public_data_lifecycle_and_module_apis() { 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() { + modules.push( + 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 { + 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 qsv_enabled { let module = plugins::build_qsv( &build, @@ -1015,6 +1042,12 @@ fn exercise(path: &std::path::Path, modules: &[plugins::Module], hevc: bool) { 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() { + 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) From 0ee3b7a739d0ece84f9c0c13bf5f01a4b622e8b2 Mon Sep 17 00:00:00 2001 From: Zach Vorhies Date: Sat, 17 Oct 2026 20:45:55 -0700 Subject: [PATCH 83/88] build: compile and stream the Linux WebRTC module through cc build --- docs/rust-port/cc-build.md | 75 +++++++ rust/obs-build/src/platform/mod.rs | 21 ++ rust/obs-build/src/plugins.rs | 68 ++++++- rust/obs-build/tests/libobs.rs | 78 +++++--- rust/obs-build/tests/libobs/render.rs | 20 +- rust/obs-build/tests/libobs/whip-probe.c | 167 ++++++++++++++++ rust/obs-build/tests/libobs/whip_receiver.py | 196 +++++++++++++++++++ 7 files changed, 594 insertions(+), 31 deletions(-) create mode 100644 rust/obs-build/tests/libobs/whip-probe.c create mode 100644 rust/obs-build/tests/libobs/whip_receiver.py diff --git a/docs/rust-port/cc-build.md b/docs/rust-port/cc-build.md index 526b8992ba..4114ec1f73 100644 --- a/docs/rust-port/cc-build.md +++ b/docs/rust-port/cc-build.md @@ -717,6 +717,11 @@ 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`. @@ -1133,3 +1138,73 @@ 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 shared libdatachannel +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. diff --git a/rust/obs-build/src/platform/mod.rs b/rust/obs-build/src/platform/mod.rs index 791b430bca..663c517741 100644 --- a/rust/obs-build/src/platform/mod.rs +++ b/rust/obs-build/src/platform/mod.rs @@ -392,6 +392,27 @@ pub fn configure_qsv( 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, diff --git a/rust/obs-build/src/plugins.rs b/rust/obs-build/src/plugins.rs index 1779b61b3d..ca543f9f96 100644 --- a/rust/obs-build/src/plugins.rs +++ b/rust/obs-build/src/plugins.rs @@ -264,6 +264,7 @@ pub struct DataChannelSdk { #[derive(Clone, Copy, Debug)] pub struct WebRtcOptions { + pub hevc: bool, pub unity: bool, pub pch: bool, } @@ -271,6 +272,7 @@ pub struct WebRtcOptions { impl Default for WebRtcOptions { fn default() -> Self { Self { + hevc: true, unity: true, pch: false, } @@ -279,13 +281,67 @@ impl Default for WebRtcOptions { /// Build the original WebRTC WHIP output and service module. pub fn build_webrtc( - _build: &NativeBuild, - _root: &Path, - _core: &Path, - _sdk: &DataChannelSdk, - _options: &WebRtcOptions, + build: &NativeBuild, + root: &Path, + core: &Path, + sdk: &DataChannelSdk, + options: &WebRtcOptions, ) -> Result { - Err("WebRTC module build is not implemented".into()) + 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)] diff --git a/rust/obs-build/tests/libobs.rs b/rust/obs-build/tests/libobs.rs index de61b8a535..7629d6b0af 100644 --- a/rust/obs-build/tests/libobs.rs +++ b/rust/obs-build/tests/libobs.rs @@ -318,28 +318,41 @@ fn c_and_rust_twins_preserve_public_data_lifecycle_and_module_apis() { } let qsv_enabled = std::env::var_os("OBS_BUILD_QSV").is_some(); if std::env::var_os("OBS_BUILD_WEBRTC").is_some() { - modules.push( - 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 { - unity: std::env::var_os("OBS_BUILD_DISABLE_WEBRTC_UNITY").is_none(), - pch: std::env::var_os("OBS_BUILD_WEBRTC_PCH").is_some(), - }, - ) - .unwrap(), - ); + 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( @@ -703,6 +716,9 @@ fn c_and_rust_twins_preserve_public_data_lifecycle_and_module_apis() { } 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); @@ -751,6 +767,7 @@ fn c_and_rust_twins_preserve_public_data_lifecycle_and_module_apis() { || 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()); } @@ -1043,6 +1060,23 @@ fn exercise(path: &std::path::Path, modules: &[plugins::Module], hevc: bool) { 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"), diff --git a/rust/obs-build/tests/libobs/render.rs b/rust/obs-build/tests/libobs/render.rs index a3ae2695fa..930513fc98 100644 --- a/rust/obs-build/tests/libobs/render.rs +++ b/rust/obs-build/tests/libobs/render.rs @@ -5,8 +5,9 @@ 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"); - if std::fs::read_to_string(&source).ok().as_deref() != Some(SOURCE) { - std::fs::write(&source, SOURCE).unwrap(); + 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(), @@ -21,6 +22,12 @@ pub fn build(build: &NativeBuild, root: &Path, core: &Path) -> PathBuf { ..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!(std::env::var_os("OBS_BUILD_RECORD").is_some()); + 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)); @@ -260,6 +267,8 @@ static void receive_frame(void *unused, struct video_data *frame) 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(); @@ -382,6 +391,11 @@ EXPORT int obs_fixture_render(const char *record_path, const char *output_id) 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) { @@ -399,7 +413,7 @@ EXPORT int obs_fixture_render(const char *record_path, const char *output_id) return 82; if (atomic_load(&invalid_frames)) return 83; - return source_status ? source_status : recording_status; + return source_status ? source_status : (streaming_status ? streaming_status : recording_status); } EXPORT void obs_fixture_close_display(void) 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)) From a425f96d8d7016d6ebede7e8f9b2b543245a0092 Mon Sep 17 00:00:00 2001 From: Zach Vorhies Date: Sat, 17 Oct 2026 20:46:33 -0700 Subject: [PATCH 84/88] test: require the original standalone WHIP tests in the Cargo graph --- rust/obs-build/Cargo.toml | 4 ++++ rust/obs-build/src/validation.rs | 5 ++++ rust/obs-build/tests/webrtc.rs | 41 ++++++++++++++++++++++++++++++++ 3 files changed, 50 insertions(+) create mode 100644 rust/obs-build/tests/webrtc.rs diff --git a/rust/obs-build/Cargo.toml b/rust/obs-build/Cargo.toml index ec0dac525d..0d4e2e5402 100644 --- a/rust/obs-build/Cargo.toml +++ b/rust/obs-build/Cargo.toml @@ -23,3 +23,7 @@ tempfile = "=3.27.0" [[test]] name = "libobs" required-features = ["libobs-integration"] + +[[test]] +name = "webrtc" +required-features = ["libobs-integration"] diff --git a/rust/obs-build/src/validation.rs b/rust/obs-build/src/validation.rs index d861fd0e7c..1894bf0f83 100644 --- a/rust/obs-build/src/validation.rs +++ b/rust/obs-build/src/validation.rs @@ -24,6 +24,11 @@ impl Default for Options { } } +/// Build the unchanged standalone WHIP clock and POSIX host tests. +pub fn build_webrtc_tests(_build: &NativeBuild, _root: &Path) -> Result, String> { + Err("standalone WebRTC test graph is not implemented".into()) +} + /// Build unchanged cmocka tests that require the native graphics module. pub fn build_graphics_tests( build: &NativeBuild, diff --git a/rust/obs-build/tests/webrtc.rs b/rust/obs-build/tests/webrtc.rs new file mode 100644 index 0000000000..42a0d74e4f --- /dev/null +++ b/rust/obs-build/tests/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).")) + ); + } +} From e94245246aff4a265cf217ad64430a1658ded2ed Mon Sep 17 00:00:00 2001 From: Zach Vorhies Date: Sat, 17 Oct 2026 20:47:55 -0700 Subject: [PATCH 85/88] build: compile the unchanged WHIP clock and host tests through Cargo --- docs/rust-port/cc-build.md | 32 +++++++++++++++++++++ rust/obs-build/Cargo.toml | 4 --- rust/obs-build/src/platform/mod.rs | 15 ++++++++++ rust/obs-build/src/validation.rs | 29 +++++++++++++++++-- rust/obs-build/tests/libobs.rs | 2 ++ rust/obs-build/tests/{ => libobs}/webrtc.rs | 0 6 files changed, 76 insertions(+), 6 deletions(-) rename rust/obs-build/tests/{ => libobs}/webrtc.rs (100%) diff --git a/docs/rust-port/cc-build.md b/docs/rust-port/cc-build.md index 4114ec1f73..7309bfdac2 100644 --- a/docs/rust-port/cc-build.md +++ b/docs/rust-port/cc-build.md @@ -1208,3 +1208,35 @@ 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. diff --git a/rust/obs-build/Cargo.toml b/rust/obs-build/Cargo.toml index 0d4e2e5402..ec0dac525d 100644 --- a/rust/obs-build/Cargo.toml +++ b/rust/obs-build/Cargo.toml @@ -23,7 +23,3 @@ tempfile = "=3.27.0" [[test]] name = "libobs" required-features = ["libobs-integration"] - -[[test]] -name = "webrtc" -required-features = ["libobs-integration"] diff --git a/rust/obs-build/src/platform/mod.rs b/rust/obs-build/src/platform/mod.rs index 663c517741..aaccd590cc 100644 --- a/rust/obs-build/src/platform/mod.rs +++ b/rust/obs-build/src/platform/mod.rs @@ -392,6 +392,21 @@ pub fn configure_qsv( 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, diff --git a/rust/obs-build/src/validation.rs b/rust/obs-build/src/validation.rs index 1894bf0f83..ea869d20f1 100644 --- a/rust/obs-build/src/validation.rs +++ b/rust/obs-build/src/validation.rs @@ -25,8 +25,33 @@ impl Default for Options { } /// Build the unchanged standalone WHIP clock and POSIX host tests. -pub fn build_webrtc_tests(_build: &NativeBuild, _root: &Path) -> Result, String> { - Err("standalone WebRTC test graph is not implemented".into()) +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. diff --git a/rust/obs-build/tests/libobs.rs b/rust/obs-build/tests/libobs.rs index 7629d6b0af..841848508c 100644 --- a/rust/obs-build/tests/libobs.rs +++ b/rust/obs-build/tests/libobs.rs @@ -15,6 +15,8 @@ mod script_tests; 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() { diff --git a/rust/obs-build/tests/webrtc.rs b/rust/obs-build/tests/libobs/webrtc.rs similarity index 100% rename from rust/obs-build/tests/webrtc.rs rename to rust/obs-build/tests/libobs/webrtc.rs From 5fee982d780458ca614cb48f70917755ed164c12 Mon Sep 17 00:00:00 2001 From: Zach Vorhies Date: Sat, 17 Oct 2026 20:57:29 -0700 Subject: [PATCH 86/88] test: stage the native runner early and honor implicit GUI recording --- docs/rust-port/cc-build.md | 40 +++++++++++++++++++++++++++ rust/obs-build/tests/libobs.rs | 20 +++++++------- rust/obs-build/tests/libobs/render.rs | 2 +- 3 files changed, 51 insertions(+), 11 deletions(-) diff --git a/docs/rust-port/cc-build.md b/docs/rust-port/cc-build.md index 7309bfdac2..d4b5a07c3f 100644 --- a/docs/rust-port/cc-build.md +++ b/docs/rust-port/cc-build.md @@ -1240,3 +1240,43 @@ 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/rust/obs-build/tests/libobs.rs b/rust/obs-build/tests/libobs.rs index 841848508c..6d28eb3c1a 100644 --- a/rust/obs-build/tests/libobs.rs +++ b/rust/obs-build/tests/libobs.rs @@ -47,6 +47,12 @@ fn c_and_rust_twins_preserve_public_data_lifecycle_and_module_apis() { .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(), @@ -576,22 +582,16 @@ fn c_and_rust_twins_preserve_public_data_lifecycle_and_module_apis() { ffmpeg = Some(artifacts); } // Mirror the app layout: the module launches its helper beside the process. - let runner = if ffmpeg.is_some() || nvenc.is_some() { - let bin = build.output.join("test-bin"); - std::fs::create_dir_all(&bin).unwrap(); + if ffmpeg.is_some() || nvenc.is_some() { + let bin = runner.parent().unwrap(); if let Some(ffmpeg) = &ffmpeg { - let helper = ffmpeg.deploy_muxer(&bin).unwrap(); + 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 runner = bin.join("obs-native-integration"); - std::fs::copy(std::env::current_exe().unwrap(), &runner).unwrap(); - runner - } else { - std::env::current_exe().unwrap() - }; + } let wants_graphics = enabled("OBS_BUILD_RENDER") || enabled("OBS_BUILD_RECORD") || enabled("OBS_BUILD_SOURCES") diff --git a/rust/obs-build/tests/libobs/render.rs b/rust/obs-build/tests/libobs/render.rs index 930513fc98..da6ec98eee 100644 --- a/rust/obs-build/tests/libobs/render.rs +++ b/rust/obs-build/tests/libobs/render.rs @@ -24,7 +24,7 @@ pub fn build(build: &NativeBuild, root: &Path, core: &Path) -> PathBuf { 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!(std::env::var_os("OBS_BUILD_RECORD").is_some()); + assert!(super::enabled("OBS_BUILD_RECORD")); library.definitions.push(("OBS_FIXTURE_WHIP".into(), None)); library.link_options.push("-lm".into()); } From 2483df4f742e436e71aa98c303ce47839d293339 Mon Sep 17 00:00:00 2001 From: Zach Vorhies Date: Sat, 17 Oct 2026 20:58:36 -0700 Subject: [PATCH 87/88] docs: defer remaining parity validation to follow-up 1390 --- docs/rust-port/cc-build.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/docs/rust-port/cc-build.md b/docs/rust-port/cc-build.md index d4b5a07c3f..ba8f68ef40 100644 --- a/docs/rust-port/cc-build.md +++ b/docs/rust-port/cc-build.md @@ -7,6 +7,14 @@ 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. From 26f33f149be4fde80c6f24769b84a7a91006f83c Mon Sep 17 00:00:00 2001 From: Zach Vorhies Date: Sat, 17 Oct 2026 21:25:16 -0700 Subject: [PATCH 88/88] docs: clarify libdatachannel SDK version in build report --- docs/rust-port/cc-build.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/rust-port/cc-build.md b/docs/rust-port/cc-build.md index ba8f68ef40..ddc0431ba0 100644 --- a/docs/rust-port/cc-build.md +++ b/docs/rust-port/cc-build.md @@ -1162,10 +1162,10 @@ 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 shared libdatachannel -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. +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`.