mpv-player / mpv-player/mpv

can't cross build x86_64 mpv on a arm64 macOS

Open
#15,562 14 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

core:meson
Dominant language
C
Stars
37k
Forks
3.5k
Avg merge
1d 10h
Merged PRs (30d)
22

Description

Important Information
- mpv version: git master
- Platform version: arm64 mac
- Meson version: latest
Reproduction Steps

My repo: https://github.com/eko5624/mpv-mac/tree/cross

failed log:
https://github.com/eko5624/mpv-mac/actions/runs/12462323821/job/34787841907

sucessed log:
https://github.com/eko5624/mpv-mac/actions/runs/12464492354/job/34788650939

workaround:

cd mpv
ln -s /PATH/TO/include/libplacebo libplacebo
ln -s /PATH/TO/include/libavutil libavutil
ln -s /PATH/TO/include/vulkan vulkan
ln -s /PATH/TO/include/vk_video vk_video
Expected Behavior

build without workaround

Actual Behavior

This is my env setting.

build env:

#!/hint/bash

DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
TOOLS="$DIR/tools"
PACKAGES="$DIR/packages"
WORKSPACE="$DIR/workspace"
mkdir -p "$TOOLS"
mkdir -p "$PACKAGES"
mkdir -p "$WORKSPACE"
PATH="${TOOLS}/bin:$PATH"
 
if [ "$ARCHS" == "x86_64" ]; then
  ARCH="x86_64"
  if [ "$(uname -m)" != "x86_64" ]; then
    BUILD_HOST="--host=x86_64-apple-darwin --target=x86_64-apple-macos11.0"
  else
    BUILD_HOST=""  
  fi  
elif [ "$ARCHS" == "arm64" ]; then
  ARCH="aarch64"
  if [ "$(uname -m)" != "arm64" ]; then
    BUILD_HOST="--host=aarch64-apple-darwin --target=arm64-apple-macos11.0"
    X265_CMAKEFLAGS="-DENABLE_NEON=OFF" #fix cross build x265 arm64 library on x86_64 macOS
  else  
    BUILD_HOST=""
  fi
fi

CC="clang"
CXX="clang++"
CPP="clang -E"
CXXCPP="clang++ -E"
MACOSX_TARGET="11.0"
MACOSX_DEPLOYMENT_TARGET="11.0"
SWIFT_FLAGS="-target $ARCHS-apple-macosx11.0"
SDKROOT="/Applications/Xcode_15.2.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk"
XCTOOLCHAIN="/Applications/Xcode_15.2.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/"
CFLAGS="-arch $ARCHS -target $ARCHS-apple-macos11.0 -isysroot $SDKROOT -mmacosx-version-min=11.0 -I$WORKSPACE/include -Wno-int-conversion"
LDFLAGS="-arch $ARCHS -target $ARCHS-apple-macos11.0 -isysroot $SDKROOT -mmacosx-version-min=11.0 -L$WORKSPACE/lib -Wl,-ld_classic -framework CoreFoundation"
CXXFLAGS="$CFLAGS"
CPPFLAGS="$CFLAGS"
EXTRALIBS="-ldl -lpthread -lm -lz -lc++"

PKG_CONFIG="pkgconf --static"
PKG_CONFIG_PATH="$WORKSPACE/lib/pkgconfig"

LIBRARY_PATH="$WORKSPACE/lib"
C_INCLUDE_PATH="$WORKSPACE/include"
CPLUS_INCLUDE_PATH="${C_INCLUDE_PATH}"

CURL_RETRIES="--connect-timeout 60 --retry 5 --retry-delay 5"

# Speed up the process
# Env Var NUMJOBS overrides automatic detection
if [[ -n "$NUMJOBS" ]]; then
  MJOBS="$NUMJOBS"
elif [[ -f /proc/cpuinfo ]]; then
  MJOBS=$(grep -c processor /proc/cpuinfo)
