Skip to content

Commit

Permalink
Add build support for macOS (arm64)
Browse files Browse the repository at this point in the history
  • Loading branch information
rsubtil committed Mar 6, 2024
1 parent cc0abad commit 036517d
Show file tree
Hide file tree
Showing 9 changed files with 109 additions and 13 deletions.
25 changes: 14 additions & 11 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ jobs:
strategy:
fail-fast: false
matrix:
target: [win64,linux64,linuxarm64,macos64]
target: [win64,linux64,linuxarm64,macos64,macosarm64]
steps:
- name: Checkout
uses: actions/checkout@v3
Expand All @@ -171,17 +171,18 @@ jobs:
- name: Stop Commands
run: T="$(echo -n ${{ github.token }} | sha256sum | head -c 64)" && echo -e "::add-mask::${T}\n::stop-commands::${T}"
- name: "Retrieve macOS SDK"
if: ${{ matrix.target == 'macos64' }}
if: ${{ matrix.target == 'macos64' || matrix.target == 'macosarm64' }}
uses: actions/cache@v4
id: "cache-sdk"
with:
path: ~/MacOSX12.3.sdk.tar.xz
key: MacOS-sdk
continue-on-error: false
- name: "Setup macOS SDK"
if: ${{ matrix.target == 'macos64' }}
if: ${{ matrix.target == 'macos64' || matrix.target == 'macosarm64' }}
run: |
cp ~/MacOSX12.3.sdk.tar.xz images/base-macos64/MacOSX12.3.sdk.tar.xz
cp ~/MacOSX12.3.sdk.tar.xz images/base-macosarm64/MacOSX12.3.sdk.tar.xz
- name: Build target base image
uses: docker/build-push-action@v3
with:
Expand Down Expand Up @@ -212,23 +213,24 @@ jobs:
strategy:
fail-fast: false
matrix:
target: [win64,linux64,macos64]
target: [win64,linux64,macos64,macosarm64]
variant: [lgpl-godot]
steps:
- name: Checkout
uses: actions/checkout@v3
- name: "Retrieve macOS SDK"
if: ${{ matrix.target == 'macos64' }}
if: ${{ matrix.target == 'macos64' || matrix.target == 'macosarm64' }}
uses: actions/cache@v4
id: "cache-sdk"
with:
path: ~/MacOSX12.3.sdk.tar.xz
key: MacOS-sdk
continue-on-error: false
- name: "Setup macOS SDK"
if: ${{ matrix.target == 'macos64' }}
if: ${{ matrix.target == 'macos64' || matrix.target == 'macosarm64' }}
run: |
ln -s ~/MacOSX12.3.sdk.tar.xz images/base-macos64/MacOSX12.3.sdk.tar.xz
cp ~/MacOSX12.3.sdk.tar.xz images/base-macos64/MacOSX12.3.sdk.tar.xz
cp ~/MacOSX12.3.sdk.tar.xz images/base-macosarm64/MacOSX12.3.sdk.tar.xz
- name: Install buildx
uses: docker/setup-buildx-action@v2
with:
Expand Down Expand Up @@ -277,23 +279,24 @@ jobs:
strategy:
fail-fast: false
matrix:
target: [win64,linux64,macos64]
target: [win64,linux64,macos64,macosarm64]
variant: [lgpl-godot]
steps:
- name: Checkout
uses: actions/checkout@v3
- name: "Retrieve macOS SDK"
if: ${{ matrix.target == 'macos64' }}
if: ${{ matrix.target == 'macos64' || matrix.target == 'macosarm64' }}
uses: actions/cache@v4
id: "cache-sdk"
with:
path: ~/MacOSX12.3.sdk.tar.xz
key: MacOS-sdk
continue-on-error: false
- name: "Setup macOS SDK"
if: ${{ matrix.target == 'macos64' }}
if: ${{ matrix.target == 'macos64' || matrix.target == 'macosarm64' }}
run: |
ln -s ~/MacOSX12.3.sdk.tar.xz images/base-macos64/MacOSX12.3.sdk.tar.xz
cp ~/MacOSX12.3.sdk.tar.xz images/base-macos64/MacOSX12.3.sdk.tar.xz
cp ~/MacOSX12.3.sdk.tar.xz images/base-macosarm64/MacOSX12.3.sdk.tar.xz
- name: Login to Docker
uses: docker/login-action@v2
with:
Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# FFmpeg Static Auto-Builds

