diff --git a/.github/workflows/build-project.yaml b/.github/workflows/build-project.yaml index 08932105d4..e2301bdc87 100644 --- a/.github/workflows/build-project.yaml +++ b/.github/workflows/build-project.yaml @@ -154,6 +154,7 @@ jobs: cross_targets: ${{ steps.native.outputs.cross_targets }} cross_lint: ${{ steps.native.outputs.cross_lint }} windows_link: ${{ steps.native.outputs.windows_link }} + cmocka_link: ${{ steps.native.outputs.cmocka_link }} swift: ${{ steps.swift.outputs.swift }} data: ${{ steps.swift.outputs.data }} steps: @@ -384,6 +385,7 @@ jobs: echo "docs_only=${docs_only:-false}" echo "cross_targets=${cross_targets:-}" echo "windows_link=${windows_link:-true}" + echo "cmocka_link=${cmocka_link:-true}" echo "platform_os=[$(IFS=,; echo "${os[*]}")]" } >> "${GITHUB_OUTPUT}" echo "full=${full} core=${core} macos=${macos} windows=${windows} qt=${qt} tier2=${tier2}" @@ -2178,15 +2180,15 @@ jobs: # lanes, so COFF-only link defects reached master (`undefined symbol: # obs_encoder_get_caps`, merge_group 42390201886 green, push 42393067345 # red). This is only the cross lane's link step for Windows x64: no clippy, - # Dylint or macOS, nothing executed (ci/windows_link_check.py). + # Dylint; selected Tier 2 links also cover Darwin, nothing executed. rust-windows-link: timeout-minutes: 30 name: Windows Link Check 🔗 (x86_64-pc-windows-msvc) - runs-on: ubuntu-26.04 + runs-on: ${{ inputs.mq-heavy-labels != '' && fromJSON(inputs.mq-heavy-labels) || 'ubuntu-26.04' }} needs: [check-event, ci-mode] - # Every fallback non-docs PR runs the link check without proof/attestation skips. - # Complete member PRs defer it; every selected queue group links again. - if: ${{ (github.event_name != 'pull_request' || needs.ci-mode.outputs.fast_path != 'true') && !inputs.flatpak-measurement-only && !inputs.native-cache-measurement-only && needs.check-event.outputs.deferred == 'true' && needs.check-event.outputs.docs_only != 'true' && needs.check-event.outputs.windows_link == 'true' }} + # Every fallback non-docs PR links categories. Tier 2 selections always run + # before the queue: existing client proofs do not attest these CMake links. + if: ${{ (github.event_name != 'pull_request' || needs.ci-mode.outputs.fast_path != 'true' || needs.check-event.outputs.cmocka_link == 'true') && !inputs.flatpak-measurement-only && !inputs.native-cache-measurement-only && needs.check-event.outputs.deferred == 'true' && needs.check-event.outputs.docs_only != 'true' && needs.check-event.outputs.windows_link == 'true' }} defaults: run: shell: bash @@ -2223,7 +2225,12 @@ jobs: save-cache: ${{ github.ref == 'refs/heads/master' }} cache-suffix: ${{ github.event.pull_request.number && format('pr-{0}', github.event.pull_request.number) || '' }} + - name: Set Up Native Link Tools + run: sudo apt-get update -qq && sudo apt-get install -y cmake ninja-build pkg-config + - name: Link Windows Test Binaries 🔗 + env: + OBS_CMOCKA_LINK: ${{ needs.check-event.outputs.cmocka_link }} run: uv run --no-project ci/windows_link_check.py rust-cross-lint-release: diff --git a/CMakeLists.txt b/CMakeLists.txt index ac54a22ed8..851efc3e55 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,12 @@ cmake_minimum_required(VERSION 3.28...3.30) +# Linux-hosted link-only Tier 2 uses the repository root so unchanged test +# registrations retain their CMAKE_SOURCE_DIR paths. +if(OBS_CROSS_TIER2) + include("${CMAKE_CURRENT_SOURCE_DIR}/cmake/cross/CMakeLists.txt") + return() +endif() + include("${CMAKE_CURRENT_SOURCE_DIR}/cmake/common/bootstrap.cmake" NO_POLICY_SCOPE) project(obs-studio VERSION ${OBS_VERSION_CANONICAL}) diff --git a/ci/ci_scope.py b/ci/ci_scope.py index 4d49ca86e1..9ac3121a15 100644 --- a/ci/ci_scope.py +++ b/ci/ci_scope.py @@ -161,12 +161,19 @@ class Scope: cross_targets: str = "" cross_lint: bool = False windows_link: bool = False + cmocka_link: bool = False # The path -> lane table (#992). Adding a module is adding a row. Globs use # `**` for any depth and `*` within one path segment. Rust crates linked into # libobs are added to tier2 at run time (linked_crates). LANES: dict[str, tuple[str, ...]] = { + "cmocka_link": ( + "libobs/**", "rust/libobs-rust/**", "rust/obs-build/**", "test/cmocka/**", "deps/**", + "cmake/cross/**", "cmake/common/soldr.cmake", "ci/cmocka_link_check.py", + "ci/windows_link_check.py", "ci/ci_scope.py", ".github/workflows/build-project.yaml", + "Cargo.toml", "Cargo.lock", "rust-toolchain.toml", "CMakeLists.txt", + ), "tier2": ( "libobs/**", "test/cmocka/**", @@ -598,6 +605,7 @@ def scope( docs_only, cross_targets(files, read), windows_link=bool(files) and not docs_only, + cmocka_link=not docs_only and any(lane_hit("cmocka_link", p, linked) for p in files), # Exercise the cross lane when its own implementation/orchestration changes. cross_lint=(event == "merge_group" and bool(files) and not docs_only) or bool(set(files) & { "ci/local_gate.py", "ci/test_local_gate.py", "ci/ci_scope.py", @@ -719,7 +727,7 @@ def main() -> int: result = Scope( core=True, macos=True, windows=True, qt=True, tier2=True, full=True, qt_sdk=True, cross_targets=",".join(sorted(CROSS_ALIASES.values())), - cross_lint=True, windows_link=True, + cross_lint=True, windows_link=True, cmocka_link=True, ) lines = [f"{k}={str(v).lower()}" for k, v in vars(result).items()] print("\n".join(lines)) diff --git a/ci/cmocka_link_check.py b/ci/cmocka_link_check.py new file mode 100644 index 0000000000..043b8b9e97 --- /dev/null +++ b/ci/cmocka_link_check.py @@ -0,0 +1,128 @@ +#!/usr/bin/env -S uv run --script +# /// script +# requires-python = ">=3.14" +# /// +"""Link the configured Tier 2 Rust fixtures and hybrid libobs on Linux. + +No target program is executed. Reuses cmake/cross's soldr SDK/dependency setup +and the unchanged test/cmocka graph, including its deferred link support. +""" +from __future__ import annotations + +import argparse +import json +import os +import shlex +import subprocess +import time +from pathlib import Path + +import local_gate + +ROOT = Path(__file__).resolve().parent.parent +TRIPLES = {"win-x64": "x86_64-pc-windows-msvc", "mac-arm64": "aarch64-apple-darwin"} + + +def discover_targets(reply: Path) -> list[str]: + 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")) + 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] + + +def windows_toolchain(work: Path, target: str) -> Path: + """Use soldr's SDK drivers in clang-cl mode so CMake evaluates MSVC guards.""" + def query(option: str) -> str: + return subprocess.run(["soldr", "cc", "--target", target, option], cwd=ROOT, + capture_output=True, text=True, check=True).stdout.strip() + + ar, rc, sdk = (query(flag) for flag in ("--print-ar", "--print-rc", "--print-sysroot")) + llvm = Path(ar).resolve().parent + compiler = llvm / "clang-cl" + if not compiler.is_file(): + raise FileNotFoundError(f"soldr LLVM is missing {compiler}") + tools = work / "soldr-tools" + # soldr's GNU driver injects -isystem, which clang-cl does not accept. + # Use the clang-cl sibling from the same managed LLVM and its xwin SDK. + recipe = [str(compiler), f"--target={target}"] + for directory in ("crt/include", "sdk/include/ucrt", "sdk/include/um", "sdk/include/shared", + "sdk/include/winrt", "sdk/include/cppwinrt"): + recipe.extend(["-imsvc", str(Path(sdk) / directory)]) + for name in ("clang-cl", "clang-cl++"): + path = tools / name + path.write_text(f'#!/bin/sh\nexec {shlex.join(recipe)} "$@"\n') + path.chmod(0o755) + settings = {"CMAKE_SYSTEM_NAME": "Windows", "CMAKE_SYSTEM_PROCESSOR": "AMD64", + "CMAKE_TRY_COMPILE_CONFIGURATION": "Release", "CMAKE_MSVC_RUNTIME_LIBRARY": "MultiThreadedDLL", + "CMAKE_C_COMPILER": str(tools / "clang-cl"), "CMAKE_CXX_COMPILER": str(tools / "clang-cl++"), + "CMAKE_AR": ar, "CMAKE_LINKER": str(llvm / "lld-link"), "CMAKE_RC_COMPILER": rc, + "CMAKE_MT": str(llvm / "llvm-mt"), "CMAKE_TRY_COMPILE_TARGET_TYPE": "STATIC_LIBRARY", + "CMAKE_FIND_ROOT_PATH": sdk, "CMAKE_FIND_ROOT_PATH_MODE_PROGRAM": "NEVER"} + # CMake's MSVC link rule invokes lld-link directly, bypassing the compiler + # driver's SDK config. Retain exactly that SDK's real import libraries. + search = " ".join(f'/libpath:"{sdk}/{directory}/x86_64"' + for directory in ("crt/lib", "sdk/lib/um", "sdk/lib/ucrt")) + for kind in ("EXE", "SHARED", "MODULE"): + settings[f"CMAKE_{kind}_LINKER_FLAGS"] = search + path = work / "windows-msvc.cmake" + path.write_text("".join(f'set({key} [==[{value}]==] CACHE STRING "soldr Tier 2 toolchain" FORCE)\n' + for key, value in settings.items())) + return path + + +def link(alias: str, work: Path, jobs: int) -> None: + started = time.monotonic() + target = TRIPLES[alias] + local_gate.add_target(target) + # Invoke Cargo even on a warm tree: the cross project's legacy custom + # command only depends on manifests, which cannot detect a Rust source edit. + local_gate.soldr_cargo(["build", "--release", "--locked", "--target", target, "-p", "libobs-rust"]) + work.mkdir(parents=True, exist_ok=True) + wrappers = work / "soldr-tools" + wrappers.mkdir(exist_ok=True) + for name in ("cargo", "rustc"): + wrapper = wrappers / name + wrapper.write_text(f'#!/bin/sh\nexec soldr {name} "$@"\n') + wrapper.chmod(0o755) + toolchain_args = [f"-DCMAKE_TOOLCHAIN_FILE={windows_toolchain(work, target)}"] if alias == "win-x64" else [] + query = work / ".cmake/api/v1/query/codemodel-v2" + query.parent.mkdir(parents=True, exist_ok=True) + query.touch() + archiver = subprocess.run(["soldr", "cc", "--target", target, "--print-ar"], + cwd=ROOT, capture_output=True, text=True, check=True).stdout.strip() + env = local_gate.soldr_env({"OBS_CROSS_TARGET": alias, "SOLDR_PORCELAIN": "0", + f"AR_{target.replace('-', '_')}": archiver}) + 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'}", + f"-DRust_COMPILER={wrappers / 'rustc'}", f"-DRust_CARGO_TARGET={target}", + "-DOBS_TEST_SANITIZE_PER_TARGET=OFF", *toolchain_args], cwd=ROOT, env=env, check=True) + targets = discover_targets(work / ".cmake/api/v1/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", flush=True) + subprocess.run(["cmake", "--build", str(work), "--parallel", str(jobs), "--target", *targets, + "--", "-k", "0"], cwd=ROOT, env=env, check=True) + print(f"Tier 2 {alias}: linked in {time.monotonic() - started:.2f}s", flush=True) + + +def main() -> int: + parser = argparse.ArgumentParser(description=__doc__) + parser.add_argument("--alias", choices=TRIPLES, default="win-x64") + parser.add_argument("--build", type=Path) + parser.add_argument("--jobs", type=int, default=min(4, os.cpu_count() or 1)) + args = parser.parse_args() + if args.jobs < 1: + parser.error("--jobs must be positive") + link(args.alias, (args.build or ROOT / f"build_cmocka_link_{args.alias}").resolve(), args.jobs) + return 0 + + +if __name__ == "__main__": + raise SystemExit(main()) diff --git a/ci/gate_jobs.py b/ci/gate_jobs.py index 5aea547ca2..2befd12959 100644 --- a/ci/gate_jobs.py +++ b/ci/gate_jobs.py @@ -196,6 +196,10 @@ def pr_expected_jobs(selected: Scope, files: list[str], plan: dict) -> set[str]: and all(gates.get(gate) == "valid" for gate in plan["required_client_gates"])) if complete: expected -= heavy + # Existing client proofs cover category links, not the cmocka CMake + # pass. The base-owned selector must witness that pass even on fast PRs. + if getattr(selected, "cmocka_link", False): + expected.add("Build 🧱 / Windows Link Check 🔗 (x86_64-pc-windows-msvc)") for key, job_names in names.items(): status = plan["jobs"].get(key, {}) needed = status.get("required_gates", []) diff --git a/ci/test_ci_scope.py b/ci/test_ci_scope.py index 91e5016ece..06ed453cef 100644 --- a/ci/test_ci_scope.py +++ b/ci/test_ci_scope.py @@ -315,7 +315,7 @@ def test_queue_runner_selection_preserves_hosted_fallbacks(self): heavy = { "rust-cross-lint", "rust-cross-lint-release", "rust-tests-macos-build", - "rust-linux-tier2-build", "rust-linux-tier2", + "rust-linux-tier2-build", "rust-linux-tier2", "rust-windows-link", } light = { "ci.yml": { @@ -324,7 +324,7 @@ def test_queue_runner_selection_preserves_hosted_fallbacks(self): }, "build-project.yaml": dict.fromkeys(( "check-event", "ci-mode", "rust-tests-linux", "cross-compile", - "rust-cross-proof", "rust-windows-link", "linux-qt-frontend", + "rust-cross-proof", "linux-qt-frontend", ), "ubuntu-26.04"), "check-format.yaml": {"checks": "ubuntu-latest"}, } diff --git a/ci/test_cmocka_link_check.py b/ci/test_cmocka_link_check.py new file mode 100644 index 0000000000..980f9a5f93 --- /dev/null +++ b/ci/test_cmocka_link_check.py @@ -0,0 +1,97 @@ +#!/usr/bin/env -S uv run --script +"""Pre-queue Tier 2 cross-link selection and configured target discovery.""" +from __future__ import annotations + +import json +import tempfile +import unittest +from pathlib import Path +from unittest import mock + +import ci_scope +import cmocka_link_check + + +class ScopeTest(unittest.TestCase): + def test_registration_and_support_select_link_checks(self): + for path in ("libobs/obs-source.c.h", "libobs/cmake/rust-hidden.d/new.txt", + "rust/libobs-rust/src/lib.rs", "rust/obs-build/src/native.rs", + "rust/obs-build/test-graph.json", "test/cmocka/tests.d/new_link_support.cmake", + "ci/cmocka_link_check.py", "cmake/cross/tier2.cmake", "CMakeLists.txt", + "libobs/build/source-sets.d/LIBOBS_WINDOWS_SOURCES.json"): + with self.subTest(path=path): + for event in ("pull_request", "merge_group"): + self.assertTrue(ci_scope.scope([path], event=event).cmocka_link) + + def test_linked_rust_crates_follow_the_real_dependency_closure(self): + root = Path(__file__).resolve().parent.parent + + def read(path): + source = root / path + return source.read_text() if source.is_file() else "" + + self.assertTrue(ci_scope.scope(["rust/obs-util/src/ffi/bmem.rs"], read=read).cmocka_link) + + def test_unrelated_changes_keep_the_cheaper_category_check(self): + for path in ("docs/ci-tooling.md", "frontend/widgets/foo.cpp", "ci/backpressure.py"): + with self.subTest(path=path): + self.assertFalse(ci_scope.scope([path], event="pull_request").cmocka_link) + + +class ToolchainTest(unittest.TestCase): + def test_windows_uses_managed_clang_cl_and_the_target_sdk(self): + with tempfile.TemporaryDirectory(prefix="tier2 sdk ") as temporary: + work = Path(temporary) + (work / "soldr-tools").mkdir() + llvm = work / "llvm" + llvm.mkdir() + (llvm / "clang-cl").touch() + sdk = work / "sdk" + values = {"--print-ar": str(llvm / "llvm-lib"), + "--print-rc": str(llvm / "llvm-rc"), "--print-sysroot": str(sdk)} + with mock.patch.object(cmocka_link_check.subprocess, "run", + side_effect=lambda args, **kw: mock.Mock(stdout=values[args[-1]])): + toolchain = cmocka_link_check.windows_toolchain(work, "x86_64-pc-windows-msvc") + content = toolchain.read_text() + self.assertIn("MultiThreadedDLL", content) + self.assertIn("lld-link", content) + self.assertIn(f'/libpath:"{sdk}/sdk/lib/um/x86_64"', content) + wrapper = (work / "soldr-tools/clang-cl").read_text() + self.assertIn("-imsvc", wrapper) + self.assertNotIn("-isystem", wrapper) + self.assertIn("--target=x86_64-pc-windows-msvc", wrapper) + + +class DiscoveryTest(unittest.TestCase): + 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"), + ("libobs-cross-shared", "SHARED_LIBRARY")): + filename = name + ".json" + (reply / filename).write_text(json.dumps({"name": name, "type": kind})) + refs.append({"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"]) + + def test_existing_reply_without_rust_executables_fails_closed(self): + with tempfile.TemporaryDirectory() as temporary: + reply = Path(temporary) + (reply / "codemodel.json").write_text(json.dumps({"configurations": [{"targets": []}]})) + (reply / "index-1.json").write_text(json.dumps({"reply": {"codemodel-v2": {"jsonFile": "codemodel.json"}}})) + with self.assertRaises(ValueError): + cmocka_link_check.discover_targets(reply) + + def test_missing_reply_or_empty_rust_inventory_fails_closed(self): + with tempfile.TemporaryDirectory() as temporary: + with self.assertRaises((ValueError, FileNotFoundError)): + cmocka_link_check.discover_targets(Path(temporary)) + + +if __name__ == "__main__": + unittest.main() diff --git a/ci/test_gate_jobs.py b/ci/test_gate_jobs.py index c291293d74..3791f11a06 100644 --- a/ci/test_gate_jobs.py +++ b/ci/test_gate_jobs.py @@ -100,8 +100,16 @@ def test_complete_pr_requires_proven_gates_and_active_queue_policy(self): result = {"trusted": True, "reasons": [], "gates": dict.fromkeys(pr_attestation.CLIENT_GATES, "valid")} plan = pr_attestation.admission(result, files, event="pull_request") - self.assertEqual(gate_jobs.pr_expected_jobs(selected, files, plan), - {gate_jobs.SCOPE_JOB, "Build 🧱 / CI Mode 🛂"}) + windows_link = "Build 🧱 / Windows Link Check 🔗 (x86_64-pc-windows-msvc)" + expected = gate_jobs.pr_expected_jobs(selected, files, plan) + self.assertEqual(expected, {gate_jobs.SCOPE_JOB, "Build 🧱 / CI Mode 🛂", windows_link}) + healthy = [job(name, "success") for name in expected if name != windows_link] + self.assertEqual(blocking(healthy, expected=expected), [windows_link]) + self.assertEqual(blocking([*healthy, job(windows_link, "skipped")], expected=expected), [windows_link]) + unrelated = ["frontend/obs-app.cpp"] + self.assertNotIn(windows_link, gate_jobs.pr_expected_jobs( + scope(unrelated, event="pull_request"), unrelated, + pr_attestation.admission(result, unrelated, event="pull_request"))) for field in ("queue_policy", "gates", "admission_version"): invalid = dict(plan) invalid.pop(field) diff --git a/ci/test_pr_attestation.py b/ci/test_pr_attestation.py index 98fb3ff4cd..1e494796d5 100644 --- a/ci/test_pr_attestation.py +++ b/ci/test_pr_attestation.py @@ -407,7 +407,9 @@ def test_planner_outputs_drive_actual_workflow_job_allocation(self): expression = expression.replace("&&", " and ").replace("||", " or ") expression = re.sub(r"!(?!=)", " not ", expression) allocated = eval(expression, {"__builtins__": {}, "fromJSON": json.loads}) - self.assertEqual(bool(allocated), case != "complete", (case, name, condition, plan)) + # Category deferral cannot stand down the selected CMake pass. + must_run = case != "complete" or (name == "rust-windows-link" and selected.cmocka_link) + self.assertEqual(bool(allocated), must_run, (case, name, condition, plan)) swift = job_block(formatting, "swift-format") self.assertIn("inputs.swift", swift) self.assertEqual(full["jobs"]["check-format.yaml:swift-format"]["skip"], True) diff --git a/ci/test_windows_link_check.py b/ci/test_windows_link_check.py index 86a2056ed5..f78d7333bb 100644 --- a/ci/test_windows_link_check.py +++ b/ci/test_windows_link_check.py @@ -43,10 +43,34 @@ def test_links_every_test_binary_for_msvc(self): def test_main_adds_target_then_links_through_soldr(self): calls = [] with mock.patch.object(windows_link_check.local_gate, "add_target", lambda t: calls.append(("add", t))), \ - mock.patch.object(windows_link_check.local_gate, "soldr_cargo", lambda a: calls.append(("cargo", a))): + mock.patch.object(windows_link_check.local_gate, "soldr_cargo", lambda a: calls.append(("cargo", a))), \ + mock.patch.dict(windows_link_check.os.environ, {"OBS_CMOCKA_LINK": "false"}): self.assertEqual(windows_link_check.main(), 0) self.assertEqual(calls, [("add", "x86_64-pc-windows-msvc"), ("cargo", windows_link_check.link_args())]) + def test_selected_tier2_pass_links_after_categories(self): + with mock.patch.object(windows_link_check.local_gate, "add_target"), \ + mock.patch.object(windows_link_check.local_gate, "soldr_cargo"), \ + mock.patch.object(windows_link_check.cmocka_link_check, "link") as link, \ + mock.patch.dict(windows_link_check.os.environ, {"OBS_CMOCKA_LINK": "true"}): + self.assertEqual(windows_link_check.main(), 0) + root = windows_link_check.cmocka_link_check.ROOT + self.assertEqual(link.call_args_list, [ + mock.call("win-x64", root / "build_cmocka_link_win-x64", 4), + mock.call("mac-arm64", root / "build_cmocka_link_mac-arm64", 4), + ]) + + def test_tier2_link_failure_propagates(self): + import subprocess + + failure = subprocess.CalledProcessError(1, ["cmake", "--build"]) + with mock.patch.object(windows_link_check.local_gate, "add_target"), \ + mock.patch.object(windows_link_check.local_gate, "soldr_cargo"), \ + mock.patch.object(windows_link_check.cmocka_link_check, "link", side_effect=[None, failure]), \ + mock.patch.dict(windows_link_check.os.environ, {"OBS_CMOCKA_LINK": "true"}): + with self.assertRaises(subprocess.CalledProcessError): + windows_link_check.main() + def test_link_failure_propagates(self): import subprocess @@ -77,9 +101,11 @@ def test_never_stands_down_on_proofs_or_attestation(self): for skip in ("cross_hit", "skip_rust-cross-lint", "cross_lint", "outputs.windows =="): self.assertNotIn(skip, self.condition) self.assertIn("needs.check-event.outputs.docs_only != 'true'", self.condition) + self.assertIn("|| needs.check-event.outputs.cmocka_link == 'true'", self.condition) def test_is_linux_hosted_and_bounded(self): - self.assertIn("runs-on: ubuntu-26.04\n", self.block) + self.assertIn("inputs.mq-heavy-labels", self.block) + self.assertIn("'ubuntu-26.04'", self.block) minutes = int(re.search(r"timeout-minutes: (\d+)", self.block).group(1)) self.assertLessEqual(minutes, 30) # far inside the queue's 60-minute response timeout diff --git a/ci/windows_link_check.py b/ci/windows_link_check.py index 975a084fb9..a997759cb1 100644 --- a/ci/windows_link_check.py +++ b/ci/windows_link_check.py @@ -2,28 +2,28 @@ # /// script # requires-python = ">=3.14" # /// -"""Link every workspace test binary for Windows MSVC from Linux (queue tier). +"""Link Windows MSVC Rust categories and selected Tier 2 fixtures from Linux. uv run --no-project ci/windows_link_check.py -The cheap pre-merge signal for Windows link defects. The merge queue runs the -deferred tier, which skips rust-cross-lint, Rust Tests (windows) and Windows -Tier 2, so a COFF-only link failure passed the queue and reddened master -twice: `lld-link: error: undefined symbol: obs_encoder_get_caps` (merge_group -run 42390201886 green, push run 42393067345 red on the same tree; fixed by -#3919). ELF archive resolution on the Linux Fast Gate cannot see it; a COFF -link can, and soldr's self-contained lld-link plus xwin SDK does it on a -Linux runner with no Windows host. - -This runs only the link step of the `cross` lane (ci/local_gate.py -cross_lint): no clippy, no Dylint, no macOS target, nothing executed. The -full cross lane, native Windows tests and Tier 2 stay on push/dispatch. +Every non-docs fallback PR and merge group links the eight category binaries, +including the C oracle (#3919). For libobs and registration/support changes, +LANES["cmocka_link"] also selects Windows and Darwin hybrid libobs and every configured cmocka +`*_rust` executable (#5189). The latter uses the real registrations, deferred +support fragments, soldr's LLVM, Windows SDK and Apple SDK. Nothing is executed. + +OBS_CMOCKA_LINK=false keeps category-only coverage for unrelated changes. +Existing client proofs cover category links only; selected cmocka links always +run on PRs, including trusted member PRs, and on merge groups. """ from __future__ import annotations +import os import sys +import cmocka_link_check + import local_gate TARGET = "x86_64-pc-windows-msvc" @@ -41,6 +41,9 @@ def link_args(target: str = TARGET) -> list[str]: def main() -> int: local_gate.add_target(TARGET) local_gate.soldr_cargo(link_args()) + if os.environ.get("OBS_CMOCKA_LINK", "true") == "true": + cmocka_link_check.link("win-x64", cmocka_link_check.ROOT / "build_cmocka_link_win-x64", 4) + cmocka_link_check.link("mac-arm64", cmocka_link_check.ROOT / "build_cmocka_link_mac-arm64", 4) return 0 diff --git a/cmake/cross/CMakeLists.txt b/cmake/cross/CMakeLists.txt index f761731f04..933baeddcf 100644 --- a/cmake/cross/CMakeLists.txt +++ b/cmake/cross/CMakeLists.txt @@ -42,6 +42,10 @@ option(OBS_CROSS_WERROR "Treat warnings as errors in the cross-compile check" OF # import libraries. The default stays compile-only: the link needs the deps' # link inputs and a working cross linker, which not every host has. option(OBS_CROSS_LINK "Link a shared libobs per alias from the cross-compile check" OFF) +option(OBS_CROSS_TIER2 "Link the unchanged Tier 2 Rust fixtures" OFF) +if(OBS_CROSS_TIER2 AND NOT OBS_CROSS_LINK) + message(FATAL_ERROR "OBS_CROSS_TIER2 requires OBS_CROSS_LINK") +endif() # The generated toolchain is rewritten when soldr.cmake (how it is made) or the # alias changes, so a fix there reaches an existing build tree. A toolchain @@ -90,7 +94,11 @@ function(_obs_cross_dependencies) set(prebuilt_destination "obs-deps-VERSION-ARCH") set(qt6_filename "${_qt_file}") set(qt6_destination "obs-deps-qt6-VERSION-ARCH") - _check_dependencies(prebuilt qt6) + if(OBS_CROSS_TIER2) + _check_dependencies(prebuilt) + else() + _check_dependencies(prebuilt qt6) + endif() _get_dependency_data(all) string(JSON data GET ${all} prebuilt) string(JSON version GET ${data} version) @@ -110,10 +118,12 @@ endif() # The Qt version of the prebuilt, for its private header directories. file(GLOB_RECURSE _qt_version_files "${OBS_CROSS_QT}/lib/cmake/Qt6/Qt6ConfigVersionImpl.cmake") -if(NOT _qt_version_files) +if(NOT OBS_CROSS_TIER2 AND NOT _qt_version_files) message(FATAL_ERROR "Prebuilt Qt6 for ${OBS_CROSS_TARGET} missing: ${OBS_CROSS_QT}") endif() -file(STRINGS "${_qt_version_files}" _qt_version REGEX "^set\\(PACKAGE_VERSION \"") +if(_qt_version_files) + file(STRINGS "${_qt_version_files}" _qt_version REGEX "^set\\(PACKAGE_VERSION \"") +endif() string(REGEX REPLACE ".*\"([0-9.]+)\".*" "\\1" OBS_CROSS_QT_VERSION "${_qt_version}") # ui-config.h from the frontend's template, without client credentials. @@ -394,6 +404,11 @@ if(_host STREQUAL WINDOWS) _obs_cross_c_conversion_ratchet(libobs-cross-rust-shims) endif() +if(OBS_CROSS_TIER2) + include("${CMAKE_CURRENT_LIST_DIR}/tier2.cmake") + return() +endif() + # The platform-only plugins, compile-only like libobs above: each one's own # sources with the libobs, shared/ and deps/ headers it builds against, through # the same precompiled headers and unity batches as the native build. This is diff --git a/cmake/cross/cmocka/CMockaConfig.cmake b/cmake/cross/cmocka/CMockaConfig.cmake new file mode 100644 index 0000000000..3781d2a315 --- /dev/null +++ b/cmake/cross/cmocka/CMockaConfig.cmake @@ -0,0 +1,2 @@ +# cmocka is cross-built by tier2.cmake before the unchanged test tree loads. +set(CMocka_FOUND TRUE) diff --git a/cmake/cross/cmocka/CMockaConfigVersion.cmake b/cmake/cross/cmocka/CMockaConfigVersion.cmake new file mode 100644 index 0000000000..bdcd3657c1 --- /dev/null +++ b/cmake/cross/cmocka/CMockaConfigVersion.cmake @@ -0,0 +1,6 @@ +set(PACKAGE_VERSION 1.1.7) +if(PACKAGE_FIND_VERSION VERSION_GREATER PACKAGE_VERSION) + set(PACKAGE_VERSION_COMPATIBLE FALSE) +else() + set(PACKAGE_VERSION_COMPATIBLE TRUE) +endif() diff --git a/cmake/cross/tier2.cmake b/cmake/cross/tier2.cmake new file mode 100644 index 0000000000..02d836e050 --- /dev/null +++ b/cmake/cross/tier2.cmake @@ -0,0 +1,114 @@ +# Link the real Tier 2 registrations; keep their host conditions, archive order +# and deferred support hooks. No CTest execution takes place on the Linux host. +set(CMAKE_INCLUDE_CURRENT_DIR TRUE) +set(ENABLE_FRONTEND OFF) +set(CMAKE_DISABLE_FIND_PACKAGE_Qt6 TRUE) +set(ENABLE_HEVC ON) +set(ENABLE_CORE_MODULES ON) +set(ENABLE_WAYLAND OFF) +set(OS_${_host} TRUE) +if(OS_WINDOWS AND NOT MSVC) + message(FATAL_ERROR "Tier 2 Windows links require clang-cl; use ci/cmocka_link_check.py") +endif() +list(APPEND CMAKE_MODULE_PATH "${OBS_SOURCE_ROOT}/cmake/finders") +include(helpers_common) +enable_testing() + +include(FetchContent) +FetchContent_Declare(Corrosion GIT_REPOSITORY https://github.com/corrosion-rs/corrosion.git GIT_TAG v0.5.2) +FetchContent_MakeAvailable(Corrosion) +corrosion_import_crate( + MANIFEST_PATH "${OBS_SOURCE_ROOT}/Cargo.toml" + CRATES libobs-rust + CRATE_TYPES staticlib + PROFILE release +) + +if(OS_MACOS) + # A host librt must never satisfy a Darwin dependency probe. + list(APPEND CMAKE_FIND_ROOT_PATH "${OBS_CROSS_DEPS}") + set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) + unset(RT_LIBRARY CACHE) + unset(CMOCKA_REQUIRED_LIBRARIES CACHE) + unset(CMOCKA_LINK_LIBRARIES CACHE) + # These are the crate-declared SDK imports in obs-util's cocoa.rs. Corrosion + # 0.5 imports the standard-library link set, not these framework annotations. + target_link_libraries( + libobs_rust-static + INTERFACE "-framework Foundation" "-framework CoreFoundation" "-framework IOKit" objc + ) + # Match production visibility: exporting private Rust shims from the dylib + # could otherwise conceal a missing standalone archive/support dependency. + include("${OBS_SOURCE_ROOT}/libobs/cmake/rust-hidden.cmake") + obs_rust_hidden_lists( + "${OBS_SOURCE_ROOT}/libobs/cmake/rust-hidden.d" + "${OBS_SOURCE_ROOT}/libobs/cmake/rust-hidden-base.txt" + "${CMAKE_BINARY_DIR}/config" + "${ENABLE_HEVC}" + ) + target_link_options( + libobs-cross-shared + PRIVATE "LINKER:-unexported_symbols_list,${CMAKE_BINARY_DIR}/config/rust-unexports-macos.txt" + ) + set_property( + TARGET libobs-cross-shared + APPEND + PROPERTY LINK_DEPENDS "${CMAKE_BINARY_DIR}/config/rust-unexports-macos.txt" + ) +endif() + +add_library(OBS::libobs ALIAS libobs-cross-shared) +add_library(libobs-objects ALIAS libobs-cross-shared-objects) +add_library(OBS::libobs-core-modules ALIAS libobs-cross-generated) +target_include_directories(libobs-cross-shared PUBLIC "${OBS_SOURCE_ROOT}/libobs" "${CMAKE_BINARY_DIR}/config") +# Rust object directives retain Windows case on Linux (MSVCRT/OLDNAMES). +if(OS_WINDOWS) + link_directories("${CMAKE_BINARY_DIR}/cross-case-libs") + # Rust libc calls external snprintf; the UCRT C headers inline it. Use + # the real SDK compatibility archive when linking with clang-cl/LLD. + link_libraries(legacy_stdio_definitions) + file( + CREATE_LINK "${CMAKE_FIND_ROOT_PATH}/sdk/lib/um/x86_64/rpcrt4.lib" "${CMAKE_BINARY_DIR}/cross-case-libs/Rpcrt4.lib" + SYMBOLIC + ) + target_include_directories(libobs-cross-shared PUBLIC "${OBS_SOURCE_ROOT}/deps/w32-pthreads") + add_library(OBS::w32-pthreads ALIAS libobs-cross-shared-pthreads) + target_include_directories(libobs-cross-shared-pthreads PUBLIC "${OBS_SOURCE_ROOT}/deps/w32-pthreads") +endif() +find_package( + FFmpeg + 8.0 + REQUIRED + COMPONENTS avcodec avformat avutil swscale swresample +) +find_package(jansson REQUIRED) +find_package(Uthash REQUIRED) +find_package(SIMDe REQUIRED) +find_package(ZLIB REQUIRED) + +# Same pinned cmocka as the Darwin run-only producer. Build for the target; +# a host cmocka or a placeholder library would conceal unresolved imports. +FetchContent_Declare( + cmocka + URL https://cmocka.org/files/1.1/cmocka-1.1.7.tar.xz + URL_HASH SHA256=810570eb0b8d64804331f82b29ff47c790ce9cd6b163e98d47a4807047ecad82 +) +set(BUILD_SHARED_LIBS OFF CACHE BOOL "Cross-built cmocka is static" FORCE) +set(UNIT_TESTING OFF) +set(WITH_EXAMPLES OFF) +set(CMAKE_POLICY_VERSION_MINIMUM 3.5) +# Function-existence probes must link: a static try-compile would claim POSIX +# sigsetjmp/siglongjmp exist in the Windows SDK merely from declarations. +set(CMAKE_TRY_COMPILE_TARGET_TYPE EXECUTABLE) +find_package(Threads REQUIRED) +if(OS_WINDOWS) + unset(HAVE_SIGSETJMP CACHE) + unset(HAVE_SIGLONGJMP CACHE) +endif() +FetchContent_MakeAvailable(cmocka) +set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY) +set_target_properties(cmocka PROPERTIES OBS_DISABLE_PCH TRUE OBS_DISABLE_UNITY_BUILD TRUE) +set(CMOCKA_INCLUDE_DIR "${cmocka_SOURCE_DIR}/include") +set(CMOCKA_LIBRARIES cmocka) +set(CMocka_DIR "${CMAKE_CURRENT_LIST_DIR}/cmocka") +add_subdirectory("${OBS_SOURCE_ROOT}/test/cmocka" "${CMAKE_BINARY_DIR}/test/cmocka") diff --git a/docs/ci-tooling.md b/docs/ci-tooling.md index 7e01809589..8c30060589 100644 --- a/docs/ci-tooling.md +++ b/docs/ci-tooling.md @@ -255,6 +255,49 @@ cmake --build build --target cross-win-x64 # cross-mac-arm64, cross-mac-x64 - **No `win-arm64`:** `util/threading-windows.h` uses MSVC-only ARM64 intrinsics that clang lacks. - **Cost, measured 2026-10-31:** a cold cross build *with* the link — a fresh build tree, `ZCCACHE_DISABLE=1`, including that alias's `libobs-rust` staticlib — took `win-x64` 32 s / 41 s, `mac-arm64` 117 s / 32 s and `mac-x64` 134 s / 26 s (two samples each, `-j 4` on a 16-thread host shared with other worker checkouts; the slower sample in each pair is the one that also rebuilt 14–18 workspace crates, and the rest of the spread is co-tenant load). The native `Build OBS-Studio-Rust` steps it stands in for are 12m25 (Windows x64), 8m01 (macOS arm64) and 7m50 (macOS x86_64) in release run 41007587429; signing and packaging stay native. +#### Tier 2 pre-queue links (#5189) + +The existing Linux-hosted Windows Link Check also links hybrid libobs and every +configured cmocka `*_rust` executable 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 +the eight Rust category links. The same check runs on PRs and merge groups; +selected cmocka links also run on fully attested member PRs because existing +client proofs do not attest this CMake pass. Category-only work keeps its +existing admission policy. + +```sh +uv run --no-project ci/cmocka_link_check.py +uv run --no-project ci/cmocka_link_check.py --alias mac-arm64 +``` + +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 +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 +manifest-only custom-command result. Ninja parallelism defaults to four and the +existing job retains its 30-minute deadline and Linux heavy-pool routing. +Darwin uses the production hidden-symbol list and the Rust crate's existing SDK +framework imports. Library discovery stays in the Apple SDK and target deps; +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): + +| Target | Fresh CMake/Corrosion tree | Warm tree | +|---|---:|---:| +| Windows MSVC x86_64 | 367.80 s | 82.49 s | +| Darwin arm64 | 418.54 s | 73.69 s | + +SDKs, prebuilt target dependencies and the Cargo registry were already installed; +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. + #### macOS Rust execution artifacts (#5008) The maintainer chose **STRICT** on 2026-11-17: nothing compiles on hosted @@ -1268,9 +1311,9 @@ and macOS/Windows jobs keep their current hosted runners. Linux matrix entries retain their matrix and hosted fallback. Required job/check names are unchanged. Rust Tier 2 Linux build, its OFF/ON test jobs, Rust Cross Lint (two main targets plus the release-target job), and the Linux macOS Rust artifact -producer use that selection. +producer and Windows Link Check use that selection. Build and tests share the selected pool so local handoff remains valid. -Event Data, CI Mode, Format, Fast Gate, Windows Link Check, Cross Compile, +Event Data, CI Mode, Format, Fast Gate, Cross Compile, Qt, app builds, proof publication, queue cancellation and CI Gate use hosted runners. Empty outputs and probe/setup errors keep every heavy job hosted.