build: rebuild macOS CI as single arm64 runner with x86_64 cross-compile

GitHub's macOS runners are all arm64 now, so the two parallel per-arch
jobs are obsolete: one macos-15 runner builds the arm64 slice natively
and the x86_64 slice via clang --target=x86_64-apple-darwin, then lipo
merges both into the universal libmpv.dylib. The build script is now
parameterized by ARCH, installs every meson dependency into its own
macos_prefix-<arch> (meson's macOS default prefix is /opt/homebrew),
uses release buildtype for the static deps, and disables harfbuzz icu
(the brew icu4c on the runner is arm64-only and must not leak into the
x86_64 slice).
This commit is contained in:
david
2026-10-01 01:54:20 +02:00
parent 4845b5e44f
commit 58ed2725fa
3 changed files with 133 additions and 161 deletions
-91
View File
@@ -1,91 +0,0 @@
name: build-macos-arch
# Builds the self-contained libmpv dylib for one macOS architecture
# (x86_64 on macos-14, arm64 on macos-15) using the vendored build script.
# The merge job in build-macos.yml combines the per-architecture dylibs into
# a universal binary.
on:
workflow_call:
inputs:
arch:
description: Target architecture (x86_64 or arm64)
required: true
type: string
runner:
description: GitHub runner image providing that architecture
required: true
type: string
env:
MPV_REF: v0.41.0
ARCH: ${{ inputs.arch }}
jobs:
build:
runs-on: ${{ inputs.runner }}
env:
CCACHE_BASEDIR: ${{ github.workspace }}
CCACHE_DIR: ${{ github.workspace }}/.ccache
CCACHE_MAXSIZE: 500M
steps:
- name: Check out mpv-natives (build scripts)
uses: actions/checkout@v4
with:
fetch-depth: 1
- name: Check out mpv (pinned tag)
uses: actions/checkout@v4
with:
repository: mpv-player/mpv
ref: ${{ env.MPV_REF }}
path: mpv
fetch-depth: 1
- name: Get time
id: get_time
run: echo "timestamp=$(date +%s)" >> $GITHUB_OUTPUT
- name: Restore ccache
uses: actions/cache/restore@v4
with:
path: ${{ env.CCACHE_DIR }}
key: macos-${{ env.ARCH }}-${{ steps.get_time.outputs.timestamp }}
restore-keys: macos-${{ env.ARCH }}-
- name: Install dependencies
run: |
# PEP 668: pip installs are blocked on the macOS runner, use brew.
brew install ccache nasm ninja meson
# Run the vendored build script from inside the mpv source tree, so the
# native build writes macos_prefix/ and the meson build next to mpv's
# meson.build and produces the self-contained dylib in mpv/artifact/.
- name: Build self-contained libmpv
working-directory: mpv
run: bash "${{ github.workspace }}/ci/build-libmpv-macos.sh"
- name: Print meson log on failure
if: failure()
run: cat mpv/macos_build/meson-logs/meson-log.txt
- name: Collect artifact
run: |
mkdir -p "artifact-macos-${{ env.ARCH }}"
cp -pv mpv/artifact/libmpv-2.dylib "artifact-macos-${{ env.ARCH }}/"
cp -pv mpv/artifact/*.h "artifact-macos-${{ env.ARCH }}/" 2>/dev/null || true
echo "=== contents ==="
ls -l "artifact-macos-${{ env.ARCH }}"
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: mpv-natives-macos-${{ env.ARCH }}-mpv-${{ env.MPV_REF }}
path: artifact-macos-${{ env.ARCH }}
- name: Save ccache
uses: actions/cache/save@v4
if: always()
with:
path: ${{ env.CCACHE_DIR }}
key: macos-${{ env.ARCH }}-${{ steps.get_time.outputs.timestamp }}
+54 -25
View File
@@ -1,9 +1,10 @@
name: build-macos
# Builds a universal (arm64 + x86_64) self-contained libmpv.dylib for macOS
# from mpv source pinned to a release tag. Two native builds run in parallel
# (x86_64 on macos-14, arm64 on macos-15); a merge job combines the two dylibs
# with lipo into one universal library and uploads it.
# from mpv source pinned to a release tag. GitHub's macOS runners are all
# arm64 now, so one arm64 runner builds the arm64 slice natively and the
# x86_64 slice via clang --target=x86_64-apple-darwin; a merge step combines
# both with lipo into one universal library and uploads it.
#
# Every dependency is built static and linked into the one dylib (same
# approach as the Windows build). jlibmpv expects the file name
@@ -22,21 +23,12 @@ env:
MPV_REF: v0.41.0
jobs:
build-x86_64:
uses: ./.github/workflows/build-macos-arch.yml
with:
arch: x86_64
runner: macos-14
build-arm64:
uses: ./.github/workflows/build-macos-arch.yml
with:
arch: arm64
runner: macos-15
merge:
needs: [build-x86_64, build-arm64]
build:
runs-on: macos-15
env:
CCACHE_BASEDIR: ${{ github.workspace }}
CCACHE_DIR: ${{ github.workspace }}/.ccache
CCACHE_MAXSIZE: 500M
steps:
- name: Check out mpv-natives (build scripts)
uses: actions/checkout@v4
@@ -51,19 +43,49 @@ jobs:
path: mpv
fetch-depth: 1
- name: Download architecture artifacts
uses: actions/download-artifact@v4
- name: Get time
id: get_time
run: echo "timestamp=$(date +%s)" >> $GITHUB_OUTPUT
- name: Restore ccache
uses: actions/cache/restore@v4
with:
pattern: mpv-natives-macos-${{ env.MPV_REF }}-*
path: arch
merge-multiple: true
path: ${{ env.CCACHE_DIR }}
key: macos-${{ steps.get_time.outputs.timestamp }}
restore-keys: macos-
- name: Install dependencies
run: |
# PEP 668: pip installs are blocked on the macOS runner, use brew.
brew install ccache nasm ninja meson
# The vendored build script runs from inside the mpv source tree, once
# per architecture. Each run writes macos_prefix-<arch>/, the meson
# build dir, and the self-contained dylib into mpv/artifact-<arch>/.
- name: Build arm64 slice
working-directory: mpv
env:
ARCH: arm64
run: bash "${{ github.workspace }}/ci/build-libmpv-macos.sh"
- name: Build x86_64 slice
working-directory: mpv
env:
ARCH: x86_64
run: bash "${{ github.workspace }}/ci/build-libmpv-macos.sh"
- name: Print meson logs on failure
if: failure()
run: |
cat mpv/macos_build-arm64/meson-logs/meson-log.txt 2>/dev/null || true
cat mpv/macos_build-x86_64/meson-logs/meson-log.txt 2>/dev/null || true
- name: Create universal dylib
run: |
mkdir -p artifact-libmpv
lipo -create \
"arch/x86_64/libmpv-2.dylib" \
"arch/arm64/libmpv-2.dylib" \
mpv/artifact-arm64/libmpv-2.dylib \
mpv/artifact-x86_64/libmpv-2.dylib \
-output artifact-libmpv/libmpv.dylib
lipo -info artifact-libmpv/libmpv.dylib
cp -pv mpv/mpvrender.h mpv/mpv/client.h mpv/ebml_types.h artifact-libmpv/ 2>/dev/null || true
@@ -75,4 +97,11 @@ jobs:
uses: actions/upload-artifact@v4
with:
name: mpv-natives-macos-universal-mpv-${{ env.MPV_REF }}
path: artifact-libmpv
path: artifact-libmpv
- name: Save ccache
uses: actions/cache/save@v4
if: always()
with:
path: ${{ env.CCACHE_DIR }}
key: macos-${{ steps.get_time.outputs.timestamp }}
+79 -45
View File
@@ -3,35 +3,41 @@ set -e
# (The shebang -e is not honored when the workflow invokes us via `bash file`,
# so set -e is repeated here to guarantee fail-fast regardless of caller.)
#
# Build a single self-contained libmpv dylib for macOS on the runner's own
# architecture (x86_64 on macos-14, arm64 on macos-15). The workflow runs
# this script on both runner kinds and merges the two dylibs into a
# universal binary with lipo.
# Build a single self-contained libmpv dylib for macOS for one architecture
# (arm64 natively, or x86_64 via clang --target=x86_64-apple-darwin).
# The workflow runs this script twice on one arm64 runner and merges the two
# dylibs into a universal binary with lipo. (GitHub's macOS runners are all
# arm64 now, so x86_64 must be cross-compiled.)
#
# Recipe: every dependency is built STATIC and linked into the one dylib
# (same approach as ci/build-libmpv-mingw64.sh for Windows). macOS needs no
# cross-compilation: the host Apple Clang builds natively. No iconv is built
# (macOS ships one), no system frameworks are vendored (CoreAudio,
# VideoToolbox, ... are always present on the host).
#
# Vulkan is intentionally NOT built: jlibmpv renders through an externally
# supplied OpenGL context (JOGL + render API) and never uses the Vulkan video
# backend. CoreAudio is the audio output (ao=coreaudio) and VideoToolbox
# provides hardware decode.
# (same approach as ci/build-libmpv-mingw64.sh for Windows). No iconv (macOS
# ships one), no zlib (macOS ships one, universal), no icu (harfbuzz built
# without it - the runner's brew icu is arm64-only and must not leak into
# the x86_64 slice). Vulkan is intentionally NOT built: jlibmpv renders
# through an externally supplied OpenGL context (JOGL + render API).
# CoreAudio is the audio output; VideoToolbox provides hardware decode.
#
# All third-party sources are pinned to the latest stable tag that existed on
# the mpv v0.41.0 release date (2025-12-21), so a rebuild reproduces the same
# binary instead of drifting to git HEAD.
# Target architecture: arm64 (native) or x86_64 (cross).
ARCH=${ARCH:-arm64}
# The mpv source tree is the current working directory (checked out by CI at
# MPV_REF). Everything is built next to it under macos_prefix/.
prefix_dir=$PWD/macos_prefix
# MPV_REF). Everything is built next to it under macos_prefix-<arch>/.
prefix_dir=$PWD/macos_prefix-$ARCH
mkdir -p "$prefix_dir"
wget="wget -nc --progress=bar:force"
export CC=cc
export CXX=c++
TARGET_FLAG=""
if [ "$ARCH" = "x86_64" ]; then
TARGET_FLAG="--target=x86_64-apple-darwin"
fi
export CC="cc $TARGET_FLAG"
export CXX="c++ $TARGET_FLAG"
export AR=ar
export NM=nm
export RANLIB=ranlib
@@ -40,7 +46,7 @@ export CFLAGS="-O2 -pipe -Wall"
export LDFLAGS=""
# Prefix for the static deps we build ourselves, added additively so the
# system/brew pkg-config files (icu-uc, zlib, ...) are still visible.
# system pkg-config files (zlib, ...) are still visible.
export PKG_CONFIG_PATH="$prefix_dir/lib/pkgconfig${PKG_CONFIG_PATH:+:$PKG_CONFIG_PATH}"
# --- Pinned dependency versions -------------------------------------------
@@ -58,6 +64,29 @@ HARFBUZZ_VER=12.2.0
# into the single libmpv dylib. (mpv's own script ships shared libs instead.)
commonflags="--disable-shared --enable-static"
# Meson cross file for the x86_64 slice. arm64 is a plain native build.
MESON_EXTRA=""
if [ "$ARCH" = "x86_64" ]; then
cat >"$prefix_dir/crossfile" <<EOF
[built-in options]
buildtype = 'release'
[binaries]
c = ['cc', '--target=x86_64-apple-darwin']
cpp = ['c++', '--target=x86_64-apple-darwin']
ar = 'ar'
strip = 'strip'
pkgconfig = 'pkg-config'
pkg-config = 'pkg-config'
nasm = 'nasm'
[host_machine]
system = 'darwin'
cpu_family = 'x86_64'
cpu = 'x86_64'
endian = 'little'
EOF
MESON_EXTRA="--cross-file $prefix_dir/crossfile"
fi
function builddir {
[ -d "$1/builddir" ] && rm -rf "$1/builddir"
mkdir -p "$1/builddir"
@@ -67,10 +96,10 @@ function builddir {
function makeplusinstall {
if [ -f build.ninja ]; then
ninja
DESTDIR="$prefix_dir" ninja install
ninja install
else
make -j$(sysctl -n hw.ncpu)
make DESTDIR="$prefix_dir" install
make install
fi
}
@@ -106,13 +135,13 @@ function build_if_missing {
fi
}
## mpv's dependencies (all static, native build)
# macOS ships zlib and iconv in the system, so neither is built here.
## mpv's dependencies (all static; macOS ships zlib and iconv in the system)
_dav1d () {
gitpin https://code.videolan.org/videolan/dav1d.git dav1d "$DAV1D_VER"
builddir dav1d
meson setup .. -Denable_{tools,tests}=false -Ddefault_library=static
meson setup .. $MESON_EXTRA --buildtype release -Dprefix="$prefix_dir" \
-Denable_{tools,tests}=false -Ddefault_library=static
makeplusinstall
popd
}
@@ -121,7 +150,8 @@ _dav1d_mark=lib/libdav1d.a
_lcms2 () {
gitpin https://github.com/mm2/Little-CMS.git lcms2 "$LCMS2_VER"
builddir lcms2
meson setup .. -Dtests=disabled -Dutils=false -Ddefault_library=static
meson setup .. $MESON_EXTRA --buildtype release -Dprefix="$prefix_dir" \
-Dtests=disabled -Dutils=false -Ddefault_library=static
makeplusinstall
popd
}
@@ -131,11 +161,9 @@ _ffmpeg () {
gitpin https://github.com/FFmpeg/FFmpeg.git ffmpeg "$FFMPEG_VER"
builddir ffmpeg
local args=(
--pkg-config=pkg-config --target-os=macosx --enable-gpl
--enable-cross-compile \
--extra-cflags="-I$prefix_dir/include" \
--extra-ldflags="-L$prefix_dir/lib" \
$commonflags
--prefix="$prefix_dir" --pkg-config=pkg-config --target-os=macosx
--enable-gpl $commonflags
--cc="$CC" --cxx="$CXX"
--disable-{doc,programs}
--enable-muxer=spdif --enable-encoder=mjpeg,png --enable-libdav1d
)
@@ -148,7 +176,7 @@ _ffmpeg_mark=lib/libavcodec.a
_freetype () {
gettar "https://download.savannah.gnu.org/releases/freetype/freetype-${FREETYPE_VER}.tar.xz"
builddir freetype-${FREETYPE_VER}
meson setup .. -Ddefault_library=static
meson setup .. $MESON_EXTRA --buildtype release -Dprefix="$prefix_dir" -Ddefault_library=static
makeplusinstall
popd
}
@@ -157,7 +185,8 @@ _freetype_mark=lib/libfreetype.a
_fribidi () {
gettar "https://github.com/fribidi/fribidi/releases/download/v${FRIBIDI_VER}/fribidi-${FRIBIDI_VER}.tar.xz"
builddir fribidi-${FRIBIDI_VER}
meson setup .. -D{tests,docs}=false -Ddefault_library=static
meson setup .. $MESON_EXTRA --buildtype release -Dprefix="$prefix_dir" \
-D{tests,docs}=false -Ddefault_library=static
makeplusinstall
popd
}
@@ -166,7 +195,10 @@ _fribidi_mark=lib/libfribidi.a
_harfbuzz () {
gettar "https://github.com/harfbuzz/harfbuzz/releases/download/${HARFBUZZ_VER}/harfbuzz-${HARFBUZZ_VER}.tar.xz"
builddir harfbuzz-${HARFBUZZ_VER}
meson setup .. -Dtests=disabled -Ddefault_library=static
# icu disabled: the runner's brew icu is arm64-only and would poison the
# x86_64 slice; harfbuzz shapes fine without it (built-in unicode data).
meson setup .. $MESON_EXTRA --buildtype release -Dprefix="$prefix_dir" \
-Dtests=disabled -Dutils=false -Dicu=disabled -Ddefault_library=static
makeplusinstall
popd
}
@@ -175,7 +207,7 @@ _harfbuzz_mark=lib/libharfbuzz.a
_libass () {
gitpin https://github.com/libass/libass.git libass "$LIBASS_VER"
builddir libass
meson setup .. -Ddefault_library=static
meson setup .. $MESON_EXTRA --buildtype release -Dprefix="$prefix_dir" -Ddefault_library=static
makeplusinstall
popd
}
@@ -191,7 +223,8 @@ _libplacebo () {
gitpin https://code.videolan.org/videolan/libplacebo.git libplacebo "$LIBPLACEBO_VER"
builddir libplacebo
# opengl enabled (the only renderer jlibmpv uses); vulkan/d3d11 off
meson setup .. -Ddemos=false -Dopengl=enabled -Dd3d11=disabled \
meson setup .. $MESON_EXTRA --buildtype release -Dprefix="$prefix_dir" \
-Ddemos=false -Dopengl=enabled -Dd3d11=disabled \
-Dvulkan=disabled -Dlcms=disabled -Ddefault_library=static
makeplusinstall
popd
@@ -201,14 +234,15 @@ build_if_missing libplacebo
## mpv
build=macos_build
build=macos_build-$ARCH
rm -rf $build
# libmpv itself is the ONE shared object (default_library=shared), linked
# against the static dependency archives built above. No CLI player, no
# tests, no lua/javascript, no vulkan. OpenGL stays (render API via JOGL);
# coreaudio is the audio output; videotoolbox gives hardware decode.
meson setup $build \
# tests, no lua/javascript, no vulkan. OpenGL render API stays (cocoa +
# gl-cocoa are the macOS backend for it); coreaudio is the audio output;
# videotoolbox gives hardware decode.
meson setup $build $MESON_EXTRA \
--buildtype release -Dstrip=true \
-Ddefault_library=shared \
-Dlibmpv=true \
@@ -227,13 +261,13 @@ meson compile -C $build
## Collect the self-contained dylib
mkdir -p artifact
mkdir -p artifact-$ARCH
LIBMPV_DYLIB=$(find $build -maxdepth 1 -name 'libmpv-2.dylib' | head -n 1)
[ -n "$LIBMPV_DYLIB" ] || { echo "ERROR: libmpv dylib not found in $build"; ls -l $build; exit 1; }
cp -pv "$LIBMPV_DYLIB" artifact/
cp -pv "$build"/*.h artifact/ 2>/dev/null || true
cp -pv "$LIBMPV_DYLIB" artifact-$ARCH/
cp -pv "$build"/*.h artifact-$ARCH/ 2>/dev/null || true
echo "=== artifact contents ==="
ls -l artifact
echo "=== libmpv-2.dylib load commands (should be system frameworks only) ==="
otool -L "artifact/$(basename "$LIBMPV_DYLIB")"
echo "=== artifact-$ARCH contents ==="
ls -l artifact-$ARCH
echo "=== libmpv-2.dylib ($ARCH) load commands (should be system frameworks only) ==="
otool -arch $ARCH "artifact-$ARCH/libmpv-2.dylib" -L