Skip to content

Commit

Permalink
Add initial support for winarm64
Browse files Browse the repository at this point in the history
  • Loading branch information
BtbN committed Mar 19, 2024
1 parent 33079e6 commit 8efdbd5
Show file tree
Hide file tree
Showing 29 changed files with 190 additions and 37 deletions.
5 changes: 3 additions & 2 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,9 @@ cat <<EOF >"$BUILD_SCRIPT"
cd ffmpeg
./configure --prefix=/ffbuild/prefix --pkg-config-flags="--static" \$FFBUILD_TARGET_FLAGS \$FF_CONFIGURE \
--extra-cflags='\$FF_CFLAGS' --extra-cxxflags='\$FF_CXXFLAGS' \
--extra-ldflags='\$FF_LDFLAGS' --extra-ldexeflags='\$FF_LDEXEFLAGS' --extra-libs='\$FF_LIBS' \
--extra-cflags="\$FF_CFLAGS" --extra-cxxflags="\$FF_CXXFLAGS" --extra-libs="\$FF_LIBS" \
--extra-ldflags="\$FF_LDFLAGS" --extra-ldexeflags="\$FF_LDEXEFLAGS" \
--cc="\$CC" --cxx="\$CXX" --ar="\$AR" --ranlib="\$RANLIB" --nm="\$NM" \
--extra-version="\$(date +%Y%m%d)"
make -j\$(nproc) V=1
make install install-doc
Expand Down
53 changes: 53 additions & 0 deletions images/base-winarm64/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
ARG GH_REPO=ghcr.io/btbn/ffmpeg-builds
FROM $GH_REPO/base:latest

RUN \
git clone --filter=blob:none https://github.com/mstorsjo/llvm-mingw /llvm-mingw && cd /llvm-mingw && \
./build-all.sh --disable-lldb --disable-lldb-mi /opt/llvm-mingw && \
cd / && \
rm -rf llvm-mingw

# LLVM/Clang workarounds
RUN \
ln -s windows.h /opt/llvm-mingw/generic-w64-mingw32/include/Windows.h

# Prepare "cross" environment to heavily favour static builds
RUN \
find /opt/llvm-mingw \
-name "*.dll" \
-or -name "*.dll.a" \
-delete && \
mkdir /opt/ffbuild

ENV FFBUILD_TOOLCHAIN=aarch64-w64-mingw32 \
FFBUILD_RUST_TARGET=aarch64-pc-windows-gnullvm

RUN \
rustup default nightly && \
rustup +nightly component add rust-src && \
echo "[unstable]\nbuild-std = [\"core\", \"alloc\", \"std\", \"proc_macro\"]\n" > "$CARGO_HOME"/config.toml && \
echo "[target.$FFBUILD_RUST_TARGET]\nlinker = \"${FFBUILD_TOOLCHAIN}-clang\"\nar = \"${FFBUILD_TOOLCHAIN}-llvm-ar\"\n" >> "$CARGO_HOME"/config.toml

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

ENV PATH="/opt/llvm-mingw/bin:${PATH}" \
FFBUILD_TARGET_FLAGS="--pkg-config=pkg-config --cross-prefix=${FFBUILD_TOOLCHAIN}- --arch=aarch64 --target-os=mingw32" \
FFBUILD_CROSS_PREFIX=${FFBUILD_TOOLCHAIN}- \
FFBUILD_PREFIX=/opt/ffbuild \
FFBUILD_CMAKE_TOOLCHAIN=/toolchain.cmake \
PKG_CONFIG=pkg-config \
PKG_CONFIG_LIBDIR=/opt/ffbuild/lib/pkgconfig:/opt/ffbuild/share/pkgconfig \
COMPILER_SYSROOT=/opt/llvm-mingw/aarch64-w64-mingw32 \
CC="${FFBUILD_TOOLCHAIN}-clang" \
CXX="${FFBUILD_TOOLCHAIN}-clang++" \
LD="${FFBUILD_TOOLCHAIN}-ld" \
AR="${FFBUILD_TOOLCHAIN}-llvm-ar" \
RANLIB="${FFBUILD_TOOLCHAIN}-llvm-ranlib" \
NM="${FFBUILD_TOOLCHAIN}-nm" \
DLLTOOL="${FFBUILD_TOOLCHAIN}-dlltool" \
CFLAGS="-I/opt/ffbuild/include -O2 -pipe -D_FORTIFY_SOURCE=2 -fstack-protector-strong" \
CXXFLAGS="-I/opt/ffbuild/include -O2 -pipe -D_FORTIFY_SOURCE=2 -fstack-protector-strong" \
LDFLAGS="-L/opt/ffbuild/lib -O2 -pipe -fstack-protector-strong" \
STAGE_CFLAGS="" \
STAGE_CXXFLAGS=""
18 changes: 18 additions & 0 deletions images/base-winarm64/cross.meson
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[binaries]
c = 'aarch64-w64-mingw32-clang'
cpp = 'aarch64-w64-mingw32-clang++'
ar = 'aarch64-w64-mingw32-llvm-ar'
ranlib = 'aarch64-w64-mingw32-llvm-ranlib'
strip = 'aarch64-w64-mingw32-strip'
windres = 'aarch64-w64-mingw32-windres'
dlltool = 'aarch64-w64-mingw32-dlltool'
exe_wrapper = ['wine']

