Skip to content

Commit db6e5cf

Browse files
authored
Add Windows ARM64 support for 5.x (#1282)
* Add Windows ARM64 support for 5.x * remove redundant CPU_BASELINE/CPU_DISPATCH NEON flags on win_arm64 * fix numpy source-build failure on win_arm64 * Revert submodule bumps, add WITH_OPENCL comment
1 parent d0823ea commit db6e5cf

3 files changed

Lines changed: 34 additions & 14 deletions

File tree

‎.github/workflows/build_wheels_windows.yml‎

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Windows x86_64
1+
name: Windows
22

33
on:
44
pull_request:
@@ -17,12 +17,11 @@ on:
1717

1818
jobs:
1919
Build:
20-
runs-on: windows-2022
20+
runs-on: ${{ matrix.platform == 'arm64' && 'windows-11-arm' || 'windows-2022' }}
2121
strategy:
2222
fail-fast: false
2323
matrix:
24-
python-version: ['3.9']
25-
platform: [x86, x64]
24+
platform: [x86, x64, arm64]
2625
with_contrib: [0, 1]
2726
without_gui: [0, 1]
2827
build_sdist: [0]
@@ -32,6 +31,7 @@ jobs:
3231
ENABLE_HEADLESS: ${{ matrix.without_gui }}
3332
ENABLE_CONTRIB: ${{ matrix.with_contrib }}
3433
OPENCV_TEST_DATA_PATH: ${{ github.workspace }}\opencv_extra\testdata
34+
PYTHON_VERSION: ${{ matrix.platform == 'arm64' && '3.11' || '3.9' }}
3535
steps:
3636
- name: Cleanup
3737
shell: bash
@@ -50,17 +50,20 @@ jobs:
5050
with:
5151
submodules: false
5252
fetch-depth: 0
53-
- name: Set up Python ${{ matrix.python-version }}
53+
- name: Set up Python ${{ env.PYTHON_VERSION }}
5454
uses: actions/setup-python@v4
5555
with:
56-
python-version: ${{ matrix.python-version }}
56+
python-version: ${{ env.PYTHON_VERSION }}
5757
architecture: ${{ matrix.platform }}
5858
- name: Setup MSBuild.exe
5959
uses: microsoft/setup-msbuild@v1.1
60+
with:
61+
msbuild-architecture: ${{ matrix.platform }}
6062
- name: Setup NASM
63+
if: matrix.platform != 'arm64'
6164
uses: ilammy/setup-nasm@v1
6265
- name: Build a package
63-
# CMake 3.25 regression fix. See https://stackoverflow.com/questions/74162633/problem-compiling-from-source-opencv-with-mvsc2019-in-64-bit-version
66+
# CMake 3.25 regression fix for x86/x64. See https://stackoverflow.com/questions/74162633/problem-compiling-from-source-opencv-with-mvsc2019-in-64-bit-version
6467
run: |
6568
python --version
6669
python -m pip install --upgrade pip
@@ -77,18 +80,26 @@ jobs:
7780

7881
Test:
7982
needs: [Build]
80-
runs-on: windows-2022
83+
runs-on: ${{ matrix.platform == 'arm64' && 'windows-11-arm' || 'windows-2022' }}
8184
defaults:
8285
run:
8386
shell: cmd
8487
strategy:
8588
fail-fast: false
8689
matrix:
8790
python-version: ['3.8', '3.9', '3.10', '3.11', '3.12', '3.13', '3.14', '3.15']
88-
platform: [x86, x64]
91+
platform: [x86, x64, arm64]
8992
with_contrib: [0, 1]
9093
without_gui: [0, 1]
9194
build_sdist: [0]
95+
exclude:
96+
# actions/setup-python does not provide prebuilt arm64 Python before 3.11
97+
- platform: arm64
98+
python-version: '3.8'
99+
- platform: arm64
100+
python-version: '3.9'
101+
- platform: arm64
102+
python-version: '3.10'
92103
env:
93104
ACTIONS_ALLOW_UNSECURE_COMMANDS: true
94105
OPENCV_TEST_DATA_PATH: ${{ github.workspace }}\opencv_extra\testdata

‎pyproject.toml‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
[build-system]
22
requires = [
33
"numpy<2.0; python_version<'3.9'",
4-
"numpy==2.0.2; python_version>='3.9' and python_version<'3.13'",
4+
"numpy==2.0.2; python_version>='3.9' and python_version<'3.13' and platform_machine!='ARM64'",
5+
"numpy>=2.3.0; python_version>='3.9' and python_version<'3.13' and platform_machine=='ARM64'",
56
"numpy==2.1.3; python_version=='3.13'",
67
"numpy==2.3.2; python_version=='3.14'",
78
"packaging",

‎setup.py‎

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,11 @@ def main():
101101

102102
# Files from CMake output to copy to package.
103103
# Path regexes with forward slashes relative to CMake install dir.
104+
# Note: FFMPEG dlls are not yet provided for Windows ARM64
104105
rearrange_cmake_output_data = {
105106
"cv2": (
106107
[r"bin/opencv_videoio_ffmpeg\d{3}%s\.dll" % ("_64" if is64 else "")]
107-
if os.name == "nt"
108+
if os.name == "nt" and not (platform.machine() == "ARM64" and sys.platform == "win32")
108109
else []
109110
)
110111
+
@@ -157,9 +158,13 @@ def main():
157158

158159
# HACK: Disabled generic assembler for now.
159160
# Windows 2025 CI environment does not provide suitable assembler or build is broken in OpenCV MLAS.
161+
# On ARM64, NOTFOUND also avoids a MinGW toolchain on PATH being misdetected by CMake's ASM probe.
160162
ci_cmake_generator = (
161-
["-G", "Visual Studio 17 2022",
162-
"-DCMAKE_ASM_COMPILER="]
163+
["-G", "Visual Studio 18 2026",
164+
"-DCMAKE_ASM_COMPILER=CMAKE_ASM_COMPILER-NOTFOUND"]
165+
if os.name == "nt" and platform.machine() == "ARM64"
166+
else ["-G", "Visual Studio 17 2022",
167+
"-DCMAKE_ASM_COMPILER="]
163168
if os.name == "nt"
164169
else ["-G", "Unix Makefiles"]
165170
)
@@ -198,7 +203,10 @@ def main():
198203
# Emulated cmake requires following flags to correctly detect
199204
# target architecture for windows/arm64 build
200205
"-DOPENCV_WORKAROUND_CMAKE_20989=ON",
201-
"-DCMAKE_SYSTEM_PROCESSOR=ARM64"]
206+
"-DCMAKE_SYSTEM_PROCESSOR=ARM64",
207+
# Adreno GPUs (used on Windows ARM64 devices) produce numerically
208+
# divergent OpenCL kernel results.
209+
"-DWITH_OPENCL=OFF"]
202210
if platform.machine() == "ARM64" and sys.platform == "win32"
203211
# If it is not defined 'linker flags: /machine:X86' on Windows x64
204212
else ["-DCMAKE_GENERATOR_PLATFORM=x64"] if is64 and sys.platform == "win32"

0 commit comments

Comments
 (0)