Skip to content

Commit

Permalink
deps.ffmpeg: Add support for Windows ARM64
Browse files Browse the repository at this point in the history
deps-ffmpeg: restore -Bdynamic after -Bstatic

ref: mstorsjo/llvm-mingw#311 (comment)
  • Loading branch information
tommyvct committed Nov 15, 2022
1 parent 258b064 commit 350de5c
Show file tree
Hide file tree
Showing 26 changed files with 212 additions and 31 deletions.
7 changes: 6 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
strategy:
fail-fast: true
matrix:
target: [macos-arm64, macos-x86_64, linux-x86_64, windows-x64, windows-x86]
target: [macos-arm64, macos-x86_64, linux-x86_64, windows-x64, windows-x86, windows-arm64]
include:
- target: macos-arm64
os: 'macos-12'
Expand All @@ -46,6 +46,11 @@ jobs:
config: 'Release'
type: 'static'
revision: 8
- target: windows-arm64
os: 'ubuntu-20.04'
config: 'Release'
type: 'static'
revision: 8
env:
CACHE_REVISION: ${{ matrix.revision }}
defaults:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@
/linux*/*
/windows*
/windows*/*
/llvm*
2 changes: 1 addition & 1 deletion deps.ffmpeg/10-zlib.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ install() {
fixup() {
cd "${dir}"

if [[ ${target} == "windows-x"* ]] {
if [[ ${target} == "windows-"* ]] {
log_info "Fixup (%F{3}${target}%f)"
autoload -Uz create_importlibs
create_importlibs ${target_config[output_dir]}/bin/zlib*.dll
Expand Down
4 changes: 2 additions & 2 deletions deps.ffmpeg/20-libpng.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ config() {
}

case ${target} {
macos-arm64 | macos-universal)
macos-arm64 | macos-universal | windows-arm64)
args+=(
-DCMAKE_ASM_FLAGS="-DPNG_ARM_NEON_IMPLEMENTATION=1"
-DPNG_ARM_NEON=on
Expand Down Expand Up @@ -116,7 +116,7 @@ install() {
fixup() {
cd "${dir}"

if [[ ${target} == "windows-x"* ]] {
if [[ ${target} == "windows-"* ]] {
log_info "Fixup (%F{3}${target}%f)"
if (( shared_libs )) {
autoload -Uz create_importlibs
Expand Down
16 changes: 15 additions & 1 deletion deps.ffmpeg/20-opus.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,20 @@ config() {
-DOPUS_FORTIFY_SOURCE=OFF
)
;;
windows-arm64)
args+=(
-DOPUS_STACK_PROTECTOR=OFF
-DOPUS_FORTIFY_SOURCE=OFF
-DRUNTIME_CPU_CAPABILITY_DETECTION=OFF
-DOPUS_DISABLE_INTRINSICS=ON
# TODO: llvm-mingw ARM64 seh __try
# -DCMAKE_ASM_FLAGS="-DPNG_ARM_NEON_IMPLEMENTATION=1"
# -DPNG_ARM_NEON=ON
# -DOPUS_USE_NEON=ON
# -DOPUS_MAY_HAVE_NEON=ON
# -DOPUS_PRESUME_NEON=ON
)
;;
}

log_info "Config (%F{3}${target}%f)"
Expand Down Expand Up @@ -103,7 +117,7 @@ install() {
fixup() {
cd "${dir}"

if [[ ${target} == "windows-x"* ]] {
if [[ ${target} == "windows-"* ]] {
if (( shared_libs )) {
log_info "Fixup (%F{3}${target}%f)"
autoload -Uz create_importlibs
Expand Down
2 changes: 1 addition & 1 deletion deps.ffmpeg/30-libogg.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ install() {
fixup() {
cd "${dir}"

if [[ ${target} == "windows-x"* ]] {
if [[ ${target} == "windows-"* ]] {
if (( shared_libs )) {
log_info "Fixup (%F{3}${target}%f)"
autoload -Uz create_importlibs
Expand Down
2 changes: 1 addition & 1 deletion deps.ffmpeg/30-libvorbis.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ install() {
fixup() {
cd "${dir}"

if [[ ${target} == "windows-x"* ]] {
if [[ ${target} == "windows-"* ]] {
if (( shared_libs )) {
log_info "Fixup (%F{3}${target}%f)"
autoload -Uz create_importlibs
Expand Down
9 changes: 7 additions & 2 deletions deps.ffmpeg/30-libvpx.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,14 @@ config() {
args+=(--target="${arch}-darwin20-gcc")
}
;;
windows-x*)
windows-*)
cross_prefix="${target_config[cross_prefix]}-w64-mingw32-"
args+=(--enable-runtime-cpu-detect --target="${target_config[gcc_target]}")
args+=(--target="${target_config[gcc_target]}")
if [[ ${target} == "windows-x"* ]]; then
args+=(--target="--enable-runtime-cpu-detect")
else
args+=(--target="--disable-runtime-cpu-detect")
fi
;;
}

Expand Down
2 changes: 1 addition & 1 deletion deps.ffmpeg/30-svt-av1.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ install() {
fixup() {
cd "${dir}"

if [[ ${target} == "windows-x"* ]] {
if [[ ${target} == "windows-"* ]] {
if (( shared_libs )) {
mv (#i)"${target_config[output_dir]}"/lib/libsvtav1*.dll "${target_config[output_dir]}"/bin/
log_info "Fixup (%F{3}${target}%f)"
Expand Down
2 changes: 1 addition & 1 deletion deps.ffmpeg/40-aom.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ install() {
fixup() {
cd "${dir}"

if [[ ${target} == "windows-x"* ]] {
if [[ ${target} == "windows-"* ]] {
if (( shared_libs )) {
log_info "Fixup (%F{3}${target}%f)"
autoload -Uz create_importlibs
Expand Down
2 changes: 1 addition & 1 deletion deps.ffmpeg/40-x264.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ config() {
;;
macos-arm64) args+=(--host="aarch64-apple-darwin${target_config[darwin_target]}") ;;
macos-x86_64) args+=(--host="x86_64-apple-darwin${target_config[darwin_target]}") ;;
windows-x*)
windows-*)
args+=(
--host="${target_config[cross_prefix]}-pc-mingw32"
--cross-prefix="${target_config[cross_prefix]}-w64-mingw32-"
Expand Down
2 changes: 1 addition & 1 deletion deps.ffmpeg/50-libtheora.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ config() {
log_info "Config (%F{3}${target}%f)"
cd "${dir}"

if [[ ${target} == "windows-x"* ]] progress ./autogen.sh
if [[ ${target} == "windows-"* ]] progress ./autogen.sh

mkcd "build_${arch}"

Expand Down
2 changes: 1 addition & 1 deletion deps.ffmpeg/60-mbedtls.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ EOF"
fixup() {
cd "${dir}"

if [[ ${target} == "windows-x"* ]] {
if [[ ${target} == "windows-"* ]] {
log_info "Fixup (%F{3}${target}%f)"
if (( shared_libs )) {
mkdir -p ${target_config[output_dir]}/bin
Expand Down
16 changes: 13 additions & 3 deletions deps.ffmpeg/60-srt.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -62,16 +62,21 @@ config() {
)

case ${target} {
windows-x*)
windows-*)
args+=(
-DUSE_OPENSSL_PC=OFF
-DCMAKE_CXX_FLAGS="-static-libgcc -static-libstdc++ -w -pipe -fno-semantic-interposition"
-DCMAKE_C_FLAGS="-static-libgcc -w -pipe -fno-semantic-interposition"
-DCMAKE_SHARED_LINKER_FLAGS="-static-libgcc -static-libstdc++ -L${target_config[output_dir]}/lib -Wl,--exclude-libs,ALL"
-DSSL_LIBRARY_DIRS="${target_config[output_dir]}/lib"
-DSSL_INCLUDE_DIRS="${target_config[output_dir]}/include"
)

if [[ ${target} == "windows-x"* ]]; then
args+=(-DCMAKE_SHARED_LINKER_FLAGS="-static-libgcc -static-libstdc++ -L${target_config[output_dir]}/lib -Wl,--exclude-libs,ALL")
else
args+=(-DCMAKE_SHARED_LINKER_FLAGS="-static-libgcc -static-libstdc++ -L${target_config[output_dir]}/lib")
fi

autoload -Uz hide_dlls && hide_dlls
;;
}
Expand Down Expand Up @@ -121,13 +126,18 @@ fixup() {

rm ${target_config[output_dir]}/bin/(srt-ffp*)(N)

if [[ ${target} == "windows-x"* ]] {
if [[ ${target} == "windows-"* ]] {
log_info "Fixup (%F{3}${target}%f)"
if (( shared_libs )) {
autoload -Uz create_importlibs
create_importlibs ${target_config[output_dir]}/bin/libsrt*.dll
}

autoload -Uz restore_dlls && restore_dlls

# TODO: To be removed once upgraded to 1.6.0
# ref: https://github.com/Haivision/srt/pull/2536
log_info "Fixup pkgconfig"
sed -i 's/-l-l:libunwind.a //g' ${target_config[output_dir]}/lib/pkgconfig/srt.pc
}
}
6 changes: 3 additions & 3 deletions deps.ffmpeg/70-librist.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ local -a patches=(
"macos ${0:a:h}/patches/librist/0001-generate-cross-compile-files-macos.patch \
f185682aba370288585dda020d259311486056b228169cdfa5559dd7a03e2473"
"windows ${0:a:h}/patches/librist/0001-generate-cross-compile-files-windows.patch \
c7b8459642281a82a85c23acf7939c7a2c8345fc23b89773b8d1e9d8152dca2e"
100fe586bc49028f8937c392c2182a4b872c6394e206be262f2d08ec92427847"
)

## Dependency Overrides
Expand Down Expand Up @@ -74,7 +74,7 @@ config() {
return
;;
macos-*) args+=(--cross-file "cross_compile_${arch}.txt") ;;
windows-x*)
windows-*)
args+=(--cross-file "cross_mingw_${target_config[cmake_arch]}.txt")

autoload -Uz hide_dlls && hide_dlls
Expand Down Expand Up @@ -143,7 +143,7 @@ fixup() {
strip_tool=strip
strip_files=("${target_config[output_dir]}"/lib/librist.so*(.))
;;
windows-x*)
windows-*)
autoload -Uz create_importlibs
create_importlibs ${target_config[output_dir]}/bin/librist*.dll(.)

Expand Down
15 changes: 15 additions & 0 deletions deps.ffmpeg/70-nv-codec.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,21 @@ local targets=('windows-x*')

## Build Steps
setup() {
if [[ ${target} == "windows-arm64" ]]; then
log_info "Skipping setup ${name} for Windows ARM64"
return
fi

log_info "Setup (%F{3}${target}%f)"
setup_dep ${url} ${hash}
}

build() {
if [[ ${target} == "windows-arm64" ]]; then
log_info "Skipping build ${name} for Windows ARM64"
return
fi

autoload -Uz mkcd progress

log_info "Build (%F{3}${target}%f)"
Expand All @@ -26,6 +36,11 @@ build() {
}

install() {
if [[ ${target} == "windows-arm64" ]]; then
log_info "Skipping install ${name} for Windows ARM64"
return
fi

autoload -Uz progress

log_info "Install (%F{3}${target}%f)"
Expand Down
10 changes: 10 additions & 0 deletions deps.ffmpeg/80-amf.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,22 @@ local targets=('windows-x*')

## Build Steps
setup() {
if [[ ${target} == "windows-arm64" ]]; then
log_info "Skipping setup ${name} for Windows ARM64"
return
fi

log_info "Setup (%F{3}${target}%f)"
mkcd ${dir}
dep_checkout ${url} ${hash} --sparse -- set amf/public/include
}

install() {
if [[ ${target} == "windows-arm64" ]]; then
log_info "Skipping install ${name} for Windows ARM64"
return
fi

autoload -Uz progress

log_info "Install (%F{3}${target}%f)"
Expand Down
18 changes: 13 additions & 5 deletions deps.ffmpeg/99-ffmpeg.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ config() {
)

if [[ ${CPUTYPE} != "${arch}" ]] args+=(--enable-cross-compile)
;;
;;
linux-*)
ff_cflags=(
-I"${target_config[output_dir]}"/include
Expand Down Expand Up @@ -142,7 +142,7 @@ config() {

if [[ ${CPUTYPE} != "${arch}" ]] args+=(--enable-cross-compile)
;;
windows-x*)
windows-*)
ff_cflags=(
-I"${target_config[output_dir]}"/include
-static-libgcc
Expand All @@ -162,7 +162,7 @@ config() {
)

if (( ! shared_libs )) {
ff_ldflags+=(-Wl,-Bstatic -pthread)
ff_ldflags+=(-Wl,-Bstatic -pthread -Wl,-Bdynamic)
args+=(
--disable-w32threads
--enable-pthreads
Expand All @@ -184,8 +184,16 @@ config() {
--disable-mediafoundation
)

if [[ ${target} == "windows-arm64" ]]; then
args+=(
--cc=aarch64-w64-mingw32-clang
--cxx=aarch64-w64-mingw32-clang++
# --host-cc=x86_64-w64-mingw32-clang
)
fi

if [[ ${arch} == 'x64' ]] args+=(--enable-libaom --enable-libsvtav1)
;;
;;
}

args+=(
Expand Down Expand Up @@ -283,7 +291,7 @@ function _fixup_ffmpeg() {

fix_rpaths "${target_config[output_dir]}"/lib/lib(sw|av|postproc)*.dylib
;;
windows-x*)
windows-*)
mv "${target_config[output_dir]}"/bin/(sw|av|postproc)*.lib "${target_config[output_dir]}"/lib

if (( ! shared_libs )) { autoload -Uz restore_dlls && restore_dlls }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,31 @@
diff --git a/cross_mingw_arm64.txt b/cross_mingw_arm64.txt
new file mode 100644
index 0000000..f4fb2a4
--- /dev/null
+++ b/cross_mingw_arm64.txt
@@ -0,0 +1,19 @@
+[host_machine]
+system = 'windows'
+cpu_family = 'aarch64'
+cpu = 'armv8'
+endian = 'little'
+
+[binaries]
+c = 'aarch64-w64-mingw32-gcc'
+cpp = 'aarch64-w64-mingw32-c++'
+ld = 'aarch64-w64-mingw32-ld'
+ar = 'aarch64-w64-mingw32-ar'
+strip = 'aarch64-w64-mingw32-strip'
+pkgconfig = '/usr/bin/pkg-config'
+objdump = 'aarch64-w64-mingw32-objdump'
+
+[built-in options]
+c_std = 'c11'
+cpp_std = 'c++11'
+c_link_args = '-static-libgcc'
diff --git a/cross_mingw_x86.txt b/cross_mingw_x86.txt
new file mode 100644
index 0000000..559f598
index 0000000..599089a
--- /dev/null
+++ b/cross_mingw_x86.txt
@@ -0,0 +1,20 @@
Expand All @@ -26,7 +51,7 @@ index 0000000..559f598
+c_link_args = '-static-libgcc'
diff --git a/cross_mingw_x86_64.txt b/cross_mingw_x86_64.txt
new file mode 100644
index 0000000..a5b0606
index 0000000..019b0af
--- /dev/null
+++ b/cross_mingw_x86_64.txt
@@ -0,0 +1,20 @@
Expand Down
1 change: 1 addition & 0 deletions utils.zsh/10-bootstrap.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ bootstrap() {
macos-universal
windows-x64
windows-x86
windows-arm64
linux-x86_64
)
local -r -a _valid_configs=(Debug RelWithDebInfo Release MinSizeRel)
Expand Down
Loading

0 comments on commit 350de5c

Please sign in to comment.