Skip to content

Commit f12d913

Browse files
build: add windows arm64 build (#420)
Signed-off-by: Coia Prant <[email protected]> Co-authored-by: ReenigneArcher <[email protected]>
1 parent 76d1607 commit f12d913

File tree

6 files changed

+104
-18
lines changed

6 files changed

+104
-18
lines changed

.github/workflows/ci.yml

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,15 @@ jobs:
6868
arch: x86_64
6969
generator: "MSYS Makefiles"
7070
shell: msys2 {0}
71+
msystem: ucrt64
72+
toolchain: ucrt-x86_64
73+
- name: Windows-ARM64
74+
os: windows-11-arm
75+
arch: aarch64
76+
generator: "MSYS Makefiles"
77+
shell: msys2 {0}
78+
msystem: clangarm64
79+
toolchain: clang-aarch64
7180
defaults:
7281
run:
7382
shell: ${{ matrix.shell }}
@@ -269,21 +278,23 @@ jobs:
269278
if: runner.os == 'Windows'
270279
uses: msys2/setup-msys2@v2
271280
with:
272-
msystem: ucrt64
281+
msystem: ${{ matrix.msystem }}
273282
update: true
274283

275284
- name: Update Windows dependencies
276285
env:
277-
MSYSTEM: ucrt64
278-
TOOLCHAIN: ucrt-x86_64
286+
MSYSTEM: ${{ matrix.msystem }}
287+
TOOLCHAIN: ${{ matrix.toolchain }}
279288
if: runner.os == 'Windows'
280289
shell: msys2 {0}
281290
run: |
282291
# variables
283292
declare -A pinned_deps
284293
pinned_deps["mingw-w64-${TOOLCHAIN}-cmake"]="3.31.6-1"
285-
pinned_deps["mingw-w64-${TOOLCHAIN}-gcc"]="14.2.0-3"
286-
pinned_deps["mingw-w64-${TOOLCHAIN}-gcc-libs"]="14.2.0-3"
294+
if [[ ${MSYSTEM} == "ucrt64" ]]; then
295+
pinned_deps["mingw-w64-${TOOLCHAIN}-gcc"]="14.2.0-3"
296+
pinned_deps["mingw-w64-${TOOLCHAIN}-gcc-libs"]="14.2.0-3"
297+
fi
287298
288299
dependencies=(
289300
"diffutils"
@@ -331,7 +342,8 @@ jobs:
331342
- name: Debug msys2.CMD
332343
if: runner.os == 'Windows'
333344
run: |
334-
cat /d/a/_temp/setup-msys2/msys2.CMD
345+
echo "MSYS2_ROOT=${{ runner.temp }}/msys64" >> $GITHUB_ENV
346+
cat "${{ runner.temp }}/setup-msys2/msys2.CMD"
335347
336348
- name: Initialize Submodules
337349
# libx265 has issues when using the recursive method of the first checkout action

CMakeLists.txt

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,17 @@ elseif(NOT N MATCHES "^[0-9]+$")
5151
set(N_PROC 1)
5252
endif()
5353

54+
set(MSYS2_ROOT "C:/msys64")
55+
if(WIN32 AND DEFINED ENV{MSYS2_ROOT})
56+
set(MSYS2_ROOT "$ENV{MSYS2_ROOT}")
57+
message(STATUS "Detected MSYS2_ROOT, get msys2 path from environment: ${MSYS2_ROOT}")
58+
endif()
59+
5460
if(NOT DEFINED BASH_EXECUTABLE)
5561
find_program(BASH_EXECUTABLE
5662
NAMES zsh bash
5763
REQUIRED
58-
HINTS D:/a/_temp/msys64/usr/bin C:/msys64/usr/bin /bin /usr/bin /usr/local/bin)
64+
HINTS "${MSYS2_ROOT}/usr/bin" /bin /usr/bin /usr/local/bin)
5965
message(STATUS "Found bash: ${BASH_EXECUTABLE}")
6066
endif()
6167

@@ -70,12 +76,25 @@ if(WIN32)
7076
set(MAKE_EXECUTABLE "make")
7177
message(STATUS "Detected Windows, falling back to using make: ${MAKE_EXECUTABLE}")
7278

79+
# fatal error when cross compiling
80+
if(CMAKE_CROSSCOMPILING)
81+
message(STATUS "System processor: ${CMAKE_SYSTEM_PROCESSOR}")
82+
message(STATUS "Host system processor: ${CMAKE_HOST_SYSTEM_PROCESSOR}")
83+
message(FATAL_ERROR "Cross-compiling is not supported on Windows")
84+
endif()
85+
7386
set(MSYSTEM "UCRT64")
74-
find_file(MSYS2_EXECUTABLE NAMES msys2_shell.cmd REQUIRED HINTS D:/a/_temp/msys64 C:/msys64)
87+
set(MSYS2_ARG "-ucrt64")
88+
if(CMAKE_SYSTEM_PROCESSOR MATCHES "ARM64")
89+
set(MSYSTEM "CLANGARM64")
90+
set(MSYS2_ARG "-clangarm64")
91+
endif()
92+
93+
find_file(MSYS2_EXECUTABLE NAMES msys2_shell.cmd REQUIRED HINTS ${MSYS2_ROOT})
7594
message(STATUS "Found MSYS2: ${MSYS2_EXECUTABLE}")
7695

7796
if(NOT DEFINED MSYS2_OPTION OR MSYS2_OPTION STREQUAL "1" OR MSYS2_OPTION STREQUAL "")
78-
set(SHELL_CMD ${MSYS2_EXECUTABLE} -ucrt64 -defterm -here -no-start -shell bash -c)
97+
set(SHELL_CMD ${MSYS2_EXECUTABLE} ${MSYS2_ARG} -defterm -here -no-start -shell bash -c)
7998
elseif(MSYS2_OPTION STREQUAL "2")
8099
# Theoretically, this is equivalent to the above
81100
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/msys2.cmd.in ${CMAKE_CURRENT_BINARY_DIR}/msys2.cmd @ONLY)
@@ -135,7 +154,7 @@ message(STATUS "Initial PKG_CONFIG_PATH: ${PKG_CONFIG_PATH}")
135154
find_program(PKG_CONFIG_EXECUTABLE
136155
NAMES pkg-config
137156
REQUIRED
138-
HINTS D:/a/_temp/msys64/usr/bin C:/msys64/usr/bin /bin /usr/bin /usr/local/bin)
157+
HINTS "${MSYS2_ROOT}/usr/bin" /bin /usr/bin /usr/local/bin)
139158
UNIX_PATH(PKG_CONFIG_EXECUTABLE ${PKG_CONFIG_EXECUTABLE})
140159
message(STATUS "Found pkg-config: ${PKG_CONFIG_EXECUTABLE}")
141160