elif [[ "$OSTYPE" == "darwin"* ]]; then
  MJOBS=$(sysctl -n machdep.cpu.thread_count)
  MACOS_LIBTOOL="$(which libtool)" # gnu libtool is installed in this script and need to avoid name conflict
else
  MJOBS=3
fi

messon_cross_x86_64.txt

[constants]
sdkroot = '/Applications/Xcode_15.2.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk'

[host_machine]
system = 'darwin'
cpu_family = 'x86_64'
cpu = 'x86_64'
endian = 'little'

[binaries]
c = ['clang']
cpp = ['clang++']
objc = ['clang']
objcpp = ['clang++']
nm = ['nm']
ar = ['ar']
strings = ['strings']
ranlib = ['ranlib']
strip = ['strip']
pkg-config = ['pkgconf']

[built-in options]
c_args = ['-arch', 'x86_64', '-isysroot', sdkroot, '-mmacosx-version-min=11.0']
cpp_args = ['-arch', 'x86_64', '-isysroot', sdkroot, '-mmacosx-version-min=11.0', '-stdlib=libc++']
objc_args = ['-arch', 'x86_64', '-isysroot', sdkroot, '-mmacosx-version-min=11.0']
objcpp_args = ['-arch', 'x86_64', '-isysroot', sdkroot, '-mmacosx-version-min=11.0', '-stdlib=libc++']
c_link_args = ['-arch', 'x86_64', '-isysroot', sdkroot, '-mmacosx-version-min=11.0']
cpp_link_args = ['-arch', 'x86_64', '-isysroot', sdkroot, '-mmacosx-version-min=11.0']
objc_link_args = ['-arch', 'x86_64', '-isysroot', sdkroot, '-mmacosx-version-min=11.0']
objcpp_link_args = ['-arch', 'x86_64', '-isysroot', sdkroot, '-mmacosx-version-min=11.0']

mpv.sh

#!/bin/bash
set -e

cd "$(dirname "$0")" && cd ..
set -a; source build.env; source ver.sh; set +a

cd $PACKAGES
git clone https://github.com/mpv-player/mpv.git

export CFLAGS="$CFLAGS -Wno-error=deprecated -Wno-error=deprecated-declarations"
export LDFLAGS="$LDFLAGS -Wl,-no_compact_unwind"
cd mpv
#git reset --hard 23843b4aa594dc8c885575f3d237cde3c29398a2
#export TOOLCHAINS=$(/usr/libexec/PlistBuddy -c "Print :CFBundleIdentifier" /Library/Developer/Toolchains/swift-latest.xctoolchain/Info.plist)
if [[ ("$(uname -m)" == "arm64") && ("$ARCHS" == "x86_64") ]] || [[ ("$(uname -m)" == "x86_64") && ("$ARCHS" == "arm64") ]]; then
  ln -s $WORKSPACE/include/libplacebo libplacebo
  ln -s $WORKSPACE/include/libavutil libavutil
  ln -s $WORKSPACE/include/vulkan vulkan
  ln -s $WORKSPACE/include/vk_video vk_video
fi  
meson setup build \
  --buildtype=release \
  --cross-file="$DIR/meson_$ARCHS.txt" \
  -Dwrap_mode=nodownload \
  -Db_lto=true \
  -Db_lto_mode=thin \
  -Dobjc_args="-Wno-error=deprecated -Wno-error=deprecated-declarations" \
  -Dlibmpv=true \
  -Dvulkan=enabled \
  -Diconv=enabled \
  -Dmanpage-build=disabled \
  -Dswift-flags="${SWIFT_FLAGS}"
meson compile -C build
#meson compile -C build macos-bundle

# get latest commit sha
short_sha=$(git rev-parse --short HEAD)
echo $short_sha > build/SHORT_SHA