Static Windows (x86_64), macOS (x86_64) and Linux (x86_64) Builds of ffmpeg master and latest release branch.
Static Windows (x86_64), macOS (x86_64 and arm64) and Linux (x86_64) Builds of ffmpeg master and latest release branch.

Windows builds are targetting Windows 7 and newer.

macOS builds are targetting macOS 12.3 and newer (Monterey - darwin21.4)
macOS (x86_64 and arm64) builds are targetting macOS 12.3 and newer (Monterey - darwin21.4)

Linux (x86_64) builds are targetting Ubuntu 16.04 (glibc-2.23 + linux-4.4) and anything more recent.

Expand Down Expand Up @@ -50,6 +50,7 @@ Available targets:
* `win64` (x86_64 Windows)
* `win32` (x86 Windows)
* `macos64` (x86_64 macOS)
* `macosarm64` (arm64 macOS)
* `linux64` (x86_64 Linux, glibc>=2.23, linux>=4.4)
* `linuxarm64` (arm64 (aarch64) Linux, glibc>=2.27, linux>=4.15)

Expand Down
39 changes: 39 additions & 0 deletions images/base-macosarm64/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
ARG GH_REPO=ghcr.io/btbn/ffmpeg-builds
FROM $GH_REPO/base:latest

RUN --mount=src=MacOSX12.3.sdk.tar.xz,dst=/sdk.tar.xz \
git clone https://github.com/tpoechtrager/osxcross.git /opt/osxcross && \
cd /opt/osxcross && \
git fetch --all && \
git checkout ff8d100f3f026b4ffbe4ce96d8aac4ce06f1278b && \
ln -s /sdk.tar.xz /opt/osxcross/tarballs/MacOSX12.3.sdk.tar.xz && \
UNATTENDED=1 ./build.sh

RUN rustup target add aarch64-apple-darwin

ADD toolchain.cmake /toolchain.cmake
ADD cross.meson /cross.meson

ENV FFBUILD_TOOLCHAIN=aarch64-apple-darwin21.4
ENV PATH="/opt/osxcross/target/bin:${PATH}" \
FFBUILD_TARGET_FLAGS="--pkg-config=pkg-config --cross-prefix=${FFBUILD_TOOLCHAIN}- --arch=aarch64 --target-os=darwin" \
FFBUILD_CROSS_PREFIX="${FFBUILD_TOOLCHAIN}-" \
FFBUILD_RUST_TARGET="aarch64-apple-darwin" \
FFBUILD_PREFIX=/opt/ffbuild \
FFBUILD_CMAKE_TOOLCHAIN=/toolchain.cmake \
PKG_CONFIG=pkg-config \
PKG_CONFIG_LIBDIR=/opt/ffbuild/lib/pkgconfig:/opt/ffbuild/share/pkgconfig \
CC="${FFBUILD_TOOLCHAIN}-clang" \
CXX="${FFBUILD_TOOLCHAIN}-clang++" \
LD="${FFBUILD_TOOLCHAIN}-ld" \
AR="${FFBUILD_TOOLCHAIN}-ar" \
RANLIB="${FFBUILD_TOOLCHAIN}-ranlib" \
NM="${FFBUILD_TOOLCHAIN}-nm" \
## zlib produces test files with off64_t variables. There is no support for _LARGE_FILE64_SOURCE / _FILE_OFFSET_BITS
## flags in Clang yet: https://github.com/llvm/llvm-project/issues/77376
## So, for now we redefine this type to int64_t
CFLAGS="-mmacosx-version-min=12.3 -Doff64_t=int64_t -I/opt/ffbuild/include -O2 -pipe -fPIC -DPIC -pthread" \
CXXFLAGS="-mmacosx-version-min=12.3 -I/opt/ffbuild/include -O2 -pipe -fPIC -DPIC -pthread" \
LDFLAGS="-L/opt/ffbuild/lib -O2 -pipe -pthread -lm" \
STAGE_CFLAGS="-fvisibility=hidden" \
STAGE_CXXFLAGS="-fvisibility=hidden"
13 changes: 13 additions & 0 deletions images/base-macosarm64/cross.meson
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[binaries]
c = 'aarch64-apple-darwin21.4-clang'
cpp = 'aarch64-apple-darwin21.4-clang++'
ld = 'aarch64-apple-darwin21.4-ld'
ar = 'aarch64-apple-darwin21.4-ar'
ranlib = 'aarch64-apple-darwin21.4-ranlib'
strip = 'aarch64-apple-darwin21.4-strip'

