Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions .github/workflows/build-project.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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}"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
7 changes: 7 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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})
Expand Down
10 changes: 9 additions & 1 deletion ci/ci_scope.py
Original file line number Diff line number Diff line change
Expand Up @@ -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/**",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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))
Expand Down
128 changes: 128 additions & 0 deletions ci/cmocka_link_check.py
Original file line number Diff line number Diff line change
@@ -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())
4 changes: 4 additions & 0 deletions ci/gate_jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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", [])
Expand Down
4 changes: 2 additions & 2 deletions ci/test_ci_scope.py
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand All @@ -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"},
}
Expand Down
97 changes: 97 additions & 0 deletions ci/test_cmocka_link_check.py
Original file line number Diff line number Diff line change
@@ -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()
12 changes: 10 additions & 2 deletions ci/test_gate_jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading
Loading