# bundle mpv
cp -r TOOLS/osxbundle/mpv.app build
cp build/mpv build/mpv.app/Contents/MacOS
cp $WORKSPACE/lib/libluajit-5.1.2.dylib build/mpv.app/Contents/MacOS/lib
#cp $WORKSPACE/lib/libvapoursynth-script.0.dylib build/mpv.app/Contents/MacOS/lib
mkdir -p build/mpv.app/Contents/Frameworks
mkdir -p build/mpv.app/Contents/Resources/vulkan/icd.d
cp $WORKSPACE/lib/libMoltenVK.dylib build/mpv.app/Contents/Frameworks
cp $WORKSPACE/share/vulkan/icd.d/MoltenVK_icd.json build/mpv.app/Contents/Resources/vulkan/icd.d
sed -i "" 's|../../../lib/libMoltenVK.dylib|../../../Frameworks/libMoltenVK.dylib|g' build/mpv.app/Contents/Resources/vulkan/icd.d/MoltenVK_icd.json

mpv_deps=($(otool -L $PACKAGES/mpv/build/mpv.app/Contents/MacOS/mpv | grep -e '\t' | grep -Ev "\/usr\/lib|\/System|@rpath" | awk '{ print $1 }'))
for f in "${mpv_deps[@]}"; do
  sudo install_name_tool -id "@executable_path/lib/$(basename $f)" "build/mpv.app/Contents/MacOS/lib/$(basename $f)"
  sudo install_name_tool -change "$f" "@executable_path/lib/$(basename $f)" build/mpv.app/Contents/MacOS/mpv
done

# setting rpath
rpaths=($(otool -l build/mpv.app/Contents/MacOS/mpv | grep -A2 LC_RPATH | grep path | awk '{ print $2 }'))
for f in "${rpaths[@]}"; do
  sudo install_name_tool -delete_rpath $f build/mpv.app/Contents/MacOS/mpv
done
sudo install_name_tool -add_rpath @executable_path/lib build/mpv.app/Contents/MacOS/mpv


# Codesign mpv.app
codesign --deep -fs - build/mpv.app

cd $DIR
# Zip mpv.app and mpv config files
mkdir mpv
git clone https://github.com/eko5624/mpv-config.git
mv mpv-config/macos_config mpv
cp -r $PACKAGES/mpv/build/mpv.app mpv
cp $PACKAGES/mpv/build/SHORT_SHA mpv
zip -r mpv-$ARCHS-git-$short_sha.zip mpv/*

# Zip libmpv
mkdir -p libmpv/include
cp $PACKAGES/mpv/build/libmpv.2.dylib libmpv
cp $PACKAGES/mpv/build/mpv.app/Contents/MacOS/lib/*.dylib libmpv
cp $PACKAGES/mpv/libmpv/client.h libmpv/include
cp $PACKAGES/mpv/libmpv/stream_cb.h libmpv/include
cp $PACKAGES/mpv/libmpv/render.h libmpv/include
cp $PACKAGES/mpv/libmpv/render_gl.h libmpv/include
zip -r libmpv-$ARCHS-$short_sha.zip libmpv/*

# Zip ffmpeg
mkdir ffmpeg
cp $WORKSPACE/bin/ffmpeg ffmpeg
mv $WORKSPACE/SHORT_SHA ffmpeg
ffmpeg_sha=$(cat ffmpeg/SHORT_SHA)
zip -r ffmpeg-$ARCHS-$ffmpeg_sha.zip ffmpeg/*
Log File

logs_32369201623.zip

I carefully read all instruction and confirm that I did the following:
  • I tested with the latest mpv version to validate that the issue is not already fixed.
  • I provided all required information including system and mpv version.
  • I produced the log file with the exact same set of parameters, and conditions used in "Reproduction Steps".
  • I produced the log file while the behaviors described in "Actual Behavior" were actively observed.
  • I attached the full, untruncated log file.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with mpv.sh and meson_cross_x86_64.txt, then compare the linked failed and successful build logs to identify why the cross-build needs the header symlinks. Verify the result by running the documented x86_64 build on arm64 macOS without those symlinks; done means the build completes without the workaround.

Written by the indexing model from the issue text.

Assessment

Tech stack
c
Domain
build-system
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.