Skip to content

Add macOS (x86_64 and arm64) builds #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 68 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -114,15 +114,40 @@ jobs:
owner_type: user
untagged_only: false
keep_latest: 20
extract_macos_sdk:
needs: build_base
runs-on: "macos-12"
name: Extract macOS SDK
steps:
- name: "Load cache"
uses: actions/cache@v4
id: "macos_sdk_cache"
with:
path: ~/MacOSX12.3.sdk.tar.xz
key: MacOS-sdk
save-always: true
continue-on-error: true

- name: "Checkout osxcross"
if: steps.macos_sdk_cache.outputs.cache-hit != 'true'
uses: actions/checkout@v3
with:
repository: tpoechtrager/osxcross

- name: "Extract SDK"
if: steps.macos_sdk_cache.outputs.cache-hit != 'true'
run: |
XCODEDIR=/Applications/Xcode_14.0.1.app ./tools/gen_sdk_package.sh
mv MacOSX12.3.sdk.tar.xz ~
build_target_bases:
name: Build target base image
if: ${{ github.event.inputs.buildOnly != 'true' }}
needs: build_base
needs: extract_macos_sdk
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
target: [win64,linux64,linuxarm64]
target: [win64,linux64,linuxarm64,macos64,macosarm64]
steps:
- name: Checkout
uses: actions/checkout@v3
Expand All @@ -145,6 +170,19 @@ jobs:
echo "gh_repo=${GITHUB_REPOSITORY,,}" >> $GITHUB_OUTPUT
- 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' || 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' || 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 @@ -175,11 +213,24 @@ jobs:
strategy:
fail-fast: false
matrix:
target: [win64,linux64]
target: [win64,linux64,macos64,macosarm64]
variant: [lgpl-godot]
steps:
- name: Checkout
uses: actions/checkout@v3
- name: "Retrieve macOS SDK"
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' || 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: Install buildx
uses: docker/setup-buildx-action@v2
with:
Expand Down Expand Up @@ -228,11 +279,24 @@ jobs:
strategy:
fail-fast: false
matrix:
target: [win64,linux64]
target: [win64,linux64,macos64,macosarm64]
variant: [lgpl-godot]
steps:
- name: Checkout
uses: actions/checkout@v3
- name: "Retrieve macOS SDK"
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' || 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: Login to Docker
uses: docker/login-action@v2
with:
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@
/ffbuild/
/artifacts/
/.cache/

