#!/bin/bash # Build an LGPL libmpv for macOS on Apple silicon (Wolvix Player, macOS Spike 1). # # scripts/macos/build-libmpv.sh [--neutral] [ROOT] # # ROOT defaults to ~/Desktop/Wolvix/libmpv-build. Run it on the Mac (over SSH is fine; no # window, no sudo). # # Neutral build root (release builds): `--neutral`, or WOLVIX_LIBMPV_NEUTRAL=1 in the # environment. The build folder's path ends up inside the libraries (FFmpeg's configuration # string, mpv's configuration and config-folder default), so a build under the home folder ships # the Mac's account name. In neutral mode ROOT defaults to /Users/Shared/WolvixBuild/libmpv, must # be a real path (no symlink) outside $HOME that does not contain /Users/, and the gate # FAILS if $HOME or /Users/ appears anywhere in the shipped libraries. Without the # switch nothing changes. ROOT is the whole build (tools venv, sources, runs), so nothing in a # neutral build refers back to the home folder; the python-mpv smoke test still uses the build # venv in the home folder, which is only run, never compiled in. # # It needs the Command Line Tools and python.org Python 3.14 at # /Library/Frameworks/Python.framework/Versions/3.14. Nothing from Homebrew or /usr/local is # used: PATH is reset to the build-tools venv plus the system folders, and pkg-config only # sees our own prefix. # # Steps: # 1. check the machine (macOS, arm64, Command Line Tools, free space); # 2. create ROOT/tools-venv (meson, ninja, pkgconf from PyPI, pip --require-hashes) if missing; # 3. download every source tarball into ROOT/sources and check its sha256 against the pins # below (each pin was checked against the upstream GPG signature or the hash the upstream # project published; docs/macos/SPIKE-1-LIBMPV.md lists how); libplacebo is a git clone # checked against the commit of its signed tag and the pinned submodule commits; # 4. build FreeType, FriBidi, HarfBuzz, libass, libplacebo, dav1d, FFmpeg and mpv into a NEW # folder ROOT/runs// (never reused); # 5. copy libmpv.2.dylib and the libraries it needs into /dist, rewrite install names to # @rpath/, leave one LC_RPATH (@loader_path), ad-hoc sign, and run the LGPL gate # (libmpv_gate.py); then load it from a fake app bundle with python-mpv (libmpv_smoke.py) # if the build venv ~/Desktop/Wolvix/venv exists. # # Idempotent and non-destructive: sources are downloaded once and re-checked on every run; # every run gets its own folder; nothing is ever deleted (a bad download stays as *.part and # the script stops). # # Licence: the result must stay LGPL. Never add --enable-gpl, --enable-nonfree or # --enable-version3 to FFmpeg, never set -Dgpl=true for mpv, and never add a dependency that is # GPL (x264, x265, rubberband, ...). The gate fails the build if any of that slips in. dav1d # (software AV1 decoding) is BSD-2-Clause, so --enable-libdav1d keeps FFmpeg LGPL. set -euo pipefail # --------------------------------------------------------------------------------------------- # Pins # --------------------------------------------------------------------------------------------- DEPLOYMENT_TARGET=13.0 # PySide6 6.11.2 wheels need macOS 13 (PLAN.md 6.3) ARCH=arm64 MIN_FREE_GB=20 # DECISIONS.md M-01: a build refuses to start below 20 GB free PY314=/Library/Frameworks/Python.framework/Versions/3.14/bin/python3.14 FREETYPE_VER=2.15.0 FRIBIDI_VER=1.0.18 HARFBUZZ_VER=15.1.0 LIBASS_VER=0.17.5 FFMPEG_VER=9.0.2 MPV_VER=0.42.0 PLACEBO_VER=7.387.0 # dav1d 1.5.5 (2026-11-17), the latest stable release: its sha256 equals the .sha256 file # VideoLAN publishes next to the tarball, and the tarball's .asc is a good signature by the # VideoLAN Release Signing Key below (its current copy, extended to 2027-08-01, is the one in # https://download.videolan.org/pub/keys/7180713BE58D1ADC.asc). DAV1D_VER=1.5.5 DAV1D_SIGNING_KEY=65F7C6B4206BD057A7EB73787180713BE58D1ADC # name|file|sha256|url SOURCES=" freetype|freetype-${FREETYPE_VER}.tar.xz|93cd47eb719c325107f2d3cf087d06299e944c3b48a40b55537302304dea1dd5|https://download.savannah.gnu.org/releases/freetype/freetype-${FREETYPE_VER}.tar.xz fribidi|fribidi-${FRIBIDI_VER}.tar.xz|1de5e8073d035388b71d0b2d452b1da1f8caeea8a7702997b401fe1b6250727f|https://github.com/fribidi/fribidi/releases/download/v${FRIBIDI_VER}/fribidi-${FRIBIDI_VER}.tar.xz harfbuzz|harfbuzz-${HARFBUZZ_VER}.tar.xz|0fc7c565443a5f4be7da65ac5ee5bd737d9b158dc908708b7689a0a5796b0c8d|https://github.com/harfbuzz/harfbuzz/releases/download/${HARFBUZZ_VER}/harfbuzz-${HARFBUZZ_VER}.tar.xz libass|libass-${LIBASS_VER}.tar.xz|2dca25c0e0c837ddf00b52011b3f82cac1e4ddd3ad018227806b0c2288864acc|https://github.com/libass/libass/releases/download/${LIBASS_VER}/libass-${LIBASS_VER}.tar.xz dav1d|dav1d-${DAV1D_VER}.tar.xz|ca96b1d0ba3f01f55de7231d775892b64994ba061aaeeaaa4f662a390b3abf9e|https://downloads.videolan.org/pub/videolan/dav1d/${DAV1D_VER}/dav1d-${DAV1D_VER}.tar.xz ffmpeg|ffmpeg-${FFMPEG_VER}.tar.xz|8c3850283eb25fa026482078a04051e0be17347b09ef81a0849bec15a96e002e|https://ffmpeg.org/releases/ffmpeg-${FFMPEG_VER}.tar.xz mpv|mpv-${MPV_VER}.tar.gz|bcfebbfa2b65a6d88dc97ea18117831072373e38b5785a2afb874ed4df5070dd|https://github.com/mpv-player/mpv/archive/refs/tags/v${MPV_VER}.tar.gz " PLACEBO_REPO=https://code.videolan.org/videolan/libplacebo.git PLACEBO_TAG_OBJECT=451d8ea5661c868562725e6500deda7fdd4e9a1e # signed tag v7.387.0 PLACEBO_COMMIT=275f7dea27924cdd34ab2e6c20e448b6bc4fab65 # The submodules the build uses (not the demo GUI). Vulkan-Headers is needed although Vulkan is # off: libplacebo always compiles src/vulkan/stubs.c, which includes . Headers # only; nothing from it is linked. PLACEBO_SUBMODULES=" 3rdparty/glad=73db193f853e2ee079bf3ca8a64aa2eaf6459043 3rdparty/jinja=15206881c006c79667fe5154fe80c01c65410679 3rdparty/markupsafe=297fc8e356e6836a62087949245d09a28e9f1b13 3rdparty/fast_float=97b54ca9e75f5303507699d27c6b4f4efe4641a1 3rdparty/Vulkan-Headers=74d8a6cb930c68ef617b202c3ff3c59d919e086b " # Upstream mpv commit f32e7ef (merged 2026-11-14, after 0.42.0): without it a libmpv build with # Vulkan disabled fails to compile (mpv issue #18817). MPV_PATCH=mpv-0.42.0-mac-view-no-vulkan.patch MPV_PATCH_SHA256=5664a908d884fae826d0171bfc8c60d4a5e503aeece260f91326302c4d4dd8f8 # Build tools (PyPI, hash-locked). TOOLS_REQUIREMENTS="meson==1.12.1 --hash=sha256:930bc7542cbd9f57009e182fd014eba48cf1a0180a7b9006d2d32d8f168d8b02 ninja==1.13.2 --hash=sha256:fd82e26c0706ad4ab88e5fdd26f3fab0a987a90f810160f6c322e752c6af298b pkgconf==3.0.7.post0 --hash=sha256:47cbf6889d84297b9a4e1741ae016daa4e198f3ec8bab7ce74554cc50b77cce4" # --------------------------------------------------------------------------------------------- # Helpers (bash 3.2: macOS /bin/bash has no associative arrays) # --------------------------------------------------------------------------------------------- SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" NEUTRAL="${WOLVIX_LIBMPV_NEUTRAL:-0}" if [ "${1:-}" = "--neutral" ]; then NEUTRAL=1; shift; fi NEUTRAL_ROOT=/Users/Shared/WolvixBuild/libmpv ACCOUNT_DIR="/Users/$(id -un)" if [ "$NEUTRAL" = 1 ]; then ROOT="${1:-$NEUTRAL_ROOT}" else ROOT="${1:-$HOME/Desktop/Wolvix/libmpv-build}" fi STAMP="$(date -u +%Y%m%d-%H%M%S)" log() { echo "[$(date -u +%H:%M:%S)] $*"; } die() { echo "[$(date -u +%H:%M:%S)] ERROR: $*" >&2; exit 1; } # Any unexpected failure in the main flow says where it happened instead of exiting silently. trap 'rc=$?; echo "[$(date -u +%H:%M:%S)] ERROR: line $LINENO exited with status $rc" >&2' ERR sha256_of() { /usr/bin/shasum -a 256 "$1" | awk '{print $1}'; } lower() { printf '%s' "$1" | tr '[:upper:]' '[:lower:]'; } # secure_path DIR: every folder from DIR up to / belongs to us or to root, and no other user can # change it (a root-owned world-writable folder such as /Users/Shared needs the sticky bit). # Neutral mode only: its default root lives under the shared, world-writable /Users/Shared. secure_path() { local d="$1" uid mode me me="$(id -u)" while :; do uid="$(stat -f %u "$d")"; mode="$(stat -f %Mp%Lp "$d")" # %Lp alone drops the sticky bit if [ "$uid" = "$me" ]; then [ $((0$mode & 022)) -eq 0 ] || die "neutral mode: $d is writable by group or others" elif [ "$uid" = 0 ]; then if [ $((0$mode & 02)) -ne 0 ] && [ $((0$mode & 01000)) -eq 0 ]; then die "neutral mode: $d is world-writable without the sticky bit" fi else die "neutral mode: $d belongs to another user (uid $uid)" fi [ "$d" != / ] || break d="$(dirname "$d")" done } STEPNO=1 # step NAME FUNCTION [ARGS...]: run FUNCTION in a subshell with set -e, output to its own log. step() { local name="$1"; shift local log_file log_file="$LOGS/$(printf '%02d' "$STEPNO")-$name.log" STEPNO=$((STEPNO + 1)) local t0 t1 rc t0=$(date +%s) log "start $name (log: $log_file)" set +e ( set -euo pipefail; "$@" ) >"$log_file" 2>&1 rc=$? set -e t1=$(date +%s) if [ "$rc" -ne 0 ]; then tail -n 60 "$log_file" >&2 die "$name failed (exit $rc) after $((t1 - t0)) s; full log: $log_file" fi echo "$name $((t1 - t0))" >>"$RUN/timings.txt" log "done $name in $((t1 - t0)) s" } # --------------------------------------------------------------------------------------------- # 1. Machine checks # --------------------------------------------------------------------------------------------- [ "$(uname -s)" = Darwin ] || die "macOS only" [ "$(uname -m)" = arm64 ] || die "Apple silicon (arm64) only" case "$ROOT" in *[[:space:]]*) die "ROOT must not contain spaces: $ROOT" ;; esac case "$ROOT" in /opt/homebrew*|/usr/local*) die "ROOT must not be under /opt/homebrew or /usr/local" ;; esac case "$NEUTRAL" in 0|1) ;; *) die "WOLVIX_LIBMPV_NEUTRAL must be 0 or 1, not $NEUTRAL" ;; esac if [ "$NEUTRAL" = 1 ]; then # Checked before anything is created. APFS is case-insensitive by default, so compare in # lower case. case "$ROOT" in /*) ;; *) die "neutral mode: ROOT must be an absolute path: $ROOT" ;; esac case "$ROOT/" in */./*|*/../*|*//*) die "neutral mode: ROOT must not contain ., .. or //: $ROOT" ;; esac case "$(lower "$ROOT")" in "$(lower "$HOME")"|"$(lower "$HOME")"/*) die "neutral mode: ROOT must be outside $HOME: $ROOT" ;; *"$(lower "$ACCOUNT_DIR")"*) die "neutral mode: ROOT must not contain $ACCOUNT_DIR: $ROOT" ;; esac fi [ -x "$PY314" ] || die "python.org Python 3.14 not found at $PY314" [ -f "$SCRIPT_DIR/patches/$MPV_PATCH" ] || die "missing $SCRIPT_DIR/patches/$MPV_PATCH" [ -f "$SCRIPT_DIR/libmpv_gate.py" ] || die "missing $SCRIPT_DIR/libmpv_gate.py" [ "$(sha256_of "$SCRIPT_DIR/patches/$MPV_PATCH")" = "$MPV_PATCH_SHA256" ] || die "$MPV_PATCH has the wrong sha256" SDK="$(/usr/bin/xcrun --sdk macosx --show-sdk-path)" || die "Command Line Tools missing (xcode-select --install)" /usr/bin/xcrun --find clang >/dev/null && /usr/bin/xcrun --find swiftc >/dev/null || die "clang or swiftc missing" mkdir -p "$ROOT" if [ "$NEUTRAL" = 1 ]; then # Meson and the compilers may record the resolved path, so a symlink back into the home # folder would defeat the purpose. PHYS_ROOT="$(cd "$ROOT" && pwd -P)" [ "$PHYS_ROOT" = "$ROOT" ] || die "neutral mode: ROOT must be a real path without symlinks; it resolves to $PHYS_ROOT" secure_path "$ROOT" fi FREE_GB=$(df -g "$ROOT" | awk 'NR==2 {print $4}') [ "$FREE_GB" -ge "$MIN_FREE_GB" ] || die "only ${FREE_GB} GB free under $ROOT; the floor is ${MIN_FREE_GB} GB" SOURCES_DIR="$ROOT/sources" TOOLS_VENV="$ROOT/tools-venv" RUN="$ROOT/runs/$STAMP" [ ! -e "$RUN" ] || die "$RUN already exists" mkdir -p "$SOURCES_DIR" "$RUN" LOGS="$RUN/logs"; SRC="$RUN/src"; BUILD="$RUN/build"; PREFIX="$RUN/prefix"; DIST="$RUN/dist" mkdir -p "$LOGS" "$SRC" "$BUILD" "$PREFIX/lib/pkgconfig" "$RUN/recipe" cp -p "$0" "$SCRIPT_DIR/libmpv_gate.py" "$SCRIPT_DIR/patches/$MPV_PATCH" "$RUN/recipe/" if [ -f "$SCRIPT_DIR/libmpv_smoke.py" ]; then cp -p "$SCRIPT_DIR/libmpv_smoke.py" "$RUN/recipe/"; fi : >"$RUN/timings.txt" T_START=$(date +%s) log "run folder: $RUN" if [ "$NEUTRAL" = 1 ]; then log "neutral build root: the gate fails if $HOME or $ACCOUNT_DIR ships in a library"; fi # --------------------------------------------------------------------------------------------- # 2. Build tools venv # --------------------------------------------------------------------------------------------- if [ ! -x "$TOOLS_VENV/bin/meson" ]; then [ ! -e "$TOOLS_VENV" ] || die "$TOOLS_VENV exists but has no meson; inspect it (not deleted)" log "creating $TOOLS_VENV" printf '%s\n' "$TOOLS_REQUIREMENTS" >"$RUN/recipe/requirements-tools.txt" "$PY314" -m venv "$TOOLS_VENV" "$TOOLS_VENV/bin/python" -m pip install --disable-pip-version-check --require-hashes \ -r "$RUN/recipe/requirements-tools.txt" fi TOOLS_PY="$TOOLS_VENV/bin/python" MESON="$TOOLS_VENV/bin/meson" NINJA="$TOOLS_VENV/bin/ninja" # The wheel's own pkgconf binary, not the Python wrapper (the wrapper's default search path is # /usr/local; PKG_CONFIG_LIBDIR below replaces any default path anyway). PKGCONF="$("$TOOLS_PY" -I -c 'import os, pkgconf; print(os.path.join(os.path.dirname(pkgconf.__file__), ".bin", "pkgconf"))')" [ -x "$PKGCONF" ] || die "pkgconf binary not found at $PKGCONF" # --------------------------------------------------------------------------------------------- # 3. Sources # --------------------------------------------------------------------------------------------- download_verify() { # file sha256 url local file="$1" want="$2" url="$3" local dest="$SOURCES_DIR/$file" if [ -f "$dest" ]; then [ "$(sha256_of "$dest")" = "$want" ] || die "$dest has the wrong sha256 (left in place; move it aside and re-run)" log "cached, sha256 ok: $file" return 0 fi local part="$dest.part.$STAMP" log "downloading $url" /usr/bin/curl -fsSL --proto '=https' --proto-redir '=https' --retry 3 --retry-delay 5 \ --connect-timeout 30 -o "$part" "$url" local got got="$(sha256_of "$part")" [ "$got" = "$want" ] || die "sha256 mismatch for $url: got $got, want $want (kept as $part)" mv "$part" "$dest" log "downloaded, sha256 ok: $file" } verify_libplacebo() { # dir local d="$1" pair path want got got="$(git -C "$d" rev-parse 'HEAD^{commit}')" [ "$got" = "$PLACEBO_COMMIT" ] || die "libplacebo HEAD is $got, want $PLACEBO_COMMIT" got="$(git -C "$d" rev-parse -q --verify "refs/tags/v$PLACEBO_VER" 2>/dev/null || true)" if [ -n "$got" ] && [ "$got" != "$PLACEBO_TAG_OBJECT" ] && [ "$got" != "$PLACEBO_COMMIT" ]; then die "libplacebo tag v$PLACEBO_VER is $got, want $PLACEBO_TAG_OBJECT" fi for pair in $PLACEBO_SUBMODULES; do path="${pair%%=*}"; want="${pair#*=}" got="$(git -C "$d" ls-tree HEAD "$path" | awk '{print $3}')" [ "$got" = "$want" ] || die "libplacebo gitlink $path is $got, want $want" got="$(git -C "$d/$path" rev-parse HEAD)" [ "$got" = "$want" ] || die "libplacebo submodule $path is at $got, want $want" [ -z "$(git -C "$d/$path" status --porcelain)" ] || die "libplacebo submodule $path has local changes" done [ -z "$(git -C "$d" status --porcelain --ignore-submodules=all)" ] || die "libplacebo checkout has local changes" } init_placebo_submodules() { # dir: check out the pinned submodules (idempotent, adds only) local d="$1" paths="" pair for pair in $PLACEBO_SUBMODULES; do paths="$paths ${pair%%=*}"; done # shellcheck disable=SC2086 if ! git -C "$d" -c protocol.file.allow=never submodule update --init --depth 1 --quiet -- $paths; then # shellcheck disable=SC2086 git -C "$d" -c protocol.file.allow=never submodule update --init --quiet -- $paths fi } fetch_libplacebo() { local dest="$SOURCES_DIR/libplacebo-$PLACEBO_VER" if [ ! -d "$dest" ]; then local tmp="$dest.clone.$STAMP" log "cloning libplacebo v$PLACEBO_VER" git -c advice.detachedHead=false clone --quiet --depth 1 --branch "v$PLACEBO_VER" "$PLACEBO_REPO" "$tmp" init_placebo_submodules "$tmp" verify_libplacebo "$tmp" mv "$tmp" "$dest" fi init_placebo_submodules "$dest" verify_libplacebo "$dest" log "libplacebo checkout ok: commit $PLACEBO_COMMIT" } echo "$SOURCES" | while IFS='|' read -r name file sha url; do [ -n "$name" ] || continue download_verify "$file" "$sha" "$url" done fetch_libplacebo # Manifest of exactly what this run built from. { echo "# libmpv build $STAMP (scripts/macos/build-libmpv.sh)" echo "# name | file | sha256 (verified) | url" echo "$SOURCES" | while IFS='|' read -r name file sha url; do if [ -n "$name" ]; then echo "$name | $file | $sha | $url"; fi done echo "libplacebo | git $PLACEBO_REPO tag v$PLACEBO_VER (tag object $PLACEBO_TAG_OBJECT) | commit $PLACEBO_COMMIT |" for pair in $PLACEBO_SUBMODULES; do echo "libplacebo submodule | ${pair%%=*} | commit ${pair#*=} |"; done echo "mpv patch | $MPV_PATCH | $MPV_PATCH_SHA256 | https://github.com/mpv-player/mpv/commit/f32e7ef1e8cd31378a3fb171ed1fa887f8df501f" echo "# dav1d's sha256 = VideoLAN's published dav1d-$DAV1D_VER.tar.xz.sha256; its .asc verified good with the VideoLAN Release Signing Key $DAV1D_SIGNING_KEY" echo "# how the other pins were established: docs/macos/SPIKE-1-LIBMPV.md section 4" if [ "$NEUTRAL" = 1 ]; then echo "# build root: neutral ($ROOT)"; else echo "# build root: default ($ROOT)"; fi echo echo "# tools" echo "macOS $(sw_vers -productVersion) ($(sw_vers -buildVersion)) $(uname -m)" echo "SDK $SDK ($(/usr/bin/xcrun --sdk macosx --show-sdk-version))" echo "clang: $(/usr/bin/xcrun clang --version | head -n 1)" echo "swiftc: $(/usr/bin/xcrun swiftc --version 2>&1 | head -n 1)" echo "meson $("$MESON" --version), ninja $("$NINJA" --version), pkgconf $("$PKGCONF" --version)" echo "git: $(git --version)" echo "python (tools): $("$TOOLS_PY" -V)" } >"$RUN/manifest.txt" # --------------------------------------------------------------------------------------------- # 4. Build # --------------------------------------------------------------------------------------------- JOBS="$(sysctl -n hw.ncpu)" export PATH="$TOOLS_VENV/bin:/usr/bin:/bin:/usr/sbin:/sbin" for v in CPATH C_INCLUDE_PATH CPLUS_INCLUDE_PATH OBJC_INCLUDE_PATH LIBRARY_PATH \ PKG_CONFIG_PATH PKG_CONFIG_SYSROOT_DIR DYLD_LIBRARY_PATH DYLD_FALLBACK_LIBRARY_PATH \ DYLD_FRAMEWORK_PATH DYLD_INSERT_LIBRARIES CMAKE_PREFIX_PATH HOMEBREW_PREFIX \ HOMEBREW_CELLAR CFLAGS CXXFLAGS OBJCFLAGS LDFLAGS CPPFLAGS CC CXX; do unset "$v" done export MACOSX_DEPLOYMENT_TARGET="$DEPLOYMENT_TARGET" export SDKROOT="$SDK" export PKG_CONFIG="$PKGCONF" export PKG_CONFIG_LIBDIR="$PREFIX/lib/pkgconfig" ARCHFLAGS="-arch $ARCH -mmacosx-version-min=$DEPLOYMENT_TARGET -isysroot $SDK" MAPFLAG="-ffile-prefix-map=$RUN=/wolvix-libmpv" LINKFLAGS="$ARCHFLAGS -Wl,-headerpad_max_install_names" NATIVE="$RUN/meson-native.ini" { echo "[binaries]" echo "c = 'clang'" echo "cpp = 'clang++'" echo "objc = 'clang'" echo "objcpp = 'clang++'" echo "ar = 'ar'" echo "strip = 'strip'" echo "pkg-config = '$PKGCONF'" echo echo "[built-in options]" for lang in c cpp objc objcpp; do echo "${lang}_args = ['-arch', '$ARCH', '-mmacosx-version-min=$DEPLOYMENT_TARGET', '-isysroot', '$SDK', '$MAPFLAG']" echo "${lang}_link_args = ['-arch', '$ARCH', '-mmacosx-version-min=$DEPLOYMENT_TARGET', '-isysroot', '$SDK', '-Wl,-headerpad_max_install_names']" done } >"$NATIVE" meson_build() { # name srcdir [meson options...] local name="$1" srcdir="$2" shift 2 "$MESON" setup "$BUILD/$name" "$srcdir" --native-file "$NATIVE" --prefix "$PREFIX" \ --libdir lib --buildtype release --default-library shared --wrap-mode nofallback "$@" "$MESON" compile -C "$BUILD/$name" -j "$JOBS" "$MESON" install -C "$BUILD/$name" --no-rebuild } extract_all() { local name file sha url echo "$SOURCES" | while IFS='|' read -r name file sha url; do [ -n "$name" ] || continue tar -xf "$SOURCES_DIR/$file" -C "$SRC" done /usr/bin/ditto "$SOURCES_DIR/libplacebo-$PLACEBO_VER" "$SRC/libplacebo-$PLACEBO_VER" patch -p1 --forward --batch -d "$SRC/mpv-$MPV_VER" <"$SCRIPT_DIR/patches/$MPV_PATCH" ls -la "$SRC" } build_freetype() { # hvf links an Apple library only recent macOS versions have; zlib is the system one. meson_build freetype "$SRC/freetype-$FREETYPE_VER" \ -Dbrotli=disabled -Dbzip2=disabled -Dharfbuzz=disabled -Dpng=disabled \ -Dzlib=system -Dhvf=disabled -Dtests=disabled } build_fribidi() { meson_build fribidi "$SRC/fribidi-$FRIBIDI_VER" -Ddocs=false -Dbin=false -Dtests=false } build_harfbuzz() { meson_build harfbuzz "$SRC/harfbuzz-$HARFBUZZ_VER" \ -Dfreetype=enabled -Dcoretext=enabled \ -Dglib=disabled -Dgobject=disabled -Dcairo=disabled -Dchafa=disabled -Dicu=disabled \ -Dpng=disabled -Dzlib=disabled -Dgraphite2=disabled -Dfontations=disabled \ -Draster=disabled -Dvector=disabled -Dgpu=disabled -Dgpu_demo=disabled -Dsubset=disabled \ -Dtests=disabled -Dintrospection=disabled -Ddocs=disabled -Dutilities=disabled \ -Dbenchmark=disabled } build_libass() { # Core Text is the font provider (no fontconfig); aarch64 assembly needs no nasm. meson_build libass "$SRC/libass-$LIBASS_VER" \ -Dfontconfig=disabled -Dcoretext=enabled -Ddirectwrite=disabled -Dlibunibreak=disabled \ -Dasm=enabled -Drequire-system-font-provider=true \ -Dtest=disabled -Dcompare=disabled -Dprofile=disabled -Dfuzz=disabled -Dcheckasm=disabled } build_libplacebo() { meson_build libplacebo "$SRC/libplacebo-$PLACEBO_VER" \ -Dvulkan=disabled -Dvk-proc-addr=disabled -Dopengl=enabled -Dd3d11=disabled \ -Dglslang=disabled -Dshaderc=disabled -Dlcms=disabled -Dlibdovi=disabled \ -Dunwind=disabled -Dxxhash=disabled \ -Ddemos=false -Dtests=false -Dbench=false -Dfuzz=false } build_dav1d() { # Software AV1 decoding for Macs without an AV1 hardware decoder (M1, M2). BSD-2-Clause. # Library only: no dav1d tool (it would want xxhash), no tests, examples or docs. aarch64 # assembly goes through clang (no nasm); both bit depths (8 and 10-bit AV1). meson_build dav1d "$SRC/dav1d-$DAV1D_VER" \ -Denable_tools=false -Denable_tests=false -Denable_examples=false -Denable_docs=false \ -Dxxhash_muxer=disabled -Denable_asm=true -Dbitdepths=8,16 } build_ffmpeg() { # LGPL 2.1+: no --enable-gpl, --enable-nonfree or --enable-version3. # --disable-autodetect keeps any stray library on the machine out; it also turns pthreads # off, so threads are enabled explicitly. TLS is Apple's Secure Transport (no OpenSSL). # libavdevice keeps only the lavfi input device (test sources such as av://lavfi:testsrc2). # --extra-libs=-liconv: with --disable-autodetect FFmpeg 9.0.2 probes iconv only in libc, # but on macOS it lives in the system /usr/lib/libiconv.2.dylib; without it the libavcodec # link fails with "_iconv" undefined. # --enable-libdav1d: dav1d is BSD-2-Clause, so the licence stays LGPL (checked below). mkdir -p "$BUILD/ffmpeg" cd "$BUILD/ffmpeg" "$SRC/ffmpeg-$FFMPEG_VER/configure" \ --prefix="$PREFIX" \ --install-name-dir='@rpath' \ --arch=aarch64 --target-os=darwin \ --cc=clang --cxx=clang++ --objcc=clang \ --extra-cflags="$ARCHFLAGS $MAPFLAG" \ --extra-cxxflags="$ARCHFLAGS $MAPFLAG" \ --extra-objcflags="$ARCHFLAGS $MAPFLAG" \ --extra-ldflags="$LINKFLAGS" \ --extra-libs=-liconv \ --pkg-config="$PKGCONF" \ --enable-shared --disable-static --enable-pic \ --disable-programs --disable-doc --disable-debug \ --disable-autodetect --enable-pthreads \ --enable-videotoolbox --enable-audiotoolbox \ --enable-securetransport --enable-network \ --enable-zlib --enable-bzlib --enable-iconv \ --enable-libdav1d \ --disable-indevs --enable-indev=lavfi --disable-outdevs \ | tee "$RUN/ffmpeg-configure-output.txt" grep -q '^License: LGPL version 2.1 or later$' "$RUN/ffmpeg-configure-output.txt" make -j "$JOBS" make install } build_mpv() { meson_build mpv "$SRC/mpv-$MPV_VER" \ -Dgpl=false -Dlibmpv=true -Dcplayer=false -Dtests=false -Dfuzzers=false \ -Dbuild-date=false \ -Dlua=disabled -Djavascript=disabled -Dlibcurl=disabled -Dcplugins=disabled \ -Dlibavdevice=enabled -Diconv=enabled -Dzlib=enabled \ -Dcocoa=enabled -Dgl=enabled -Dplain-gl=enabled -Dgl-cocoa=enabled \ -Dvideotoolbox-gl=enabled -Dswift-build=enabled \ -Dswift-flags="-target $ARCH-apple-macosx$DEPLOYMENT_TARGET" \ -Dcoreaudio=enabled \ -Dmacos-cocoa-cb=disabled -Dmacos-media-player=disabled -Dmacos-touchbar=disabled \ -Dvulkan=disabled -Dvideotoolbox-pl=disabled -Dshaderc=disabled -Dspirv-cross=disabled \ -Dlibbluray=disabled -Dlibarchive=disabled -Duchardet=disabled -Drubberband=disabled \ -Dzimg=disabled -Dlcms2=disabled -Djpeg=disabled -Dvapoursynth=disabled \ -Dsixel=disabled -Dcaca=disabled -Dsubrandr=disabled -Djack=disabled \ -Dmanpage-build=disabled -Dhtml-build=disabled -Dpdf-build=disabled "$MESON" introspect --buildoptions "$BUILD/mpv" >"$RUN/mpv-buildoptions.json" } step extract extract_all step freetype build_freetype step fribidi build_fribidi step harfbuzz build_harfbuzz step libass build_libass step libplacebo build_libplacebo step dav1d build_dav1d step ffmpeg build_ffmpeg step mpv build_mpv # meson's own summary of the mpv configuration (features on and off, user options). sed -n "/^mpv $MPV_VER\$/,/^Found ninja/p" "$LOGS"/*-mpv.log >"$RUN/mpv-meson-summary.txt" || true # --------------------------------------------------------------------------------------------- # 5. Stage, gate, smoke test # --------------------------------------------------------------------------------------------- step stage "$TOOLS_PY" -I "$SCRIPT_DIR/libmpv_gate.py" stage --prefix "$PREFIX" --dist "$DIST" # Neutral mode: the account's home folder must not appear in any shipped library. GATE_NEUTRAL=() if [ "$NEUTRAL" = 1 ]; then GATE_NEUTRAL=(--forbid "$HOME" --forbid "$ACCOUNT_DIR"); fi # (${a[@]+"${a[@]}"}: bash 3.2 calls an empty array unbound under set -u.) step gate "$TOOLS_PY" -I "$SCRIPT_DIR/libmpv_gate.py" gate --dist "$DIST" \ --min-os "$DEPLOYMENT_TARGET" --arch "$ARCH" \ --forbid /opt/homebrew --forbid /usr/local/Cellar --forbid /usr/local/opt \ ${GATE_NEUTRAL[@]+"${GATE_NEUTRAL[@]}"} \ --build-root "$ROOT" cp "$LOGS"/*-gate.log "$RUN/gate-report.txt" (cd "$DIST" && /usr/bin/shasum -a 256 ./*.dylib) >"$RUN/dist-SHA256SUMS.txt" # A fake app bundle (with a space in its name, as the real one will have) to load from. BUNDLE_FW="$RUN/stage/Wolvix Player.app/Contents/Frameworks" mkdir -p "$BUNDLE_FW" /usr/bin/ditto "$DIST" "$BUNDLE_FW" VENV_PY="${WOLVIX_VENV_PY:-$HOME/Desktop/Wolvix/venv/bin/python}" if [ -x "$VENV_PY" ] && [ -f "$SCRIPT_DIR/libmpv_smoke.py" ]; then # Empty environment: proves the set needs no DYLD_* variable and no PATH. step smoke /usr/bin/env -i "$VENV_PY" -I "$SCRIPT_DIR/libmpv_smoke.py" \ "$BUNDLE_FW/libmpv.2.dylib" "$RUN/smoke" cp "$LOGS"/*-smoke.log "$RUN/smoke-report.txt" else log "skipping the python-mpv smoke test (no venv at $VENV_PY)" fi T_END=$(date +%s) echo "total $((T_END - T_START))" >>"$RUN/timings.txt" log "all steps passed in $((T_END - T_START)) s" log "libraries: $DIST" ls -l "$DIST" du -sh "$DIST"