From 58ed2725fa0d0768100db2c94590c27831653b29 Mon Sep 17 00:00:00 2001 From: david Date: Thu, 1 Oct 2026 01:54:20 +0200 Subject: [PATCH] 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- (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). --- .github/workflows/build-macos-arch.yml | 91 ------------------ .github/workflows/build-macos.yml | 79 +++++++++++----- ci/build-libmpv-macos.sh | 124 ++++++++++++++++--------- 3 files changed, 133 insertions(+), 161 deletions(-) delete mode 100644 .github/workflows/build-macos-arch.yml diff --git a/.github/workflows/build-macos-arch.yml b/.github/workflows/build-macos-arch.yml deleted file mode 100644 index 72be3c3..0000000 --- a/.github/workflows/build-macos-arch.yml +++ /dev/null @@ -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 }} \ No newline at end of file diff --git a/.github/workflows/build-macos.yml b/.github/workflows/build-macos.yml index 680dfbd..5559d54 100644 --- a/.github/workflows/build-macos.yml +++ b/.github/workflows/build-macos.yml @@ -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-/, the meson + # build dir, and the self-contained dylib into mpv/artifact-/. + - 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 \ No newline at end of file + 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 }} \ No newline at end of file diff --git a/ci/build-libmpv-macos.sh b/ci/build-libmpv-macos.sh index fa7aa44..0a9d88b 100644 --- a/ci/build-libmpv-macos.sh +++ b/ci/build-libmpv-macos.sh @@ -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-/. +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" </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")" \ No newline at end of file +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 \ No newline at end of file