|
| 1 | +#!/usr/bin/env bash |
| 2 | +set -euo pipefail |
| 3 | + |
| 4 | +# Build and package the obs-moq plugin for release. |
| 5 | +# Usage: ./build.sh [--target TARGET] [--version VERSION] [--output DIR] |
| 6 | +# |
| 7 | +# The required toolchain must already be on PATH; this script only drives |
| 8 | +# CMake. Per platform: |
| 9 | +# Linux - run inside `nix develop` (provides cmake/ninja/obs-studio/qt6/ffmpeg) |
| 10 | +# macOS - full Xcode, run OUTSIDE nix (libobs/Qt6/ffmpeg all come from the |
| 11 | +# obs-deps bundle downloaded by buildspec.json at configure time) |
| 12 | +# Windows - Visual Studio 2022; run from Git Bash with cmake on PATH |
| 13 | +# (libobs/Qt6 downloaded by buildspec.json) |
| 14 | +# |
| 15 | +# Produces $OUTPUT_DIR/obs-moq-$VERSION-$TARGET.{tar.gz,zip}. The archive is |
| 16 | +# unsigned; macOS Gatekeeper / Windows SmartScreen will warn on first load. |
| 17 | + |
| 18 | +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" |
| 19 | + |
| 20 | +TARGET="" |
| 21 | +VERSION="" |
| 22 | +OUTPUT_DIR="dist" |
| 23 | +MOQ_RELEASE="" |
| 24 | + |
| 25 | +while [[ $# -gt 0 ]]; do |
| 26 | + case $1 in |
| 27 | + --target) |
| 28 | + TARGET="$2" |
| 29 | + shift 2 |
| 30 | + ;; |
| 31 | + --version) |
| 32 | + VERSION="$2" |
| 33 | + shift 2 |
| 34 | + ;; |
| 35 | + --output) |
| 36 | + OUTPUT_DIR="$2" |
| 37 | + shift 2 |
| 38 | + ;; |
| 39 | + --libmoq-release) |
| 40 | + # Link a published libmoq release of this version instead of |
| 41 | + # building rs/libmoq from source. CMake fetches the matching |
| 42 | + # moq-<version>-<target> archive from the GitHub release and the |
| 43 | + # plugin is versioned to match. Used by CI on a libmoq-v* tag. |
| 44 | + MOQ_RELEASE="$2" |
| 45 | + shift 2 |
| 46 | + ;; |
| 47 | + -h | --help) |
| 48 | + echo "Usage: $0 [--target TARGET] [--version VERSION] [--output DIR] [--libmoq-release VERSION]" |
| 49 | + exit 0 |
| 50 | + ;; |
| 51 | + *) |
| 52 | + echo "Unknown option: $1" >&2 |
| 53 | + exit 1 |
| 54 | + ;; |
| 55 | + esac |
| 56 | +done |
| 57 | + |
| 58 | +# In libmoq-release mode the plugin version tracks the libmoq version. |
| 59 | +if [[ -n "$MOQ_RELEASE" ]]; then |
| 60 | + VERSION="$MOQ_RELEASE" |
| 61 | +fi |
| 62 | + |
| 63 | +if [[ -z "$TARGET" ]]; then |
| 64 | + TARGET=$(cc -dumpmachine 2>/dev/null || echo unknown) |
| 65 | + echo "Detected target: $TARGET" |
| 66 | +fi |
| 67 | + |
| 68 | +# Default the version from buildspec.json's top-level "version" (the nested |
| 69 | +# dependency entries also have "version" keys, hence the leading-indent anchor). |
| 70 | +if [[ -z "$VERSION" ]]; then |
| 71 | + VERSION=$(grep -E '^[[:space:]]{4}"version"' "$SCRIPT_DIR/buildspec.json" | head -1 | sed 's/.*: *"\([^"]*\)".*/\1/') |
| 72 | + echo "Detected version: $VERSION" |
| 73 | +fi |
| 74 | + |
| 75 | +# Map the target triple to a CMake preset and build tree. |
| 76 | +case "$TARGET" in |
| 77 | +*-linux-*) |
| 78 | + PRESET="ubuntu-x86_64" |
| 79 | + BUILD_DIR="$SCRIPT_DIR/build_x86_64" |
| 80 | + KIND="unix" |
| 81 | + ;; |
| 82 | +*-apple-darwin) |
| 83 | + PRESET="macos" |
| 84 | + BUILD_DIR="$SCRIPT_DIR/build_macos" |
| 85 | + KIND="macos" |
| 86 | + ;; |
| 87 | +*-windows-*) |
| 88 | + PRESET="windows-x64" |
| 89 | + BUILD_DIR="$SCRIPT_DIR/build_x64" |
| 90 | + KIND="windows" |
| 91 | + ;; |
| 92 | +*) |
| 93 | + echo "Unsupported target: $TARGET" >&2 |
| 94 | + exit 1 |
| 95 | + ;; |
| 96 | +esac |
| 97 | + |
| 98 | +# Resolve the output dir to an absolute path before we cd into the plugin |
| 99 | +# directory (cmake --preset reads CMakePresets.json from the current dir). |
| 100 | +mkdir -p "$OUTPUT_DIR" |
| 101 | +OUTPUT_DIR="$(cd "$OUTPUT_DIR" && pwd)" |
| 102 | +cd "$SCRIPT_DIR" |
| 103 | + |
| 104 | +echo "Building obs-moq $VERSION for $TARGET (preset: $PRESET)..." |
| 105 | +CONFIGURE_ARGS=() |
| 106 | +# Stamp the plugin's compiled-in version (project version, macOS Info.plist, |
| 107 | +# Windows resource) to match what we're building, not buildspec.json's 0.0.1. |
| 108 | +if [[ -n "$VERSION" ]]; then |
| 109 | + CONFIGURE_ARGS+=("-DPLUGIN_VERSION_OVERRIDE=$VERSION") |
| 110 | +fi |
| 111 | +if [[ -n "$MOQ_RELEASE" ]]; then |
| 112 | + # Empty MOQ_LOCAL forces CMake's release-download branch; MOQ_VERSION and |
| 113 | + # MOQ_TARGET steer it at this target's archive (the presets hard-code an |
| 114 | + # x86_64/stale default). MOQ_ARCHIVE is correct per preset already. |
| 115 | + echo "Linking libmoq release v$MOQ_RELEASE ($TARGET)" |
| 116 | + CONFIGURE_ARGS+=(-DMOQ_LOCAL= "-DMOQ_VERSION=$MOQ_RELEASE" "-DMOQ_TARGET=$TARGET") |
| 117 | +fi |
| 118 | +cmake --preset "$PRESET" ${CONFIGURE_ARGS[@]+"${CONFIGURE_ARGS[@]}"} |
| 119 | +cmake --build --preset "$PRESET" |
| 120 | + |
| 121 | +NAME="obs-moq-${VERSION}-${TARGET}" |
| 122 | +STAGE="$OUTPUT_DIR/$NAME" |
| 123 | +rm -rf "$STAGE" |
| 124 | +mkdir -p "$OUTPUT_DIR" |
| 125 | + |
| 126 | +if [[ "$KIND" == "macos" ]]; then |
| 127 | + # Self-contained loadable bundle; drop into the OBS plugins directory. |
| 128 | + PLUGIN=$(find "$BUILD_DIR" -name 'obs-moq.plugin' -maxdepth 4 -print -quit) |
| 129 | + [[ -n "$PLUGIN" ]] || { |
| 130 | + echo "obs-moq.plugin not found under $BUILD_DIR" >&2 |
| 131 | + exit 1 |
| 132 | + } |
| 133 | + mkdir -p "$STAGE" |
| 134 | + cp -R "$PLUGIN" "$STAGE/" |
| 135 | +else |
| 136 | + # OBS portable-plugin layout: extract into your OBS plugins directory. |
| 137 | + LIB=$(find "$BUILD_DIR" \( -name 'obs-moq.so' -o -name 'obs-moq.dll' \) -print -quit) |
| 138 | + [[ -n "$LIB" ]] || { |
| 139 | + echo "obs-moq.{so,dll} not found under $BUILD_DIR" >&2 |
| 140 | + exit 1 |
| 141 | + } |
| 142 | + mkdir -p "$STAGE/obs-moq/bin/64bit" |
| 143 | + cp "$LIB" "$STAGE/obs-moq/bin/64bit/" |
| 144 | + cp -R "$SCRIPT_DIR/data" "$STAGE/obs-moq/" |
| 145 | +fi |
| 146 | + |
| 147 | +cp "$SCRIPT_DIR/LICENSE" "$STAGE/" |
| 148 | +cp "$SCRIPT_DIR/README.md" "$STAGE/" |
| 149 | + |
| 150 | +# Archive with CMake's tar so we don't depend on zip/gtar being present |
| 151 | +# (notably on the Windows runner). tar.gz on unix, zip on macOS/Windows. |
| 152 | +( |
| 153 | + cd "$OUTPUT_DIR" |
| 154 | + if [[ "$KIND" == "unix" ]]; then |
| 155 | + ARCHIVE="$NAME.tar.gz" |
| 156 | + cmake -E tar czf "$ARCHIVE" "$NAME" |
| 157 | + else |
| 158 | + ARCHIVE="$NAME.zip" |
| 159 | + cmake -E tar cf "$ARCHIVE" --format=zip "$NAME" |
| 160 | + fi |
| 161 | + rm -rf "$NAME" |
| 162 | + echo "Created: $OUTPUT_DIR/$ARCHIVE" |
| 163 | +) |
0 commit comments