MacOS*sdk.tar.xz
11 changes: 9 additions & 2 deletions 50-vulkan/50-shaderc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,15 @@ ffbuild_dockerbuild() {
# for some reason, this does not get installed...
cp libshaderc_util/libshaderc_util.a "$FFBUILD_PREFIX"/lib

echo "Libs: -lstdc++" >> "$FFBUILD_PREFIX"/lib/pkgconfig/shaderc_combined.pc
echo "Libs: -lstdc++" >> "$FFBUILD_PREFIX"/lib/pkgconfig/shaderc_static.pc
unset CPP_LIB
if [[ $TARGET == macos* ]]; then
CPP_LIB="c++"
else
CPP_LIB="stdc++"
fi

echo "Libs: -l$CPP_LIB" >> "$FFBUILD_PREFIX"/lib/pkgconfig/shaderc_combined.pc
echo "Libs: -l$CPP_LIB" >> "$FFBUILD_PREFIX"/lib/pkgconfig/shaderc_static.pc

cp "$FFBUILD_PREFIX"/lib/pkgconfig/{shaderc_combined,shaderc}.pc

Expand Down
9 changes: 8 additions & 1 deletion 50-vulkan/55-spirv-cross.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@ ffbuild_dockerbuild() {
make -j$(nproc)
make install

unset CPP_LIB
if [[ $TARGET == macos* ]]; then
CPP_LIB="c++"
else
CPP_LIB="stdc++"
fi

cat >"$FFBUILD_PREFIX"/lib/pkgconfig/spirv-cross-c-shared.pc <<EOF
prefix=$FFBUILD_PREFIX
exec_prefix=\${prefix}
Expand All @@ -35,7 +42,7 @@ Description: C API for SPIRV-Cross
Version: $VER_FULL

Requires:
Libs: -L\${libdir} -L\${sharedlibdir} -lspirv-cross-c -lspirv-cross-glsl -lspirv-cross-hlsl -lspirv-cross-reflect -lspirv-cross-msl -lspirv-cross-util -lspirv-cross-core -lstdc++
Libs: -L\${libdir} -L\${sharedlibdir} -lspirv-cross-c -lspirv-cross-glsl -lspirv-cross-hlsl -lspirv-cross-reflect -lspirv-cross-msl -lspirv-cross-util -lspirv-cross-core -l\${CPP_LIB}
Cflags: -I\${includedir}
EOF
}
11 changes: 9 additions & 2 deletions 50-vulkan/60-libplacebo.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ ffbuild_dockerbuild() {
)
fi

if [[ $TARGET == win* || $TARGET == linux* ]]; then
if [[ $TARGET == win* || $TARGET == linux* || $TARGET == macos* ]]; then
myconf+=(
--cross-file=/cross.meson
)
Expand All @@ -55,7 +55,14 @@ ffbuild_dockerbuild() {
ninja -j$(nproc)
ninja install

echo "Libs.private: -lstdc++" >> "$FFBUILD_PREFIX"/lib/pkgconfig/libplacebo.pc
unset CPP_LIB
if [[ $TARGET == macos* ]]; then
CPP_LIB="c++"
else
CPP_LIB="stdc++"
fi

echo "Libs.private: -l$CPP_LIB" >> "$FFBUILD_PREFIX"/lib/pkgconfig/libplacebo.pc
}

ffbuild_configure() {
Expand Down
13 changes: 12 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
# FFmpeg Static Auto-Builds

Static Windows (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 (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.

Linux (arm64) builds are targetting Ubuntu 18.04 (glibc-2.27 + linux-4.15) and anything more recent.
Expand Down Expand Up @@ -32,6 +34,13 @@ Every file corresponds to its respective package.
* bash
* docker

> [!WARNING]
> To compile for macOS, you'll need to provide the SDK (`MacOSX12.3.sdk.tar.xz`) yourself. This can be extracted from a macOS machine or from downloading Xcode by [follow these instructions](https://github.com/tpoechtrager/osxcross?tab=readme-ov-file#packaging-the-sdk).
>
> Once extracted, place the SDK in the following directories, depending on your target:
> - **x86_64** - `images/base-macos64`
> - **arm64** - `images/base-macosarm64`

### Build Image

* `./makeimage.sh target variant [addin [addin] [addin] ...]`
Expand All @@ -47,6 +56,8 @@ On success, the resulting zip file will be in the `artifacts` subdir.
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
5 changes: 5 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ for script in scripts.d/**/*.sh; do
FF_LIBS+=" $(get_output $script libs)"
done

if [[ $TARGET == macos* ]]; then
FF_CFLAGS+=" -mmacosx-version-min=12.3"
FF_CXXFLAGS+=" -mmacosx-version-min=12.3"
fi

FF_CONFIGURE="$(xargs <<< "$FF_CONFIGURE")"
FF_CFLAGS="$(xargs <<< "$FF_CFLAGS")"
FF_CXXFLAGS="$(xargs <<< "$FF_CXXFLAGS")"
Expand Down
39 changes: 39 additions & 0 deletions images/base-macos64/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 x86_64-apple-darwin

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

ENV FFBUILD_TOOLCHAIN=x86_64-apple-darwin21.4
ENV PATH="/opt/osxcross/target/bin:${PATH}" \
FFBUILD_TARGET_FLAGS="--pkg-config=pkg-config --cross-prefix=${FFBUILD_TOOLCHAIN}- --arch=x86_64 --target-os=darwin" \
FFBUILD_CROSS_PREFIX="${FFBUILD_TOOLCHAIN}-" \
FFBUILD_RUST_TARGET="x86_64-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-macos64/cross.meson
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[binaries]
c = 'x86_64-apple-darwin21.4-clang'
cpp = 'x86_64-apple-darwin21.4-clang++'
ld = 'x86_64-apple-darwin21.4-ld'
ar = 'x86_64-apple-darwin21.4-ar'
ranlib = 'x86_64-apple-darwin21.4-ranlib'
strip = 'x86_64-apple-darwin21.4-strip'

[host_machine]
system = 'darwin'
cpu_family = 'x86_64'
cpu = 'x86_64'
endian = 'little'
11 changes: 11 additions & 0 deletions images/base-macos64/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 x86_64)

set(triple x86_64-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)
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)
3 changes: 2 additions & 1 deletion images/base/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ RUN \
gperf itstool ragel libc6-dev libssl-dev \
gtk-doc-tools gobject-introspection gawk \
ocaml ocamlbuild libnum-ocaml-dev indent p7zip-full \
python3-distutils python3-jinja2 python3-jsonschema python3-apt python-is-python3 && \
python3-distutils python3-jinja2 python3-jsonschema python3-apt python-is-python3 \
zlib1g-dev && \
apt-get -y clean && \
git config --global user.email "builder@localhost" && \
git config --global user.name "Builder" && \
Expand Down
5 changes: 4 additions & 1 deletion scripts.d/20-libiconv.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
SCRIPT_REPO="https://git.savannah.gnu.org/git/libiconv.git"
SCRIPT_COMMIT="6e2b31f6d66739c5abd850338ea68c6bd2012812"

# macOS has iconv in the system, but this one is GNU's iconv. This creates name clash between iconv and libiconv, and
# linker fails to find the correct one. More info at https://stackoverflow.com/questions/57734434/libiconv-or-iconv-undefined-symbol-on-mac-osx
ffbuild_enabled() {
if [[ $TARGET == macos* ]]; then return -1; fi
return 0
}

Expand All @@ -25,7 +28,7 @@ ffbuild_dockerbuild() {
--with-pic
)

if [[ $TARGET == win* || $TARGET == linux* ]]; then
if [[ $TARGET == win* || $TARGET == linux* || $TARGET == macos* ]]; then
myconf+=(
--host="$FFBUILD_TOOLCHAIN"
)
Expand Down
Loading