[host_machine]
system = 'darwin'
cpu_family = 'aarch64'
cpu = 'aarch64'
endian = 'little'
11 changes: 11 additions & 0 deletions images/base-macosarm64/toolchain.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
set(CMAKE_SYSTEM_NAME Darwin)
set(CMAKE_SYSTEM_PROCESSOR aarch64)

set(triple aarch64-apple-darwin21.4)

set(CMAKE_C_COMPILER ${triple}-clang)
set(CMAKE_CXX_COMPILER ${triple}-clang++)
set(CMAKE_RANLIB ${triple}-ranlib)
set(CMAKE_AR ${triple}-ar)

set(CMAKE_OSX_DEPLOYMENT_TARGET 12.3)
5 changes: 5 additions & 0 deletions scripts.d/25-openssl.sh
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ ffbuild_dockerbuild() {
--cross-compile-prefix="$FFBUILD_CROSS_PREFIX"
darwin64-x86_64-cc
)
elif [[ $TARGET == macosarm64 ]]; then
myconf+=(
--cross-compile-prefix="$FFBUILD_CROSS_PREFIX"
darwin64-arm64-cc
)
else
echo "Unknown target"
return -1
Expand Down
5 changes: 5 additions & 0 deletions scripts.d/50-libvpx.sh
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ ffbuild_dockerbuild() {
--target=x86_64-darwin21-gcc
)
export CROSS="$FFBUILD_CROSS_PREFIX"
elif [[ $TARGET == macosarm64 ]]; then
myconf+=(
--target=arm64-darwin21-gcc
)
export CROSS="$FFBUILD_CROSS_PREFIX"
else
echo "Unknown target"
return -1
Expand Down
6 changes: 6 additions & 0 deletions scripts.d/50-openh264.sh
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ ffbuild_dockerbuild() {
ARCH=x86_64
STATIC_LDFLAGS=-lc++
)
elif [[ $TARGET == macosarm64 ]]; then
myconf+=(
OS=darwin
ARCH=arm64
STATIC_LDFLAGS=-lc++
)
else
echo "Unknown target"
return -1
Expand Down
13 changes: 13 additions & 0 deletions variants/macosarm64-lgpl-godot.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash
source "$(dirname "$BASH_SOURCE")"/macos-install-shared-godot.sh
source "$(dirname "$BASH_SOURCE")"/defaults-lgpl-shared.sh
source "$(dirname "$BASH_SOURCE")"/lgpl-godot.sh

FFBUILD_TOOLCHAIN=arm64-apple-darwin21.4

FF_CONFIGURE+=" --cc=${FFBUILD_TOOLCHAIN}-clang --cxx=${FFBUILD_TOOLCHAIN}-clang++ --install-name-dir=@loader_path"

TOOLBOX="--enable-videotoolbox"
NEON="--enable-neon"

FF_CONFIGURE+=" $TOOLBOX $NEON"

0 comments on commit 036517d

Please sign in to comment.