[properties]
needs_exe_wrapper = true

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

set(triple aarch64-w64-mingw32)

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

set(CMAKE_SYSROOT /opt/llvm-mingw/${triple})
set(CMAKE_FIND_ROOT_PATH /opt/llvm-mingw /opt/llvm-mingw/${triple} /opt/ffbuild)

set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
12 changes: 9 additions & 3 deletions scripts.d/10-mingw.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@ ffbuild_enabled() {
}

ffbuild_dockerlayer() {
[[ $TARGET == winarm* ]] && return 0
to_df "COPY --from=${SELFLAYER} /opt/mingw/. /"
to_df "COPY --from=${SELFLAYER} /opt/mingw/. /opt/mingw"
}

ffbuild_dockerfinal() {
[[ $TARGET == winarm* ]] && return 0
to_df "COPY --from=${PREVLAYER} /opt/mingw/. /"
}

Expand All @@ -22,17 +24,21 @@ ffbuild_dockerdl() {
}

ffbuild_dockerbuild() {
[[ $TARGET == winarm* ]] && return 0

cd mingw-w64-headers

unset CFLAGS
unset CXXFLAGS
unset LDFLAGS
unset PKG_CONFIG_LIBDIR

GCC_SYSROOT="$(${FFBUILD_CROSS_PREFIX}gcc -print-sysroot)"
if [[ -z "$COMPILER_SYSROOT" ]]; then
COMPILER_SYSROOT="$(${CC} -print-sysroot)/usr"
fi

local myconf=(
--prefix="$GCC_SYSROOT/usr/$FFBUILD_TOOLCHAIN"
--prefix="$COMPILER_SYSROOT"
--host="$FFBUILD_TOOLCHAIN"
--with-default-win32-winnt="0x601"
--with-default-msvcrt=ucrt
Expand All @@ -46,7 +52,7 @@ ffbuild_dockerbuild() {
cd ../mingw-w64-libraries/winpthreads

local myconf=(
--prefix="$GCC_SYSROOT/usr/$FFBUILD_TOOLCHAIN"
--prefix="$COMPILER_SYSROOT"
--host="$FFBUILD_TOOLCHAIN"
--with-pic
--disable-shared
Expand Down
8 changes: 0 additions & 8 deletions scripts.d/20-zlib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,6 @@ ffbuild_dockerbuild() {
--static
)

if [[ $TARGET == win* || $TARGET == linux* ]]; then
export CC="${FFBUILD_CROSS_PREFIX}gcc"
export AR="${FFBUILD_CROSS_PREFIX}ar"
else
echo "Unknown target"
return -1
fi

./configure "${myconf[@]}"
make -j$(nproc)
make install
Expand Down
2 changes: 2 additions & 0 deletions scripts.d/25-fftw3.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ ffbuild_dockerbuild() {
return -1
fi

sed -i 's/windows.h/process.h/' configure.ac

./bootstrap.sh "${myconf[@]}"
make -j$(nproc)
make install
Expand Down
28 changes: 23 additions & 5 deletions scripts.d/25-openssl.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/bin/bash

SCRIPT_REPO="https://github.com/openssl/openssl.git"
SCRIPT_COMMIT="openssl-3.0.13"
SCRIPT_TAGFILTER="openssl-3.0.*"
SCRIPT_COMMIT="openssl-3.2.1"
SCRIPT_TAGFILTER="openssl-3.2.*"

ffbuild_enabled() {
return 0
Expand Down Expand Up @@ -40,6 +40,27 @@ ffbuild_dockerbuild() {
--cross-compile-prefix="$FFBUILD_CROSS_PREFIX"
mingw
)
elif [[ $TARGET == winarm64 ]]; then
myconf+=(
--cross-compile-prefix="$FFBUILD_CROSS_PREFIX"
mingwarm64
)

cat <<EOF >Configurations/50-win-arm-mingw.conf
my %targets = (
"mingwarm64" => {
inherit_from => [ "mingw-common" ],
cflags => "",
sys_id => "MINGWARM64",
bn_ops => add("SIXTY_FOUR_BIT"),
asm_arch => 'aarch64',
uplink_arch => 'armv8',
perlasm_scheme => "win64",
shared_rcflag => "",
multilib => "-arm64",
},
);
EOF
elif [[ $TARGET == linux64 ]]; then
myconf+=(
--cross-compile-prefix="$FFBUILD_CROSS_PREFIX"
Expand All @@ -64,9 +85,6 @@ ffbuild_dockerbuild() {
export AR="${AR/${FFBUILD_CROSS_PREFIX}/}"
export RANLIB="${RANLIB/${FFBUILD_CROSS_PREFIX}/}"

# Actually allow Configure to disable apps
sed -i '/^my @disablables =/ s/$/"apps",/' Configure

./Configure "${myconf[@]}"

sed -i -e "/^CFLAGS=/s|=.*|=${CFLAGS}|" -e "/^LDFLAGS=/s|=[[:space:]]*$|=${LDFLAGS}|" Makefile
Expand Down
2 changes: 2 additions & 0 deletions scripts.d/45-harfbuzz.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ ffbuild_dockerbuild() {
./autogen.sh "${myconf[@]}"
make -j$(nproc)
make install

echo "Libs.private: -lpthread" >> "$FFBUILD_PREFIX"/lib/pkgconfig/harfbuzz.pc
}

ffbuild_configure() {
Expand Down
2 changes: 1 addition & 1 deletion scripts.d/45-vmaf.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ ffbuild_dockerbuild() {
return -1
fi

meson "${myconf[@]}" ../libvmaf
meson "${myconf[@]}" ../libvmaf || cat meson-logs/meson-log.txt
ninja -j"$(nproc)"
ninja install

Expand Down
1 change: 1 addition & 0 deletions scripts.d/50-aom.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ SCRIPT_REPO="https://aomedia.googlesource.com/aom"
SCRIPT_COMMIT="158761dfb40e77f3a54c3b14a596112837baa24b"

ffbuild_enabled() {
[[ $TARGET == winarm64 ]] && return -1
return 0
}

Expand Down
2 changes: 1 addition & 1 deletion scripts.d/50-davs2.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ ffbuild_enabled() {
[[ $VARIANT == lgpl* ]] && return -1
[[ $TARGET == win32 ]] && return -1
# davs2 aarch64 support is broken
[[ $TARGET == linuxarm64 ]] && return -1
[[ $TARGET == *arm64 ]] && return -1
return 0
}

Expand Down
1 change: 1 addition & 0 deletions scripts.d/50-ffnvcodec.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ SCRIPT_COMMIT2="18c24977c67a94d1969993444cf06ff91b0068a7"
SCRIPT_BRANCH2="sdk/11.1"

ffbuild_enabled() {
[[ $TARGET == winarm64 ]] && return -1
return 0
}

Expand Down
1 change: 1 addition & 0 deletions scripts.d/50-kvazaar.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ ffbuild_dockerbuild() {
make install

echo "Cflags.private: -DKVZ_STATIC_LIB" >> "$FFBUILD_PREFIX"/lib/pkgconfig/kvazaar.pc
echo "Libs.private: -lpthread" >> "$FFBUILD_PREFIX"/lib/pkgconfig/kvazaar.pc
}

ffbuild_configure() {
Expand Down
2 changes: 1 addition & 1 deletion scripts.d/50-libjxl/50-libjxl.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ ffbuild_dockerbuild() {
if [[ $TARGET == linux* ]]; then
# our glibc is too old(<2.25), and their detection fails for some reason
export CXXFLAGS="$CXXFLAGS -DVQSORT_GETRANDOM=0 -DVQSORT_SECURE_SEED=0"
elif [[ $TARGET == win* ]]; then
elif [[ $TARGET == win32 || $TARGET == win64 ]]; then
# Fix AVX2 related crash due to unaligned stack memory
export CXXFLAGS="$CXXFLAGS -Wa,-muse-unaligned-vector-move"
export CFLAGS="$CFLAGS -Wa,-muse-unaligned-vector-move"
Expand Down
8 changes: 3 additions & 5 deletions scripts.d/50-libopus.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,16 @@ ffbuild_dockerdl() {
ffbuild_dockerbuild() {
local myconf=(
--prefix="$FFBUILD_PREFIX"
--host="$FFBUILD_TOOLCHAIN"
--disable-shared
--enable-static
--disable-extra-programs
)

if [[ $TARGET == win* || $TARGET == linux* ]]; then
if [[ $TARGET == winarm* ]]; then
myconf+=(
--host="$FFBUILD_TOOLCHAIN"
--disable-rtcd
)
else
echo "Unknown target"
return -1
fi

./configure "${myconf[@]}"
Expand Down
6 changes: 3 additions & 3 deletions scripts.d/50-libssh.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@ ffbuild_dockerbuild() {
mkdir build && cd build

cmake -GNinja -DCMAKE_TOOLCHAIN_FILE="$FFBUILD_CMAKE_TOOLCHAIN" -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX="$FFBUILD_PREFIX" \
-DBUILD_SHARED_LIBS=OFF \
-DWITH_EXAMPLES=OFF -DWITH_SERVER=OFF \
-DWITH_SFTP=ON -DWITH_ZLIB=ON ..
-DBUILD_SHARED_LIBS=OFF -DWITH_EXAMPLES=OFF -DWITH_SERVER=OFF -DWITH_SFTP=ON -DWITH_ZLIB=ON \
..

ninja -j$(nproc)
ninja install
Expand All @@ -24,6 +23,7 @@ ffbuild_dockerbuild() {
if [[ $TARGET == win* ]]; then
echo "Libs.private: -liphlpapi -lws2_32"
fi
echo "Libs.private: -lpthread"
} >> "$FFBUILD_PREFIX"/lib/pkgconfig/libssh.pc
}

Expand Down
6 changes: 6 additions & 0 deletions scripts.d/50-libvpx.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ SCRIPT_REPO="https://chromium.googlesource.com/webm/libvpx"
SCRIPT_COMMIT="c29e63728316486082dd6083c2062434b441b77d"

ffbuild_enabled() {
[[ $TARGET == winarm64 ]] && return -1
return 0
}

Expand All @@ -30,6 +31,11 @@ ffbuild_dockerbuild() {
--target=x86-win32-gcc
)
export CROSS="$FFBUILD_CROSS_PREFIX"
elif [[ $TARGET == winarm64 ]]; then
myconf+=(
--target=arm64-win64-gcc
)
export CROSS="$FFBUILD_CROSS_PREFIX"
elif [[ $TARGET == linux64 ]]; then
myconf+=(
--target=x86_64-linux-gcc
Expand Down
11 changes: 8 additions & 3 deletions scripts.d/50-openh264.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ ffbuild_dockerbuild() {
BUILDTYPE=Release
DEBUGSYMBOLS=False
LIBDIR_NAME=lib
CC="$FFBUILD_CROSS_PREFIX"gcc
CXX="$FFBUILD_CROSS_PREFIX"g++
AR="$FFBUILD_CROSS_PREFIX"ar
CC="$CC"
CXX="$CXX"
AR="$AR"
)

if [[ $TARGET == win32 ]]; then
Expand All @@ -29,6 +29,11 @@ ffbuild_dockerbuild() {
OS=mingw_nt
ARCH=x86_64
)
elif [[ $TARGET == winarm64 ]]; then
myconf+=(
OS=mingw_nt
ARCH=aarch64
)
elif [[ $TARGET == linux64 ]]; then
myconf+=(
OS=linux
Expand Down
9 changes: 8 additions & 1 deletion scripts.d/50-openmpt.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ SCRIPT_REPO="https://source.openmpt.org/svn/openmpt/trunk/OpenMPT"
SCRIPT_REV="20417"

ffbuild_enabled() {
[[ $TARGET == winarm64 ]] && return -1
return 0
}

Expand Down Expand Up @@ -42,7 +43,13 @@ ffbuild_dockerbuild() {
NO_FLAC=1
)

if [[ $TARGET == win* ]]; then
if [[ $TARGET == winarm64 ]]; then
myconf+=(
CONFIG=mingw64-win64
WINDOWS_ARCH=arm64
)
export CPPFLAGS="$CPPFLAGS -DMPT_WITH_MINGWSTDTHREADS"
elif [[ $TARGET == win* ]]; then
myconf+=(
CONFIG=mingw64-"$TARGET"
)
Expand Down
Loading

0 comments on commit 8efdbd5

Please sign in to comment.