diff --git a/.github/justfile b/.github/justfile index 38aaa244d6b..9d7cdc5e3e6 100644 --- a/.github/justfile +++ b/.github/justfile @@ -26,7 +26,7 @@ test: python3 sh/gh/install-formula.test.py sh/gh/release.test.sh python3 sh/gh/ffi.test.py - bun test sh/gh/ffi.test.ts + bun test sh/gh/ffi.test.ts sh/gh/cpp.test.ts python3 sh/rs/package-rename.test.py python3 sh/rs/select.test.py python3 sh/js/workspace.test.py diff --git a/.github/workflows/release-cpp.yml b/.github/workflows/release-cpp.yml index 4ba1a3e9035..98b6d88d541 100644 --- a/.github/workflows/release-cpp.yml +++ b/.github/workflows/release-cpp.yml @@ -151,6 +151,16 @@ jobs: fi just cpp package "${args[@]}" + - name: Check packaged archive + shell: bash + env: + TARGET: ${{ matrix.target }} + run: | + version=$(tr -d '[:space:]' < cpp/moq/VERSION) + extension=tar.gz + [[ "$TARGET" == *-windows-* ]] && extension=zip + just cpp check --archive "dist/moq-cpp-$version-$TARGET.$extension" + - name: Upload artifact uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7 with: @@ -199,11 +209,12 @@ jobs: # every release: rebuild it against the release just published (no second # cargo build, guaranteed-matching bindings) and cut a parallel # obs-moq-v release. The plugin's version is its own, - # cpp/obs/VERSION. Runs after `release` so the archives - # the plugin's CMake fetches are already live. + # cpp/obs/VERSION. Tags wait for `release` so downloads are live; dry runs + # consume this run's checked local archive without publishing anything. obs-build: name: OBS plugin (${{ matrix.target }}) - needs: release + needs: [build, release] + if: ${{ always() && !cancelled() && needs.build.result == 'success' && (github.ref_type != 'tag' || needs.release.result == 'success') }} runs-on: ${{ matrix.os }} # macOS + Windows only. These link the ffmpeg the obs-deps bundle ships @@ -234,16 +245,30 @@ jobs: shell: bash run: echo "version=$(tr -d '[:space:]' < cpp/moq/VERSION)" >>"$GITHUB_OUTPUT" + - name: Download local C++ archive + if: github.ref_type != 'tag' + uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8 + with: + name: moq-cpp-${{ matrix.target }} + path: cpp-archive + # Native Xcode / Visual Studio; libobs/Qt6/ffmpeg come from the obs-deps - # bundle and the C++ package from the release just published (--moq-release). + # bundle and C++ comes from the checked local archive, or the published tag. # build.sh versions the plugin from cpp/obs/VERSION. - name: Build and package shell: bash env: TARGET: ${{ matrix.target }} MOQ_RELEASE: ${{ steps.parse.outputs.version }} + REF_TYPE: ${{ github.ref_type }} run: | - just obs package --target "$TARGET" --moq-release "$MOQ_RELEASE" --output dist + args=(--moq-release "$MOQ_RELEASE") + if [[ "$REF_TYPE" != tag ]]; then + extension=tar.gz + [[ "$TARGET" == *-windows-* ]] && extension=zip + args=(--moq-archive "$GITHUB_WORKSPACE/cpp-archive/moq-cpp-$MOQ_RELEASE-$TARGET.$extension") + fi + just obs package --target "$TARGET" "${args[@]}" --output dist - name: Upload artifact uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7 @@ -254,6 +279,7 @@ jobs: obs-release: name: OBS plugin release needs: obs-build + if: github.ref_type == 'tag' runs-on: ubuntu-latest permissions: contents: write diff --git a/cpp/justfile b/cpp/justfile index c97fd39ed36..90ff37bb27a 100644 --- a/cpp/justfile +++ b/cpp/justfile @@ -8,11 +8,12 @@ set working-directory := '.' default: just check -# Build the package and run the probe and doc samples against its install. +# Build the package, or check an archive, and run its installed consumers. +[no-cd] [positional-arguments] check *args: - python3 ../sh/cpp/ffi.test.py - ../sh/cpp/check.sh "$@" + python3 {{ quote(justfile_directory() / "sh/cpp/ffi.test.py") }} + {{ quote(justfile_directory() / "sh/cpp/check.sh") }} "$@" # Run the in-process binding benchmark with the release library. bench: diff --git a/cpp/moq/README.md b/cpp/moq/README.md index f411cda92da..7e7bfc04e49 100644 --- a/cpp/moq/README.md +++ b/cpp/moq/README.md @@ -12,7 +12,7 @@ C++17 bindings for [rs/moq-ffi](../../rs/moq-ffi): the sources `uniffi-bindgen-c ## Checking -`just cpp check` builds and installs the package, builds the probe against it with `find_package` at C++17 and C++23 and, outside Windows, with pkg-config at C++17, runs each, and compiles the doc samples (also outside Windows). It also builds the probe at C++23 over bindings at C++17, to prove the two link. The probe builds with exceptions and RTTI disabled. +`just cpp check` builds and installs the package, builds the probe against it with `find_package` at C++17 and C++23 and, outside Windows, with pkg-config at C++17, runs each, and compiles the doc samples (also outside Windows). It also builds the probe at C++23 over bindings at C++17, to prove the two link. The probe builds with exceptions and RTTI disabled. `just cpp check --archive FILE` runs the same consumer checks against an extracted release archive, without rebuilding the package. Release dry runs check every archive this way. The generator is a fork, [kixelated/uniffi-bindgen-cpp](https://github.com/kixelated/uniffi-bindgen-cpp). It carries LiveKit's async support ported to uniffi 0.32, plus the `error_style = "expected"` and `strip_type_prefix` options `uniffi.toml` turns on. The dev shell provides it. Without Nix: diff --git a/cpp/obs/CMakeLists.txt b/cpp/obs/CMakeLists.txt index 41d12c2fb15..159ff2df9e1 100644 --- a/cpp/obs/CMakeLists.txt +++ b/cpp/obs/CMakeLists.txt @@ -1,10 +1,19 @@ cmake_minimum_required(VERSION 3.28) # Build the in-tree C++ package (cpp/moq) by default. Release-only builds clear -# MOQ_LOCAL and must select the published archive explicitly, so this never +# MOQ_LOCAL and must select a release archive explicitly, so this never # silently drifts to an old static version. set(MOQ_LOCAL "${CMAKE_CURRENT_SOURCE_DIR}/../.." CACHE PATH "Path to the moq repo (builds cpp/moq in-tree)") -set(MOQ_VERSION "" CACHE STRING "Published moq-cpp version (required without MOQ_LOCAL)") +set(MOQ_VERSION "" CACHE STRING "moq-cpp archive version (required without MOQ_LOCAL)") +set(MOQ_ARCHIVE_FILE "" CACHE FILEPATH "Local moq-cpp release archive instead of a download") +if(MOQ_ARCHIVE_FILE) + if(MOQ_LOCAL) + message(FATAL_ERROR "MOQ_ARCHIVE_FILE requires an empty MOQ_LOCAL") + endif() + if(NOT EXISTS "${MOQ_ARCHIVE_FILE}" OR IS_DIRECTORY "${MOQ_ARCHIVE_FILE}") + message(FATAL_ERROR "moq-cpp archive not found: ${MOQ_ARCHIVE_FILE}") + endif() +endif() # One predicate for both the version derivation here and the link/fetch choice # below, so the two can't drift apart. @@ -22,7 +31,16 @@ else() if(NOT MOQ_VERSION) message(FATAL_ERROR "MOQ_VERSION is required when MOQ_LOCAL does not contain cpp/moq") endif() + if(NOT MOQ_VERSION MATCHES "^[0-9]+\\.[0-9]+\\.[0-9]+$") + message(FATAL_ERROR "Unsupported moq-cpp version: ${MOQ_VERSION}") + endif() set(_moq_link_version "${MOQ_VERSION}") + if(MOQ_ARCHIVE_FILE) + get_filename_component(_moq_archive_name "${MOQ_ARCHIVE_FILE}" NAME) + if(NOT _moq_archive_name STREQUAL "moq-cpp-${MOQ_VERSION}-${MOQ_TARGET}.${MOQ_ARCHIVE}") + message(FATAL_ERROR "moq-cpp archive does not match version, target, and format: ${_moq_archive_name}") + endif() + endif() endif() include("${CMAKE_CURRENT_SOURCE_DIR}/cmake/common/bootstrap.cmake" NO_POLICY_SCOPE) @@ -70,11 +88,17 @@ if(_moq_local_build) add_subdirectory("${MOQ_LOCAL}/cpp/moq" moq-cpp) else() include(FetchContent) - FetchContent_Declare( - moq-cpp - URL - https://github.com/moq-dev/moq/releases/download/cpp-v${_moq_link_version}/moq-cpp-${_moq_link_version}-${MOQ_TARGET}.${MOQ_ARCHIVE} - ) + if(MOQ_ARCHIVE_FILE) + file(SHA256 "${MOQ_ARCHIVE_FILE}" _moq_archive_hash) + set(_moq_archive "${MOQ_ARCHIVE_FILE}") + set(_moq_archive_options URL_HASH "SHA256=${_moq_archive_hash}") + else() + set( + _moq_archive + "https://github.com/moq-dev/moq/releases/download/cpp-v${_moq_link_version}/moq-cpp-${_moq_link_version}-${MOQ_TARGET}.${MOQ_ARCHIVE}" + ) + endif() + FetchContent_Declare(moq-cpp URL "${_moq_archive}" ${_moq_archive_options}) FetchContent_MakeAvailable(moq-cpp) find_package(moq-cpp REQUIRED PATHS ${moq-cpp_SOURCE_DIR} NO_DEFAULT_PATH) diff --git a/cpp/obs/README.md b/cpp/obs/README.md index 0af672f572e..ed0e868ce53 100644 --- a/cpp/obs/README.md +++ b/cpp/obs/README.md @@ -21,3 +21,8 @@ just obs build Licensed under GPL-2.0-or-later (see [LICENSE](LICENSE)), separate from the rest of the repository, because it links OBS. + +Release dry runs use `just obs package --target TARGET --moq-archive FILE` to +link the matching local C++ release archive. Tag builds use +`--moq-release VERSION` to download the published archive. The two inputs are +mutually exclusive; neither changes the plugin version in `VERSION`. diff --git a/cpp/obs/build.sh b/cpp/obs/build.sh index 9c00bff2b9d..04e3d3f7dd5 100755 --- a/cpp/obs/build.sh +++ b/cpp/obs/build.sh @@ -3,6 +3,7 @@ set -euo pipefail # Build and package the obs-moq plugin for release. # Usage: ./build.sh [--target TARGET] [--version VERSION] [--output DIR] +# [--moq-release VERSION | --moq-archive FILE] # # The required toolchain must already be on PATH; this script only drives # CMake. Per platform: @@ -21,6 +22,7 @@ TARGET="" VERSION="" OUTPUT_DIR="dist" MOQ_RELEASE="" +MOQ_ARCHIVE_FILE="" while [[ $# -gt 0 ]]; do case $1 in @@ -36,6 +38,14 @@ while [[ $# -gt 0 ]]; do OUTPUT_DIR="$2" shift 2 ;; + --moq-archive) + MOQ_ARCHIVE_FILE="$(cd "$(dirname "$2")" && pwd)/$(basename "$2")" + [[ -f "$MOQ_ARCHIVE_FILE" ]] || { + echo "Archive not found: $MOQ_ARCHIVE_FILE" >&2 + exit 1 + } + shift 2 + ;; --moq-release) # Link a published moq-cpp release of this version instead of # building cpp/moq from source. CMake fetches the matching @@ -45,7 +55,7 @@ while [[ $# -gt 0 ]]; do shift 2 ;; -h | --help) - echo "Usage: $0 [--target TARGET] [--version VERSION] [--output DIR] [--moq-release VERSION]" + echo "Usage: $0 [--target TARGET] [--version VERSION] [--output DIR] [--moq-release VERSION | --moq-archive FILE]" exit 0 ;; *) @@ -55,6 +65,19 @@ while [[ $# -gt 0 ]]; do esac done +if [[ -n "$MOQ_RELEASE" && -n "$MOQ_ARCHIVE_FILE" ]]; then + echo "Choose --moq-release or --moq-archive" >&2 + exit 1 +fi +if [[ -n "$MOQ_ARCHIVE_FILE" ]]; then + archive_name=$(basename "$MOQ_ARCHIVE_FILE") + if [[ ! "$archive_name" =~ ^moq-cpp-([0-9]+\.[0-9]+\.[0-9]+)- ]]; then + echo "Malformed moq-cpp archive name: $archive_name" >&2 + exit 1 + fi + MOQ_RELEASE="${BASH_REMATCH[1]}" +fi + if [[ -z "$TARGET" ]]; then TARGET=$(cc -dumpmachine 2>/dev/null || echo unknown) echo "Detected target: $TARGET" @@ -96,17 +119,18 @@ OUTPUT_DIR="$(cd "$OUTPUT_DIR" && pwd)" cd "$SCRIPT_DIR" echo "Building obs-moq $VERSION for $TARGET (preset: $PRESET)..." -CONFIGURE_ARGS=() +# Clear cached archive/source choices when changing package inputs. +CONFIGURE_ARGS=("-DMOQ_LOCAL=$SCRIPT_DIR/../.." -DMOQ_VERSION= "-DMOQ_ARCHIVE_FILE=$MOQ_ARCHIVE_FILE") # Stamp the plugin's compiled-in version (project version, macOS Info.plist, # Windows resource) to match what we're building, not buildspec.json's 0.0.1. if [[ -n "$VERSION" ]]; then CONFIGURE_ARGS+=("-DPLUGIN_VERSION_OVERRIDE=$VERSION") fi if [[ -n "$MOQ_RELEASE" ]]; then - # Empty MOQ_LOCAL forces CMake's release-download branch; MOQ_VERSION and + # Empty MOQ_LOCAL selects an archive; MOQ_VERSION and # MOQ_TARGET steer it at this target's archive. MOQ_ARCHIVE is correct per # preset already. - echo "Linking moq-cpp release v$MOQ_RELEASE ($TARGET)" + echo "Linking moq-cpp v$MOQ_RELEASE ($TARGET)${MOQ_ARCHIVE_FILE:+ from $MOQ_ARCHIVE_FILE}" CONFIGURE_ARGS+=(-DMOQ_LOCAL= "-DMOQ_VERSION=$MOQ_RELEASE" "-DMOQ_TARGET=$TARGET") fi cmake --preset "$PRESET" ${CONFIGURE_ARGS[@]+"${CONFIGURE_ARGS[@]}"} diff --git a/sh/cpp/check.sh b/sh/cpp/check.sh index 826a5f2febb..7a133c6423b 100755 --- a/sh/cpp/check.sh +++ b/sh/cpp/check.sh @@ -7,12 +7,21 @@ set -euo pipefail ffi_dir="" +archive="" if [[ $# -gt 0 ]]; then - if [[ $# != 2 || "$1" != --ffi-dir ]]; then - echo "Usage: $0 [--ffi-dir DIR]" >&2 + if [[ $# != 2 || ("$1" != --ffi-dir && "$1" != --archive) ]]; then + echo "Usage: $0 [--ffi-dir DIR | --archive FILE]" >&2 exit 1 fi - ffi_dir="$(cd "$2" && pwd)" + if [[ "$1" == --archive ]]; then + archive="$(cd "$(dirname "$2")" && pwd)/$(basename "$2")" + [[ -f "$archive" ]] || { + echo "Archive not found: $archive" >&2 + exit 1 + } + else + ffi_dir="$(cd "$2" && pwd)" + fi fi cd "$(dirname "${BASH_SOURCE[0]}")/../../cpp" @@ -21,11 +30,32 @@ cd "$(dirname "${BASH_SOURCE[0]}")/../../cpp" # --config Release, since the Rust staticlib links the release CRT (/MD) either way. build=moq/build if [[ -n "$ffi_dir" ]]; then build=moq/build/prebuilt; fi -prefix="$PWD/$build/prefix" -cmake -S moq -B "$build/package" -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_LIBDIR=lib -DMOQ_FFI_DIR="$ffi_dir" -cmake --build "$build/package" --config Release -rm -rf "$prefix" -cmake --install "$build/package" --config Release --prefix "$prefix" +if [[ -n "$archive" ]]; then + build=moq/build/archive + version=$(tr -d '[:space:]' &2 + exit 1 + fi + prefix="$PWD/$build/package/$name" + rm -rf "$build/package" + mkdir -p "$build/package" + (cd "$build/package" && cmake -E tar xf "$archive") + if [[ ! -f "$prefix/lib/cmake/moq-cpp/moq-cpp-config.cmake" ]]; then + echo "Missing moq-cpp package in $archive" >&2 + exit 1 + fi +else + prefix="$PWD/$build/prefix" + cmake -S moq -B "$build/package" -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_LIBDIR=lib -DMOQ_FFI_DIR="$ffi_dir" + cmake --build "$build/package" --config Release + rm -rf "$prefix" + cmake --install "$build/package" --config Release --prefix "$prefix" +fi run() { if [[ -x "$1/probe" ]]; then "$1/probe"; else "$1/Release/probe.exe"; fi diff --git a/sh/gh/cpp.test.ts b/sh/gh/cpp.test.ts new file mode 100644 index 00000000000..913de1f4e67 --- /dev/null +++ b/sh/gh/cpp.test.ts @@ -0,0 +1,38 @@ +// biome-ignore-all lint/suspicious/noTemplateCurlyInString: GitHub Actions expressions are literal strings. +import { expect, test } from "bun:test"; +import { YAML } from "bun"; + +test("C++ dry runs check packaged archives and build OBS without publishing", async () => { + const workflow = YAML.parse(await Bun.file(".github/workflows/release-cpp.yml").text()); + const jobs = workflow.jobs; + expect(jobs.build.steps.find((step: { name: string }) => step.name === "Check packaged archive")?.run).toContain( + "just cpp check --archive", + ); + expect(jobs["obs-build"].needs).toEqual(["build", "release"]); + const runs = new Function( + "github", + "needs", + "always", + "cancelled", + `return (${jobs["obs-build"].if.replace(/\$\{\{|\}\}/g, "")});`, + ); + for (const [ref, build, release, wanted] of [ + ["branch", "success", "skipped", true], + ["tag", "success", "success", true], + ["tag", "success", "failure", false], + ["branch", "failure", "skipped", false], + ] as const) { + expect(runs({ ref_type: ref }, { build: { result: build }, release: { result: release } }, () => true, () => false)).toBe( + wanted, + ); + } + const steps = jobs["obs-build"].steps; + expect(steps.find((step: { name: string }) => step.name === "Download local C++ archive").if).toBe( + "github.ref_type != 'tag'", + ); + expect(steps.find((step: { name: string }) => step.name === "Download local C++ archive").with.name).toBe( + "moq-cpp-${{ matrix.target }}", + ); + expect(steps.find((step: { name: string }) => step.name === "Build and package").run).toContain("--moq-archive"); + for (const name of ["release", "obs-release"]) expect(jobs[name].if).toBe("github.ref_type == 'tag'"); +}); diff --git a/sh/obs/check.sh b/sh/obs/check.sh index fefa788ac31..5588f74d90f 100755 --- a/sh/obs/check.sh +++ b/sh/obs/check.sh @@ -59,6 +59,30 @@ if command -v cmake >/dev/null; then cat "$build_dir/configure.log" >&2 exit 1 fi + archive="$build_dir/moq-cpp-0.0.0-x86_64-unknown-linux-gnu.tar.gz" + touch "$archive" + for scenario in conflict missing mismatch; do + args=("-DMOQ_ARCHIVE_FILE=$archive" -DMOQ_VERSION=0.0.0 -DMOQ_TARGET=x86_64-unknown-linux-gnu -DMOQ_ARCHIVE=tar.gz) + case "$scenario" in + conflict) expected="MOQ_ARCHIVE_FILE requires an empty MOQ_LOCAL" ;; + missing) + args+=(-DMOQ_LOCAL= "-DMOQ_ARCHIVE_FILE=$build_dir/missing.tar.gz") + expected="moq-cpp archive not found" + ;; + mismatch) + args+=(-DMOQ_LOCAL= -DMOQ_TARGET=aarch64-apple-darwin) + expected="moq-cpp archive does not match" + ;; + esac + if cmake -S . -B "$build_dir/$scenario" "${args[@]}" >"$build_dir/configure.log" 2>&1; then + echo "CMake accepted invalid archive input: $scenario" >&2 + exit 1 + fi + if ! grep -Fq "$expected" "$build_dir/configure.log"; then + cat "$build_dir/configure.log" >&2 + exit 1 + fi + done fi if command -v clang-format >/dev/null; then git ls-files 'src/*.cpp' 'src/*.h' 'test/*.cpp' | xargs clang-format --dry-run --Werror