Skip to content

Commit

Permalink
Add build support for macOS (x86_64)
Browse files Browse the repository at this point in the history
  • Loading branch information
rsubtil committed Mar 5, 2024
1 parent 0e1b975 commit a11f514
Show file tree
Hide file tree
Showing 40 changed files with 276 additions and 44 deletions.
51 changes: 46 additions & 5 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
steps:
- name: Repo Check
run: |
if [[ "$GITHUB_REPOSITORY" != "EIRTeam/FFmpeg-Builds" ]]; then
if [[ "$GITHUB_REPOSITORY" != "retrohub-org/FFmpeg-Builds" ]]; then
echo "When forking this repository to make your own builds, you have to adjust this check."
echo "When doing so make sure to randomize the scheduled cron time above, in order to spread out the various build times as much as possible."
echo "This has been put in place due to the enormous amounts of traffic hundreds/thousands of parallel builds can cause on external infrastructure."
Expand Down 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: "cache"
with:
path: /MacOSX12.3.sdk.tar.xz
key: MacOS-sdk
save-always: true
continue-on-error: true

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

- name: "Extract SDK"
if: steps.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]
steps:
- name: Checkout
uses: actions/checkout@v3
Expand Down Expand Up @@ -175,9 +200,17 @@ jobs:
strategy:
fail-fast: false
matrix:
target: [win64,linux64]
target: [win64,linux64,macos64]
variant: [lgpl-godot]
steps:
- name: "Retrieve macOS SDK"
if: ${{ matrix.target == 'macos64' }}
uses: actions/cache@v4
id: "cache-sdk"
with:
path: /MacOSX12.3.sdk.tar.xz
key: MacOS-sdk
continue-on-error: false
- name: Checkout
uses: actions/checkout@v3
- name: Install buildx
Expand Down Expand Up @@ -228,9 +261,17 @@ jobs:
strategy:
fail-fast: false
matrix:
target: [win64,linux64]
target: [win64,linux64,macos64]
variant: [lgpl-godot]
steps:
- name: "Retrieve macOS SDK"
if: ${{ matrix.target == 'macos64' }}
uses: actions/cache@v4
id: "cache-sdk"
with:
path: /MacOSX12.3.sdk.tar.xz
key: MacOS-sdk
continue-on-error: false
- name: Checkout
uses: actions/checkout@v3
- name: Login to Docker
Expand Down
5 changes: 4 additions & 1 deletion .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
strategy:
fail-fast: false
matrix:
target: [win64,linux64,linuxarm64]
target: [win64,linux64,linuxarm64,macos]
variant: [lgpl,gpl 6.0,gpl 5.1,lgpl 6.0,lgpl 5.1,gpl-shared,lgpl-shared,gpl-shared 6.0,gpl-shared 5.1,lgpl-shared 6.0,lgpl-shared 5.1]
quickbuild: [1]
include:
Expand All @@ -30,6 +30,9 @@ jobs:
- target: linuxarm64
variant: gpl
quickbuild: ''
- target: macos
variant: gpl
quickbuild: ''
steps:
- name: Checkout
uses: actions/checkout@v3
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
5 changes: 4 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 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)

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 @@ -47,6 +49,7 @@ 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)
* `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)
5 changes: 3 additions & 2 deletions images/base/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@ RUN \
xxd pkgconf curl wget unzip git subversion mercurial \
autoconf automake libtool libtool-bin autopoint gettext cmake clang meson ninja-build \
texinfo texi2html help2man flex bison groff \
gperf itstool ragel libc6-dev libssl-dev \
gperf itstool ragel 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, and this one is GNU's iconv. This creates name class between iconb 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
2 changes: 1 addition & 1 deletion scripts.d/20-libxml2.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ ffbuild_dockerbuild() {
--enable-static
)

if [[ $TARGET == win* || $TARGET == linux* ]]; then
if [[ $TARGET == win* || $TARGET == linux* || $TARGET == macos* ]]; then
myconf+=(
--host="$FFBUILD_TOOLCHAIN"
)
Expand Down
4 changes: 3 additions & 1 deletion scripts.d/20-zlib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@ ffbuild_dockerbuild() {
--static
)

export AR="${FFBUILD_CROSS_PREFIX}ar"
if [[ $TARGET == win* || $TARGET == linux* ]]; then
export CC="${FFBUILD_CROSS_PREFIX}gcc"
export AR="${FFBUILD_CROSS_PREFIX}ar"
elif [[ $TARGET == macos* ]]; then
export CC="${FFBUILD_CROSS_PREFIX}clang"
else
echo "Unknown target"
return -1
Expand Down
2 changes: 1 addition & 1 deletion scripts.d/25-fftw3.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ ffbuild_dockerbuild() {
)
fi

if [[ $TARGET == win* || $TARGET == linux* ]]; then
if [[ $TARGET == win* || $TARGET == linux* || $TARGET == macos* ]]; then
myconf+=(
--host="$FFBUILD_TOOLCHAIN"
)
Expand Down
2 changes: 1 addition & 1 deletion scripts.d/25-fribidi.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ ffbuild_dockerbuild() {
-Dtests=false
)

if [[ $TARGET == win* || $TARGET == linux* ]]; then
if [[ $TARGET == win* || $TARGET == linux* || $TARGET == macos* ]]; then
myconf+=(
--cross-file=/cross.meson
)
Expand Down
2 changes: 1 addition & 1 deletion scripts.d/25-gmp.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,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
2 changes: 1 addition & 1 deletion scripts.d/25-libogg.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,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
5 changes: 5 additions & 0 deletions scripts.d/25-openssl.sh
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ ffbuild_dockerbuild() {
--cross-compile-prefix="$FFBUILD_CROSS_PREFIX"
linux-aarch64
)
elif [[ $TARGET == macos64 ]]; then
myconf+=(
--cross-compile-prefix="$FFBUILD_CROSS_PREFIX"
darwin64-x86_64-cc
)
else
echo "Unknown target"
return -1
Expand Down
2 changes: 1 addition & 1 deletion scripts.d/25-xz.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,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

0 comments on commit a11f514

Please sign in to comment.