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
2 changes: 1 addition & 1 deletion .github/justfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
36 changes: 31 additions & 5 deletions .github/workflows/release-cpp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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<version> 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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
7 changes: 4 additions & 3 deletions cpp/justfile
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion cpp/moq/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down
38 changes: 31 additions & 7 deletions cpp/obs/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
5 changes: 5 additions & 0 deletions cpp/obs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
32 changes: 28 additions & 4 deletions cpp/obs/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -21,6 +22,7 @@ TARGET=""
VERSION=""
OUTPUT_DIR="dist"
MOQ_RELEASE=""
MOQ_ARCHIVE_FILE=""

while [[ $# -gt 0 ]]; do
case $1 in
Expand All @@ -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
Expand All @@ -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
;;
*)
Expand All @@ -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"
Expand Down Expand Up @@ -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[@]}"}
Expand Down
46 changes: 38 additions & 8 deletions sh/cpp/check.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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:]' <moq/VERSION)
target=$(rustc -vV | sed -n 's/^host: //p')
name="moq-cpp-$version-$target"
extension=tar.gz
[[ "$target" == *-windows-* ]] && extension=zip
if [[ "$(basename "$archive")" != "$name.$extension" ]]; then
echo "Expected $name.$extension, got $archive" >&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
Expand Down
38 changes: 38 additions & 0 deletions sh/gh/cpp.test.ts
Original file line number Diff line number Diff line change
@@ -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'");
});
24 changes: 24 additions & 0 deletions sh/obs/check.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading