Skip to content
Open
36 changes: 25 additions & 11 deletions .github/workflows/build_wheels_windows.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Windows x86_64
name: Windows

on:
pull_request:
Expand All @@ -17,12 +17,11 @@ on:

jobs:
Build:
runs-on: windows-2025
runs-on: ${{ matrix.platform == 'arm64' && 'windows-11-arm' || 'windows-2025' }}
strategy:
fail-fast: false
matrix:
python-version: ['3.9']
platform: [x86, x64]
platform: [x86, x64, arm64]
with_contrib: [0, 1]
without_gui: [0, 1]
build_sdist: [0]
Expand All @@ -32,6 +31,8 @@ jobs:
ENABLE_HEADLESS: ${{ matrix.without_gui }}
ENABLE_CONTRIB: ${{ matrix.with_contrib }}
OPENCV_TEST_DATA_PATH: ${{ github.workspace }}\opencv_extra\testdata
PYTHON_VERSION: ${{ matrix.platform == 'arm64' && '3.11' || '3.9' }}
CMAKE_VERSION: ${{ matrix.platform == 'arm64' && '4.1.0' || '3.24.2' }}
steps:
- name: Cleanup
shell: bash
Expand All @@ -50,22 +51,25 @@ jobs:
with:
submodules: false
fetch-depth: 0
- name: Set up Python ${{ matrix.python-version }}
- name: Set up Python ${{ env.PYTHON_VERSION }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
python-version: ${{ env.PYTHON_VERSION }}
architecture: ${{ matrix.platform }}
- name: Setup MSBuild.exe
uses: microsoft/setup-msbuild@v1.1
with:
msbuild-architecture: ${{ matrix.platform }}
- name: Setup NASM
if: matrix.platform != 'arm64'
uses: ilammy/setup-nasm@v1
- name: Build a package
# CMake 3.25 regression fix. See https://stackoverflow.com/questions/74162633/problem-compiling-from-source-opencv-with-mvsc2019-in-64-bit-version
# 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
run: |
python --version
python -m pip install --upgrade pip
python -m pip install --upgrade setuptools
python -m pip install cmake==3.24.2
python -m pip install cmake==${{ env.CMAKE_VERSION }}
python -m pip install toml && python -c "import toml; c = toml.load('pyproject.toml'); print('\n'.join(c['build-system']['requires']))" >> requirements.txt | python -m pip install -r requirements.txt
set "CI_BUILD=1" && python setup.py bdist_wheel --py-limited-api=cp37 --dist-dir=%cd%\wheelhouse -v
shell: cmd
Expand All @@ -74,21 +78,31 @@ jobs:
with:
name: wheel-${{ matrix.with_contrib }}-${{ matrix.without_gui }}-${{ matrix.build_sdist }}-${{ matrix.platform }}
path: wheelhouse/opencv*

Test:
needs: [Build]
runs-on: windows-2025
runs-on: ${{ matrix.platform == 'arm64' && 'windows-11-arm' || 'windows-2025' }}
defaults:
run:
shell: cmd
strategy:
fail-fast: false
matrix:
platform: [x86, x64, arm64]
python-version: ['3.7', '3.8', '3.9', '3.10', '3.11', '3.12', '3.13']
platform: [x86, x64]
with_contrib: [0, 1]
without_gui: [0, 1]
build_sdist: [0]
exclude:
# actions/setup-python does not provide prebuilt arm64 Python before 3.11
- platform: arm64
python-version: '3.7'
- platform: arm64
python-version: '3.8'
- platform: arm64
python-version: '3.9'
- platform: arm64
python-version: '3.10'
env:
ACTIONS_ALLOW_UNSECURE_COMMANDS: true
OPENCV_TEST_DATA_PATH: ${{ github.workspace }}\opencv_extra\testdata
Expand Down
6 changes: 3 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
[build-system]
requires = [
"numpy<2.0; python_version<'3.9'",
"numpy==2.0.2; python_version>='3.9' and python_version<'3.13'",
"numpy==2.1.3; python_version=='3.13'",
"numpy==2.3.2; python_version=='3.14'",
"numpy==2.0.2; python_version >= '3.9' and python_version < '3.13' and (sys_platform != 'win32' or platform_machine != 'ARM64')",
"numpy==2.1.3; python_version == '3.13' and (sys_platform != 'win32' or platform_machine != 'ARM64')",
"numpy==2.3.1;sys_platform == 'win32' and platform_machine == 'ARM64'",
"packaging",
"pip",
"scikit-build>=0.14.0",
Expand Down
12 changes: 9 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,12 @@ def main():

# Files from CMake output to copy to package.
# Path regexes with forward slashes relative to CMake install dir.
# Note: FFMPEG dlls are not yet provided for Windows ARM64
rearrange_cmake_output_data = {
"cv2": (
[r"bin/opencv_videoio_ffmpeg\d{4}%s\.dll" % ("_64" if is64 else "")]
if os.name == "nt"
else []
([r"bin/opencv_videoio_ffmpeg\d{4}%s\.dll" % ("_64" if is64 else "")]
if not (platform.machine() == "ARM64" and sys.platform == "win32")
else [])
)
+
# In Windows, in python/X.Y/<arch>/; in Linux, in just python/X.Y/.
Expand Down Expand Up @@ -260,6 +261,11 @@ def main():
cmake_args.append("-DWITH_LAPACK=ON")
cmake_args.append("-DENABLE_PRECOMPILED_HEADERS=OFF")

if sys.platform.startswith('win') and platform.machine().lower() in ("arm64", "aarch64"):
# MSVC does not support OpenCV dispatch features such as NEON_FP16, NEON_BF16 and NEON_DOTPROD. So use NEON as both baseline and dispatch units
cmake_args.append("-DCPU_BASELINE=NEON")
cmake_args.append("-DCPU_DISPATCH=NEON")

# works via side effect
RearrangeCMakeOutput(
rearrange_cmake_output_data, files_outside_package_dir, package_data.keys()
Expand Down