diff --git a/ci/cmocka_link_check.py b/ci/cmocka_link_check.py index 5e64de3f50..88527f0041 100644 --- a/ci/cmocka_link_check.py +++ b/ci/cmocka_link_check.py @@ -25,15 +25,46 @@ TRIPLES = {"win-x64": "x86_64-pc-windows-msvc", "mac-arm64": "aarch64-apple-darwin"} -def discover_targets(reply: Path) -> list[str]: +def configured_targets(reply: Path) -> list[dict]: indexes = sorted(reply.glob("index-*.json")) if not indexes: raise FileNotFoundError(f"No CMake file-api reply in {reply}") index = json.loads(indexes[-1].read_text()) model = json.loads((reply / index["reply"]["codemodel-v2"]["jsonFile"]).read_text()) - targets = [json.loads((reply / target["jsonFile"]).read_text()) - for target in model["configurations"][0]["targets"]] - rust = sorted(t["name"] for t in targets if t["type"] == "EXECUTABLE" and t["name"].endswith("_rust")) + return [json.loads((reply / target["jsonFile"]).read_text()) + for target in model["configurations"][0]["targets"]] + + +def links_rust_archive(target: dict) -> bool: + # Imported Corrosion archives do not have codemodel target entries. + return any(Path(part["fragment"].strip('"')).name in ("libobs_rust.lib", "liblibobs_rust.a") + for part in target.get("link", {}).get("commandFragments", [])) + + +def validate_msvc_providers(reply: Path) -> None: + for target in configured_targets(reply): + if target["type"] != "EXECUTABLE" or not links_rust_archive(target): + continue + if any(Path(part["fragment"].strip('"')).name == "obs.lib" + for part in target.get("link", {}).get("commandFragments", [])): + raise ValueError(f"{target['name']}: standalone Rust/support must not mix with obs.dll's full import library") + + +def discover_targets(reply: Path) -> list[str]: + targets = configured_targets(reply) + by_id = {t.get("id", t["name"]): t for t in targets} + + def uses_rust(target: dict, visited: frozenset[str] = frozenset()) -> bool: + name = target["name"] + if name == "libobs_rust-static": + return True + if name in visited or target["type"] in ("SHARED_LIBRARY", "MODULE_LIBRARY"): + return False + return any(uses_rust(by_id[dep["id"]], visited | {name}) + for dep in target.get("dependencies", []) if dep["id"] in by_id) + + rust = sorted(t["name"] for t in targets if t["type"] == "EXECUTABLE" + and (t["name"].endswith("_rust") or uses_rust(t) or links_rust_archive(t))) if not rust or not any(t["name"] == "libobs-cross-shared" and t["type"] == "SHARED_LIBRARY" for t in targets): raise ValueError("Tier 2 cross-link inventory needs Rust executables and hybrid libobs") return ["libobs-cross-shared", *rust] @@ -94,7 +125,12 @@ def cache_env(work: Path, tools: Path | None = None) -> dict[str, str]: def build_targets(alias: str, work: Path, jobs: int, env: dict[str, str]) -> None: - targets = discover_targets(work / ".cmake/api/v1/reply") + reply = work / ".cmake/api/v1/reply" + targets = discover_targets(reply) + if alias == "win-x64": + # LLD and native LINK resolve late archive members differently. Enforce + # the component boundary even when LLD happens to accept an import mix. + validate_msvc_providers(reply) (work / "link-targets.json").write_text(json.dumps(targets, indent=2) + "\n") print(f"Tier 2 {alias}: linking hybrid libobs and {len(targets) - 1} Rust fixtures ({jobs} Ninja workers)", flush=True) subprocess.run(["cmake", "--build", str(work), "--parallel", str(jobs), "--target", *targets, @@ -136,7 +172,7 @@ def _link(alias: str, work: Path, jobs: int, env: dict[str, str]) -> None: configured = time.monotonic() subprocess.run(["cmake", "-S", str(ROOT), "-B", str(work), "-G", "Ninja", f"-DOBS_CROSS_TARGET={alias}", "-DOBS_CROSS_LINK=ON", "-DOBS_CROSS_TIER2=ON", - "-DCMAKE_BUILD_TYPE=Release", f"-DRust_CARGO={wrappers / 'cargo'}", + "-DCMAKE_BUILD_TYPE=RelWithDebInfo", f"-DRust_CARGO={wrappers / 'cargo'}", f"-DRust_COMPILER={wrappers / 'rustc'}", f"-DRust_CARGO_TARGET={target}", "-DOBS_TEST_SANITIZE_PER_TARGET=OFF", f"-DCMAKE_C_COMPILER_LAUNCHER={env['CMAKE_C_COMPILER_LAUNCHER']}", diff --git a/ci/test_cmocka_link_check.py b/ci/test_cmocka_link_check.py index a984901fa0..d6928df70a 100644 --- a/ci/test_cmocka_link_check.py +++ b/ci/test_cmocka_link_check.py @@ -69,6 +69,7 @@ def test_each_alias_builds_the_full_inventory_at_the_cpu_budget(self): with self.subTest(alias=alias), tempfile.TemporaryDirectory() as temporary: work = Path(temporary) with mock.patch.object(cmocka_link_check, "discover_targets", return_value=inventory), \ + mock.patch.object(cmocka_link_check, "validate_msvc_providers"), \ mock.patch.object(cmocka_link_check.subprocess, "run") as run: cmocka_link_check.build_targets(alias, work, 3, {}) args = run.call_args.args[0] @@ -84,6 +85,7 @@ def test_alias_link_failures_propagate(self): work = Path(temporary) failure = subprocess.CalledProcessError(1, ["cmake", "--build"]) with mock.patch.object(cmocka_link_check, "discover_targets", return_value=["libobs-cross-shared", "test_existing_rust"]), \ + mock.patch.object(cmocka_link_check, "validate_msvc_providers"), \ mock.patch.object(cmocka_link_check.subprocess, "run", side_effect=failure): with self.assertRaises(subprocess.CalledProcessError): cmocka_link_check.build_targets(alias, work, 2, {}) @@ -113,21 +115,47 @@ def test_cache_is_fresh_and_cannot_inherit_relaxed_or_remote_policy(self): class DiscoveryTest(unittest.TestCase): + def test_msvc_rejects_full_dll_imports_beside_the_rust_archive(self): + with tempfile.TemporaryDirectory() as temporary: + reply = Path(temporary) + target = {"name": "fixture", "type": "EXECUTABLE", "link": {"commandFragments": [ + {"fragment": "libobs_rust.lib", "role": "libraries"}, + {"fragment": '"/build/obs.lib"', "role": "libraries"}, + ]}} + (reply / "fixture.json").write_text(json.dumps(target)) + (reply / "codemodel.json").write_text(json.dumps({"configurations": [{ + "targets": [{"name": "fixture", "jsonFile": "fixture.json"}]}]})) + (reply / "index-1.json").write_text(json.dumps({"reply": { + "codemodel-v2": {"jsonFile": "codemodel.json"}}})) + with self.assertRaisesRegex(ValueError, "must not mix"): + cmocka_link_check.validate_msvc_providers(reply) + target["link"]["commandFragments"].pop() + (reply / "fixture.json").write_text(json.dumps(target)) + cmocka_link_check.validate_msvc_providers(reply) + def test_uses_generated_target_types_and_names_not_source_regexes(self): with tempfile.TemporaryDirectory() as temporary: reply = Path(temporary) refs = [] for name, kind in (("test_existing_rust", "EXECUTABLE"), ("test_new_steps_rust", "EXECUTABLE"), - ("test_plain", "EXECUTABLE"), ("support_rust", "STATIC_LIBRARY"), + ("test_plain", "EXECUTABLE"), ("support_rust", "STATIC_LIBRARY"), + ("test_hotkey_background_enum", "EXECUTABLE"), + ("test_video_level_queries", "EXECUTABLE"), + ("libobs_rust-static", "STATIC_LIBRARY"), ("libobs-cross-shared", "SHARED_LIBRARY")): filename = name + ".json" - (reply / filename).write_text(json.dumps({"name": name, "type": kind})) - refs.append({"name": name, "jsonFile": filename}) + target = {"id": name, "name": name, "type": kind} + if name == "test_hotkey_background_enum": + target["dependencies"] = [{"id": "libobs_rust-static"}] + if name == "test_video_level_queries": + target["link"] = {"commandFragments": [{"fragment": '"/build/libobs_rust.lib"', "role": "libraries"}]} + (reply / filename).write_text(json.dumps(target)) + refs.append({"id": name, "name": name, "jsonFile": filename}) (reply / "codemodel.json").write_text(json.dumps({"configurations": [{"targets": refs}]})) (reply / "index-1.json").write_text(json.dumps({"reply": {"codemodel-v2": {"jsonFile": "codemodel.json"}}})) self.assertEqual(cmocka_link_check.discover_targets(reply), - ["libobs-cross-shared", "test_existing_rust", "test_new_steps_rust"]) + ["libobs-cross-shared", "test_existing_rust", "test_hotkey_background_enum", "test_new_steps_rust", "test_video_level_queries"]) def test_existing_reply_without_rust_executables_fails_closed(self): with tempfile.TemporaryDirectory() as temporary: diff --git a/ci/test_native_b2_portability.py b/ci/test_native_b2_portability.py index 453e9b2b8a..b7ca7ea5e3 100644 --- a/ci/test_native_b2_portability.py +++ b/ci/test_native_b2_portability.py @@ -222,6 +222,8 @@ def test_scene_archive_consumers_supply_getter_logging(self): # pulled by these pure rule tests (#3891, Windows LNK2019). graph = json.loads((ROOT / "test/cmocka/build/test-graph.json").read_text()) stub = "test/cmocka/scene-getter-log-link-stub.c" + support = json.loads((ROOT / "test/cmocka/build/rust-static-support.json").read_text()) + self.assertIn("test/cmocka/output-starting-queries-link-support.c", support["sources"]) for name in ("test_scene_audio_window_steps_rust", "test_scene_render_plan_steps_rust"): with self.subTest(name=name): self.assertEqual(graph["targets"][name]["sources"], [ @@ -244,7 +246,6 @@ def test_scene_archive_consumers_supply_getter_logging(self): "test/cmocka/source-update-properties-link-support.c", "test/cmocka/weak-object-identity-link-stub.c", "libobs/build/libobs.image-decode-adapter+.h.c", - "test/cmocka/output-starting-queries-link-support.c", ]) def test_portal_app_id_getter_uses_live_hotkey_adapters(self): diff --git a/ci/test_rust_static_link_support.py b/ci/test_rust_static_link_support.py new file mode 100644 index 0000000000..47f409fe5a --- /dev/null +++ b/ci/test_rust_static_link_support.py @@ -0,0 +1,203 @@ +#!/usr/bin/env -S uv run --script +"""Exercise the standalone Rust-static support contract with real native links.""" + +from pathlib import Path +import json +import shutil +import subprocess +import tempfile +import unittest + +ROOT = Path(__file__).resolve().parents[1] +HELPER = ROOT / "test/cmocka/rust-static-link-support.cmake" + + +@unittest.skipUnless(shutil.which("cmake") and shutil.which("cc"), "requires CMake and C compiler") +class RustStaticLinkSupport(unittest.TestCase): + def test_independent_cmake_inherits_physical_windows_sources(self): + with tempfile.TemporaryDirectory() as directory: + source = Path(directory) + manifest = source / "test/cmocka/build/rust-static-support.json" + manifest.parent.mkdir(parents=True) + manifest.write_text(json.dumps({"sources": ["common.c"], "platform_sources": { + "OS_WINDOWS": ["windows.c"], "UNIX": ["posix.c"]}})) + for name, body in { + "common.c": "int common_support(void) { return 0; }\n", + "rust.c": "int rust_support(void) { return 0; }\n", + "windows.c": "int platform_value(void) { return 13; }\n", + "posix.c": "int platform_value(void) { return 27; }\n", + "main.c": "int platform_value(void); int main(void) { return platform_value() != 13; }\n", + }.items(): + (source / name).write_text(body) + (source / "CMakeLists.txt").write_text( + "cmake_minimum_required(VERSION 3.28)\nproject(independent_support C)\n" + "set(MSVC TRUE)\nset(WIN32 TRUE)\nset(UNIX FALSE)\nunset(OS_WINDOWS)\n" + "add_library(libobs_rust-static STATIC rust.c)\n" + "add_library(caption INTERFACE)\nadd_library(OBS::caption ALIAS caption)\n" + "add_library(uthash INTERFACE)\nadd_library(Uthash::Uthash ALIAS uthash)\n" + "add_library(host_owner INTERFACE)\nadd_executable(consumer main.c)\n" + "target_link_libraries(consumer PRIVATE libobs_rust-static)\n" + f'include("{HELPER.as_posix()}")\n' + 'obs_add_rust_static_support("${CMAKE_CURRENT_SOURCE_DIR}" host_owner)\n' + ) + build = source / "build" + self.run_command(["cmake", "-S", str(source), "-B", str(build)]) + self.run_command(["cmake", "--build", str(build), "--target", "consumer"]) + self.run_command([str(build / "consumer")]) + + def test_shared_consumer_transitive_host_and_static_allocator(self): + self.check_fixture(False) + + def test_allocator_member_is_selected_before_shared_import_provider(self): + self.check_fixture(True) + + def test_non_msvc_preserves_declared_shared_binding(self): + self.check_fixture(False, False) + + def test_non_msvc_preserves_declared_static_binding(self): + self.check_fixture(False, False, True) + + def test_real_logger_members_preserve_fixture_owned_guards(self): + with tempfile.TemporaryDirectory() as directory: + source = Path(directory) + (source / "build").mkdir() + (source / "build/libobs-util.pch.h").write_text( + "#include \n#include \n#include \n" + "typedef void (*log_handler_t)(int, const char *, va_list, void *);\n" + "#define LOG_DEBUG 100\n#define LOG_INFO 200\n#define LOG_WARNING 300\n#define LOG_ERROR 400\n" + "#define UNUSED_PARAMETER(x) (void)(x)\n#define OBS_NORETURN _Noreturn\n" + ) + manifest = json.loads((ROOT / "test/cmocka/build/rust-static-support.json").read_text()) + objects = [] + for member in manifest["sources"]: + if not Path(member).name.startswith("base-"): + continue + output = source / (Path(member).stem + ".o") + self.run_command(["cc", "-std=c11", "-I", str(source), "-I", str(ROOT), + "-c", str(ROOT / member), "-o", str(output)]) + objects.append(str(output)) + archive = source / "support.a" + self.run_command(["ar", "rcs", str(archive), *objects]) + main = source / "main.c" + main.write_text( + '#include "build/libobs-util.pch.h"\n#include \n' + "static int calls, guards;\n" + "static void handler(int level, const char *fmt, va_list args, void *p) " + "{ (void)level; (void)fmt; (void)args; (void)p; ++calls; }\n" + "void base_get_log_handler(log_handler_t *h, void **p) { *h = handler; *p = NULL; }\n" + "int base_begin_crash(void (**h)(const char *, va_list, void *), void **p, int *d) " + "{ (void)h; (void)p; *d = 1; return 0; }\n" + "void blogva(int, const char *, va_list);\n" + "void base_log_literal(log_handler_t, void *, int, const char *);\n" + "log_handler_t base_default_log_handler(void);\n" + "#ifdef FIXTURE_GUARDS\n" + "void blog(int level, const char *fmt, ...) { (void)level; (void)fmt; ++guards; }\n" + "_Noreturn void bcrash(const char *fmt, ...) { (void)fmt; exit(77); }\n" + "#else\nvoid blog(int, const char *, ...);\n_Noreturn void bcrash(const char *, ...);\n#endif\n" + "static void forward(const char *fmt, ...) " + "{ va_list args; va_start(args, fmt); blogva(100, fmt, args); va_end(args); }\n" + "int main(int argc, char **argv) { (void)argv; if (argc > 1) bcrash(\"guard\"); " + "forward(\"log\"); base_log_literal(handler, NULL, 100, \"literal\"); " + "blog(100, \"public\"); if (!base_default_log_handler()) return 1;\n" + "#ifdef FIXTURE_GUARDS\nreturn calls != 2 || guards != 1;\n" + "#else\nreturn calls != 3;\n#endif\n}\n" + ) + for guarded in (False, True): + executable = source / ("guarded" if guarded else "real") + self.run_command(["cc", "-std=c11", *(["-DFIXTURE_GUARDS"] if guarded else []), + str(main), str(archive), "-o", str(executable)]) + self.run_command([str(executable)]) + result = subprocess.run([str(executable), "crash"], capture_output=True, timeout=10) + self.assertEqual(result.returncode, 77 if guarded else 0, result.stderr) + + def check_fixture(self, baseline_host, msvc=True, rust_first=False): + with tempfile.TemporaryDirectory() as directory: + source = Path(directory) + files = { + "main.c": "int rust_entry(void); int bmalloc(void); int main(void) { return rust_entry() != " + + ("18 || bmalloc() != 7" if msvc else "17 || bmalloc() != 7" if rust_first else "110 || bmalloc() != 100") + "; }\n", + "rust.c": "int private_adapter(void); int error_data_add(void); int rust_entry(void) { return error_data_add() + private_adapter(); }\n", + "allocator.c": "int bmalloc(void) { return 7; } int error_data_add(void) { return bmalloc(); }\n", + "import.c": "int bmalloc(void) { return 100; } int error_data_add(void) { return bmalloc(); }\n", + "adapter.c": "int host_value(void); int rust_callback(void); int private_adapter(void) { return host_value() + rust_callback(); }\n", + "callback.c": ("int rust_callback(void) { return 0; }\n" if msvc else + "int private_callback_adapter(void); int rust_callback(void) { return private_callback_adapter(); }\n"), + "callback-adapter.c": "int rust_leaf(void); int private_callback_adapter(void) { return rust_leaf(); }\n", + "leaf.c": "int rust_leaf(void) { return 0; }\n", + "unused.c": "int unavailable(void); int unused_adapter(void) { return unavailable(); }\n", + "host.c": "int host_value(void) { return 10; }\n", + "eager-link-support.c": "int unavailable(void); int unused_eager_adapter(void) { return unavailable(); }\n", + "fixture-link-support.c": "int host_value(void); int private_adapter(void) { return host_value() + 1; }\n", + "reference-link-support.c": "int bmalloc(void); int dll_counter(void) { return bmalloc(); }\n", + } + for name, content in files.items(): + (source / name).write_text(content) + (source / "CMakeLists.txt").write_text( + "cmake_minimum_required(VERSION 3.28)\nproject(rust_support C)\n" + # Model the MSVC import boundary with host-linkable providers. + + f"set(MSVC {'TRUE' if msvc else 'FALSE'})\n" + + + "add_library(host SHARED host.c)\n" + "add_library(host_owner INTERFACE)\n" + 'target_link_libraries(host_owner INTERFACE host "$<$:Optional::Host>")\n' + "add_library(libobs_rust-static STATIC rust.c allocator.c callback.c leaf.c)\n" + "add_library(imported_obs SHARED import.c)\n" + "add_library(OBS::libobs ALIAS imported_obs)\n" + "add_library(support STATIC adapter.c callback-adapter.c unused.c)\n" + + ("target_link_libraries(support PRIVATE host_owner)\n" if baseline_host else "") + + + "add_library(indirect INTERFACE)\n" + "target_link_libraries(indirect INTERFACE libobs_rust-static)\n" + "foreach(name IN ITEMS direct direct_copy indirect_consumer conditional_consumer)\n" + " add_executable(${name} main.c)\n" + + (" target_sources(${name} PRIVATE eager-link-support.c fixture-link-support.c)\n" if msvc else "") + + (" target_link_libraries(${name} PRIVATE libobs_rust-static OBS::libobs)\n" if rust_first else + " target_link_libraries(${name} PRIVATE OBS::libobs)\n") + + "endforeach()\n" + "target_link_libraries(direct PRIVATE libobs_rust-static)\n" + "target_link_libraries(direct_copy PRIVATE libobs_rust-static)\n" + "target_link_libraries(indirect_consumer PRIVATE indirect)\n" + 'target_link_libraries(conditional_consumer PRIVATE "$<$:indirect>")\n' + "file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/reference.c \"int dll_counter(void); int main(void) { return dll_counter() != 100; }\\n\")\n" + "add_executable(reference ${CMAKE_CURRENT_BINARY_DIR}/reference.c reference-link-support.c)\n" + 'target_link_libraries(reference PRIVATE OBS::libobs "$<$:libobs_rust-static>")\n' + f'include("{HELPER.as_posix()}" OPTIONAL)\n' + f'include("{(ROOT / "test/cmocka/shared-link-support.cmake").as_posix()}")\n' + 'cmake_language(DEFER CALL obs_share_test_link_support)\n' + "if(COMMAND obs_rust_static_consumers)\n" + " obs_rust_static_consumers(support host_owner)\n" + "else()\n" + # Baseline models the old per-target archive with no host interface. + " target_link_libraries(direct PRIVATE support)\n" + " target_link_libraries(indirect_consumer PRIVATE support)\n" + "endif()\n" + 'file(GENERATE OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/reference-links.txt" CONTENT "$>")\n' + 'if(MSVC)\n' + 'foreach(name IN ITEMS direct direct_copy indirect_consumer conditional_consumer)\n' + ' file(GENERATE OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/${name}-links.txt" CONTENT "$>")\n' + 'endforeach()\n' + 'endif()\n' + ) + build = source / "build" + self.run_command(["cmake", "-S", str(source), "-B", str(build)]) + reference_links = (build / "reference-links.txt").read_text() + self.assertNotIn("libobs_rust-static", reference_links) + self.assertNotIn("support", reference_links) + targets = ("direct",) if baseline_host else ("direct", "direct_copy", "indirect_consumer", "conditional_consumer") + self.run_command(["cmake", "--build", str(build), "--parallel", "2", "--target", "reference", *targets]) + self.run_command([str(build / "reference")]) + for name in targets: + self.run_command([str(build / name)]) + if msvc: + links = (build / f"{name}-links.txt").read_text().split(";") + self.assertEqual(links[:3], ["libobs_rust-static", f"{name}-rust-static-support", "support"]) + self.assertNotIn("OBS::libobs", links, + "standalone MSVC Rust must not mix its objects with the full OBS import provider") + + def run_command(self, command): + result = subprocess.run(command, capture_output=True, text=True, check=False, timeout=60) + self.assertEqual(result.returncode, 0, result.stdout + result.stderr) + + +if __name__ == "__main__": + unittest.main() diff --git a/cmake/cross/CMakeLists.txt b/cmake/cross/CMakeLists.txt index 933baeddcf..81159f85f6 100644 --- a/cmake/cross/CMakeLists.txt +++ b/cmake/cross/CMakeLists.txt @@ -282,12 +282,16 @@ function(_obs_cross_shared_libobs name) swresample jansson ) + add_library(${name}-native INTERFACE) + add_library(OBS::libobs-native-dependencies ALIAS ${name}-native) + target_link_directories(${name}-native INTERFACE "${OBS_CROSS_DEPS}/lib") + target_link_libraries(${name} PRIVATE ${name}-native) if(_host STREQUAL WINDOWS) # The Rust standard library pulls winsock and NT APIs in through its # objects; the shipped libobs link gets these from the same system libs. target_link_libraries( - ${name} - PRIVATE ${_common_deps} avrt dwmapi dxgi winmm rpcrt4 ws2_32 ntdll bcrypt userenv + ${name}-native + INTERFACE ${_common_deps} avrt dwmapi dxgi winmm rpcrt4 ws2_32 ntdll bcrypt userenv ) # The Rust staticlib's object directives request MSVCRT.lib / OLDNAMES.lib # with Windows' case, while the Linux-side xwin SDK ships msvcrt.lib / @@ -308,6 +312,7 @@ function(_obs_cross_shared_libobs name) ) endforeach() target_link_directories(${name} PRIVATE "${_case_lib_dir}") + target_link_directories(${name}-native INTERFACE "${_case_lib_dir}") # Rust no_mangle shims in a staticlib are not dllexport, so name them, as # libobs/cmake/rust-os-windows.cmake does for the native build. file(GLOB _obs_rust_export_fragments "${OBS_SOURCE_ROOT}/libobs/cmake/rust-exports.d/*.txt") @@ -333,12 +338,12 @@ function(_obs_cross_shared_libobs name) ${name}-pthreads PROPERTIES C_STANDARD 17 C_STANDARD_REQUIRED TRUE PREFIX "" OUTPUT_NAME w32-pthreads ) - target_link_libraries(${name} PRIVATE ${name}-pthreads) + target_link_libraries(${name}-native INTERFACE ${name}-pthreads) set_target_properties(${name} PROPERTIES IMPORT_PREFIX "" IMPORT_SUFFIX ".lib") else() target_link_libraries( - ${name} - PRIVATE + ${name}-native + INTERFACE ${_common_deps} "-framework AppKit" "-framework AudioToolbox" diff --git a/cmake/cross/tier2.cmake b/cmake/cross/tier2.cmake index 02d836e050..6d75bce12d 100644 --- a/cmake/cross/tier2.cmake +++ b/cmake/cross/tier2.cmake @@ -23,6 +23,7 @@ corrosion_import_crate( CRATE_TYPES staticlib PROFILE release ) +target_link_libraries(libobs_rust-static INTERFACE OBS::libobs-native-dependencies) if(OS_MACOS) # A host librt must never satisfy a Darwin dependency probe. diff --git a/cmake/finders/FindGio.cmake b/cmake/finders/FindGio.cmake index 42da5747e5..527a4850c6 100644 --- a/cmake/finders/FindGio.cmake +++ b/cmake/finders/FindGio.cmake @@ -109,6 +109,8 @@ if(Gio_FOUND) gio::gio PROPERTIES INTERFACE_COMPILE_OPTIONS "${PC_Gio_CFLAGS_OTHER}" + INTERFACE_LINK_LIBRARIES "${PC_Gio_LINK_LIBRARIES}" + INTERFACE_LINK_OPTIONS "${PC_Gio_LDFLAGS_OTHER}" INTERFACE_INCLUDE_DIRECTORIES "${Gio_INCLUDE_DIR};${GioUnix_INCLUDE_DIR};${Glib_INCLUDE_DIR}" VERSION ${Gio_VERSION} ) diff --git a/docs/ci-tooling.md b/docs/ci-tooling.md index 26c625434e..c097d797e3 100644 --- a/docs/ci-tooling.md +++ b/docs/ci-tooling.md @@ -258,7 +258,7 @@ cmake --build build --target cross-win-x64 # cross-mac-arm64, cross-mac-x64 #### Tier 2 pre-queue links (#5189) The Linux-hosted Tier 2 Link Check matrix links hybrid libobs and every -configured cmocka `*_rust` executable independently for Windows MSVC x86_64 and Darwin arm64 +configured Rust-static cmocka executable independently for Windows MSVC x86_64 and Darwin arm64 when `LANES["cmocka_link"]` selects the change. This includes libobs, its linked crates, obs-build registration/support, cmocka, Cargo inputs and the check's own implementation. Unrelated changes keep @@ -274,7 +274,13 @@ uv run --no-project --with cmake==3.31.10 --with ninja==1.13.0 ci/cmocka_link_ch The root CMake cross-link mode includes the unchanged cmocka graph and deferred support fragments. CMake's file-api discovers executable targets after host -conditions have been evaluated; an empty Rust inventory fails. The check builds +conditions have been evaluated, including consumers without a `_rust` suffix. +Imported Corrosion archives are discovered through generated link arguments as +well as target dependencies; an empty Rust inventory fails. The check uses +`RelWithDebInfo`, matching native Tier 2. Windows static consumers retain the +core's headers and demand-linked real C support without its full DLL import +library. The check rejects that import/static mix even if LLD accepts a link +that native MSVC LINK would reject (#5246). The check builds against real target cmocka and SDK libraries, never executes target programs, and saves `link-targets.json` in its build tree. It always refreshes the Rust archive through soldr so source-only edits cannot reuse the cross project's @@ -297,7 +303,8 @@ host Linux libraries cannot satisfy Darwin probes. A successful link does not prove runtime recording/allocator behavior or every binding/order error whose final link succeeds. -Local measurements on a shared Linux worker (four Ninja jobs, 2026-11-19): +Earlier Release measurements before #5246's complete inventory and static-only +Windows support (four Ninja jobs on a shared Linux worker, 2026-11-19): | Target | Fresh CMake/Corrosion tree | Warm tree | |---|---:|---:| @@ -309,6 +316,22 @@ these are build-tree cold timings, excluding first-host downloads. The original eight Windows category binaries also linked (128.53 s with partial Cargo reuse). These local timings are not a hosted critical-path guarantee. +Standalone Rust-static support is selected for every consumer, including tests +that also link shared libobs or inherit Rust through an interface target. +`test/cmocka/build/rust-static-support.json` owns the real private adapter members +for both CMake and Cargo-native fixtures. Linux resolves Rust and support as a +rescan group so newly selected members can call back in either direction. +Fixture-owned adapters keep their compile definitions and take precedence over +the shared fallback members. +Add new shared adapters there as separate +lazy archive members; fixture-owned definitions retain precedence. CMake inherits +the native owner (`libobs-objects`) link interface rather than maintaining host +libraries per test. Cargo's production Rust-archive dependency carries its native +package interface. Both paths put Rust before MSVC import providers so allocator +and parser symbols are selected consistently; ELF/Darwin retain the fixture's +declared DSO binding order. Link checks prove linking only; +native runtime checks still own recording callbacks and allocator behavior. + #### macOS Rust execution artifacts (#5008) The maintainer chose **STRICT** on 2026-11-17: nothing compiles on hosted diff --git a/libobs/CMakeLists.txt b/libobs/CMakeLists.txt index 3dd214e69a..4a65f947bb 100644 --- a/libobs/CMakeLists.txt +++ b/libobs/CMakeLists.txt @@ -264,6 +264,17 @@ if(TARGET libobs-c-reference) ) endif() +# Keep native link requirements in the owner's directory so imported targets and +# conditional dependencies retain their scope. Standalone Rust consumers inherit +# this interface without importing the native core's objects or the shared DSO. +add_library(libobs-native-dependencies INTERFACE) +add_library(OBS::libobs-native-dependencies ALIAS libobs-native-dependencies) +get_target_property(_native_libraries libobs-objects INTERFACE_LINK_LIBRARIES) +target_link_libraries(libobs-native-dependencies INTERFACE ${_native_libraries}) +if(TARGET libobs_rust-static) + target_link_libraries(libobs_rust-static INTERFACE OBS::libobs-native-dependencies) +endif() + # Last, once every source list and host file has filled libobs-objects: split # its groups into the lib-modules of build/modules.d (#3259). include(cmake/modules.cmake) diff --git a/libobs/build/libobs.core+.h.c b/libobs/build/libobs.core+.h.c index 4f39379c9b..eaf99c008e 100644 --- a/libobs/build/libobs.core+.h.c +++ b/libobs/build/libobs.core+.h.c @@ -4,6 +4,7 @@ #include "libobs/obs-audio-info-queries.c.h" #include "libobs/obs-base-effect-fields.c.h" +#include "libobs/obs-context-runtime.c.h" #include "libobs/obs-core-cmdline-fields.c.h" #include "libobs/obs-core-frame-interval-fields.c.h" #include "libobs/obs-core-global-fields.c.h" diff --git a/libobs/build/libobs.core-output+.h.c b/libobs/build/libobs.core-output+.h.c index fdd98c5197..d4c49b0543 100644 --- a/libobs/build/libobs.core-output+.h.c +++ b/libobs/build/libobs.core-output+.h.c @@ -38,6 +38,7 @@ #include "libobs/obs-encoder-state-queries-fields.c.h" #include "libobs/obs-encoder-type-info-fields.c.h" #include "libobs/obs-encoder-video-tex-active-fields.c.h" +#include "libobs/obs-encoder-weak-refs.c.h" #include "libobs/obs-encoder.c.h" #include "libobs/obs-output-active-fields.c.h" #include "libobs/obs-output-can-pause-fields.c.h" diff --git a/libobs/build/libobs.core-source+.h.c b/libobs/build/libobs.core-source+.h.c index 774f481b9a..a8fc16940e 100644 --- a/libobs/build/libobs.core-source+.h.c +++ b/libobs/build/libobs.core-source+.h.c @@ -100,6 +100,7 @@ #include "libobs/obs-source-update-properties-fields.c.h" #include "libobs/obs-source-update.c.h" #include "libobs/obs-source-weak-predicates-fields.c.h" +#include "libobs/obs-source-weak-refs.c.h" #include "libobs/obs-source.c.h" #include "libobs/obs-texture-metadata-fields.c.h" #include "libobs/obs-timer-dispatch-fields.c.h" diff --git a/libobs/obs-context-runtime.c.h b/libobs/obs-context-runtime.c.h new file mode 100644 index 0000000000..62e139344b --- /dev/null +++ b/libobs/obs-context-runtime.c.h @@ -0,0 +1,281 @@ +#include "libobs/build/libobs.pch.h" + +/* ensures that names are never blank (obs-context-names.c) */ +static inline char *dup_name(const char *name, bool private) +{ + return obs_context_name_dup(name, private, &obs->data.unnamed_index); +} + +static inline bool obs_context_data_init_wrap(struct obs_context_data *context, enum obs_obj_type type, + obs_data_t *settings, const char *name, const char *uuid, + obs_data_t *hotkey_data, bool private) +{ + assert(context); + memset(context, 0, sizeof(*context)); + context->private = private; + context->type = type; + + pthread_mutex_init_value(&context->rename_cache_mutex); + if (pthread_mutex_init(&context->rename_cache_mutex, NULL) != 0) + return false; + + context->signals = signal_handler_create(); + if (!context->signals) + return false; + + context->procs = proc_handler_create(); + if (!context->procs) + return false; + + if (uuid && strlen(uuid) == UUID_STR_LENGTH) + context->uuid = bstrdup(uuid); + /* Only automatically generate UUIDs for sources */ + else if (type == OBS_OBJ_TYPE_SOURCE || type == OBS_OBJ_TYPE_CANVAS) + context->uuid = os_generate_uuid(); + + context->name = dup_name(name, private); + context->settings = obs_data_newref(settings); + context->hotkey_data = obs_data_newref(hotkey_data); + return true; +} + +bool obs_context_data_init(struct obs_context_data *context, enum obs_obj_type type, obs_data_t *settings, + const char *name, const char *uuid, obs_data_t *hotkey_data, bool private) +{ + if (obs_context_data_init_wrap(context, type, settings, name, uuid, hotkey_data, private)) { + return true; + } else { + obs_context_data_free(context); + return false; + } +} + +void obs_context_data_free(struct obs_context_data *context) +{ + obs_hotkeys_context_release(context); + signal_handler_destroy(context->signals); + proc_handler_destroy(context->procs); + obs_data_release(context->settings); + obs_context_data_remove(context); + pthread_mutex_destroy(&context->rename_cache_mutex); + bfree(context->name); + bfree((void *)(uintptr_t)context->uuid); + + for (size_t i = 0; i < context->rename_cache.num; i++) + bfree(context->rename_cache.array[i]); + da_free(context->rename_cache); + + memset(context, 0, sizeof(*context)); +} + +void obs_context_init_control(struct obs_context_data *context, void *object, obs_destroy_cb destroy) +{ + context->control = bzalloc(sizeof(obs_weak_object_t)); + context->control->object = object; + context->destroy = destroy; +} + +void obs_context_data_insert(struct obs_context_data *context, pthread_mutex_t *mutex, void *pfirst) +{ + struct obs_context_data **first = pfirst; + + assert(context); + assert(mutex); + assert(first); + + context->mutex = mutex; + + pthread_mutex_lock(mutex); + context->prev_next = first; + context->next = *first; + *first = context; + if (context->next) + context->next->prev_next = &context->next; + pthread_mutex_unlock(mutex); +} + +static bool context_name_exists(void *phash, const char *name) +{ + struct obs_context_data *head = phash; + struct obs_context_data *item = NULL; + + HASH_FIND_STR(head, name, item); + return item != NULL; +} + +/* NULL when the name is free, else the name made unique + * (obs-context-names.c) */ +static inline char *obs_context_deduplicate_name(void *phash, const char *name) +{ + return obs_context_name_deduplicate(name, context_name_exists, phash); +} + +void obs_context_data_insert_name(struct obs_context_data *context, pthread_mutex_t *mutex, void *pfirst) +{ + struct obs_context_data **first = pfirst; + char *new_name; + + assert(context); + assert(mutex); + assert(first); + + context->mutex = mutex; + + pthread_mutex_lock(mutex); + + /* Ensure name is not a duplicate. */ + new_name = obs_context_deduplicate_name(*first, context->name); + if (new_name) { + blog(LOG_WARNING, + "Attempted to insert context with duplicate name \"%s\"!" + " Name has been changed to \"%s\"", + context->name, new_name); + /* Since this happens before the context creation finishes, + * do not bother to add it to the rename cache. */ + bfree(context->name); + context->name = new_name; + } + + HASH_ADD_STR(*first, name, context); + + pthread_mutex_unlock(mutex); +} + +void obs_context_data_insert_uuid(struct obs_context_data *context, pthread_mutex_t *mutex, void *pfirst_uuid) +{ + struct obs_context_data **first_uuid = pfirst_uuid; + struct obs_context_data *item = NULL; + + assert(context); + assert(mutex); + assert(first_uuid); + + context->mutex = mutex; + + pthread_mutex_lock(mutex); + + /* Ensure UUID is not a duplicate. + * This should only ever happen if a scene collection file has been + * manually edited and an entry has been duplicated without removing + * or regenerating the UUID. */ + HASH_FIND_UUID(*first_uuid, context->uuid, item); + if (item) { + blog(LOG_WARNING, "Attempted to insert context with duplicate UUID \"%s\"!", context->uuid); + /* It is practically impossible for the new UUID to be a + * duplicate, so don't bother checking again. */ + bfree((void *)(uintptr_t)context->uuid); + context->uuid = os_generate_uuid(); + } + + HASH_ADD_UUID(*first_uuid, uuid, context); + pthread_mutex_unlock(mutex); +} + +void obs_context_data_remove(struct obs_context_data *context) +{ + if (context && context->prev_next) { + pthread_mutex_lock(context->mutex); + *context->prev_next = context->next; + if (context->next) + context->next->prev_next = context->prev_next; + context->prev_next = NULL; + pthread_mutex_unlock(context->mutex); + } +} + +void obs_context_data_remove_name(struct obs_context_data *context, pthread_mutex_t *mutex, void *phead) +{ + struct obs_context_data **head = phead; + + assert(head); + + /* A context whose object failed to initialize was never added (its + * hash handle is still zeroed), and deleting it would corrupt or + * dereference the table. */ + if (!context || !context->hh.tbl) + return; + + pthread_mutex_lock(mutex); + HASH_DELETE(hh, *head, context); + pthread_mutex_unlock(mutex); +} + +void obs_context_data_remove_uuid(struct obs_context_data *context, pthread_mutex_t *mutex, void *puuid_head) +{ + struct obs_context_data **uuid_head = puuid_head; + + assert(uuid_head); + + if (!context || !context->uuid || !uuid_head) + return; + + pthread_mutex_lock(mutex); + HASH_DELETE(hh_uuid, *uuid_head, context); + pthread_mutex_unlock(mutex); +} + +void obs_context_wait(struct obs_context_data *context) +{ + /* Not in any list: its object failed to initialize. */ + if (!context->mutex) + return; + + pthread_mutex_lock(context->mutex); + pthread_mutex_unlock(context->mutex); +} + +void obs_context_data_setname(struct obs_context_data *context, const char *name) +{ + pthread_mutex_lock(&context->rename_cache_mutex); + + if (context->name) + da_push_back(context->rename_cache, &context->name); + context->name = dup_name(name, context->private); + + pthread_mutex_unlock(&context->rename_cache_mutex); +} + +void obs_context_data_setname_ht(struct obs_context_data *context, const char *name, void *phead) +{ + struct obs_context_data **head = phead; + char *new_name; + + pthread_mutex_lock(context->mutex); + pthread_mutex_lock(&context->rename_cache_mutex); + + HASH_DEL(*head, context); + if (context->name) + da_push_back(context->rename_cache, &context->name); + + /* Ensure new name is not a duplicate. A NULL name takes the unnamed + * name, as an empty one does. */ + new_name = name ? obs_context_deduplicate_name(*head, name) : NULL; + if (new_name) { + blog(LOG_WARNING, + "Attempted to rename context to duplicate name \"%s\"!" + " New name has been changed to \"%s\"", + name, new_name); + context->name = new_name; + } else { + context->name = dup_name(name, context->private); + } + + HASH_ADD_STR(*head, name, context); + + pthread_mutex_unlock(&context->rename_cache_mutex); + pthread_mutex_unlock(context->mutex); +} + +profiler_name_store_t *obs_get_profiler_name_store(void) +{ + return obs->name_store; +} + +void *obs_obj_get_data(void *obj) +{ + struct obs_context_data *context = obj; + if (!context) + return NULL; + + return context->data; +} diff --git a/libobs/obs-encoder-weak-refs.c.h b/libobs/obs-encoder-weak-refs.c.h new file mode 100644 index 0000000000..bb4380b91a --- /dev/null +++ b/libobs/obs-encoder-weak-refs.c.h @@ -0,0 +1,32 @@ +#include "libobs/build/libobs.pch.h" + +#define get_weak(encoder) ((obs_weak_encoder_t *)encoder->context.control) + +void obs_weak_encoder_addref(obs_weak_encoder_t *weak) +{ + if (!weak) + return; + + obs_weak_ref_addref(&weak->ref); +} + +void obs_weak_encoder_release(obs_weak_encoder_t *weak) +{ + if (!weak) + return; + + if (obs_weak_ref_release(&weak->ref)) + bfree(weak); +} + +obs_weak_encoder_t *obs_encoder_get_weak_encoder(obs_encoder_t *encoder) +{ + if (!encoder) + return NULL; + + obs_weak_encoder_t *weak = get_weak(encoder); + obs_weak_encoder_addref(weak); + return weak; +} + +#undef get_weak diff --git a/libobs/obs-encoder.c.h b/libobs/obs-encoder.c.h index a66e984d60..49f7f0f353 100644 --- a/libobs/obs-encoder.c.h +++ b/libobs/obs-encoder.c.h @@ -1545,23 +1545,6 @@ void obs_encoder_release(obs_encoder_t *encoder) } } -void obs_weak_encoder_addref(obs_weak_encoder_t *weak) -{ - if (!weak) - return; - - obs_weak_ref_addref(&weak->ref); -} - -void obs_weak_encoder_release(obs_weak_encoder_t *weak) -{ - if (!weak) - return; - - if (obs_weak_ref_release(&weak->ref)) - bfree(weak); -} - obs_encoder_t *obs_encoder_get_ref(obs_encoder_t *encoder) { if (!encoder) @@ -1570,16 +1553,6 @@ obs_encoder_t *obs_encoder_get_ref(obs_encoder_t *encoder) return obs_weak_encoder_get_encoder(get_weak(encoder)); } -obs_weak_encoder_t *obs_encoder_get_weak_encoder(obs_encoder_t *encoder) -{ - if (!encoder) - return NULL; - - obs_weak_encoder_t *weak = get_weak(encoder); - obs_weak_encoder_addref(weak); - return weak; -} - obs_encoder_t *obs_weak_encoder_get_encoder(obs_weak_encoder_t *weak) { if (!weak) diff --git a/libobs/obs-source-weak-refs.c.h b/libobs/obs-source-weak-refs.c.h new file mode 100644 index 0000000000..9708bfdcad --- /dev/null +++ b/libobs/obs-source-weak-refs.c.h @@ -0,0 +1,18 @@ +#include "libobs/build/libobs.pch.h" + +void obs_weak_source_addref(obs_weak_source_t *weak) +{ + if (!weak) + return; + + obs_weak_ref_addref(&weak->ref); +} + +void obs_weak_source_release(obs_weak_source_t *weak) +{ + if (!weak) + return; + + if (obs_weak_ref_release(&weak->ref)) + bfree(weak); +} diff --git a/libobs/obs-source.c.h b/libobs/obs-source.c.h index 613fb14e14..6fc60df62b 100644 --- a/libobs/obs-source.c.h +++ b/libobs/obs-source.c.h @@ -717,23 +717,6 @@ void obs_source_release(obs_source_t *source) } } -void obs_weak_source_addref(obs_weak_source_t *weak) -{ - if (!weak) - return; - - obs_weak_ref_addref(&weak->ref); -} - -void obs_weak_source_release(obs_weak_source_t *weak) -{ - if (!weak) - return; - - if (obs_weak_ref_release(&weak->ref)) - bfree(weak); -} - obs_source_t *obs_source_get_ref(obs_source_t *source) { if (!source) diff --git a/libobs/obs.c.h b/libobs/obs.c.h index 2d61887617..fa205cd589 100644 --- a/libobs/obs.c.h +++ b/libobs/obs.c.h @@ -2541,286 +2541,6 @@ void obs_reset_source_uuids(void) pthread_mutex_unlock(&obs->data.sources_mutex); } -/* ensures that names are never blank (obs-context-names.c) */ -static inline char *dup_name(const char *name, bool private) -{ - return obs_context_name_dup(name, private, &obs->data.unnamed_index); -} - -static inline bool obs_context_data_init_wrap(struct obs_context_data *context, enum obs_obj_type type, - obs_data_t *settings, const char *name, const char *uuid, - obs_data_t *hotkey_data, bool private) -{ - assert(context); - memset(context, 0, sizeof(*context)); - context->private = private; - context->type = type; - - pthread_mutex_init_value(&context->rename_cache_mutex); - if (pthread_mutex_init(&context->rename_cache_mutex, NULL) != 0) - return false; - - context->signals = signal_handler_create(); - if (!context->signals) - return false; - - context->procs = proc_handler_create(); - if (!context->procs) - return false; - - if (uuid && strlen(uuid) == UUID_STR_LENGTH) - context->uuid = bstrdup(uuid); - /* Only automatically generate UUIDs for sources */ - else if (type == OBS_OBJ_TYPE_SOURCE || type == OBS_OBJ_TYPE_CANVAS) - context->uuid = os_generate_uuid(); - - context->name = dup_name(name, private); - context->settings = obs_data_newref(settings); - context->hotkey_data = obs_data_newref(hotkey_data); - return true; -} - -bool obs_context_data_init(struct obs_context_data *context, enum obs_obj_type type, obs_data_t *settings, - const char *name, const char *uuid, obs_data_t *hotkey_data, bool private) -{ - if (obs_context_data_init_wrap(context, type, settings, name, uuid, hotkey_data, private)) { - return true; - } else { - obs_context_data_free(context); - return false; - } -} - -void obs_context_data_free(struct obs_context_data *context) -{ - obs_hotkeys_context_release(context); - signal_handler_destroy(context->signals); - proc_handler_destroy(context->procs); - obs_data_release(context->settings); - obs_context_data_remove(context); - pthread_mutex_destroy(&context->rename_cache_mutex); - bfree(context->name); - bfree((void *)(uintptr_t)context->uuid); - - for (size_t i = 0; i < context->rename_cache.num; i++) - bfree(context->rename_cache.array[i]); - da_free(context->rename_cache); - - memset(context, 0, sizeof(*context)); -} - -void obs_context_init_control(struct obs_context_data *context, void *object, obs_destroy_cb destroy) -{ - context->control = bzalloc(sizeof(obs_weak_object_t)); - context->control->object = object; - context->destroy = destroy; -} - -void obs_context_data_insert(struct obs_context_data *context, pthread_mutex_t *mutex, void *pfirst) -{ - struct obs_context_data **first = pfirst; - - assert(context); - assert(mutex); - assert(first); - - context->mutex = mutex; - - pthread_mutex_lock(mutex); - context->prev_next = first; - context->next = *first; - *first = context; - if (context->next) - context->next->prev_next = &context->next; - pthread_mutex_unlock(mutex); -} - -static bool context_name_exists(void *phash, const char *name) -{ - struct obs_context_data *head = phash; - struct obs_context_data *item = NULL; - - HASH_FIND_STR(head, name, item); - return item != NULL; -} - -/* NULL when the name is free, else the name made unique - * (obs-context-names.c) */ -static inline char *obs_context_deduplicate_name(void *phash, const char *name) -{ - return obs_context_name_deduplicate(name, context_name_exists, phash); -} - -void obs_context_data_insert_name(struct obs_context_data *context, pthread_mutex_t *mutex, void *pfirst) -{ - struct obs_context_data **first = pfirst; - char *new_name; - - assert(context); - assert(mutex); - assert(first); - - context->mutex = mutex; - - pthread_mutex_lock(mutex); - - /* Ensure name is not a duplicate. */ - new_name = obs_context_deduplicate_name(*first, context->name); - if (new_name) { - blog(LOG_WARNING, - "Attempted to insert context with duplicate name \"%s\"!" - " Name has been changed to \"%s\"", - context->name, new_name); - /* Since this happens before the context creation finishes, - * do not bother to add it to the rename cache. */ - bfree(context->name); - context->name = new_name; - } - - HASH_ADD_STR(*first, name, context); - - pthread_mutex_unlock(mutex); -} - -void obs_context_data_insert_uuid(struct obs_context_data *context, pthread_mutex_t *mutex, void *pfirst_uuid) -{ - struct obs_context_data **first_uuid = pfirst_uuid; - struct obs_context_data *item = NULL; - - assert(context); - assert(mutex); - assert(first_uuid); - - context->mutex = mutex; - - pthread_mutex_lock(mutex); - - /* Ensure UUID is not a duplicate. - * This should only ever happen if a scene collection file has been - * manually edited and an entry has been duplicated without removing - * or regenerating the UUID. */ - HASH_FIND_UUID(*first_uuid, context->uuid, item); - if (item) { - blog(LOG_WARNING, "Attempted to insert context with duplicate UUID \"%s\"!", context->uuid); - /* It is practically impossible for the new UUID to be a - * duplicate, so don't bother checking again. */ - bfree((void *)(uintptr_t)context->uuid); - context->uuid = os_generate_uuid(); - } - - HASH_ADD_UUID(*first_uuid, uuid, context); - pthread_mutex_unlock(mutex); -} - -void obs_context_data_remove(struct obs_context_data *context) -{ - if (context && context->prev_next) { - pthread_mutex_lock(context->mutex); - *context->prev_next = context->next; - if (context->next) - context->next->prev_next = context->prev_next; - context->prev_next = NULL; - pthread_mutex_unlock(context->mutex); - } -} - -void obs_context_data_remove_name(struct obs_context_data *context, pthread_mutex_t *mutex, void *phead) -{ - struct obs_context_data **head = phead; - - assert(head); - - /* A context whose object failed to initialize was never added (its - * hash handle is still zeroed), and deleting it would corrupt or - * dereference the table. */ - if (!context || !context->hh.tbl) - return; - - pthread_mutex_lock(mutex); - HASH_DELETE(hh, *head, context); - pthread_mutex_unlock(mutex); -} - -void obs_context_data_remove_uuid(struct obs_context_data *context, pthread_mutex_t *mutex, void *puuid_head) -{ - struct obs_context_data **uuid_head = puuid_head; - - assert(uuid_head); - - if (!context || !context->uuid || !uuid_head) - return; - - pthread_mutex_lock(mutex); - HASH_DELETE(hh_uuid, *uuid_head, context); - pthread_mutex_unlock(mutex); -} - -void obs_context_wait(struct obs_context_data *context) -{ - /* Not in any list: its object failed to initialize. */ - if (!context->mutex) - return; - - pthread_mutex_lock(context->mutex); - pthread_mutex_unlock(context->mutex); -} - -void obs_context_data_setname(struct obs_context_data *context, const char *name) -{ - pthread_mutex_lock(&context->rename_cache_mutex); - - if (context->name) - da_push_back(context->rename_cache, &context->name); - context->name = dup_name(name, context->private); - - pthread_mutex_unlock(&context->rename_cache_mutex); -} - -void obs_context_data_setname_ht(struct obs_context_data *context, const char *name, void *phead) -{ - struct obs_context_data **head = phead; - char *new_name; - - pthread_mutex_lock(context->mutex); - pthread_mutex_lock(&context->rename_cache_mutex); - - HASH_DEL(*head, context); - if (context->name) - da_push_back(context->rename_cache, &context->name); - - /* Ensure new name is not a duplicate. A NULL name takes the unnamed - * name, as an empty one does. */ - new_name = name ? obs_context_deduplicate_name(*head, name) : NULL; - if (new_name) { - blog(LOG_WARNING, - "Attempted to rename context to duplicate name \"%s\"!" - " New name has been changed to \"%s\"", - name, new_name); - context->name = new_name; - } else { - context->name = dup_name(name, context->private); - } - - HASH_ADD_STR(*head, name, context); - - pthread_mutex_unlock(&context->rename_cache_mutex); - pthread_mutex_unlock(context->mutex); -} - -profiler_name_store_t *obs_get_profiler_name_store(void) -{ - return obs->name_store; -} - -void *obs_obj_get_data(void *obj) -{ - struct obs_context_data *context = obj; - if (!context) - return NULL; - - return context->data; -} - void obs_reset_audio_monitoring(void) { if (!obs_audio_monitoring_available()) diff --git a/rust/obs-build/src/platform/mod.rs b/rust/obs-build/src/platform/mod.rs index 9faa943281..5ed77e32f6 100644 --- a/rust/obs-build/src/platform/mod.rs +++ b/rust/obs-build/src/platform/mod.rs @@ -997,6 +997,42 @@ pub fn native_test_rust_static_options(target: &str) -> Result, Stri .into()) } +/// Native libraries used by the production Rust archive, independent of which +/// exported function first causes the linker to extract an archive member. +pub fn configure_rust_static_dependencies( + target: &str, + library: &mut crate::SharedLibrary, +) -> Result<(), String> { + configure_core_dependencies(target, &crate::libobs::Options::default(), library)?; + if target.contains("linux") { + crate::libobs::add_package(library, target, "uuid")?; + // Match the optional native owner: no-GIO archives remain usable on + // hosts without GIO. Archives that actually need it still fail to link. + if pkg_config::Config::new() + .cargo_metadata(false) + .probe("gio-2.0") + .is_ok() + { + crate::libobs::add_package(library, target, "gio-2.0")?; + } + } + Ok(()) +} + +pub fn native_test_static_rescan_options(target: &str, archives: &[&Path]) -> Vec { + if !target.contains("-linux-") { + return Vec::new(); + } + let mut options = vec!["-Wl,--start-group".into()]; + options.extend( + archives + .iter() + .map(|path| path.to_string_lossy().into_owned()), + ); + options.push("-Wl,--end-group".into()); + options +} + pub fn native_test_math_options(target: &str) -> Vec { if target.contains("msvc") { vec![] diff --git a/rust/obs-build/src/validation/graph.rs b/rust/obs-build/src/validation/graph.rs index 86c2a17e09..b7ee063240 100644 --- a/rust/obs-build/src/validation/graph.rs +++ b/rust/obs-build/src/validation/graph.rs @@ -1,11 +1,13 @@ //! Declarative native test targets and their execution contracts. //! //! Selection is explicit: callers provide platform, feature and dependency -//! facts. Unknown facts are errors; the optional HAVE_X11_DISPLAY runtime fact +//! facts. Production archive owners supply their known platform facts; explicit +//! caller values override them. Unknown facts are errors; the optional HAVE_X11_DISPLAY runtime fact //! alone defaults to false when no X server is declared. use crate::{NativeBuild, SharedLibrary}; #[path = "configured_headers.rs"] mod configured_headers; +mod rust_static_support; use configured_headers::ConfiguredHeader; use serde::Deserialize; use std::{ @@ -241,10 +243,11 @@ impl Target { &self, target: &mut SharedLibrary, libraries: &BTreeMap, + facts: &BTreeMap, ) -> Result<(), String> { + let names = self.library_names(facts)?; for name in &self.header_libraries { - let dependency = libraries - .get(name) + let dependency = native_dependency(name, libraries, &names) .ok_or_else(|| format!("unresolved native test header library {name}"))?; target .include_dirs @@ -358,6 +361,14 @@ impl Target { names.push(name.into()); } } + // MSVC import members collide with Rust allocators/parser helpers. + // ELF/Darwin fixtures retain their explicitly declared DSO bindings. + if facts.get("MSVC") == Some(&true) + && let Some(index) = names.iter().position(|name| name == "libobs_rust-static") + { + let rust = names.remove(index); + names.insert(0, rust); + } Ok(names) } @@ -368,12 +379,24 @@ impl Target { facts: &BTreeMap, libraries: &BTreeMap, ) -> Result, String> { + let facts = inherited_facts(facts, libraries); + let names = self.library_names(&facts)?; + let standalone_msvc = facts.get("MSVC") == Some(&true) + && names.iter().any(|name| { + name == "libobs_rust-static" + && libraries + .get(name) + .is_some_and(|dep| dep.rust_static_support) + }); let mut artifacts = Vec::new(); - for name in self.library_names(facts)? { - let dependency = libraries - .get(&name) + for name in &names { + let dependency = native_dependency(name, libraries, &names) .ok_or_else(|| format!("unresolved native test library {name}"))?; - artifacts.extend(dependency.artifacts.iter().cloned()); + // Preserve OBS's header interface, but never let its complete DLL + // imports compete with the standalone Rust/support component. + if !(standalone_msvc && name == "OBS::libobs") { + artifacts.extend(dependency.artifacts.iter().cloned()); + } } Ok(artifacts) } @@ -542,6 +565,12 @@ pub struct Selection<'a> { /// have no artifacts; they still carry required headers and definitions. #[derive(Clone, Debug, Default)] pub struct Dependency { + /// Production Rust archives also select the shared demand-linked C bridge. + pub rust_static_support: bool, + /// SDK interfaces provided by this owner rather than redeclared per fixture. + pub native_libraries: BTreeMap, + /// Known archive-target facts. Explicit caller values take precedence. + pub native_facts: BTreeMap, pub runtime_path_prepend: BTreeMap>, pub artifacts: Vec, pub include_dirs: Vec, @@ -555,6 +584,9 @@ pub struct Dependency { impl From for Dependency { fn from(library: SharedLibrary) -> Self { Self { + rust_static_support: false, + native_libraries: BTreeMap::new(), + native_facts: BTreeMap::new(), runtime_path_prepend: BTreeMap::new(), artifacts: library.dependencies, include_dirs: library.include_dirs, @@ -568,6 +600,14 @@ impl From for Dependency { } impl Dependency { + /// Facts known from an archive's target. SDK and feature choices stay explicit. + pub fn target_facts(target: &str) -> BTreeMap { + crate::platform::native_test_facts(target, false, false) + .into_iter() + .filter(|(name, _)| name == "UNIX" || name == "MSVC" || name.starts_with("OS_")) + .collect() + } + /// Import the production archive for the scoped Linux pacing characterization. pub fn rust_static(target: &str, archive: &Path) -> Result { let archive = dunce::canonicalize(archive) @@ -578,11 +618,40 @@ impl Dependency { archive.display() )); } - Ok(Self { - artifacts: vec![archive], - link_options: crate::platform::native_test_rust_static_options(target)?, - ..Default::default() - }) + let mut native = SharedLibrary::default(); + crate::platform::configure_rust_static_dependencies(target, &mut native)?; + let mut dependency = Self::from(native); + dependency.rust_static_support = true; + dependency.native_facts = Self::target_facts(target); + dependency + .native_facts + .insert("HAVE_LIBOBS_RUST_STATIC".into(), true); + for name in [ + "OBS::caption", + "Uthash::Uthash", + "SIMDe::SIMDe", + "Threads::Threads", + "FFmpeg::avcodec", + "FFmpeg::avformat", + "FFmpeg::avutil", + "FFmpeg::swscale", + "FFmpeg::swresample", + "jansson::jansson", + "ZLIB::ZLIB", + "LibUUID::LibUUID", + "gio::gio", + "m", + ] { + dependency + .native_libraries + .insert(name.into(), Self::default()); + } + dependency.artifacts.push(archive); + dependency.link_options.splice( + 0..0, + crate::platform::native_test_rust_static_options(target)?, + ); + Ok(dependency) } /// Resolve a native SDK package into its compile and link interface. @@ -600,6 +669,37 @@ impl Dependency { } } +fn inherited_facts( + facts: &BTreeMap, + libraries: &BTreeMap, +) -> BTreeMap { + let mut inherited = libraries + .get("libobs_rust-static") + .map(|owner| owner.native_facts.clone()) + .unwrap_or_default(); + inherited.extend(facts.iter().map(|(name, value)| (name.clone(), *value))); + inherited +} + +fn native_dependency<'a>( + name: &str, + libraries: &'a BTreeMap, + selected: &[String], +) -> Option<&'a Dependency> { + libraries.get(name).or_else(|| { + selected + .iter() + .any(|name| name == "libobs_rust-static") + .then(|| { + libraries + .get("libobs_rust-static")? + .native_libraries + .get(name) + }) + .flatten() + }) +} + impl Graph { pub fn load(path: &Path) -> Result { let text = fs::read_to_string(path) @@ -751,8 +851,11 @@ impl Graph { libraries: &BTreeMap, ) -> Result, String> { let root = dunce::canonicalize(root).map_err(|error| error.to_string())?; + let inherited = inherited_facts(facts, libraries); + let facts = &inherited; let selected = self.select(facts)?; let mut artifacts = BTreeMap::new(); + let mut rust_support = None; let mut watched_inputs = BTreeSet::new(); for (name, spec) in selected.targets { let mut target = SharedLibrary { @@ -798,7 +901,12 @@ impl Graph { &root.join(&import.definition), &output, )?; - target.dependencies.insert(0, library); + let index = usize::from( + spec.library_names(facts)? + .first() + .is_some_and(|name| name == "libobs_rust-static"), + ); + target.dependencies.insert(index, library); } for source in &spec.sources { if !source.selected(facts)? { @@ -894,7 +1002,15 @@ impl Graph { }); target.definitions.push((key.into(), value)); } - spec.add_header_libraries(&mut target, libraries)?; + spec.add_header_libraries(&mut target, libraries, facts)?; + rust_static_support::select( + build, + &root, + libraries, + &spec.library_names(facts)?, + &mut target, + &mut rust_support, + )?; for package in &spec.packages { crate::libobs::add_package(&mut target, &build.target, package)?; } @@ -903,9 +1019,9 @@ impl Graph { } // Static archives precede their dynamic dependencies under // --as-needed, as in the existing native compatibility builder. - for name in spec.library_names(facts)? { - let dependency = libraries - .get(&name) + let names = spec.library_names(facts)?; + for name in &names { + let dependency = native_dependency(name, libraries, &names) .ok_or_else(|| format!("unresolved native test library {name}"))?; target .include_dirs diff --git a/rust/obs-build/src/validation/graph/rust_static_support.rs b/rust/obs-build/src/validation/graph/rust_static_support.rs new file mode 100644 index 0000000000..b353b1a60d --- /dev/null +++ b/rust/obs-build/src/validation/graph/rust_static_support.rs @@ -0,0 +1,128 @@ +//! The same real, demand-linked bridge members selected by cmocka's CMake graph. +use super::{Dependency, NativeBuild, SharedLibrary}; +use std::{ + collections::BTreeMap, + path::{Path, PathBuf}, +}; + +const MANIFEST: &str = include_str!("../../../../../test/cmocka/build/rust-static-support.json"); + +pub(super) fn sources(root: &Path, facts: &BTreeMap) -> Result, String> { + #[derive(serde::Deserialize)] + #[serde(deny_unknown_fields)] + struct Manifest { + sources: Vec, + #[serde(default)] + platform_sources: BTreeMap>, + } + let manifest: Manifest = serde_json::from_str(MANIFEST) + .map_err(|error| format!("Rust-static support manifest: {error}"))?; + let mut sources = manifest.sources; + for (fact, paths) in manifest.platform_sources { + if *facts + .get(&fact) + .ok_or_else(|| format!("unknown Rust-static support target fact {fact}"))? + { + sources.extend(paths); + } + } + Ok(sources.iter().map(|path| root.join(path)).collect()) +} + +pub(super) struct Support { + archive: PathBuf, + caption: PathBuf, +} + +fn prepare( + build: &NativeBuild, + root: &Path, + libraries: &BTreeMap, +) -> Result { + let mut support = SharedLibrary { + name: "rust-static-link-support".into(), + sources: sources(root, &Dependency::target_facts(&build.target))?, + include_dirs: vec![ + root.into(), + root.join("libobs"), + root.join("deps/libcaption"), + ], + ..Default::default() + }; + // These are owner interfaces, not a list repeated for each executable. + for name in [ + "OBS::libobs", + "SIMDe::SIMDe", + "Uthash::Uthash", + "libobs_rust-static", + ] { + if let Some(owner) = libraries.get(name) { + support + .include_dirs + .extend(owner.include_dirs.iter().cloned()); + support + .definitions + .extend(owner.definitions.iter().cloned()); + } + } + println!( + "cargo:rerun-if-changed={}", + root.join("test/cmocka/build/rust-static-support.json") + .display() + ); + Ok(Support { + archive: build.static_library(&support)?, + caption: crate::libobs::build_caption(build, root)?, + }) +} + +pub(super) fn select( + build: &NativeBuild, + root: &Path, + libraries: &BTreeMap, + names: &[String], + target: &mut SharedLibrary, + cached: &mut Option, +) -> Result<(), String> { + if !names.iter().any(|name| { + name == "libobs_rust-static" + && libraries + .get(name) + .is_some_and(|dep| dep.rust_static_support) + }) { + return Ok(()); + } + let support = match cached { + Some(support) => support, + None => cached.insert(prepare(build, root, libraries)?), + }; + // Private adapters follow Rust, including when a fixture deliberately + // selects a shared provider before that archive. + let archive = libraries["libobs_rust-static"] + .artifacts + .first() + .ok_or("Rust-static dependency has no archive")?; + let index = target + .dependencies + .iter() + .position(|path| path == archive) + .ok_or("Rust-static archive missing from native link")?; + target + .dependencies + .insert(index + 1, support.archive.clone()); + // A support member can introduce a previously unseen Rust callback. + target.dependencies.insert(index + 2, archive.clone()); + target + .link_options + .extend(crate::platform::native_test_static_rescan_options( + &build.target, + &[archive.as_path(), support.archive.as_path()], + )); + target.include_dirs.push(root.join("deps/libcaption")); + target + .link_options + .push(support.caption.to_string_lossy().into_owned()); + // Fixture-owned providers retain their compile definitions and precedence. + // The archive supplies only members those providers do not define. + Ok(()) +} diff --git a/rust/obs-build/tests/native.rs b/rust/obs-build/tests/native.rs index a6a8cab241..8caf1debbd 100644 --- a/rust/obs-build/tests/native.rs +++ b/rust/obs-build/tests/native.rs @@ -495,6 +495,7 @@ mod canonical_undo_stack_is_registered; mod canonical_vaapi_device_select_is_registered; #[path = "native/registration/canonical_video_info_query_is_registered.rs"] mod canonical_video_info_query_is_registered; + #[path = "native/registration/canonical_video_output_compatibility_is_registered.rs"] mod canonical_video_output_compatibility_is_registered; #[path = "native/registration/canonical_video_scaler_direct_is_registered.rs"] @@ -515,6 +516,8 @@ mod canonical_x11_keymap_is_registered; mod canonical_xcomposite_decisions_are_registered; #[path = "native/registration/canonical_youtube_broadcast_settings_is_registered.rs"] mod canonical_youtube_broadcast_settings_is_registered; +#[path = "native/registration/shared_rust_static_support.rs"] +mod shared_rust_static_support; /// #1390: the libobs built from this checkout for real-libobs graph runtimes. /// `OBS_GRAPH_LIBOBS` selects the Tier 2 implementation explicitly: `hybrid` diff --git a/rust/obs-build/tests/native/registration/canonical_rust_static_header_steps_are_registered.rs b/rust/obs-build/tests/native/registration/canonical_rust_static_header_steps_are_registered.rs index 4f2502c2a2..55ca4ebb33 100644 --- a/rust/obs-build/tests/native/registration/canonical_rust_static_header_steps_are_registered.rs +++ b/rust/obs-build/tests/native/registration/canonical_rust_static_header_steps_are_registered.rs @@ -218,6 +218,8 @@ fn canonical_rust_static_header_steps_run_unchanged() { ("HAVE_LIBOBS_RUST_STATIC".into(), true), ("MSVC".into(), false), ("UNIX".into(), true), + // This fixture imports no local portal SDK; Rust owns its native closure. + ("HAVE_PORTAL_TEST_GIO".into(), false), ] .into(); for target in graph.targets.values() { diff --git a/rust/obs-build/tests/native/registration/rust-static/cases/private-link-rules/test_graphics_state_stacks.json b/rust/obs-build/tests/native/registration/rust-static/cases/private-link-rules/test_graphics_state_stacks.json index ee9f033fe3..31414d058c 100644 --- a/rust/obs-build/tests/native/registration/rust-static/cases/private-link-rules/test_graphics_state_stacks.json +++ b/rust/obs-build/tests/native/registration/rust-static/cases/private-link-rules/test_graphics_state_stacks.json @@ -9,8 +9,7 @@ "libobs/graphics/graphics-linear-srgb-fields.c.h", "libobs/build/libobs.image-decode-adapter+.h.c", "libobs/obs-graphics-effect-file-fields.c.h", - "test/cmocka/source-update-properties-link-support.c", - "test/cmocka/output-starting-queries-link-support.c" + "test/cmocka/source-update-properties-link-support.c" ], "requires": "HAVE_LIBOBS_RUST_STATIC", "includes": [ diff --git a/rust/obs-build/tests/native/registration/rust-static/cases/private-link-rules/test_window_match_steps.json b/rust/obs-build/tests/native/registration/rust-static/cases/private-link-rules/test_window_match_steps.json index 1240a9741a..9e3cad8559 100644 --- a/rust/obs-build/tests/native/registration/rust-static/cases/private-link-rules/test_window_match_steps.json +++ b/rust/obs-build/tests/native/registration/rust-static/cases/private-link-rules/test_window_match_steps.json @@ -6,8 +6,7 @@ "test/cmocka/test_window_match_steps.c", "libobs/util/base-variadic.c.h", "libobs/build/libobs.image-decode-adapter+.h.c", - "test/cmocka/source-update-properties-link-support.c", - "test/cmocka/output-starting-queries-link-support.c" + "test/cmocka/source-update-properties-link-support.c" ], "includes": [ ".", diff --git a/rust/obs-build/tests/native/registration/rust-static/support/video-info-query.json b/rust/obs-build/tests/native/registration/rust-static/support/video-info-query.json deleted file mode 100644 index 9f20bb8264..0000000000 --- a/rust/obs-build/tests/native/registration/rust-static/support/video-info-query.json +++ /dev/null @@ -1,653 +0,0 @@ -{ - "test_async_conversion_plan_rust": { - "sources": [ - "test/cmocka/video-info-query-link-support.c", - "test/cmocka/core-state-link-support.c" - ], - "includes": [ - "." - ], - "header_libraries": [ - "OBS::libobs", - "SIMDe::SIMDe" - ], - "libraries": [ - "OBS::caption", - "Uthash::Uthash", - { - "name": "OBS::w32-pthreads", - "requires": "OS_WINDOWS" - } - ] - }, - "test_async_frame_pacing_steps_rust": { - "sources": [ - "test/cmocka/video-info-query-link-support.c", - "test/cmocka/core-state-link-support.c" - ], - "includes": [ - "." - ], - "header_libraries": [ - "OBS::libobs", - "SIMDe::SIMDe" - ], - "libraries": [ - "OBS::caption", - "Uthash::Uthash", - { - "name": "OBS::w32-pthreads", - "requires": "OS_WINDOWS" - } - ] - }, - "test_async_upload_steps_rust": { - "sources": [ - "test/cmocka/video-info-query-link-support.c", - "test/cmocka/core-state-link-support.c" - ], - "includes": [ - "." - ], - "header_libraries": [ - "OBS::libobs", - "SIMDe::SIMDe" - ], - "libraries": [ - "OBS::caption", - "Uthash::Uthash", - { - "name": "OBS::w32-pthreads", - "requires": "OS_WINDOWS" - } - ] - }, - "test_audio_monitor_delay_steps_rust": { - "sources": [ - "test/cmocka/video-info-query-link-support.c", - "test/cmocka/core-state-link-support.c" - ], - "includes": [ - "." - ], - "header_libraries": [ - "OBS::libobs", - "SIMDe::SIMDe" - ], - "libraries": [ - "OBS::caption", - "Uthash::Uthash", - { - "name": "OBS::w32-pthreads", - "requires": "OS_WINDOWS" - } - ] - }, - "test_coreaudio_device_rules_rust": { - "sources": [ - "test/cmocka/video-info-query-link-support.c", - "test/cmocka/core-state-link-support.c" - ], - "includes": [ - "." - ], - "header_libraries": [ - "OBS::libobs", - "SIMDe::SIMDe" - ], - "libraries": [ - "OBS::caption", - "Uthash::Uthash", - { - "name": "OBS::w32-pthreads", - "requires": "OS_WINDOWS" - } - ] - }, - "test_coreaudio_pacing_steps_rust": { - "sources": [ - "test/cmocka/video-info-query-link-support.c", - "test/cmocka/core-state-link-support.c" - ], - "includes": [ - "." - ], - "header_libraries": [ - "OBS::libobs", - "SIMDe::SIMDe" - ], - "libraries": [ - "OBS::caption", - "Uthash::Uthash", - { - "name": "OBS::w32-pthreads", - "requires": "OS_WINDOWS" - } - ] - }, - "test_deinterlace_draw_plan_steps_rust": { - "sources": [ - "test/cmocka/video-info-query-link-support.c", - "test/cmocka/core-state-link-support.c" - ], - "includes": [ - "." - ], - "header_libraries": [ - "OBS::libobs", - "SIMDe::SIMDe" - ], - "libraries": [ - "OBS::caption", - "Uthash::Uthash", - { - "name": "OBS::w32-pthreads", - "requires": "OS_WINDOWS" - } - ] - }, - "test_deinterlace_pacing_steps_rust": { - "sources": [ - "test/cmocka/video-info-query-link-support.c", - "test/cmocka/core-state-link-support.c" - ], - "includes": [ - "." - ], - "header_libraries": [ - "OBS::libobs", - "SIMDe::SIMDe" - ], - "libraries": [ - "OBS::caption", - "Uthash::Uthash", - { - "name": "OBS::w32-pthreads", - "requires": "OS_WINDOWS" - } - ] - }, - "test_deinterlace_select_steps_rust": { - "sources": [ - "test/cmocka/video-info-query-link-support.c", - "test/cmocka/core-state-link-support.c" - ], - "includes": [ - "." - ], - "header_libraries": [ - "OBS::libobs", - "SIMDe::SIMDe" - ], - "libraries": [ - "OBS::caption", - "Uthash::Uthash", - { - "name": "OBS::w32-pthreads", - "requires": "OS_WINDOWS" - } - ] - }, - "test_monitor_speaker_layout_rust": { - "sources": [ - "test/cmocka/video-info-query-link-support.c", - "test/cmocka/core-state-link-support.c" - ], - "includes": [ - "." - ], - "header_libraries": [ - "OBS::libobs", - "SIMDe::SIMDe" - ], - "libraries": [ - "OBS::caption", - "Uthash::Uthash", - { - "name": "OBS::w32-pthreads", - "requires": "OS_WINDOWS" - } - ] - }, - "test_monitor_video_sync_rust": { - "sources": [ - "test/cmocka/video-info-query-link-support.c", - "test/cmocka/core-state-link-support.c" - ], - "includes": [ - "." - ], - "header_libraries": [ - "OBS::libobs", - "SIMDe::SIMDe" - ], - "libraries": [ - "OBS::caption", - "Uthash::Uthash", - { - "name": "OBS::w32-pthreads", - "requires": "OS_WINDOWS" - } - ] - }, - "test_monitor_wasapi_steps_rust": { - "sources": [ - "test/cmocka/video-info-query-link-support.c", - "test/cmocka/core-state-link-support.c" - ], - "includes": [ - "." - ], - "header_libraries": [ - "OBS::libobs", - "SIMDe::SIMDe" - ], - "libraries": [ - "OBS::caption", - "Uthash::Uthash", - { - "name": "OBS::w32-pthreads", - "requires": "OS_WINDOWS" - } - ] - }, - "test_pulse_monitor_steps_rust": { - "sources": [ - "test/cmocka/video-info-query-link-support.c", - "test/cmocka/core-state-link-support.c" - ], - "includes": [ - "." - ], - "header_libraries": [ - "OBS::libobs", - "SIMDe::SIMDe" - ], - "libraries": [ - "OBS::caption", - "Uthash::Uthash", - { - "name": "OBS::w32-pthreads", - "requires": "OS_WINDOWS" - } - ] - }, - "test_service_handler_getters_rust": { - "sources": [ - "test/cmocka/video-info-query-link-support.c", - "test/cmocka/core-state-link-support.c" - ], - "includes": [ - "." - ], - "header_libraries": [ - "OBS::libobs", - "SIMDe::SIMDe" - ], - "libraries": [ - "OBS::caption", - "Uthash::Uthash", - { - "name": "OBS::w32-pthreads", - "requires": "OS_WINDOWS" - } - ] - }, - "test_source_audio_input_steps_rust": { - "sources": [ - "test/cmocka/video-info-query-link-support.c", - "test/cmocka/core-state-link-support.c" - ], - "includes": [ - "." - ], - "header_libraries": [ - "OBS::libobs", - "SIMDe::SIMDe" - ], - "libraries": [ - "OBS::caption", - "Uthash::Uthash", - { - "name": "OBS::w32-pthreads", - "requires": "OS_WINDOWS" - } - ] - }, - "test_source_audio_place_steps_rust": { - "sources": [ - "test/cmocka/video-info-query-link-support.c", - "test/cmocka/core-state-link-support.c" - ], - "includes": [ - "." - ], - "header_libraries": [ - "OBS::libobs", - "SIMDe::SIMDe" - ], - "libraries": [ - "OBS::caption", - "Uthash::Uthash", - { - "name": "OBS::w32-pthreads", - "requires": "OS_WINDOWS" - } - ] - }, - "test_source_audio_render_steps_rust": { - "sources": [ - "test/cmocka/video-info-query-link-support.c", - "test/cmocka/core-state-link-support.c" - ], - "includes": [ - "." - ], - "header_libraries": [ - "OBS::libobs", - "SIMDe::SIMDe" - ], - "libraries": [ - "OBS::caption", - "Uthash::Uthash", - { - "name": "OBS::w32-pthreads", - "requires": "OS_WINDOWS" - } - ] - }, - "test_source_audio_timing_steps_rust": { - "sources": [ - "test/cmocka/video-info-query-link-support.c", - "test/cmocka/core-state-link-support.c" - ], - "includes": [ - "." - ], - "header_libraries": [ - "OBS::libobs", - "SIMDe::SIMDe" - ], - "libraries": [ - "OBS::caption", - "Uthash::Uthash", - { - "name": "OBS::w32-pthreads", - "requires": "OS_WINDOWS" - } - ] - }, - "test_source_color_space_steps_rust": { - "sources": [ - "test/cmocka/video-info-query-link-support.c", - "test/cmocka/core-state-link-support.c" - ], - "includes": [ - "." - ], - "header_libraries": [ - "OBS::libobs", - "SIMDe::SIMDe" - ], - "libraries": [ - "OBS::caption", - "Uthash::Uthash", - { - "name": "OBS::w32-pthreads", - "requires": "OS_WINDOWS" - } - ] - }, - "test_source_draw_plan_steps_rust": { - "sources": [ - "test/cmocka/video-info-query-link-support.c", - "test/cmocka/core-state-link-support.c" - ], - "includes": [ - "." - ], - "header_libraries": [ - "OBS::libobs", - "SIMDe::SIMDe" - ], - "libraries": [ - "OBS::caption", - "Uthash::Uthash", - { - "name": "OBS::w32-pthreads", - "requires": "OS_WINDOWS" - } - ] - }, - "test_source_frame_copy_steps_rust": { - "sources": [ - "test/cmocka/video-info-query-link-support.c", - "test/cmocka/core-state-link-support.c" - ], - "includes": [ - "." - ], - "header_libraries": [ - "OBS::libobs", - "SIMDe::SIMDe" - ], - "libraries": [ - "OBS::caption", - "Uthash::Uthash", - { - "name": "OBS::w32-pthreads", - "requires": "OS_WINDOWS" - } - ] - }, - "test_source_media_admission_steps_rust": { - "sources": [ - "test/cmocka/video-info-query-link-support.c", - "test/cmocka/core-state-link-support.c" - ], - "includes": [ - "." - ], - "header_libraries": [ - "OBS::libobs", - "SIMDe::SIMDe" - ], - "libraries": [ - "OBS::caption", - "Uthash::Uthash", - { - "name": "OBS::w32-pthreads", - "requires": "OS_WINDOWS" - } - ] - }, - "test_source_monitoring_steps_rust": { - "sources": [ - "test/cmocka/video-info-query-link-support.c", - "test/cmocka/core-state-link-support.c" - ], - "includes": [ - "." - ], - "header_libraries": [ - "OBS::libobs", - "SIMDe::SIMDe" - ], - "libraries": [ - "OBS::caption", - "Uthash::Uthash", - { - "name": "OBS::w32-pthreads", - "requires": "OS_WINDOWS" - } - ] - }, - "test_source_ptm_gate_steps_rust": { - "sources": [ - "test/cmocka/video-info-query-link-support.c", - "test/cmocka/core-state-link-support.c" - ], - "includes": [ - "." - ], - "header_libraries": [ - "OBS::libobs", - "SIMDe::SIMDe" - ], - "libraries": [ - "OBS::caption", - "Uthash::Uthash", - { - "name": "OBS::w32-pthreads", - "requires": "OS_WINDOWS" - } - ] - }, - "test_source_render_route_steps_rust": { - "sources": [ - "test/cmocka/video-info-query-link-support.c", - "test/cmocka/core-state-link-support.c" - ], - "includes": [ - "." - ], - "header_libraries": [ - "OBS::libobs", - "SIMDe::SIMDe" - ], - "libraries": [ - "OBS::caption", - "Uthash::Uthash", - { - "name": "OBS::w32-pthreads", - "requires": "OS_WINDOWS" - } - ] - }, - "test_source_size_route_steps_rust": { - "sources": [ - "test/cmocka/video-info-query-link-support.c", - "test/cmocka/core-state-link-support.c" - ], - "includes": [ - "." - ], - "header_libraries": [ - "OBS::libobs", - "SIMDe::SIMDe" - ], - "libraries": [ - "OBS::caption", - "Uthash::Uthash", - { - "name": "OBS::w32-pthreads", - "requires": "OS_WINDOWS" - } - ] - }, - "test_source_video_tick_steps_rust": { - "sources": [ - "test/cmocka/video-info-query-link-support.c", - "test/cmocka/core-state-link-support.c" - ], - "includes": [ - "." - ], - "header_libraries": [ - "OBS::libobs", - "SIMDe::SIMDe" - ], - "libraries": [ - "OBS::caption", - "Uthash::Uthash", - { - "name": "OBS::w32-pthreads", - "requires": "OS_WINDOWS" - } - ] - }, - "test_source_volume_apply_steps_rust": { - "sources": [ - "test/cmocka/video-info-query-link-support.c", - "test/cmocka/core-state-link-support.c" - ], - "includes": [ - "." - ], - "header_libraries": [ - "OBS::libobs", - "SIMDe::SIMDe" - ], - "libraries": [ - "OBS::caption", - "Uthash::Uthash", - { - "name": "OBS::w32-pthreads", - "requires": "OS_WINDOWS" - } - ] - }, - "test_transition_load_steps_rust": { - "sources": [ - "test/cmocka/video-info-query-link-support.c", - "test/cmocka/core-state-link-support.c" - ], - "includes": [ - "." - ], - "header_libraries": [ - "OBS::libobs", - "SIMDe::SIMDe" - ], - "libraries": [ - "OBS::caption", - "Uthash::Uthash", - { - "name": "OBS::w32-pthreads", - "requires": "OS_WINDOWS" - } - ] - }, - "test_transition_render_steps_rust": { - "sources": [ - "test/cmocka/video-info-query-link-support.c", - "test/cmocka/core-state-link-support.c" - ], - "includes": [ - "." - ], - "header_libraries": [ - "OBS::libobs", - "SIMDe::SIMDe" - ], - "libraries": [ - "OBS::caption", - "Uthash::Uthash", - { - "name": "OBS::w32-pthreads", - "requires": "OS_WINDOWS" - } - ] - }, - "test_transition_start_steps_rust": { - "sources": [ - "test/cmocka/video-info-query-link-support.c", - "test/cmocka/core-state-link-support.c" - ], - "includes": [ - "." - ], - "header_libraries": [ - "OBS::libobs", - "SIMDe::SIMDe" - ], - "libraries": [ - "OBS::caption", - "Uthash::Uthash", - { - "name": "OBS::w32-pthreads", - "requires": "OS_WINDOWS" - } - ] - } -} diff --git a/rust/obs-build/tests/native/registration/rust-static/support/zz-output-starting-queries.json b/rust/obs-build/tests/native/registration/rust-static/support/zz-output-starting-queries.json deleted file mode 100644 index a47e496438..0000000000 --- a/rust/obs-build/tests/native/registration/rust-static/support/zz-output-starting-queries.json +++ /dev/null @@ -1,317 +0,0 @@ -{ - "test_async_conversion_plan_rust": { - "sources": [ - "test/cmocka/output-starting-queries-link-support.c" - ] - }, - "test_async_frame_pacing_steps_rust": { - "sources": [ - "test/cmocka/output-starting-queries-link-support.c" - ] - }, - "test_async_upload_steps_rust": { - "sources": [ - "test/cmocka/output-starting-queries-link-support.c" - ] - }, - "test_audio_monitor_delay_steps_rust": { - "sources": [ - "test/cmocka/output-starting-queries-link-support.c" - ] - }, - "test_coreaudio_device_rules_rust": { - "sources": [ - "test/cmocka/output-starting-queries-link-support.c" - ] - }, - "test_coreaudio_pacing_steps_rust": { - "sources": [ - "test/cmocka/output-starting-queries-link-support.c" - ] - }, - "test_deinterlace_draw_plan_steps_rust": { - "sources": [ - "test/cmocka/output-starting-queries-link-support.c" - ] - }, - "test_deinterlace_pacing_steps_rust": { - "sources": [ - "test/cmocka/output-starting-queries-link-support.c" - ] - }, - "test_deinterlace_select_steps_rust": { - "sources": [ - "test/cmocka/output-starting-queries-link-support.c" - ] - }, - "test_effect_param_types_steps_rust": { - "sources": [ - "test/cmocka/output-starting-queries-link-support.c" - ] - }, - "test_effect_parser_blocks_rust": { - "sources": [ - "test/cmocka/output-starting-queries-link-support.c" - ] - }, - "test_effect_parser_compile_rust": { - "sources": [ - "test/cmocka/output-starting-queries-link-support.c" - ] - }, - "test_effect_parser_lifecycle_rust": { - "sources": [ - "test/cmocka/output-starting-queries-link-support.c" - ] - }, - "test_effect_parser_params_rust": { - "sources": [ - "test/cmocka/output-starting-queries-link-support.c" - ] - }, - "test_effect_parser_passes_rust": { - "sources": [ - "test/cmocka/output-starting-queries-link-support.c" - ] - }, - "test_effect_parser_shader_call_rust": { - "sources": [ - "test/cmocka/output-starting-queries-link-support.c" - ] - }, - "test_encoder_video_tex_active_rust": { - "sources": [ - "test/cmocka/output-starting-queries-link-support.c" - ] - }, - "test_graphics_ffmpeg_pq_steps_rust": { - "sources": [ - "test/cmocka/output-starting-queries-link-support.c" - ] - }, - "test_graphics_ffmpeg_route_steps_rust": { - "sources": [ - "test/cmocka/output-starting-queries-link-support.c" - ] - }, - "test_graphics_ffmpeg_wic_checks_rust": { - "sources": [ - "test/cmocka/output-starting-queries-link-support.c" - ] - }, - "test_graphics_immediate_steps_rust": { - "sources": [ - "test/cmocka/output-starting-queries-link-support.c" - ] - }, - "test_graphics_state_stacks_rust": { - "sources": [ - "test/cmocka/output-starting-queries-link-support.c" - ] - }, - "test_monitor_speaker_layout_rust": { - "sources": [ - "test/cmocka/output-starting-queries-link-support.c" - ] - }, - "test_monitor_video_sync_rust": { - "sources": [ - "test/cmocka/output-starting-queries-link-support.c" - ] - }, - "test_monitor_wasapi_steps_rust": { - "sources": [ - "test/cmocka/output-starting-queries-link-support.c" - ] - }, - "test_nsgif_decode_rust": { - "sources": [ - "test/cmocka/output-starting-queries-link-support.c" - ] - }, - "test_pulse_monitor_steps_rust": { - "sources": [ - "test/cmocka/output-starting-queries-link-support.c" - ] - }, - "test_scene_audio_window_steps_rust": { - "sources": [ - "test/cmocka/output-starting-queries-link-support.c" - ] - }, - "test_scene_bounds_place_rust": { - "sources": [ - "test/cmocka/output-starting-queries-link-support.c" - ] - }, - "test_scene_item_crop_rust": { - "sources": [ - "test/cmocka/output-starting-queries-link-support.c" - ] - }, - "test_scene_item_names_steps_rust": { - "sources": [ - "test/cmocka/output-starting-queries-link-support.c" - ] - }, - "test_scene_item_order_steps_rust": { - "sources": [ - "test/cmocka/output-starting-queries-link-support.c" - ] - }, - "test_scene_item_transform_steps_rust": { - "sources": [ - "test/cmocka/output-starting-queries-link-support.c" - ] - }, - "test_scene_render_plan_steps_rust": { - "sources": [ - "test/cmocka/output-starting-queries-link-support.c" - ] - }, - "test_scene_transform_update_steps_rust": { - "sources": [ - "test/cmocka/output-starting-queries-link-support.c" - ] - }, - "test_service_handler_getters_rust": { - "sources": [ - "test/cmocka/output-starting-queries-link-support.c" - ] - }, - "test_source_audio_input_steps_rust": { - "sources": [ - "test/cmocka/output-starting-queries-link-support.c" - ] - }, - "test_source_audio_place_steps_rust": { - "sources": [ - "test/cmocka/output-starting-queries-link-support.c" - ] - }, - "test_source_audio_render_steps_rust": { - "sources": [ - "test/cmocka/output-starting-queries-link-support.c" - ] - }, - "test_source_audio_timing_steps_rust": { - "sources": [ - "test/cmocka/output-starting-queries-link-support.c" - ] - }, - "test_source_color_space_steps_rust": { - "sources": [ - "test/cmocka/output-starting-queries-link-support.c" - ] - }, - "test_source_draw_plan_steps_rust": { - "sources": [ - "test/cmocka/output-starting-queries-link-support.c" - ] - }, - "test_source_duplicate_steps_rust": { - "sources": [ - "test/cmocka/output-starting-queries-link-support.c" - ] - }, - "test_source_filter_chain_steps_rust": { - "sources": [ - "test/cmocka/output-starting-queries-link-support.c" - ] - }, - "test_source_frame_copy_steps_rust": { - "sources": [ - "test/cmocka/output-starting-queries-link-support.c" - ] - }, - "test_source_init_context_rust": { - "sources": [ - "test/cmocka/output-starting-queries-link-support.c" - ] - }, - "test_source_media_admission_steps_rust": { - "sources": [ - "test/cmocka/output-starting-queries-link-support.c" - ] - }, - "test_source_monitoring_steps_rust": { - "sources": [ - "test/cmocka/output-starting-queries-link-support.c" - ] - }, - "test_source_ptm_gate_steps_rust": { - "sources": [ - "test/cmocka/output-starting-queries-link-support.c" - ] - }, - "test_source_render_route_steps_rust": { - "sources": [ - "test/cmocka/output-starting-queries-link-support.c" - ] - }, - "test_source_size_route_steps_rust": { - "sources": [ - "test/cmocka/output-starting-queries-link-support.c" - ] - }, - "test_source_video_tick_steps_rust": { - "sources": [ - "test/cmocka/output-starting-queries-link-support.c" - ] - }, - "test_source_volume_apply_steps_rust": { - "sources": [ - "test/cmocka/output-starting-queries-link-support.c" - ] - }, - "test_sprite_geometry_steps_rust": { - "sources": [ - "test/cmocka/output-starting-queries-link-support.c" - ] - }, - "test_transition_clock_steps_rust": { - "sources": [ - "test/cmocka/output-starting-queries-link-support.c" - ] - }, - "test_transition_load_steps_rust": { - "sources": [ - "test/cmocka/output-starting-queries-link-support.c" - ] - }, - "test_transition_render_steps_rust": { - "sources": [ - "test/cmocka/output-starting-queries-link-support.c" - ] - }, - "test_transition_sample_time_steps_rust": { - "sources": [ - "test/cmocka/output-starting-queries-link-support.c" - ] - }, - "test_transition_start_steps_rust": { - "sources": [ - "test/cmocka/output-starting-queries-link-support.c" - ] - }, - "test_video_info_query_rust": { - "sources": [ - "test/cmocka/output-starting-queries-link-support.c" - ] - }, - "test_video_stop_requested_rust": { - "sources": [ - "test/cmocka/output-starting-queries-link-support.c" - ] - }, - "test_window_match_steps_rust": { - "sources": [ - "test/cmocka/output-starting-queries-link-support.c" - ] - }, - "test_windows_keys_steps_rust": { - "sources": [ - "test/cmocka/output-starting-queries-link-support.c" - ] - } -} diff --git a/rust/obs-build/tests/native/registration/shared_rust_static_support.rs b/rust/obs-build/tests/native/registration/shared_rust_static_support.rs new file mode 100644 index 0000000000..4e05c4058d --- /dev/null +++ b/rust/obs-build/tests/native/registration/shared_rust_static_support.rs @@ -0,0 +1,113 @@ +#[test] +fn rust_static_precedes_import_providers_and_their_host_closure() { + use obs_build::validation::graph::{Dependency, Graph}; + let graph = Graph::parse( + r#"{"schema":1,"targets":{"fixture":{"sources":["main.c"], + "libraries":["OBS::libobs","host_consumer","libobs_rust-static"]}}, + "tests":{"fixture":{"target":"fixture"}}}"#, + ) + .unwrap(); + let dependencies = [ + ( + "OBS::libobs".into(), + Dependency { + artifacts: vec!["obs.lib".into()], + ..Default::default() + }, + ), + ( + "host_consumer".into(), + Dependency { + artifacts: vec!["consumer.a".into(), "host.so".into()], + ..Default::default() + }, + ), + ( + "libobs_rust-static".into(), + Dependency { + artifacts: vec!["rust.lib".into()], + ..Default::default() + }, + ), + ] + .into(); + assert_eq!( + graph.targets["fixture"] + .dependency_artifacts(&[("MSVC".into(), true)].into(), &dependencies) + .unwrap(), + ["rust.lib", "obs.lib", "consumer.a", "host.so"].map(std::path::PathBuf::from) + ); + assert_eq!( + graph.targets["fixture"] + .dependency_artifacts(&[("MSVC".into(), false)].into(), &dependencies) + .unwrap(), + ["obs.lib", "consumer.a", "host.so", "rust.lib"].map(std::path::PathBuf::from) + ); + let mut standalone = dependencies.clone(); + standalone + .get_mut("libobs_rust-static") + .unwrap() + .rust_static_support = true; + assert_eq!( + graph.targets["fixture"] + .dependency_artifacts(&[("MSVC".into(), true)].into(), &standalone) + .unwrap(), + ["rust.lib", "consumer.a", "host.so"].map(std::path::PathBuf::from) + ); +} + +#[test] +fn rust_archive_owns_transitive_sdk_interfaces_and_target_facts() { + use obs_build::validation::graph::{Dependency, Graph}; + let graph = Graph::parse( + r#"{"schema":1,"targets":{"fixture":{"sources":["main.c"], + "libraries":[{"name":"host_sdk","requires":"OS_LINUX"},"libobs_rust-static"]}}, + "tests":{"fixture":{"target":"fixture"}}}"#, + ) + .unwrap(); + let owner = Dependency { + artifacts: vec!["rust.a".into()], + native_facts: Dependency::target_facts("x86_64-unknown-linux-gnu"), + native_libraries: [( + "host_sdk".into(), + Dependency { + artifacts: vec!["host.a".into()], + ..Default::default() + }, + )] + .into(), + ..Default::default() + }; + let libraries = [("libobs_rust-static".into(), owner)].into(); + assert_eq!( + graph.targets["fixture"] + .dependency_artifacts(&Default::default(), &libraries) + .unwrap(), + ["host.a", "rust.a"].map(std::path::PathBuf::from) + ); + assert_eq!( + graph.targets["fixture"] + .dependency_artifacts(&[("OS_LINUX".into(), false)].into(), &libraries) + .unwrap(), + ["rust.a"].map(std::path::PathBuf::from) + ); + for feature in ["ENABLE_HEVC", "UNDECLARED_SDK"] { + let graph = Graph::parse( + &serde_json::json!({ + "schema": 1, + "targets": {"fixture": {"sources": ["main.c"], "libraries": [ + {"name": "host_sdk", "requires": feature}, "libobs_rust-static" + ]}}, + "tests": {"fixture": {"target": "fixture"}} + }) + .to_string(), + ) + .unwrap(); + assert_eq!( + graph.targets["fixture"] + .dependency_artifacts(&Default::default(), &libraries) + .unwrap_err(), + format!("unknown native test requirement {feature}") + ); + } +} diff --git a/rust/obs-c-oracle/build.rs b/rust/obs-c-oracle/build.rs index e6dcbb870c..7a0e335d67 100644 --- a/rust/obs-c-oracle/build.rs +++ b/rust/obs-c-oracle/build.rs @@ -666,7 +666,7 @@ fn main() { "}", ), extract_c( - &libobs.join("obs-source.c.h"), + &libobs.join("obs-source-weak-refs.c.h"), "void obs_weak_source_release(", "}", ), diff --git a/rust/obs-output/src/lib.rs b/rust/obs-output/src/lib.rs index 6ba4e379f4..cded49f4bb 100644 --- a/rust/obs-output/src/lib.rs +++ b/rust/obs-output/src/lib.rs @@ -218,6 +218,7 @@ pub mod raw_audio; pub mod raw_audio_trim; pub mod service; pub mod service_context_getters; +pub mod service_find; pub mod service_module_lookup; pub mod service_state; pub mod service_weak_acquire; diff --git a/rust/obs-output/src/service_find.rs b/rust/obs-output/src/service_find.rs new file mode 100644 index 0000000000..898c89c83c --- /dev/null +++ b/rust/obs-output/src/service_find.rs @@ -0,0 +1,7 @@ +//! Borrowed, byte-exact lookup in the C-owned service registry. + +/// Walk IDs lazily and return the first matching entry without copying it. +pub fn find<'a, T>(id: &[u8], entries: impl IntoIterator) -> Option { + let _ = (id, entries); + todo!("port find_service") +} diff --git a/rust/obs-output/tests/output/main.rs b/rust/obs-output/tests/output/main.rs index 39496e507d..353e448159 100644 --- a/rust/obs-output/tests/output/main.rs +++ b/rust/obs-output/tests/output/main.rs @@ -147,6 +147,7 @@ mod raw_audio_trim_parity; mod service; mod service_context_getters; mod service_context_getters_parity; +mod service_find; mod service_lifecycle; mod service_lifecycle_parity; mod service_module_lookup; diff --git a/rust/obs-output/tests/output/service_find.rs b/rust/obs-output/tests/output/service_find.rs new file mode 100644 index 0000000000..0386d7dc55 --- /dev/null +++ b/rust/obs-output/tests/output/service_find.rs @@ -0,0 +1,55 @@ +//! Tier 1 mirrors test_service_find.c::registry_lookup without FFI. +use obs_output::service_find::find; + +#[derive(Clone, Debug, PartialEq)] +struct Entry { + id: Vec, + owner: usize, +} + +fn lookup<'a>(entries: &'a [Entry], count: usize, query: &[u8]) -> Option<&'a Entry> { + find(query, entries[..count].iter().map(|entry| (entry.id.as_slice(), entry))) +} + +#[test] +fn registry_lookup() { + for query in [b"".as_slice(), b"missing"] { + assert!(lookup(&[], 0, query).is_none()); + } + let ids: &[&[u8]] = &[b"svc", b"svc.suffix", b"SVC", b"", b"\xff\x80x", b"svc", b"last", b"outside"]; + let mut entries: Vec<_> = ids.iter().enumerate().map(|(owner, id)| Entry { id: id.to_vec(), owner }).collect(); + assert!(lookup(&entries, 0, b"svc").is_none()); + let queries: &[(&[u8], Option)] = &[ + (b"svc", Some(0)), (b"sv", None), (b"svc.suffix", Some(1)), + (b"svc.suffix.more", None), (b"SVC", Some(2)), (b"Svc", None), + (b"", Some(3)), (b"\xff\x80x", Some(4)), (b"\xff\x81x", None), + (b"last", Some(6)), (b"outside", None), (b"missing", None), + ]; + let before = entries.clone(); + for &(query, expected) in queries { + let actual = lookup(&entries, 7, query); + assert_eq!(actual.map(|entry| entry.owner), expected); + if let Some(index) = expected { + assert!(std::ptr::eq(actual.unwrap(), &entries[index])); + } + assert_eq!(entries, before); + } + entries.swap(0, 5); + assert!(std::ptr::eq(lookup(&entries, 7, b"svc").unwrap(), &entries[0])); + entries[0].id = b"replaced".to_vec(); + assert!(std::ptr::eq(lookup(&entries, 7, b"svc").unwrap(), &entries[5])); + assert_eq!(entries[5].id, b"svc"); + assert_eq!(entries[0].owner, 5); +} + +#[test] +fn stops_before_reading_later_entries() { + let mut reads = 0; + let entries = [b"svc".as_slice(), b"svc", b"other"]; + let found = find(b"svc", entries.iter().enumerate().map(|(index, id)| { + reads += 1; + (*id, index) + })); + assert_eq!(found, Some(0)); + assert_eq!(reads, 1); +} diff --git a/test/cmocka/base-blog-link-support.c b/test/cmocka/base-blog-link-support.c new file mode 100644 index 0000000000..d9f1696885 --- /dev/null +++ b/test/cmocka/base-blog-link-support.c @@ -0,0 +1,6 @@ +/* A fixture's own public logger must take precedence over this lazy provider. */ +#define base_default_log_handler obs_link_support_blog_default_handler +#define base_log_literal obs_link_support_blog_literal +#define blogva obs_link_support_blog_blogva +#define bcrash obs_link_support_blog_bcrash +#include "libobs/util/base-variadic.c.h" diff --git a/test/cmocka/base-blogva-link-support.c b/test/cmocka/base-blogva-link-support.c new file mode 100644 index 0000000000..a73da17ffe --- /dev/null +++ b/test/cmocka/base-blogva-link-support.c @@ -0,0 +1,6 @@ +/* Requesting the real va_list forwarder must not also select blog or bcrash. */ +#define base_default_log_handler obs_link_support_blogva_default_handler +#define base_log_literal obs_link_support_blogva_literal +#define blog obs_link_support_blogva_blog +#define bcrash obs_link_support_blogva_bcrash +#include "libobs/util/base-variadic.c.h" diff --git a/test/cmocka/base-crash-link-support.c b/test/cmocka/base-crash-link-support.c new file mode 100644 index 0000000000..43c873fd1d --- /dev/null +++ b/test/cmocka/base-crash-link-support.c @@ -0,0 +1,6 @@ +/* Keep the real crash provider independent of fixture-owned public loggers. */ +#define base_default_log_handler obs_link_support_crash_default_handler +#define base_log_literal obs_link_support_crash_literal +#define blog obs_link_support_crash_blog +#define blogva obs_link_support_crash_blogva +#include "libobs/util/base-variadic.c.h" diff --git a/test/cmocka/base-variadic-link-support.c b/test/cmocka/base-variadic-link-support.c new file mode 100644 index 0000000000..458a13af10 --- /dev/null +++ b/test/cmocka/base-variadic-link-support.c @@ -0,0 +1,5 @@ +/* Demand-link the real private logger bridge, preserving fixture-owned loggers. */ +#define blog obs_link_support_bridge_blog +#define blogva obs_link_support_bridge_blogva +#define bcrash obs_link_support_bridge_bcrash +#include "libobs/util/base-variadic.c.h" diff --git a/test/cmocka/build/rust-static-support.json b/test/cmocka/build/rust-static-support.json new file mode 100644 index 0000000000..7858afaa3c --- /dev/null +++ b/test/cmocka/build/rust-static-support.json @@ -0,0 +1,45 @@ +{ + "sources": [ + "test/cmocka/core-state-link-support.c", + "test/cmocka/video-info-query-link-support.c", + "test/cmocka/base-variadic-link-support.c", + "test/cmocka/base-blog-link-support.c", + "test/cmocka/base-blogva-link-support.c", + "test/cmocka/base-crash-link-support.c", + "test/cmocka/core-initialized-link-support.c", + "test/cmocka/source-save-load-link-support.c", + "test/cmocka/source-settings-getter-link-support.c", + "test/cmocka/encoder-video-tex-active-fields-link-support.c", + "test/cmocka/encoder-video-tex-active-mix-link-support.c", + "test/cmocka/hotkey-fields-link-support.c", + "test/cmocka/service-runtime-link-support.c", + "test/cmocka/service-state-link-support.c", + "test/cmocka/source-weak-control-link-support.c", + "test/cmocka/context-runtime-link-support.c", + "test/cmocka/encoder-weak-refs-link-support.c", + "test/cmocka/source-weak-refs-link-support.c", + "test/cmocka/profiler-variadic-link-support.c", + "test/cmocka/cf-preprocessor-link-support.c", + "test/cmocka/graphics-runtime-link-support.c", + "test/cmocka/dstr-variadic-link-support.c", + "test/cmocka/graphics-image-max-size-link-support.c", + "test/cmocka/graphics-image-deps-link-support.c", + "test/cmocka/graphics-texture-file-data-link-support.c", + "test/cmocka/effect-parser-funcs-link-support.c", + "test/cmocka/texture-creators-fields-link-support.c", + "test/cmocka/graphics-image-convert-link-support.c", + "test/cmocka/graphics-preprocessor-link-support.c", + "test/cmocka/output-starting-queries-link-support.c", + "test/cmocka/graphics-indexbuffer-maintenance-link-support.c", + "test/cmocka/encoder-get-name-link-support.c", + "test/cmocka/output-interleave-name-link-support.c" + ], + "platform_sources": { + "OS_WINDOWS": [ + "test/cmocka/hosts/windows/graphics-image-fallback-link-support.c" + ], + "UNIX": [ + "test/cmocka/hosts/posix/graphics-image-fallback-link-support.c" + ] + } +} diff --git a/test/cmocka/build/test-graph.json b/test/cmocka/build/test-graph.json index 6586858424..846a2b0fe2 100644 --- a/test/cmocka/build/test-graph.json +++ b/test/cmocka/build/test-graph.json @@ -304,13 +304,10 @@ "test/cmocka/source-push-query-link-stubs.c", "test/cmocka/source-state-getter-link-stubs.c", "test/cmocka/source-update-properties-link-support.c", - "test/cmocka/video-info-query-link-support.c", - "test/cmocka/core-state-link-support.c", "test/cmocka/weak-encoder-identity-link-stub.c", "test/cmocka/weak-object-identity-link-stub.c", "libobs/build/libobs.image-decode-adapter+.h.c", - "test/cmocka/source-icon-type-link-support.c", - "test/cmocka/output-starting-queries-link-support.c" + "test/cmocka/source-icon-type-link-support.c" ], "requires": "HAVE_LIBOBS_RUST_STATIC", "includes": [ @@ -428,13 +425,10 @@ "test/cmocka/source-push-query-link-stubs.c", "test/cmocka/source-state-getter-link-stubs.c", "test/cmocka/source-update-properties-link-support.c", - "test/cmocka/video-info-query-link-support.c", - "test/cmocka/core-state-link-support.c", "test/cmocka/weak-encoder-identity-link-stub.c", "test/cmocka/weak-object-identity-link-stub.c", "libobs/build/libobs.image-decode-adapter+.h.c", - "test/cmocka/source-icon-type-link-support.c", - "test/cmocka/output-starting-queries-link-support.c" + "test/cmocka/source-icon-type-link-support.c" ], "requires": "HAVE_LIBOBS_RUST_STATIC", "includes": [ @@ -540,13 +534,10 @@ "test/cmocka/source-push-query-link-stubs.c", "test/cmocka/source-state-getter-link-stubs.c", "test/cmocka/source-update-properties-link-support.c", - "test/cmocka/video-info-query-link-support.c", - "test/cmocka/core-state-link-support.c", "test/cmocka/weak-encoder-identity-link-stub.c", "test/cmocka/weak-object-identity-link-stub.c", "libobs/build/libobs.image-decode-adapter+.h.c", - "test/cmocka/source-icon-type-link-support.c", - "test/cmocka/output-starting-queries-link-support.c" + "test/cmocka/source-icon-type-link-support.c" ], "includes": [ "libobs", @@ -723,11 +714,8 @@ "test/cmocka/output-service-getter-link-stub.c", "test/cmocka/source-handler-getter-link-support.c", "test/cmocka/source-update-properties-link-support.c", - "test/cmocka/video-info-query-link-support.c", - "test/cmocka/core-state-link-support.c", "test/cmocka/weak-object-identity-link-stub.c", - "libobs/build/libobs.image-decode-adapter+.h.c", - "test/cmocka/output-starting-queries-link-support.c" + "libobs/build/libobs.image-decode-adapter+.h.c" ], "requires": { "all": [ @@ -1646,11 +1634,8 @@ "test/cmocka/output-service-getter-link-stub.c", "test/cmocka/source-handler-getter-link-support.c", "test/cmocka/source-update-properties-link-support.c", - "test/cmocka/video-info-query-link-support.c", - "test/cmocka/core-state-link-support.c", "test/cmocka/weak-object-identity-link-stub.c", - "libobs/build/libobs.image-decode-adapter+.h.c", - "test/cmocka/output-starting-queries-link-support.c" + "libobs/build/libobs.image-decode-adapter+.h.c" ], "requires": { "all": [ @@ -1742,11 +1727,8 @@ "test/cmocka/output-service-getter-link-stub.c", "test/cmocka/source-handler-getter-link-support.c", "test/cmocka/source-update-properties-link-support.c", - "test/cmocka/video-info-query-link-support.c", - "test/cmocka/core-state-link-support.c", "test/cmocka/weak-object-identity-link-stub.c", - "libobs/build/libobs.image-decode-adapter+.h.c", - "test/cmocka/output-starting-queries-link-support.c" + "libobs/build/libobs.image-decode-adapter+.h.c" ], "requires": { "all": [ @@ -2012,13 +1994,10 @@ "test/cmocka/source-push-query-link-stubs.c", "test/cmocka/source-state-getter-link-stubs.c", "test/cmocka/source-update-properties-link-support.c", - "test/cmocka/video-info-query-link-support.c", - "test/cmocka/core-state-link-support.c", "test/cmocka/weak-encoder-identity-link-stub.c", "test/cmocka/weak-object-identity-link-stub.c", "libobs/build/libobs.image-decode-adapter+.h.c", - "test/cmocka/source-icon-type-link-support.c", - "test/cmocka/output-starting-queries-link-support.c" + "test/cmocka/source-icon-type-link-support.c" ], "includes": [ "libobs", @@ -2110,13 +2089,10 @@ "test/cmocka/source-push-query-link-stubs.c", "test/cmocka/source-state-getter-link-stubs.c", "test/cmocka/source-update-properties-link-support.c", - "test/cmocka/video-info-query-link-support.c", - "test/cmocka/core-state-link-support.c", "test/cmocka/weak-encoder-identity-link-stub.c", "test/cmocka/weak-object-identity-link-stub.c", "libobs/build/libobs.image-decode-adapter+.h.c", - "test/cmocka/source-icon-type-link-support.c", - "test/cmocka/output-starting-queries-link-support.c" + "test/cmocka/source-icon-type-link-support.c" ], "requires": "HAVE_LIBOBS_RUST_STATIC", "includes": [ @@ -2185,13 +2161,10 @@ "test/cmocka/source-push-query-link-stubs.c", "test/cmocka/source-state-getter-link-stubs.c", "test/cmocka/source-update-properties-link-support.c", - "test/cmocka/video-info-query-link-support.c", - "test/cmocka/core-state-link-support.c", "test/cmocka/weak-encoder-identity-link-stub.c", "test/cmocka/weak-object-identity-link-stub.c", "libobs/build/libobs.image-decode-adapter+.h.c", - "test/cmocka/source-icon-type-link-support.c", - "test/cmocka/output-starting-queries-link-support.c" + "test/cmocka/source-icon-type-link-support.c" ], "requires": "HAVE_LIBOBS_RUST_STATIC", "includes": [ @@ -2699,8 +2672,7 @@ "libobs/obs-graphics-effect-file-fields.c.h", "test/cmocka/object-validity-query-link-stubs.c", "test/cmocka/source-update-properties-link-support.c", - "libobs/build/libobs.image-decode-adapter+.h.c", - "test/cmocka/output-starting-queries-link-support.c" + "libobs/build/libobs.image-decode-adapter+.h.c" ], "requires": "HAVE_LIBOBS_RUST_STATIC", "includes": [ @@ -2785,8 +2757,7 @@ }, "libobs/obs-graphics-effect-file-fields.c.h", "test/cmocka/source-update-properties-link-support.c", - "libobs/build/libobs.image-decode-adapter+.h.c", - "test/cmocka/output-starting-queries-link-support.c" + "libobs/build/libobs.image-decode-adapter+.h.c" ], "requires": "HAVE_LIBOBS_RUST_STATIC", "includes": [ @@ -2871,8 +2842,7 @@ "libobs/graphics/graphics-linear-srgb-fields.c.h", "libobs/obs-graphics-effect-file-fields.c.h", "test/cmocka/source-update-properties-link-support.c", - "libobs/build/libobs.image-decode-adapter+.h.c", - "test/cmocka/output-starting-queries-link-support.c" + "libobs/build/libobs.image-decode-adapter+.h.c" ], "requires": "HAVE_LIBOBS_RUST_STATIC", "includes": [ @@ -2995,8 +2965,7 @@ "libobs/obs-graphics-effect-file-fields.c.h", "test/cmocka/object-validity-query-link-stubs.c", "test/cmocka/source-update-properties-link-support.c", - "libobs/build/libobs.image-decode-adapter+.h.c", - "test/cmocka/output-starting-queries-link-support.c" + "libobs/build/libobs.image-decode-adapter+.h.c" ], "requires": "HAVE_LIBOBS_RUST_STATIC", "includes": [ @@ -3063,8 +3032,7 @@ }, "libobs/obs-graphics-effect-file-fields.c.h", "test/cmocka/source-update-properties-link-support.c", - "libobs/build/libobs.image-decode-adapter+.h.c", - "test/cmocka/output-starting-queries-link-support.c" + "libobs/build/libobs.image-decode-adapter+.h.c" ], "requires": "HAVE_LIBOBS_RUST_STATIC", "includes": [ @@ -3147,8 +3115,7 @@ }, "libobs/obs-graphics-effect-file-fields.c.h", "test/cmocka/source-update-properties-link-support.c", - "libobs/build/libobs.image-decode-adapter+.h.c", - "test/cmocka/output-starting-queries-link-support.c" + "libobs/build/libobs.image-decode-adapter+.h.c" ], "requires": "HAVE_LIBOBS_RUST_STATIC", "includes": [ @@ -3235,8 +3202,7 @@ }, "libobs/obs-graphics-effect-file-fields.c.h", "test/cmocka/source-update-properties-link-support.c", - "libobs/build/libobs.image-decode-adapter+.h.c", - "test/cmocka/output-starting-queries-link-support.c" + "libobs/build/libobs.image-decode-adapter+.h.c" ], "requires": "HAVE_LIBOBS_RUST_STATIC", "includes": [ @@ -4143,8 +4109,7 @@ "test_encoder_video_tex_active_rust": { "sources": [ "test/cmocka/test_encoder_video_tex_active.c", - "test/cmocka/encoder-video-tex-active-fields-link-support.c", - "test/cmocka/output-starting-queries-link-support.c" + "test/cmocka/encoder-video-tex-active-fields-link-support.c" ], "definitions": [ "get_mix_for_video=tex_active_recording_mix_lookup", @@ -5074,8 +5039,7 @@ "libobs/obs-graphics-effect-file-fields.c.h", "test/cmocka/object-validity-query-link-stubs.c", "test/cmocka/source-update-properties-link-support.c", - "libobs/build/libobs.image-decode-adapter+.h.c", - "test/cmocka/output-starting-queries-link-support.c" + "libobs/build/libobs.image-decode-adapter+.h.c" ], "requires": "HAVE_LIBOBS_RUST_STATIC", "includes": [ @@ -5160,8 +5124,7 @@ "libobs/obs-graphics-effect-file-fields.c.h", "test/cmocka/object-validity-query-link-stubs.c", "test/cmocka/source-update-properties-link-support.c", - "libobs/build/libobs.image-decode-adapter+.h.c", - "test/cmocka/output-starting-queries-link-support.c" + "libobs/build/libobs.image-decode-adapter+.h.c" ], "requires": "HAVE_LIBOBS_RUST_STATIC", "includes": [ @@ -5221,8 +5184,7 @@ "libobs/obs-graphics-effect-file-fields.c.h", "test/cmocka/object-validity-query-link-stubs.c", "test/cmocka/source-update-properties-link-support.c", - "libobs/build/libobs.image-decode-adapter+.h.c", - "test/cmocka/output-starting-queries-link-support.c" + "libobs/build/libobs.image-decode-adapter+.h.c" ], "requires": "HAVE_LIBOBS_RUST_STATIC", "includes": [ @@ -5320,8 +5282,7 @@ "libobs/graphics/graphics-linear-srgb-fields.c.h", "libobs/obs-graphics-effect-file-fields.c.h", "test/cmocka/source-update-properties-link-support.c", - "libobs/build/libobs.image-decode-adapter+.h.c", - "test/cmocka/output-starting-queries-link-support.c" + "libobs/build/libobs.image-decode-adapter+.h.c" ], "requires": "HAVE_LIBOBS_RUST_STATIC", "includes": [ @@ -5499,8 +5460,7 @@ "libobs/graphics/graphics-linear-srgb-fields.c.h", "libobs/build/libobs.image-decode-adapter+.h.c", "libobs/obs-graphics-effect-file-fields.c.h", - "test/cmocka/source-update-properties-link-support.c", - "test/cmocka/output-starting-queries-link-support.c" + "test/cmocka/source-update-properties-link-support.c" ], "requires": "HAVE_LIBOBS_RUST_STATIC", "includes": [ @@ -8854,11 +8814,8 @@ "test/cmocka/output-service-getter-link-stub.c", "test/cmocka/source-handler-getter-link-support.c", "test/cmocka/source-update-properties-link-support.c", - "test/cmocka/video-info-query-link-support.c", - "test/cmocka/core-state-link-support.c", "test/cmocka/weak-object-identity-link-stub.c", - "libobs/build/libobs.image-decode-adapter+.h.c", - "test/cmocka/output-starting-queries-link-support.c" + "libobs/build/libobs.image-decode-adapter+.h.c" ], "requires": { "all": [ @@ -8916,11 +8873,8 @@ "test/cmocka/output-service-getter-link-stub.c", "test/cmocka/source-handler-getter-link-support.c", "test/cmocka/source-update-properties-link-support.c", - "test/cmocka/video-info-query-link-support.c", - "test/cmocka/core-state-link-support.c", "test/cmocka/weak-object-identity-link-stub.c", - "libobs/build/libobs.image-decode-adapter+.h.c", - "test/cmocka/output-starting-queries-link-support.c" + "libobs/build/libobs.image-decode-adapter+.h.c" ], "requires": { "all": [ @@ -8979,11 +8933,8 @@ "test/cmocka/output-service-getter-link-stub.c", "test/cmocka/source-handler-getter-link-support.c", "test/cmocka/source-update-properties-link-support.c", - "test/cmocka/video-info-query-link-support.c", - "test/cmocka/core-state-link-support.c", "test/cmocka/weak-object-identity-link-stub.c", - "libobs/build/libobs.image-decode-adapter+.h.c", - "test/cmocka/output-starting-queries-link-support.c" + "libobs/build/libobs.image-decode-adapter+.h.c" ], "requires": { "all": [ @@ -9314,8 +9265,7 @@ "libobs/obs-graphics-effect-file-fields.c.h", "test/cmocka/object-validity-query-link-stubs.c", "test/cmocka/source-update-properties-link-support.c", - "libobs/build/libobs.image-decode-adapter+.h.c", - "test/cmocka/output-starting-queries-link-support.c" + "libobs/build/libobs.image-decode-adapter+.h.c" ], "requires": "HAVE_LIBOBS_RUST_STATIC", "includes": [ @@ -12825,11 +12775,8 @@ "test/cmocka/output-service-getter-link-stub.c", "test/cmocka/source-handler-getter-link-support.c", "test/cmocka/source-update-properties-link-support.c", - "test/cmocka/video-info-query-link-support.c", - "test/cmocka/core-state-link-support.c", "test/cmocka/weak-object-identity-link-stub.c", - "libobs/build/libobs.image-decode-adapter+.h.c", - "test/cmocka/output-starting-queries-link-support.c" + "libobs/build/libobs.image-decode-adapter+.h.c" ], "requires": { "all": [ @@ -14091,8 +14038,7 @@ "test/cmocka/source-handler-getter-link-support.c", "test/cmocka/source-update-properties-link-support.c", "test/cmocka/weak-object-identity-link-stub.c", - "libobs/build/libobs.image-decode-adapter+.h.c", - "test/cmocka/output-starting-queries-link-support.c" + "libobs/build/libobs.image-decode-adapter+.h.c" ], "requires": "HAVE_LIBOBS_RUST_STATIC", "includes": [ @@ -14191,8 +14137,7 @@ "test/cmocka/scene-item-visible-link-support.c", "test/cmocka/scene-source-getter-link-stubs.c", "test/cmocka/source-update-properties-link-support.c", - "libobs/build/libobs.image-decode-adapter+.h.c", - "test/cmocka/output-starting-queries-link-support.c" + "libobs/build/libobs.image-decode-adapter+.h.c" ], "requires": "HAVE_LIBOBS_RUST_STATIC", "libraries": [ @@ -14535,8 +14480,7 @@ "test/cmocka/scene-item-visible-link-support.c", "test/cmocka/scene-source-getter-link-support.c", "test/cmocka/source-update-properties-link-support.c", - "libobs/build/libobs.image-decode-adapter+.h.c", - "test/cmocka/output-starting-queries-link-support.c" + "libobs/build/libobs.image-decode-adapter+.h.c" ], "includes": [ "libobs", @@ -14650,8 +14594,7 @@ "test/cmocka/scene-item-visible-link-support.c", "test/cmocka/scene-source-getter-link-stubs.c", "test/cmocka/source-update-properties-link-support.c", - "libobs/build/libobs.image-decode-adapter+.h.c", - "test/cmocka/output-starting-queries-link-support.c" + "libobs/build/libobs.image-decode-adapter+.h.c" ], "requires": "HAVE_LIBOBS_RUST_STATIC", "libraries": [ @@ -14709,8 +14652,7 @@ "test/cmocka/scene-item-visible-link-support.c", "test/cmocka/scene-source-getter-link-stubs.c", "test/cmocka/source-update-properties-link-support.c", - "libobs/build/libobs.image-decode-adapter+.h.c", - "test/cmocka/output-starting-queries-link-support.c" + "libobs/build/libobs.image-decode-adapter+.h.c" ], "requires": "HAVE_LIBOBS_RUST_STATIC", "libraries": [ @@ -14866,8 +14808,7 @@ "test/cmocka/scene-item-visible-link-support.c", "test/cmocka/scene-source-getter-link-stubs.c", "test/cmocka/source-update-properties-link-support.c", - "libobs/build/libobs.image-decode-adapter+.h.c", - "test/cmocka/output-starting-queries-link-support.c" + "libobs/build/libobs.image-decode-adapter+.h.c" ], "requires": "HAVE_LIBOBS_RUST_STATIC", "libraries": [ @@ -15010,8 +14951,7 @@ "test/cmocka/source-handler-getter-link-support.c", "test/cmocka/source-update-properties-link-support.c", "test/cmocka/weak-object-identity-link-stub.c", - "libobs/build/libobs.image-decode-adapter+.h.c", - "test/cmocka/output-starting-queries-link-support.c" + "libobs/build/libobs.image-decode-adapter+.h.c" ], "includes": [ "libobs", @@ -15145,8 +15085,7 @@ "test/cmocka/scene-item-visible-link-support.c", "test/cmocka/scene-source-getter-link-stubs.c", "test/cmocka/source-update-properties-link-support.c", - "libobs/build/libobs.image-decode-adapter+.h.c", - "test/cmocka/output-starting-queries-link-support.c" + "libobs/build/libobs.image-decode-adapter+.h.c" ], "requires": "HAVE_LIBOBS_RUST_STATIC", "includes": [ @@ -15425,10 +15364,7 @@ "test/cmocka/test_service_handler_getters.c", "test/cmocka/service-handler-getters-link-support.c", "libobs/util/base-variadic.c.h", - "test/cmocka/source-update-properties-link-support.c", - "test/cmocka/video-info-query-link-support.c", - "test/cmocka/core-state-link-support.c", - "test/cmocka/output-starting-queries-link-support.c" + "test/cmocka/source-update-properties-link-support.c" ], "requires": "HAVE_LIBOBS_RUST_STATIC", "includes": [ @@ -16094,13 +16030,10 @@ "test/cmocka/source-push-query-link-stubs.c", "test/cmocka/source-state-getter-link-stubs.c", "test/cmocka/source-update-properties-link-support.c", - "test/cmocka/video-info-query-link-support.c", - "test/cmocka/core-state-link-support.c", "test/cmocka/weak-encoder-identity-link-stub.c", "test/cmocka/weak-object-identity-link-stub.c", "libobs/build/libobs.image-decode-adapter+.h.c", - "test/cmocka/source-icon-type-link-support.c", - "test/cmocka/output-starting-queries-link-support.c" + "test/cmocka/source-icon-type-link-support.c" ], "requires": "HAVE_LIBOBS_RUST_STATIC", "includes": [ @@ -16182,13 +16115,10 @@ "test/cmocka/source-push-query-link-stubs.c", "test/cmocka/source-state-getter-link-stubs.c", "test/cmocka/source-update-properties-link-support.c", - "test/cmocka/video-info-query-link-support.c", - "test/cmocka/core-state-link-support.c", "test/cmocka/weak-encoder-identity-link-stub.c", "test/cmocka/weak-object-identity-link-stub.c", "libobs/build/libobs.image-decode-adapter+.h.c", - "test/cmocka/source-icon-type-link-support.c", - "test/cmocka/output-starting-queries-link-support.c" + "test/cmocka/source-icon-type-link-support.c" ], "includes": [ "libobs", @@ -16276,13 +16206,10 @@ "test/cmocka/source-push-query-link-stubs.c", "test/cmocka/source-state-getter-link-stubs.c", "test/cmocka/source-update-properties-link-support.c", - "test/cmocka/video-info-query-link-support.c", - "test/cmocka/core-state-link-support.c", "test/cmocka/weak-encoder-identity-link-stub.c", "test/cmocka/weak-object-identity-link-stub.c", "libobs/build/libobs.image-decode-adapter+.h.c", - "test/cmocka/source-icon-type-link-support.c", - "test/cmocka/output-starting-queries-link-support.c" + "test/cmocka/source-icon-type-link-support.c" ], "requires": "HAVE_LIBOBS_RUST_STATIC", "includes": [ @@ -16383,13 +16310,10 @@ "test/cmocka/source-push-query-link-stubs.c", "test/cmocka/source-state-getter-link-stubs.c", "test/cmocka/source-update-properties-link-support.c", - "test/cmocka/video-info-query-link-support.c", - "test/cmocka/core-state-link-support.c", "test/cmocka/weak-encoder-identity-link-stub.c", "test/cmocka/weak-object-identity-link-stub.c", "libobs/build/libobs.image-decode-adapter+.h.c", - "test/cmocka/source-icon-type-link-support.c", - "test/cmocka/output-starting-queries-link-support.c" + "test/cmocka/source-icon-type-link-support.c" ], "requires": "HAVE_LIBOBS_RUST_STATIC", "includes": [ @@ -16502,13 +16426,10 @@ "test/cmocka/source-push-query-link-stubs.c", "test/cmocka/source-state-getter-link-stubs.c", "test/cmocka/source-update-properties-link-support.c", - "test/cmocka/video-info-query-link-support.c", - "test/cmocka/core-state-link-support.c", "test/cmocka/weak-encoder-identity-link-stub.c", "test/cmocka/weak-object-identity-link-stub.c", "libobs/build/libobs.image-decode-adapter+.h.c", - "test/cmocka/source-icon-type-link-support.c", - "test/cmocka/output-starting-queries-link-support.c" + "test/cmocka/source-icon-type-link-support.c" ], "requires": "HAVE_LIBOBS_RUST_STATIC", "includes": [ @@ -16661,13 +16582,10 @@ "test/cmocka/source-push-query-link-stubs.c", "test/cmocka/source-state-getter-link-stubs.c", "test/cmocka/source-update-properties-link-support.c", - "test/cmocka/video-info-query-link-support.c", - "test/cmocka/core-state-link-support.c", "test/cmocka/weak-encoder-identity-link-stub.c", "test/cmocka/weak-object-identity-link-stub.c", "libobs/build/libobs.image-decode-adapter+.h.c", - "test/cmocka/source-icon-type-link-support.c", - "test/cmocka/output-starting-queries-link-support.c" + "test/cmocka/source-icon-type-link-support.c" ], "includes": [ "libobs", @@ -16732,8 +16650,7 @@ "test/cmocka/source-state-getter-link-stubs.c", "test/cmocka/source-update-properties-link-support.c", "libobs/build/libobs.image-decode-adapter+.h.c", - "test/cmocka/source-icon-type-link-support.c", - "test/cmocka/output-starting-queries-link-support.c" + "test/cmocka/source-icon-type-link-support.c" ], "includes": [ "libobs", @@ -16808,8 +16725,7 @@ "test/cmocka/source-state-getter-link-stubs.c", "test/cmocka/source-update-properties-link-support.c", "libobs/build/libobs.image-decode-adapter+.h.c", - "test/cmocka/source-icon-type-link-support.c", - "test/cmocka/output-starting-queries-link-support.c" + "test/cmocka/source-icon-type-link-support.c" ], "includes": [ "libobs", @@ -16892,13 +16808,10 @@ "test/cmocka/source-push-query-link-stubs.c", "test/cmocka/source-state-getter-link-stubs.c", "test/cmocka/source-update-properties-link-support.c", - "test/cmocka/video-info-query-link-support.c", - "test/cmocka/core-state-link-support.c", "test/cmocka/weak-encoder-identity-link-stub.c", "test/cmocka/weak-object-identity-link-stub.c", "libobs/build/libobs.image-decode-adapter+.h.c", - "test/cmocka/source-icon-type-link-support.c", - "test/cmocka/output-starting-queries-link-support.c" + "test/cmocka/source-icon-type-link-support.c" ], "requires": "HAVE_LIBOBS_RUST_STATIC", "includes": [ @@ -17021,8 +16934,7 @@ "test/cmocka/source-identity-getter-link-stubs.c", "test/cmocka/source-push-query-link-stubs.c", "test/cmocka/source-state-getter-link-stubs.c", - "test/cmocka/source-update-properties-link-support.c", - "test/cmocka/output-starting-queries-link-support.c" + "test/cmocka/source-update-properties-link-support.c" ], "header_libraries": [ "OBS::source-init-context-rust-headers", @@ -17152,13 +17064,10 @@ "test/cmocka/source-push-query-link-stubs.c", "test/cmocka/source-state-getter-link-stubs.c", "test/cmocka/source-update-properties-link-support.c", - "test/cmocka/video-info-query-link-support.c", - "test/cmocka/core-state-link-support.c", "test/cmocka/weak-encoder-identity-link-stub.c", "test/cmocka/weak-object-identity-link-stub.c", "libobs/build/libobs.image-decode-adapter+.h.c", - "test/cmocka/source-icon-type-link-support.c", - "test/cmocka/output-starting-queries-link-support.c" + "test/cmocka/source-icon-type-link-support.c" ], "includes": [ "libobs", @@ -17280,13 +17189,10 @@ "test/cmocka/source-push-query-link-stubs.c", "test/cmocka/source-state-getter-link-stubs.c", "test/cmocka/source-update-properties-link-support.c", - "test/cmocka/video-info-query-link-support.c", - "test/cmocka/core-state-link-support.c", "test/cmocka/weak-encoder-identity-link-stub.c", "test/cmocka/weak-object-identity-link-stub.c", "libobs/build/libobs.image-decode-adapter+.h.c", - "test/cmocka/source-icon-type-link-support.c", - "test/cmocka/output-starting-queries-link-support.c" + "test/cmocka/source-icon-type-link-support.c" ], "includes": [ "libobs", @@ -17445,13 +17351,10 @@ "test/cmocka/source-push-query-link-stubs.c", "test/cmocka/source-state-getter-link-stubs.c", "test/cmocka/source-update-properties-link-support.c", - "test/cmocka/video-info-query-link-support.c", - "test/cmocka/core-state-link-support.c", "test/cmocka/weak-encoder-identity-link-stub.c", "test/cmocka/weak-object-identity-link-stub.c", "libobs/build/libobs.image-decode-adapter+.h.c", - "test/cmocka/source-icon-type-link-support.c", - "test/cmocka/output-starting-queries-link-support.c" + "test/cmocka/source-icon-type-link-support.c" ], "requires": "HAVE_LIBOBS_RUST_STATIC", "includes": [ @@ -17561,13 +17464,10 @@ "test/cmocka/source-push-query-link-stubs.c", "test/cmocka/source-state-getter-link-stubs.c", "test/cmocka/source-update-properties-link-support.c", - "test/cmocka/video-info-query-link-support.c", - "test/cmocka/core-state-link-support.c", "test/cmocka/weak-encoder-identity-link-stub.c", "test/cmocka/weak-object-identity-link-stub.c", "libobs/build/libobs.image-decode-adapter+.h.c", - "test/cmocka/source-icon-type-link-support.c", - "test/cmocka/output-starting-queries-link-support.c" + "test/cmocka/source-icon-type-link-support.c" ], "includes": [ "libobs", @@ -17660,13 +17560,10 @@ "test/cmocka/source-push-query-link-stubs.c", "test/cmocka/source-state-getter-link-stubs.c", "test/cmocka/source-update-properties-link-support.c", - "test/cmocka/video-info-query-link-support.c", - "test/cmocka/core-state-link-support.c", "test/cmocka/weak-encoder-identity-link-stub.c", "test/cmocka/weak-object-identity-link-stub.c", "libobs/build/libobs.image-decode-adapter+.h.c", - "test/cmocka/source-icon-type-link-support.c", - "test/cmocka/output-starting-queries-link-support.c" + "test/cmocka/source-icon-type-link-support.c" ], "requires": "HAVE_LIBOBS_RUST_STATIC", "includes": [ @@ -18039,13 +17936,10 @@ "test/cmocka/source-push-query-link-stubs.c", "test/cmocka/source-state-getter-link-stubs.c", "test/cmocka/source-update-properties-link-support.c", - "test/cmocka/video-info-query-link-support.c", - "test/cmocka/core-state-link-support.c", "test/cmocka/weak-encoder-identity-link-stub.c", "test/cmocka/weak-object-identity-link-stub.c", "libobs/build/libobs.image-decode-adapter+.h.c", - "test/cmocka/source-icon-type-link-support.c", - "test/cmocka/output-starting-queries-link-support.c" + "test/cmocka/source-icon-type-link-support.c" ], "includes": [ "libobs", @@ -18117,13 +18011,10 @@ "test/cmocka/source-push-query-link-stubs.c", "test/cmocka/source-state-getter-link-stubs.c", "test/cmocka/source-update-properties-link-support.c", - "test/cmocka/video-info-query-link-support.c", - "test/cmocka/core-state-link-support.c", "test/cmocka/weak-encoder-identity-link-stub.c", "test/cmocka/weak-object-identity-link-stub.c", "libobs/build/libobs.image-decode-adapter+.h.c", - "test/cmocka/source-icon-type-link-support.c", - "test/cmocka/output-starting-queries-link-support.c" + "test/cmocka/source-icon-type-link-support.c" ], "requires": "HAVE_LIBOBS_RUST_STATIC", "includes": [ @@ -18264,8 +18155,7 @@ "libobs/graphics/graphics-linear-srgb-fields.c.h", "libobs/obs-graphics-effect-file-fields.c.h", "test/cmocka/source-update-properties-link-support.c", - "libobs/build/libobs.image-decode-adapter+.h.c", - "test/cmocka/output-starting-queries-link-support.c" + "libobs/build/libobs.image-decode-adapter+.h.c" ], "requires": "HAVE_LIBOBS_RUST_STATIC", "includes": [ @@ -18842,8 +18732,7 @@ "test/cmocka/source-state-getter-link-stubs.c", "test/cmocka/source-update-properties-link-support.c", "libobs/build/libobs.image-decode-adapter+.h.c", - "test/cmocka/source-icon-type-link-support.c", - "test/cmocka/output-starting-queries-link-support.c" + "test/cmocka/source-icon-type-link-support.c" ], "includes": [ "libobs", @@ -18942,13 +18831,10 @@ "test/cmocka/source-push-query-link-stubs.c", "test/cmocka/source-state-getter-link-stubs.c", "test/cmocka/source-update-properties-link-support.c", - "test/cmocka/video-info-query-link-support.c", - "test/cmocka/core-state-link-support.c", "test/cmocka/weak-encoder-identity-link-stub.c", "test/cmocka/weak-object-identity-link-stub.c", "libobs/build/libobs.image-decode-adapter+.h.c", - "test/cmocka/source-icon-type-link-support.c", - "test/cmocka/output-starting-queries-link-support.c" + "test/cmocka/source-icon-type-link-support.c" ], "includes": [ "libobs", @@ -19061,13 +18947,10 @@ "test/cmocka/source-push-query-link-stubs.c", "test/cmocka/source-state-getter-link-stubs.c", "test/cmocka/source-update-properties-link-support.c", - "test/cmocka/video-info-query-link-support.c", - "test/cmocka/core-state-link-support.c", "test/cmocka/weak-encoder-identity-link-stub.c", "test/cmocka/weak-object-identity-link-stub.c", "libobs/build/libobs.image-decode-adapter+.h.c", - "test/cmocka/source-icon-type-link-support.c", - "test/cmocka/output-starting-queries-link-support.c" + "test/cmocka/source-icon-type-link-support.c" ], "requires": "HAVE_LIBOBS_RUST_STATIC", "includes": [ @@ -19143,8 +19026,7 @@ "test/cmocka/source-state-getter-link-stubs.c", "test/cmocka/source-update-properties-link-support.c", "libobs/build/libobs.image-decode-adapter+.h.c", - "test/cmocka/source-icon-type-link-support.c", - "test/cmocka/output-starting-queries-link-support.c" + "test/cmocka/source-icon-type-link-support.c" ], "includes": [ "libobs", @@ -19278,13 +19160,10 @@ "test/cmocka/source-push-query-link-stubs.c", "test/cmocka/source-state-getter-link-stubs.c", "test/cmocka/source-update-properties-link-support.c", - "test/cmocka/video-info-query-link-support.c", - "test/cmocka/core-state-link-support.c", "test/cmocka/weak-encoder-identity-link-stub.c", "test/cmocka/weak-object-identity-link-stub.c", "libobs/build/libobs.image-decode-adapter+.h.c", - "test/cmocka/source-icon-type-link-support.c", - "test/cmocka/output-starting-queries-link-support.c" + "test/cmocka/source-icon-type-link-support.c" ], "includes": [ "libobs", @@ -20228,8 +20107,7 @@ "test/cmocka/test_video_info_query.c", "test/cmocka/video-info-query-link-support.c", "libobs/util/base-variadic.c.h", - "test/cmocka/source-update-properties-link-support.c", - "test/cmocka/output-starting-queries-link-support.c" + "test/cmocka/source-update-properties-link-support.c" ], "libraries": [ "libobs_rust-static", @@ -20579,8 +20457,7 @@ "test_video_stop_requested_rust": { "sources": [ "test/cmocka/test_video_stop_requested.c", - "test/cmocka/source-update-properties-link-support.c", - "test/cmocka/output-starting-queries-link-support.c" + "test/cmocka/source-update-properties-link-support.c" ], "compile_options": [ { @@ -21427,8 +21304,7 @@ "test/cmocka/test_window_match_steps.c", "libobs/util/base-variadic.c.h", "libobs/build/libobs.image-decode-adapter+.h.c", - "test/cmocka/source-update-properties-link-support.c", - "test/cmocka/output-starting-queries-link-support.c" + "test/cmocka/source-update-properties-link-support.c" ], "includes": [ ".", @@ -21493,8 +21369,7 @@ "test/cmocka/module-name-lookup-link-stubs.c", "test/cmocka/object-validity-query-link-stubs.c", "test/cmocka/source-update-properties-link-support.c", - "libobs/build/libobs.image-decode-adapter+.h.c", - "test/cmocka/output-starting-queries-link-support.c" + "libobs/build/libobs.image-decode-adapter+.h.c" ], "watch_inputs": [ "Cargo.toml" diff --git a/test/cmocka/cf-preprocessor-link-support.c b/test/cmocka/cf-preprocessor-link-support.c new file mode 100644 index 0000000000..bb4f79df89 --- /dev/null +++ b/test/cmocka/cf-preprocessor-link-support.c @@ -0,0 +1,2 @@ +/* The unported C preprocessor, using the Rust tokenizer and allocator. */ +#include "libobs/util/cf-lexer.c.h" diff --git a/test/cmocka/context-runtime-link-support.c b/test/cmocka/context-runtime-link-support.c new file mode 100644 index 0000000000..b3773651eb --- /dev/null +++ b/test/cmocka/context-runtime-link-support.c @@ -0,0 +1,2 @@ +/* Demand-link the unchanged production C runtime implementation. */ +#include "libobs/obs-context-runtime.c.h" diff --git a/test/cmocka/core-initialized-link-support.c b/test/cmocka/core-initialized-link-support.c new file mode 100644 index 0000000000..32f766f300 --- /dev/null +++ b/test/cmocka/core-initialized-link-support.c @@ -0,0 +1,2 @@ +/* Demand-link the real core-state field adapter for standalone Rust consumers. */ +#include "libobs/obs-core-initialized-fields.c.h" diff --git a/test/cmocka/dstr-variadic-link-support.c b/test/cmocka/dstr-variadic-link-support.c new file mode 100644 index 0000000000..51ff5c43c2 --- /dev/null +++ b/test/cmocka/dstr-variadic-link-support.c @@ -0,0 +1,2 @@ +/* The real production provider, selected only on demand. */ +#include "libobs/util/dstr-variadic.c.h" diff --git a/test/cmocka/effect-parser-funcs-link-support.c b/test/cmocka/effect-parser-funcs-link-support.c new file mode 100644 index 0000000000..e06363c5b5 --- /dev/null +++ b/test/cmocka/effect-parser-funcs-link-support.c @@ -0,0 +1,2 @@ +/* The real production provider, selected only on demand. */ +#include "libobs/graphics/effect-parser-funcs.c.h" diff --git a/test/cmocka/encoder-weak-refs-link-support.c b/test/cmocka/encoder-weak-refs-link-support.c new file mode 100644 index 0000000000..eb84a36734 --- /dev/null +++ b/test/cmocka/encoder-weak-refs-link-support.c @@ -0,0 +1,2 @@ +/* Demand-link the unchanged production C runtime implementation. */ +#include "libobs/obs-encoder-weak-refs.c.h" diff --git a/test/cmocka/graphics-image-convert-link-support.c b/test/cmocka/graphics-image-convert-link-support.c new file mode 100644 index 0000000000..40ccf5bed6 --- /dev/null +++ b/test/cmocka/graphics-image-convert-link-support.c @@ -0,0 +1,3 @@ +/* The real FFmpeg frame conversion used by the production image loader. */ +#include "libobs/graphics/graphics-ffmpeg-orientation-adapter.c.h" +#include "libobs/graphics/graphics-texture-file-data-convert.c.h" diff --git a/test/cmocka/graphics-image-deps-link-support.c b/test/cmocka/graphics-image-deps-link-support.c new file mode 100644 index 0000000000..5c64ccb0dd --- /dev/null +++ b/test/cmocka/graphics-image-deps-link-support.c @@ -0,0 +1,2 @@ +/* The real production provider, selected only on demand. */ +#include "libobs/graphics/graphics-ffmpeg.c.h" diff --git a/test/cmocka/graphics-image-max-size-link-support.c b/test/cmocka/graphics-image-max-size-link-support.c new file mode 100644 index 0000000000..abdc53289f --- /dev/null +++ b/test/cmocka/graphics-image-max-size-link-support.c @@ -0,0 +1,2 @@ +/* The real production provider, selected only on demand. */ +#include "libobs/graphics/graphics-image-max-size.c.h" diff --git a/test/cmocka/graphics-preprocessor-link-support.c b/test/cmocka/graphics-preprocessor-link-support.c new file mode 100644 index 0000000000..4cea97d6c7 --- /dev/null +++ b/test/cmocka/graphics-preprocessor-link-support.c @@ -0,0 +1,9 @@ +/* A fixture-owned backend name takes precedence over the real runtime. */ +#include "libobs/build/libobs-graphics.pch.h" + +extern const char *obs_link_support_preprocessor_name(void); + +const char *gs_preprocessor_name(void) +{ + return obs_link_support_preprocessor_name(); +} diff --git a/test/cmocka/graphics-runtime-link-support.c b/test/cmocka/graphics-runtime-link-support.c new file mode 100644 index 0000000000..b211b71c4d --- /dev/null +++ b/test/cmocka/graphics-runtime-link-support.c @@ -0,0 +1,6 @@ +/* Retain the production graphics runtime only for consumers that request it. + * These files share the same private context and imports in the native group. */ +#define gs_preprocessor_name obs_link_support_preprocessor_name +#include "libobs/graphics/graphics-imports.c.h" +#include "libobs/graphics/graphics.c.h" +#include "libobs/graphics/viewport-entrypoints.c.h" diff --git a/test/cmocka/graphics-texture-file-data-link-support.c b/test/cmocka/graphics-texture-file-data-link-support.c new file mode 100644 index 0000000000..8f75eefca4 --- /dev/null +++ b/test/cmocka/graphics-texture-file-data-link-support.c @@ -0,0 +1,2 @@ +/* The real production provider, selected only on demand. */ +#include "libobs/graphics/graphics-texture-file-data.c.h" diff --git a/test/cmocka/hosts/posix/graphics-image-fallback-link-support.c b/test/cmocka/hosts/posix/graphics-image-fallback-link-support.c new file mode 100644 index 0000000000..ec57c82994 --- /dev/null +++ b/test/cmocka/hosts/posix/graphics-image-fallback-link-support.c @@ -0,0 +1,2 @@ +/* The production POSIX fallback, selected by the target facts. */ +#include "libobs/graphics/graphics-ffmpeg-host-posix.c.h" diff --git a/test/cmocka/hosts/windows/graphics-image-fallback-link-support.c b/test/cmocka/hosts/windows/graphics-image-fallback-link-support.c new file mode 100644 index 0000000000..473cd31a2c --- /dev/null +++ b/test/cmocka/hosts/windows/graphics-image-fallback-link-support.c @@ -0,0 +1,2 @@ +/* The production Windows WIC fallback, selected by the target facts. */ +#include "libobs/graphics/graphics-ffmpeg-host-windows.c.h" diff --git a/test/cmocka/hotkey-fields-link-support.c b/test/cmocka/hotkey-fields-link-support.c new file mode 100644 index 0000000000..86fe8f30bb --- /dev/null +++ b/test/cmocka/hotkey-fields-link-support.c @@ -0,0 +1,3 @@ +/* Real private adapters, retained only when a Rust archive member needs them. */ +#include "libobs/obs-hotkey-identity-fields.c.h" +#include "libobs/obs-hotkey-object-fields.c.h" diff --git a/test/cmocka/native-test-graph.cmake b/test/cmocka/native-test-graph.cmake index 11055cba32..3bb953de2a 100644 --- a/test/cmocka/native-test-graph.cmake +++ b/test/cmocka/native-test-graph.cmake @@ -947,4 +947,8 @@ function(obs_native_test_graph path root) endif() endforeach() endif() + if(EXISTS "${root}/test/cmocka/build/rust-static-support.json") + include("${root}/test/cmocka/rust-static-link-support.cmake") + obs_rust_static_fixture_support("${root}") + endif() endfunction() diff --git a/test/cmocka/profiler-variadic-link-support.c b/test/cmocka/profiler-variadic-link-support.c new file mode 100644 index 0000000000..3e071c8613 --- /dev/null +++ b/test/cmocka/profiler-variadic-link-support.c @@ -0,0 +1,2 @@ +/* Demand-link the unchanged production C runtime implementation. */ +#include "libobs/util/profiler-variadic.c.h" diff --git a/test/cmocka/rust-static-link-support.cmake b/test/cmocka/rust-static-link-support.cmake new file mode 100644 index 0000000000..29ca67af65 --- /dev/null +++ b/test/cmocka/rust-static-link-support.cmake @@ -0,0 +1,334 @@ +# One selection rule for standalone consumers, including interface dependencies. +include_guard(GLOBAL) + +function(_obs_uses_rust_static target visited output) + if(target STREQUAL "libobs_rust-static") + set(${output} 1 PARENT_SCOPE) + return() + endif() + if(NOT TARGET "${target}" OR target IN_LIST visited) + set(${output} 0 PARENT_SCOPE) + return() + endif() + list(APPEND visited "${target}") + get_target_property(type "${target}" TYPE) + # A shared library's implementation is not a standalone Rust consumer. + if(type MATCHES "^(SHARED|MODULE)_LIBRARY$") + set(${output} 0 PARENT_SCOPE) + return() + endif() + get_target_property(links "${target}" INTERFACE_LINK_LIBRARIES) + get_target_property(private_links "${target}" LINK_LIBRARIES) + set(links "${links};${private_links}") + string(REPLACE ";" "$" condition_links "${links}") + string(REGEX MATCHALL "[A-Za-z0-9_.+-]+(::[A-Za-z0-9_.+-]+)*" dependencies "${links}") + list(REMOVE_DUPLICATES dependencies) + set(conditions) + foreach(dependency IN LISTS dependencies) + _obs_uses_rust_static("${dependency}" "${visited}" uses_rust) + if(NOT uses_rust STREQUAL "0") + if(dependency IN_LIST links) + if(uses_rust STREQUAL "1") + set(${output} 1 PARENT_SCOPE) + return() + endif() + list(APPEND conditions "${uses_rust}") + else() + # Evaluate conditional edges with their original owner and links, not + # the subsequently rewritten consumer property (which would recurse). + list( + APPEND conditions + "$>,${uses_rust}>" + ) + endif() + endif() + endforeach() + if(conditions) + list(JOIN conditions "," condition) + set(${output} "$" PARENT_SCOPE) + else() + set(${output} 0 PARENT_SCOPE) + endif() +endfunction() + +function(_obs_demand_rust_static_support) + get_directory_property(targets BUILDSYSTEM_TARGETS) + foreach(target IN LISTS targets) + get_target_property(type "${target}" TYPE) + if(NOT type STREQUAL "EXECUTABLE") + continue() + endif() + _obs_uses_rust_static("${target}" "" uses_rust) + if(uses_rust STREQUAL "0") + continue() + endif() + get_target_property(sources "${target}" SOURCES) + set(adapters) + set(fixture_sources) + foreach(source IN LISTS sources) + if(source MATCHES "-link-(support|stubs?)\\.c$" OR source MATCHES "^\\$]+>$") + list(APPEND adapters "${source}") + if(NOT uses_rust STREQUAL "1") + list(APPEND fixture_sources "$<$:${source}>") + endif() + else() + list(APPEND fixture_sources "${source}") + endif() + endforeach() + if(NOT adapters) + continue() + endif() + # Preserve the fixture's definitions, source properties and header order. + # Each adapter remains an independent member; unrelated runtime callbacks + # must not select Rust objects or DLL imports in an isolated fixture. + set(local_support "${target}-rust-static-support") + add_library("${local_support}" STATIC EXCLUDE_FROM_ALL ${adapters}) + set_target_properties("${local_support}" PROPERTIES UNITY_BUILD OFF) + foreach( + property + IN + ITEMS + COMPILE_DEFINITIONS + COMPILE_OPTIONS + COMPILE_FLAGS + COMPILE_FEATURES + INCLUDE_DIRECTORIES + SYSTEM_INCLUDE_DIRECTORIES + C_STANDARD + C_STANDARD_REQUIRED + C_EXTENSIONS + MSVC_RUNTIME_LIBRARY + MSVC_DEBUG_INFORMATION_FORMAT + ) + get_target_property(value "${target}" "${property}") + if(NOT value MATCHES "-NOTFOUND$") + set_property(TARGET "${local_support}" PROPERTY "${property}" "${value}") + endif() + endforeach() + get_target_property(links "${target}" LINK_LIBRARIES) + target_link_libraries("${local_support}" PRIVATE "$") + # Fixture-owned recording adapters precede the generic fallback archive. + if(uses_rust STREQUAL "1") + list(INSERT links 1 "${local_support}") + else() + list(INSERT links 1 "$<${uses_rust}:${local_support}>") + endif() + set_property(TARGET "${target}" PROPERTY LINK_LIBRARIES "${links}") + set_property(TARGET "${target}" PROPERTY SOURCES "${fixture_sources}") + endforeach() +endfunction() + +function(obs_rust_static_consumers support native_owner) + if(MSVC AND TARGET OBS::libobs AND NOT TARGET obs-rust-static-headers) + # A standalone Rust executable must use one allocator/logger implementation. + # Keep the core's header requirements without its competing DLL imports. + add_library(obs-rust-static-headers INTERFACE) + foreach( + property + IN + ITEMS INCLUDE_DIRECTORIES SYSTEM_INCLUDE_DIRECTORIES COMPILE_DEFINITIONS COMPILE_OPTIONS COMPILE_FEATURES + ) + get_target_property(value OBS::libobs INTERFACE_${property}) + if(value) + set_property(TARGET obs-rust-static-headers PROPERTY INTERFACE_${property} "${value}") + endif() + endforeach() + endif() + # Real C adapters call back into Rust. Retain that return edge so ELF archive + # selection searches Rust again after extracting a lazy support member. + target_link_libraries("${support}" PRIVATE libobs_rust-static) + set(support_link "${support}") + if(NOT MSVC AND (CMAKE_C_LINK_GROUP_USING_RESCAN_SUPPORTED OR CMAKE_LINK_GROUP_USING_RESCAN_SUPPORTED)) + # Resolve the complete Rust/C callback component, including newly extracted + # members that introduce another callback in the opposite direction. + # Keep the direct support edge visible to existing graph assertions. CMake + # replaces its non-group occurrence with this same group during generation. + set(support_link "${support};$") + endif() + if(TARGET "${native_owner}") + # Inherit the owner's full native closure, including host-selected libraries + # and their transitive interfaces. Never copy GObject/Jansson lists per test. + target_link_libraries("${support}" PRIVATE "${native_owner}") + endif() + get_directory_property(targets BUILDSYSTEM_TARGETS) + foreach(target IN LISTS targets) + get_target_property(type "${target}" TYPE) + if(NOT type STREQUAL "EXECUTABLE") + continue() + endif() + _obs_uses_rust_static("${target}" "" uses_rust) + if(NOT uses_rust STREQUAL "0") + get_target_property(links "${target}" LINK_LIBRARIES) + if(MSVC AND TARGET obs-rust-static-headers) + set(provider_links) + foreach(link IN LISTS links) + if(link MATCHES "^(OBS::libobs|libobs)$") + if(uses_rust STREQUAL "1") + list(APPEND provider_links obs-rust-static-headers) + else() + list(APPEND provider_links "$") + endif() + else() + list(APPEND provider_links "${link}") + endif() + endforeach() + set(links "${provider_links}") + endif() + # Resolve static allocators/parser/logging before OBS's DLL import members. + # An indirect consumer also needs this explicit first provider. + if(uses_rust STREQUAL "1") + if(MSVC) + list(REMOVE_ITEM links libobs_rust-static) + set(links "libobs_rust-static;${support};${links}") + elseif(NOT "libobs_rust-static" IN_LIST links) + # Preserve intentional ELF/Darwin DSO selection. Make an indirect + # Rust edge explicit before support so the archive is searched first. + list(APPEND links libobs_rust-static) + endif() + if(MSVC) + set_property(TARGET "${target}" PROPERTY LINK_LIBRARIES "${links}") + else() + set_property(TARGET "${target}" PROPERTY LINK_LIBRARIES "${links};${support_link}") + endif() + else() + if(MSVC) + set(links "$<${uses_rust}:libobs_rust-static>;$<${uses_rust}:${support}>;${links}") + else() + set(links "${links};$<${uses_rust}:libobs_rust-static>") + endif() + if(MSVC) + set_property(TARGET "${target}" PROPERTY LINK_LIBRARIES "${links}") + else() + set_property(TARGET "${target}" PROPERTY LINK_LIBRARIES "${links};$<${uses_rust}:${support_link}>") + endif() + endif() + endif() + endforeach() + if(MSVC) + # Run after every legacy deferred fragment has supplied its real adapters. + cmake_language(DEFER CALL _obs_demand_rust_static_support) + endif() +endfunction() + +# Shared by the complete cmocka project and independent graph fixture projects. +function(obs_add_rust_static_support root native_owner) + if(NOT DEFINED OS_WINDOWS) + set(OS_WINDOWS "${WIN32}") + endif() + if(NOT TARGET video_info_query_link_support) + file(READ "${root}/test/cmocka/build/rust-static-support.json" manifest) + string(JSON count LENGTH "${manifest}" sources) + math(EXPR last "${count} - 1") + set(sources) + foreach(index RANGE ${last}) + string(JSON source GET "${manifest}" sources ${index}) + list(APPEND sources "${root}/${source}") + endforeach() + string(JSON platforms ERROR_VARIABLE missing LENGTH "${manifest}" platform_sources) + if(NOT missing AND platforms GREATER 0) + math(EXPR platform_last "${platforms} - 1") + foreach(index RANGE ${platform_last}) + string(JSON fact MEMBER "${manifest}" platform_sources ${index}) + if(${fact}) + string(JSON count LENGTH "${manifest}" platform_sources "${fact}") + math(EXPR last "${count} - 1") + foreach(member RANGE ${last}) + string(JSON source GET "${manifest}" platform_sources "${fact}" ${member}) + list(APPEND sources "${root}/${source}") + endforeach() + endif() + endforeach() + endif() + set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS "${root}/test/cmocka/build/rust-static-support.json") + add_library(video_info_query_link_support STATIC ${sources}) + target_include_directories( + video_info_query_link_support + PRIVATE "${root}" "${root}/libobs" "${CMAKE_BINARY_DIR}/config" + ) + if(TARGET OBS::libobs) + target_include_directories( + video_info_query_link_support + PRIVATE "$" + ) + endif() + target_link_libraries( + video_info_query_link_support + PRIVATE OBS::caption Uthash::Uthash $<$:OBS::w32-pthreads> + ) + endif() + obs_rust_static_consumers(video_info_query_link_support "${native_owner}") +endfunction() + +function(obs_rust_static_fixture_support root) + # Real archive replays need the same owners as the full project. Configuration + # models with an INTERFACE placeholder keep their dependency-free contract. + if( + NOT CMAKE_C_COMPILER_LOADED + OR NOT TARGET libobs_rust-static + OR TARGET OBS::libobs-native-dependencies + OR OBS_CROSS_TIER2 + ) + return() + endif() + get_target_property(type libobs_rust-static TYPE) + get_target_property(archive libobs_rust-static IMPORTED_LOCATION) + if(NOT type STREQUAL "STATIC_LIBRARY" OR NOT EXISTS "${archive}") + return() + endif() + get_directory_property(targets BUILDSYSTEM_TARGETS) + set(has_consumer FALSE) + foreach(target IN LISTS targets) + get_target_property(type "${target}" TYPE) + if(type STREQUAL "EXECUTABLE") + _obs_uses_rust_static("${target}" "" uses_rust) + if(NOT uses_rust STREQUAL "0") + set(has_consumer TRUE) + endif() + endif() + endforeach() + if(NOT has_consumer) + return() + endif() + list(APPEND CMAKE_MODULE_PATH "${root}/cmake/finders") + if(NOT TARGET OBS::caption) + add_subdirectory("${root}/deps/libcaption" "${CMAKE_BINARY_DIR}/rust-static-caption") + endif() + find_package(Uthash REQUIRED) + find_package(SIMDe REQUIRED) + find_package(jansson REQUIRED) + find_package(ZLIB REQUIRED) + find_package(Threads REQUIRED) + find_package( + FFmpeg + REQUIRED + COMPONENTS avcodec avformat avutil swscale swresample + ) + add_library(obs-rust-static-fixture-native INTERFACE) + add_library(OBS::libobs-native-dependencies ALIAS obs-rust-static-fixture-native) + target_link_libraries( + obs-rust-static-fixture-native + INTERFACE + OBS::caption + Uthash::Uthash + SIMDe::SIMDe + jansson::jansson + ZLIB::ZLIB + Threads::Threads + FFmpeg::avcodec + FFmpeg::avformat + FFmpeg::avutil + FFmpeg::swscale + FFmpeg::swresample + ${CMAKE_DL_LIBS} + ) + if(CMAKE_SYSTEM_NAME STREQUAL "Linux") + find_package(LibUUID REQUIRED) + find_package(Gio QUIET) + target_link_libraries(obs-rust-static-fixture-native INTERFACE LibUUID::LibUUID m rt util) + if(TARGET gio::gio) + target_link_libraries(obs-rust-static-fixture-native INTERFACE gio::gio) + endif() + endif() + target_link_libraries(libobs_rust-static INTERFACE OBS::libobs-native-dependencies) + obs_add_rust_static_support("${root}" OBS::libobs-native-dependencies) +endfunction() diff --git a/test/cmocka/service-runtime-link-support.c b/test/cmocka/service-runtime-link-support.c new file mode 100644 index 0000000000..6665a485a0 --- /dev/null +++ b/test/cmocka/service-runtime-link-support.c @@ -0,0 +1,2 @@ +/* The production C lifecycle steps called by the Rust service implementation. */ +#include "libobs/obs-service.c.h" diff --git a/test/cmocka/service-state-link-support.c b/test/cmocka/service-state-link-support.c new file mode 100644 index 0000000000..0cc05238a7 --- /dev/null +++ b/test/cmocka/service-state-link-support.c @@ -0,0 +1,2 @@ +/* Real private layouts for Rust service state and output ownership. */ +#include "libobs/obs-service-state-adapter.c.h" diff --git a/test/cmocka/source-weak-control-link-support.c b/test/cmocka/source-weak-control-link-support.c new file mode 100644 index 0000000000..652d487042 --- /dev/null +++ b/test/cmocka/source-weak-control-link-support.c @@ -0,0 +1,2 @@ +/* The production weak-control accessor for standalone Rust consumers. */ +#include "libobs/obs-source-get-weak-fields.c.h" diff --git a/test/cmocka/source-weak-refs-link-support.c b/test/cmocka/source-weak-refs-link-support.c new file mode 100644 index 0000000000..22a7e070ed --- /dev/null +++ b/test/cmocka/source-weak-refs-link-support.c @@ -0,0 +1,2 @@ +/* Demand-link the unchanged production C runtime implementation. */ +#include "libobs/obs-source-weak-refs.c.h" diff --git a/test/cmocka/tests.d/output_starting_queries_link_support.cmake b/test/cmocka/tests.d/output_starting_queries_link_support.cmake deleted file mode 100644 index 34446a00e0..0000000000 --- a/test/cmocka/tests.d/output_starting_queries_link_support.cmake +++ /dev/null @@ -1,21 +0,0 @@ -# A Rust archive member can pull this query into unrelated source-step tests. -# Link the real adapter there as well as in production libobs. -function(_output_starting_queries_link_support) - get_directory_property(_targets BUILDSYSTEM_TARGETS) - foreach(_target IN LISTS _targets) - get_target_property(_links ${_target} LINK_LIBRARIES) - if("libobs_rust-static" IN_LIST _links AND NOT _target STREQUAL "test_output_starting_queries_rust") - get_target_property(_sources ${_target} SOURCES) - set(_adapter "${CMAKE_CURRENT_SOURCE_DIR}/output-starting-queries-link-support.c") - if(NOT _adapter IN_LIST _sources) - target_sources(${_target} PRIVATE "${_adapter}") - target_include_directories(${_target} PRIVATE "${CMAKE_SOURCE_DIR}" "${CMAKE_SOURCE_DIR}/libobs") - target_link_libraries( - ${_target} - PRIVATE OBS::caption Uthash::Uthash $<$:OBS::w32-pthreads> - ) - endif() - endif() - endforeach() -endfunction() -cmake_language(DEFER CALL _output_starting_queries_link_support) diff --git a/test/cmocka/tests.d/video_info_query_link_support.cmake b/test/cmocka/tests.d/video_info_query_link_support.cmake index 7e72d5f80c..ccb859466f 100644 --- a/test/cmocka/tests.d/video_info_query_link_support.cmake +++ b/test/cmocka/tests.d/video_info_query_link_support.cmake @@ -1,31 +1,6 @@ -# Keep global-dependent adapters in an archive: fixture-owned cores take precedence. -# Shared libobs hides these private adapters; every Rust-static consumer needs -# the support archive, including consumers that also link OBS::libobs. +# Real private adapters in separate lazy members, shared by every Rust consumer. +include("${CMAKE_CURRENT_LIST_DIR}/../rust-static-link-support.cmake") function(_video_info_query_link_support) - add_library( - video_info_query_link_support - STATIC - "${CMAKE_CURRENT_SOURCE_DIR}/video-info-query-link-support.c" - "${CMAKE_CURRENT_SOURCE_DIR}/core-state-link-support.c" - "${CMAKE_CURRENT_SOURCE_DIR}/encoder-get-name-link-support.c" - "${CMAKE_CURRENT_SOURCE_DIR}/output-interleave-name-link-support.c" - "${CMAKE_CURRENT_SOURCE_DIR}/encoder-video-tex-active-fields-link-support.c" - "${CMAKE_CURRENT_SOURCE_DIR}/encoder-video-tex-active-mix-link-support.c" - ) - target_include_directories( - video_info_query_link_support - PRIVATE "${CMAKE_SOURCE_DIR}" "${CMAKE_SOURCE_DIR}/libobs" "${CMAKE_BINARY_DIR}/config" - ) - target_link_libraries( - video_info_query_link_support - PRIVATE OBS::caption Uthash::Uthash $<$:OBS::w32-pthreads> - ) - get_directory_property(_targets BUILDSYSTEM_TARGETS) - foreach(_target IN LISTS _targets) - get_target_property(_links ${_target} LINK_LIBRARIES) - if("libobs_rust-static" IN_LIST _links) - target_link_libraries(${_target} PRIVATE video_info_query_link_support) - endif() - endforeach() + obs_add_rust_static_support("${CMAKE_SOURCE_DIR}" OBS::libobs-native-dependencies) endfunction() cmake_language(DEFER CALL _video_info_query_link_support) diff --git a/test/cmocka/texture-creators-fields-link-support.c b/test/cmocka/texture-creators-fields-link-support.c new file mode 100644 index 0000000000..d69a718405 --- /dev/null +++ b/test/cmocka/texture-creators-fields-link-support.c @@ -0,0 +1,2 @@ +/* The real production provider, selected only on demand. */ +#include "libobs/graphics/texture-creators-fields.c.h"