README.md

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,13 @@ brew install \
121121

122122
#### Windows
123123

124-
First, install [MSYS2](https://www.msys2.org/), then open the UCRT64 shell and run the following commands:
124+
ℹ️ Cross-compilation is not supported on Windows. You must build on the target architecture.
125+
126+
First, install [MSYS2](https://www.msys2.org/).
127+
128+
##### x86_64 / amd64
129+
130+
Open the UCRT64 shell and run the following commands:
125131

126132
```bash
127133
pacman -Syu
@@ -139,6 +145,26 @@ pacman -S \
139145
mingw-w64-ucrt-x86_64-onevpl
140146
```
141147

148+
##### aarch64 / arm64
149+
150+
Open the CLANGARM64 shell and run the following commands:
151+
152+
```bash
153+
pacman -Syu
154+
pacman -S \
155+
diffutils \
156+
git \
157+
make \
158+
pkg-config \
159+
mingw-w64-clang-aarch64-binutils \
160+
mingw-w64-clang-aarch64-cmake \
161+
mingw-w64-clang-aarch64-gcc \
162+
mingw-w64-clang-aarch64-make \
163+
mingw-w64-clang-aarch64-nasm \
164+
mingw-w64-clang-aarch64-ninja \
165+
mingw-w64-clang-aarch64-onevpl
166+
```
167+
142168
### Configure
143169

144170
Use the `Unix Makefiles` generator for Linux and macOS, and the `MSYS Makefiles` generator for Windows.

cmake/ffmpeg/ffmpeg.cmake

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,17 +52,35 @@ list(APPEND FFMPEG_EXTRA_CONFIGURE
5252
if(WIN32)
5353
list(APPEND FFMPEG_EXTRA_CONFIGURE
5454
--enable-amf
55-
--enable-cuda
5655
--enable-d3d11va
5756
--enable-encoder=h264_amf,hevc_amf,av1_amf
5857
--enable-encoder=h264_mf,hevc_mf
59-
--enable-encoder=h264_nvenc,hevc_nvenc,av1_nvenc
6058
--enable-encoder=h264_qsv,hevc_qsv,av1_qsv
61-
--enable-ffnvcodec
6259
--enable-libvpl
63-
--enable-nvenc
6460
--enable-mediafoundation
6561
)
62+
63+
# On Windows Arm64
64+
# We must specify the arch parameter until one of the following issues is resolved
65+
#
66+
# https://github.com/msys2/msys2-runtime/issues/171
67+
# https://github.com/FFmpeg/FFmpeg/blob/4e5523c98597a417eb43555933b1075d18ec5f8b/configure#L4161
68+
#
69+
# We must disable CUDA and NVENC until following issues is resolved
70+
#
71+
# https://github.com/FFmpeg/FFmpeg/blob/4e5523c98597a417eb43555933b1075d18ec5f8b/configure#L7443
72+
if(${arch} STREQUAL "aarch64" OR ${arch} STREQUAL "arm64")
73+
list(APPEND FFMPEG_EXTRA_CONFIGURE
74+
--arch=${arch}
75+
)
76+
elseif (${arch} STREQUAL "amd64" OR ${arch} STREQUAL "x86_64")
77+
list(APPEND FFMPEG_EXTRA_CONFIGURE
78+
--enable-cuda
79+
--enable-encoder=h264_nvenc,hevc_nvenc,av1_nvenc
80+
--enable-ffnvcodec
81+
--enable-nvenc
82+
)
83+
endif()
6684
elseif(APPLE)
6785
list(APPEND FFMPEG_EXTRA_CONFIGURE
6886
--enable-encoder=h264_videotoolbox,hevc_videotoolbox

cmake/ffmpeg/x264.cmake

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ else()
1919
endif()
2020

2121
if(WIN32)
22-
set(X264_HOST ${X264_ARCH}-windows)
22+
set(X264_HOST ${X264_ARCH}-mingw64)
2323
elseif(APPLE)
24-
set(X264_HOST ${X264_ARCH}-macos)
24+
set(X264_HOST ${X264_ARCH}-darwin)
2525
elseif(UNIX)
2626
set(X264_HOST ${X264_ARCH}-linux)
2727
else()
@@ -37,6 +37,17 @@ if(CMAKE_CROSSCOMPILING)
3737
endif()
3838
endif()
3939

40+
# On Windows Arm64
41+
# We must specify the host parameter until one of the following issues is resolved
42+
#
43+
# https://github.com/msys2/msys2-runtime/issues/171
44+
# https://code.videolan.org/videolan/x264/-/tree/1ecc51ee971e0056a53bd6cf9c6f6af18b167e4b/config.guess#L809
45+
if(${X264_HOST} STREQUAL "aarch64-mingw64")
46+
set(FFMPEG_X264_EXTRA_CONFIGURE
47+
--host=${X264_HOST}
48+
)
49+
endif()
50+
4051
# convert list to string
4152
# configure command will only take the first argument if not converted to string
4253
string(REPLACE ";" " " FFMPEG_X264_EXTRA_CONFIGURE "${FFMPEG_X264_EXTRA_CONFIGURE}")

msys2.cmd.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ setlocal
33
IF NOT DEFINED MSYSTEM set MSYSTEM=@MSYSTEM@
44
IF NOT DEFINED MSYS2_PATH_TYPE set MSYS2_PATH_TYPE=inherit
55
set CHERE_INVOKING=1
6-
@MSYS2_EXECUTABLE@ -ucrt64 -defterm -here -no-start -shell bash -c %*
6+
@MSYS2_EXECUTABLE@ @MSYS2_ARG@ -defterm -here -no-start -shell bash -c %*

0 commit comments

Comments
 (0)