Repository: python-pillow/Pillow

Issue:
Failed to build Windows ARM64 dependencies
<!--
Thank you for reporting an issue.

Follow these guidelines to ensure your issue is handled properly.

If you have a ...

1.  General question: consider asking the question on Stack Overflow
    with the python-imaging-library tag:

    * https://stackoverflow.com/questions/tagged/python-imaging-library

    Do not ask a question in both places.

    If you think you have found a bug or have an unexplained exception
    then file a bug report here.

2.  Bug report: include a self-contained, copy-pastable example that
    generates the issue if possible. Be concise with code posted.
    Guidelines on how to provide a good bug report:

    * https://stackoverflow.com/help/mcve

    Bug reports which follow these guidelines are easier to diagnose,
    and are often handled much more quickly.

3.  Feature request: do a quick search of existing issues
    to make sure this has not been asked before.

We know asking good questions takes effort, and we appreciate your time.
Thank you.
-->

### What did you do?
I'm trying to build a Python 3.11 ARM64 wheel for Windows ARM64 using the [provided instructions](https://github.com/python-pillow/Pillow/blob/main/winbuild/build.rst) and used the command `build_prepare.py --architecture=ARM64`. However it fails when I try to build the dependencies afterwards. I have Visual Studio Community 2022 installed on my system.

### What did you expect to happen?
The dependencies should have been built successfully.

### What actually happened?
Fails when trying to build for ARM64

### What are your OS, Python and Pillow versions?

* OS: Windows 11 Build 22621.675
* Python: Python 3.11.0rc2
* Pillow: Cloned GitHub main branch

<!--
Please include **code** that reproduces the issue and whenever possible, an **image** that demonstrates the issue. Please upload images to GitHub, not to third-party file hosting sites. If necessary, add the image to a zip or tar archive.

The best reproductions are self-contained scripts with minimal dependencies. If you are using a framework such as Plone, Django, or Buildout, try to replicate the issue just using Pillow.
-->

```
PS C:\Users\Ahnaf\Desktop\Pillow\winbuild\build> .\build_dep_all.cmd

C:\Users\Ahnaf\Desktop\Pillow\winbuild\build>cmd.exe /c "C:\Users\Ahnaf\Desktop\Pillow\winbuild\build\build_dep_libjpeg.cmd"
======================================================================
==== Building libjpeg (libjpeg-turbo-2.1.4)                       ====
======================================================================

C:\Users\Ahnaf\Desktop\Pillow\winbuild\build>cd /D C:\Users\Ahnaf\Desktop\Pillow\winbuild\build\libjpeg-turbo-2.1.4

C:\Users\Ahnaf\Desktop\Pillow\winbuild\build\libjpeg-turbo-2.1.4>set INCLUDE=C:\Users\Ahnaf\Desktop\Pillow\winbuild\build\inc

C:\Users\Ahnaf\Desktop\Pillow\winbuild\build\libjpeg-turbo-2.1.4>set INCLIB=C:\Users\Ahnaf\Desktop\Pillow\winbuild\build\lib

C:\Users\Ahnaf\Desktop\Pillow\winbuild\build\libjpeg-turbo-2.1.4>set LIB=C:\Users\Ahnaf\Desktop\Pillow\winbuild\build\lib

C:\Users\Ahnaf\Desktop\Pillow\winbuild\build\libjpeg-turbo-2.1.4>path C:\Program Files\PowerShell\7;C:\Program Files\Common Files\Oracle\Java\javapath;C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\WINDOWS\System32\OpenSSH\;C:\Program Files\NVIDIA Corporation\NVIDIA NvDLISR;C:\msys64\mingw64\bin;C:\Program Files\dotnet\;C:\Gradle\gradle-7.4\bin;C:\Program Files (x86)\gnupg\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\WINDOWS\System32\OpenSSH\;C:\Program Files\MATLAB\R2022b\bin;C:\Users\Ahnaf\AppData\Roaming\nvm;C:\Program Files\nodejs;C:\Program Files\TortoiseSVN\bin;C:\Program Files\Git\cmd;C:\Program Files\PowerShell\7\;C:\Program Files\GitHub CLI\;C:\Users\Ahnaf\AppData\Local\Programs\Python\Python311\Scripts\;C:\Users\Ahnaf\AppData\Local\Programs\Python\Python311\;C:\Users\Ahnaf\AppData\Local\Microsoft\WindowsApps;C:\Program Files\JetBrains\IntelliJ IDEA 2021.2.3\bin;C:\Users\Ahnaf\AppData\Local\Programs\Microsoft VS Code\bin;C:\Program Files\JetBrains\PyCharm 2021.2.3\bin;C:\Program Files\JetBrains\CLion 2021.2.3\bin;C:\Program Files\heroku\bin;C:\Users\Ahnaf\AppData\Local\GitHubDesktop\bin;C:\Users\Ahnaf\.dotnet\tools;C:\Users\Ahnaf\AppData\Local\JetBrains\Toolbox\scripts;C:\Users\Ahnaf\AppData\Local\Microsoft\WindowsApps;C:\Users\Ahnaf\.dotnet\tools;C:\flutter\bin;C:\Users\Ahnaf\AppData\Local\gitkraken\bin;C:\Users\Ahnaf\AppData\Local\Pub\Cache\bin;C:\Users\Ahnaf\.dotnet\tools;C:\Users\Ahnaf\Desktop\Pillow\winbuild\build\bin

C:\Users\Ahnaf\Desktop\Pillow\winbuild\build\libjpeg-turbo-2.1.4>call "C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build\vcvarsall.bat" x86_arm64
**********************************************************************
** Visual Studio 2022 Developer Command Prompt v17.3.6
** Copyright (c) 2022 Microsoft Corporation
**********************************************************************
[vcvarsall.bat] Environment initialized for: 'x86_arm64'

C:\Users\Ahnaf\Desktop\Pillow\winbuild\build\libjpeg-turbo-2.1.4>cmake.exe -DCMAKE_VERBOSE_MAKEFILE=ON -DCMAKE_RULE_MESSAGES:BOOL=OFF -DCMAKE_BUILD_TYPE=Release -DENABLE_SHARED:BOOL=FALSE -DWITH_JPEG8:BOOL=TRUE -DWITH_CRT_DLL:BOOL=TRUE -G "NMake Makefiles" "."
-- The C compiler identification is MSVC 19.33.31630.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - failed
-- Check for working C compiler: C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.33.31629/bin/Hostx86/x86/cl.exe
-- Check for working C compiler: C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.33.31629/bin/Hostx86/x86/cl.exe - broken
CMake Error at C:/Program Files/Microsoft Visual Studio/2022/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.23/Modules/CMakeTestCCompiler.cmake:69 (message):
  The C compiler

    "C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.33.31629/bin/Hostx86/x86/cl.exe"

  is not able to compile a simple test program.

  It fails with the following output:

    Change Dir: C:/Users/Ahnaf/Desktop/Pillow/winbuild/build/libjpeg-turbo-2.1.4/CMakeFiles/CMakeTmp

    Run Build Command(s):nmake -f Makefile /nologo cmTC_21cae\fast &&   "C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.33.31629\bin\HostX86\x86\nmake.exe"  -f CMakeFiles\cmTC_21cae.dir\build.make /nologo -L                  CMakeFiles\cmTC_21cae.dir\build
    Building C object CMakeFiles/cmTC_21cae.dir/testCCompiler.c.obj
        "C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin\cmake.exe" -E cmake_cl_compile_depends --dep-file=CMakeFiles\cmTC_21cae.dir\testCCompiler.c.obj.d --working-dir=C:\Users\Ahnaf\Desktop\Pillow\winbuild\build\libjpeg-turbo-2.1.4\CMakeFiles\CMakeTmp --filter-prefix="Note: including file: " -- C:\PROGRA~1\MICROS~4\2022\COMMUN~1\VC\Tools\MSVC\1433~1.316\bin\Hostx86\x86\cl.exe @C:\Users\Ahnaf\AppData\Local\Temp\nm8AF.tmp
    testCCompiler.c
    Linking C executable cmTC_21cae.exe
        "C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin\cmake.exe" -E vs_link_exe --intdir=CMakeFiles\cmTC_21cae.dir --rc=C:\PROGRA~2\WI3CF2~1\10\bin\100226~1.0\x86\rc.exe --mt=C:\PROGRA~2\WI3CF2~1\10\bin\100226~1.0\x86\mt.exe --manifests -- C:\PROGRA~1\MICROS~4\2022\COMMUN~1\VC\Tools\MSVC\1433~1.316\bin\Hostx86\x86\link.exe /nologo @CMakeFiles\cmTC_21cae.dir\objects1.rsp @C:\Users\Ahnaf\AppData\Local\Temp\nm91E.tmp
    LINK Pass 1: command "C:\PROGRA~1\MICROS~4\2022\COMMUN~1\VC\Tools\MSVC\1433~1.316\bin\Hostx86\x86\link.exe /nologo @CMakeFiles\cmTC_21cae.dir\objects1.rsp /out:cmTC_21cae.exe /implib:cmTC_21cae.lib /pdb:C:\Users\Ahnaf\Desktop\Pillow\winbuild\build\libjpeg-turbo-2.1.4\CMakeFiles\CMakeTmp\cmTC_21cae.pdb /version:0.0 /machine:X86 /debug /INCREMENTAL /subsystem:console kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib /MANIFEST /MANIFESTFILE:CMakeFiles\cmTC_21cae.dir/intermediate.manifest CMakeFiles\cmTC_21cae.dir/manifest.res" failed (exit code 1104) with the following output:
    LINK : fatal error LNK1104: cannot open file 'MSVCRTD.lib'
    NMAKE : fatal error U1077: '"C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin\cmake.exe"' : return code '0xffffffff'
    Stop.
    NMAKE : fatal error U1077: '"C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.33.31629\bin\HostX86\x86\nmake.exe"' : return code '0x2'
    Stop.





  CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
  CMakeLists.txt:12 (project)


-- Configuring incomplete, errors occurred!
See also "C:/Users/Ahnaf/Desktop/Pillow/winbuild/build/libjpeg-turbo-2.1.4/CMakeFiles/CMakeOutput.log".
See also "C:/Users/Ahnaf/Desktop/Pillow/winbuild/build/libjpeg-turbo-2.1.4/CMakeFiles/CMakeError.log".

C:\Users\Ahnaf\Desktop\Pillow\winbuild\build\libjpeg-turbo-2.1.4>nmake.exe -nologo   "clean"
NMAKE : fatal error U1073: don't know how to make 'clean'
Stop.

C:\Users\Ahnaf\Desktop\Pillow\winbuild\build\libjpeg-turbo-2.1.4>nmake.exe -nologo   "jpeg-static"
NMAKE : fatal error U1073: don't know how to make 'jpeg-static'
Stop.

C:\Users\Ahnaf\Desktop\Pillow\winbuild\build\libjpeg-turbo-2.1.4>copy /Y /B "jpeg-static.lib" "libjpeg.lib"
The system cannot find the file specified.

C:\Users\Ahnaf\Desktop\Pillow\winbuild\build\libjpeg-turbo-2.1.4>nmake.exe -nologo   "cjpeg-static"
NMAKE : fatal error U1073: don't know how to make 'cjpeg-static'
Stop.

C:\Users\Ahnaf\Desktop\Pillow\winbuild\build\libjpeg-turbo-2.1.4>copy /Y /B "cjpeg-static.exe" "cjpeg.exe"
The system cannot find the file specified.

C:\Users\Ahnaf\Desktop\Pillow\winbuild\build\libjpeg-turbo-2.1.4>nmake.exe -nologo   "djpeg-static"
NMAKE : fatal error U1073: don't know how to make 'djpeg-static'
Stop.

C:\Users\Ahnaf\Desktop\Pillow\winbuild\build\libjpeg-turbo-2.1.4>copy /Y /B "djpeg-static.exe" "djpeg.exe"
The system cannot find the file specified.

C:\Users\Ahnaf\Desktop\Pillow\winbuild\build\libjpeg-turbo-2.1.4>copy /Y /B "j*.h" "C:\Users\Ahnaf\Desktop\Pillow\winbuild\build\inc"
jchuff.h
jdcoefct.h
jdct.h
jdhuff.h
jdmainct.h
jdmaster.h
jdmerge.h
jdsample.h
jerror.h
jinclude.h
jmemsys.h
jmorecfg.h
jpegcomp.h
jpegint.h
jpeglib.h
jpeg_nbits_table.h
jsimd.h
jsimddct.h
       18 file(s) copied.

C:\Users\Ahnaf\Desktop\Pillow\winbuild\build\libjpeg-turbo-2.1.4>copy /Y /B "libjpeg.lib" "C:\Users\Ahnaf\Desktop\Pillow\winbuild\build\lib"
The system cannot find the file specified.

C:\Users\Ahnaf\Desktop\Pillow\winbuild\build\libjpeg-turbo-2.1.4>copy /Y /B "cjpeg.exe" "C:\Users\Ahnaf\Desktop\Pillow\winbuild\build\bin"
The system cannot find the file specified.

C:\Users\Ahnaf\Desktop\Pillow\winbuild\build\libjpeg-turbo-2.1.4>copy /Y /B "djpeg.exe" "C:\Users\Ahnaf\Desktop\Pillow\winbuild\build\bin"
The system cannot find the file specified.

C:\Users\Ahnaf\Desktop\Pillow\winbuild\build>if errorlevel 1 echo Build failed!   && exit /B 1
Build failed!
```



Discussion:
AFAIK none of the regular Pillow contributors have access to a Windows system running on ARM64, build support for that platform was added in https://github.com/python-pillow/Pillow/pull/5811.

However, `libjpeg-turbo` is the first dependency to be built in the script, and the CMake error suggests your CMake is not configured properly. I would therefore suggest you check that you have the Visual Studio components for C++ build tools and a Windows SDK installed. From the CMake output it seems it is failing to find `MSVCRTD.lib`, which https://stackoverflow.com/a/55606007/1648883 suggests might require installing C++ libs.
> AFAIK none of the regular Pillow contributors have access to a Windows system running on ARM64

I should have access to a "Windows Dev Kit 2023" soon and will try to build Pillow among other packages
AMD64 builds fine though. It's only ARM64 that ends up failing.

If you have access to an M1/M2 Mac you could also use that to install the ARM64 Windows 11 on Parallels or UTM and then run the ARM64 Python that way
> Figured it out, installing MSVC v143 - VS 2022 C++ ARM64 build tools (Latest) via Visual Studio Installer appeared to have solved the problem.

You made this comment, but it's not appearing, so I imagine you deleted it. That didn't solve the problem after all?
It did make some progress after installing that, but ended up failing at some point in the process:

https://gist.github.com/infinitepower18/e1190d4ba2a08bd5fa74f08d20499b7b
> It did make some progress after installing that, but ended up failing at some point in the process:
>
> https://gist.github.com/infinitepower18/e1190d4ba2a08bd5fa74f08d20499b7b

The error is triggered by libimagequant, but seems to be in a C++ standard library file:

> C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.33.31629\include\xmmintrin.h(27): fatal error C1189: #error:  This header is specific to X86, X64 and ARM64EC targets

I think this error should have been prevented by the commit https://github.com/ImageOptim/libimagequant/commit/94adecb956eac74801bc035a0c403aaf44866d16.

This makes me think that `if(${CMAKE_SYSTEM_PROCESSOR} STREQUAL ARM64)` is not true for your CMake for some reason, but that would probably be an issue between your CMake configuration and the libimagequant library not directly related to Pillow.

libimagequant is not required to build Pillow, you can skip it with: `build_prepare.py --architecture=ARM64 --no-imagequant`
```
This version of C:\Users\Ahnaf\Desktop\Pillow\winbuild\build\fribidi-1.0.12\gen-unicode-version.exe is not compatible with the version of Windows you're running. Check your computer's system information and then contact the software publisher.
NMAKE : fatal error U1077: '.\gen-unicode-version.exe' : return code '0x1'
Stop.
NMAKE : fatal error U1077: '"C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.33.31629\bin\HostX86\ARM64\nmake.exe"' : return code '0x2'
Stop.
NMAKE : fatal error U1077: '"C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.33.31629\bin\HostX86\ARM64\nmake.exe"' : return code '0x2'
Stop.
NMAKE : fatal error U1077: '"C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.33.31629\bin\HostX86\ARM64\nmake.exe"' : return code '0x2'
Stop.

C:\Users\Ahnaf\Desktop\Pillow\winbuild\build\fribidi-1.0.12>copy /Y /B "*.dll" "C:\Users\Ahnaf\Desktop\Pillow\winbuild\build\bin"
*.dll
The system cannot find the file specified.
        0 file(s) copied.

C:\Users\Ahnaf\Desktop\Pillow\winbuild\build>if errorlevel 1 echo Build failed!   && exit /B 1
Build failed!
```
Oops, I thought I already replied two days ago...

> This version of C:\Users\Ahnaf\Desktop\Pillow\winbuild\build\fribidi-1.0.12\gen-unicode-version.exe is not compatible with the version of Windows you're running. Check your computer's system information and then contact the software publisher.

Are you actually running on an ARM64 system, or are you attempting to cross-compile?

Compiling FriBiDi requires compiling and running short programs to parse the Unicode specification and generate source code. These should be compiled for the host system, while the final DLL should be compiled for the target system. From the output I'm guessing these were compiled for ARM64 which cannot be run on your host system.

However, FriBiDi is also an optional dependency you can skip:
`build_prepare.py --architecture=ARM64 --no-imagequant --no-fribidi`
I was doing it on a normal x64 system, but I do have Windows ARM64 running in a VM on my M1 Pro MacBook Pro. However after installing the required tools on Windows ARM64 I am back to the error that I initially reported. Which I don't get because I installed the ARM64 build tools as well. Not sure what I'm doing wrong here.

<img width="1267" alt="Screenshot 2022-10-29 at 12 19 54 am" src="https://user-images.githubusercontent.com/44692189/198749625-ea5c054f-6460-4cb2-99a9-e0b5ef29f569.png">
Do you have a Windows 10 SDK installed as a VS2022 component on the ARM64 system?

BTW, FriBiDi is the last dependency, and optional, so you could just skip to running `build_pillow.cmd bdist_wheel` on the x86 system (where you got this error https://github.com/python-pillow/Pillow/issues/6679#issuecomment-1292760071). The failed step is just to build `fribidi.dll` which is not needed for the wheel.
Just noting here for my future reference:

The x86_64 build tools should not be needed, but I suspect `build_prepare.py` will not detect Visual Studio without this component, even on ARM64: https://github.com/python-pillow/Pillow/blob/7adda3d4ab005a15478f96b70e1d8d08fbcb847f/winbuild/build_prepare.py#L404

This should probably end with `ARM64` if compiling for ARM64.

It should probably also require `Microsoft.VisualStudio.Component.Windows10SDK`.
Good news. Besides the mentioned change in [build_prepare.py](https://github.com/python-pillow/Pillow/blob/7adda3d4ab005a15478f96b70e1d8d08fbcb847f/winbuild/build_prepare.py#L404), there are only two issues in dependencies:

1. the liblzma solution is missing ARM64 target
2. libopenjpeg `ht_dec.c` uses `popcnt`, which is not available on win-arm64.

Both issues are easy to fix/patch and the Pillow build succeeds and passes all tests besides the usual `TestEmbeddable::test_embeddable` failure (that test should be fixed or better removed).

```
============================= test session starts =============================
platform win32 -- Python 3.11.0, pytest-7.2.0, pluggy-1.0.0
--------------------------------------------------------------------
Pillow 9.3.0
Python 3.11.0 (main, Oct 24 2022, 18:15:22) [MSC v.1933 64 bit (ARM64)]
--------------------------------------------------------------------
Python modules loaded from C:\Python311-arm64\Lib\site-packages\PIL
Binary modules loaded from C:\Python311-arm64\Lib\site-packages\PIL
--------------------------------------------------------------------
--- PIL CORE support ok, compiled for 9.3.0
--- TKINTER support ok, loaded 8.6
--- FREETYPE2 support ok, loaded 2.12.1
--- LITTLECMS2 support ok, loaded 2.13.1
--- WEBP support ok, loaded 1.2.4
--- WEBP Transparency support ok
--- WEBPMUX support ok
--- WEBP Animation support ok
--- JPEG support ok, compiled for libjpeg-turbo 2.1.4
--- OPENJPEG (JPEG2000) support ok, loaded 2.5.0
--- ZLIB (PNG/ZIP) support ok, loaded 1.2.13
--- LIBTIFF support ok, loaded 4.4.0
*** RAQM (Bidirectional Text) support not installed
*** LIBIMAGEQUANT (Quantization method) support not installed
*** XCB (X protocol) support not installed
--------------------------------------------------------------------

rootdir: C:\Build\Pillow\Pillow-9.3.0.git, configfile: setup.cfg
plugins: cov-4.0.0, timeout-2.1.0
collected 2949 items / 1 skipped

Tests\test_000_sanity.py .                                               [  0%]
Tests\test_binary.py ...                                                 [  0%]
Tests\test_bmp_reference.py ...                                          [  0%]
Tests\test_box_blur.py ..............                                    [  0%]
Tests\test_color_lut.py ..........................                       [  1%]
Tests\test_core_resources.py ..............                              [  2%]
Tests\test_decompression_bomb.py ..........                              [  2%]
Tests\test_deprecate.py ..........                                       [  2%]
Tests\test_deprecated_imageqt.py .                                       [  2%]
Tests\test_features.py ......s..............                             [  3%]
Tests\test_file_apng.py ................................                 [  4%]
Tests\test_file_blp.py .............                                     [  5%]
Tests\test_file_bmp.py ..................                                [  5%]
Tests\test_file_bufrstub.py .....                                        [  5%]
Tests\test_file_container.py ...............                             [  6%]
Tests\test_file_cur.py ..                                                [  6%]
Tests\test_file_dcx.py .........                                         [  6%]
Tests\test_file_dds.py ...........................                       [  7%]
Tests\test_file_eps.py ss.sssss..sssssss......s.                         [  8%]
Tests\test_file_fits.py .....                                            [  8%]
Tests\test_file_fli.py ...............                                   [  9%]
Tests\test_file_fpx.py ...                                               [  9%]
Tests\test_file_ftex.py ....                                             [  9%]
Tests\test_file_gbr.py ....                                              [  9%]
Tests\test_file_gd.py ...                                                [  9%]
Tests\test_file_gif.py ......................ss......................... [ 11%]
................................                                         [ 12%]
Tests\test_file_gimpgradient.py ..........                               [ 12%]
Tests\test_file_gimppalette.py ..                                        [ 12%]
Tests\test_file_gribstub.py .....                                        [ 12%]
Tests\test_file_hdf5stub.py .....                                        [ 13%]
Tests\test_file_icns.py ...........                                      [ 13%]
Tests\test_file_ico.py ...................                               [ 14%]
Tests\test_file_im.py ...............                                    [ 14%]
Tests\test_file_imt.py ....                                              [ 14%]
Tests\test_file_iptc.py .....                                            [ 14%]
Tests\test_file_jpeg.py ................................................ [ 16%]
..ss..................................                                   [ 17%]
Tests\test_file_jpeg2k.py ...........................................sss [ 19%]
s....                                                                    [ 19%]
Tests\test_file_libtiff.py ............................................. [ 21%]
.......................................                                  [ 22%]
Tests\test_file_libtiff_small.py ...                                     [ 22%]
Tests\test_file_mcidas.py ..                                             [ 22%]
Tests\test_file_mic.py ......                                            [ 22%]
Tests\test_file_mpo.py .............................                     [ 23%]
Tests\test_file_msp.py ....ss.                                           [ 24%]
Tests\test_file_palm.py .X..                                             [ 24%]
Tests\test_file_pcd.py .                                                 [ 24%]
Tests\test_file_pcx.py ................                                  [ 24%]
Tests\test_file_pdf.py ................                                  [ 25%]
Tests\test_file_pixar.py ..                                              [ 25%]
Tests\test_file_png.py ................................................. [ 26%]
........s                                                                [ 27%]
Tests\test_file_ppm.py .....................................             [ 28%]
Tests\test_file_psd.py ..................                                [ 29%]
Tests\test_file_sgi.py ..........                                        [ 29%]
Tests\test_file_spider.py ................                               [ 30%]
Tests\test_file_sun.py ..s                                               [ 30%]
Tests\test_file_tar.py ....                                              [ 30%]
Tests\test_file_tga.py ..................                                [ 30%]
Tests\test_file_tiff.py ................................................ [ 32%]
..............................s...                                       [ 33%]
Tests\test_file_tiff_metadata.py ......................                  [ 34%]
Tests\test_file_wal.py ..                                                [ 34%]
Tests\test_file_webp.py ....................                             [ 35%]
Tests\test_file_webp_alpha.py ....                                       [ 35%]
Tests\test_file_webp_animated.py ......                                  [ 35%]
Tests\test_file_webp_lossless.py .                                       [ 35%]
Tests\test_file_webp_metadata.py .......                                 [ 35%]
Tests\test_file_wmf.py .......                                           [ 36%]
Tests\test_file_xbm.py ......                                            [ 36%]
Tests\test_file_xpm.py ...                                               [ 36%]
Tests\test_file_xvthumb.py ...                                           [ 36%]
Tests\test_font_bdf.py ..                                                [ 36%]
Tests\test_font_leaks.py ss                                              [ 36%]
Tests\test_font_pcf.py ......                                            [ 36%]
Tests\test_font_pcf_charsets.py .........                                [ 37%]
Tests\test_format_hsv.py ....                                            [ 37%]
Tests\test_format_lab.py ...                                             [ 37%]
Tests\test_image.py ........................................s........... [ 39%]
....................................................                     [ 40%]
Tests\test_image_access.py ............................................. [ 42%]
.........................F                                               [ 43%]
Tests\test_image_array.py ...                                            [ 43%]
Tests\test_image_convert.py .............................                [ 44%]
Tests\test_image_copy.py .......                                         [ 44%]
Tests\test_image_crop.py .............                                   [ 44%]
Tests\test_image_draft.py ...                                            [ 45%]
Tests\test_image_entropy.py .                                            [ 45%]
Tests\test_image_filter.py ............................................. [ 46%]
.........................................                                [ 48%]
Tests\test_image_frombytes.py .                                          [ 48%]
Tests\test_image_fromqimage.py sssss                                     [ 48%]
Tests\test_image_getbands.py .                                           [ 48%]
Tests\test_image_getbbox.py ..                                           [ 48%]
Tests\test_image_getcolors.py ..                                         [ 48%]
Tests\test_image_getdata.py ..                                           [ 48%]
Tests\test_image_getextrema.py ..                                        [ 48%]
Tests\test_image_getim.py .                                              [ 48%]
Tests\test_image_getpalette.py ..                                        [ 48%]
Tests\test_image_getprojection.py .                                      [ 48%]
Tests\test_image_histogram.py .                                          [ 48%]
Tests\test_image_load.py .....                                           [ 48%]
Tests\test_image_mode.py ..                                              [ 48%]
Tests\test_image_paste.py ..................................             [ 50%]
Tests\test_image_point.py .....                                          [ 50%]
Tests\test_image_putalpha.py ...                                         [ 50%]
Tests\test_image_putdata.py .........                                    [ 50%]
Tests\test_image_putpalette.py .....                                     [ 50%]
Tests\test_image_quantize.py .s.............                             [ 51%]
Tests\test_image_reduce.py ............................................. [ 52%]
........................................................................ [ 55%]
........................................................................ [ 57%]
....................                                                     [ 58%]
Tests\test_image_resample.py ........................................... [ 59%]
....xx...................................                                [ 61%]
Tests\test_image_resize.py ............................................. [ 62%]
................................                                         [ 63%]
Tests\test_image_rotate.py ..........................                    [ 64%]
Tests\test_image_split.py ...........                                    [ 65%]
Tests\test_image_thumbnail.py ..........                                 [ 65%]
Tests\test_image_tobitmap.py .                                           [ 65%]
Tests\test_image_tobytes.py .                                            [ 65%]
Tests\test_image_transform.py .......................................... [ 67%]
.................................                                        [ 68%]
Tests\test_image_transpose.py ........................................   [ 69%]
Tests\test_imagechops.py ..............................                  [ 70%]
Tests\test_imagecms.py ...............................                   [ 71%]
Tests\test_imagecolor.py .....                                           [ 71%]
Tests\test_imagedraw.py ................................................ [ 73%]
......................................s................................. [ 75%]
                                                                         [ 75%]
Tests\test_imagedraw2.py ................                                [ 76%]
Tests\test_imageenhance.py ......                                        [ 76%]
Tests\test_imagefile.py .........................                        [ 77%]
Tests\test_imagefont.py ................................................ [ 79%]
.........................................sssssssssssssssssssssssssssssss [ 81%]
sssssssssssssssssssssssssssssssssssssssssssssssssssssssss....ss......    [ 83%]
Tests\test_imagefontctl.py sssssssssssssssssssssssssssssssssssssssssssss [ 85%]
sssssssssssssssssssssssssssssssssss                                      [ 86%]
Tests\test_imagegrab.py .s.s...                                          [ 86%]
Tests\test_imagemath.py .........................                        [ 87%]
Tests\test_imagemorph.py .......................                         [ 88%]
Tests\test_imageops.py ............................                      [ 89%]
Tests\test_imageops_usm.py .....                                         [ 89%]
Tests\test_imagepalette.py ...............                               [ 89%]
Tests\test_imagepath.py .............                                    [ 90%]
Tests\test_imageqt.py sss                                                [ 90%]
Tests\test_imagesequence.py ........                                     [ 90%]
Tests\test_imageshow.py ....sssss...ss                                   [ 91%]
Tests\test_imagestat.py ...                                              [ 91%]
Tests\test_imagetk.py ..............                                     [ 91%]
Tests\test_imagewin.py ........                                          [ 92%]
Tests\test_imagewin_pointers.py .                                        [ 92%]
Tests\test_lib_image.py .                                                [ 92%]
Tests\test_lib_pack.py ....................................              [ 93%]
Tests\test_locale.py .                                                   [ 93%]
Tests\test_main.py .                                                     [ 93%]
Tests\test_map.py ...                                                    [ 93%]
Tests\test_mode_i16.py .......                                           [ 93%]
Tests\test_numpy.py ...................................                  [ 95%]
Tests\test_pdfparser.py ....                                             [ 95%]
Tests\test_pickle.py ................................................... [ 96%]
.........................................                                [ 98%]
Tests\test_psdraw.py ...                                                 [ 98%]
Tests\test_pyroma.py .                                                   [ 98%]
Tests\test_qt_image_qapplication.py s                                    [ 98%]
Tests\test_qt_image_toqimage.py sssss                                    [ 98%]
Tests\test_sgi_crash.py ...........                                      [ 98%]
Tests\test_shell_injection.py ssss                                       [ 99%]
Tests\test_tiff_crashes.py ss...........s.                               [ 99%]
Tests\test_tiff_ifdrational.py ....                                      [ 99%]
Tests\test_util.py ......                                                [ 99%]
Tests\test_webp_leaks.py s                                               [100%]

================================== FAILURES ===================================
_______________________ TestEmbeddable.test_embeddable ________________________
<snip>
C:\Python311-arm64\Lib\site-packages\setuptools\_distutils\_msvccompiler.py:514: LinkError
---------------------------- Captured stdout call -----------------------------
embed_pil.c
embed_pil.c(8): warning C4996: 'Py_SetPythonHome': deprecated in 3.11
LINK : fatal error LNK1104: cannot open file 'python311.lib'
=========================== short test summary info ===========================
SKIPPED [1] Tests\oss-fuzz\test_fuzzers.py:11: Fuzzer is linux only
SKIPPED [1] Tests\test_features.py:68: libimagequant not available
SKIPPED [1] Tests\test_file_eps.py:32: Ghostscript not available
SKIPPED [1] Tests\test_file_eps.py:61: Ghostscript not available
SKIPPED [1] Tests\test_file_eps.py:77: Ghostscript not available
SKIPPED [1] Tests\test_file_eps.py:97: Ghostscript not available
SKIPPED [1] Tests\test_file_eps.py:108: Ghostscript not available
SKIPPED [1] Tests\test_file_eps.py:119: Ghostscript not available
SKIPPED [1] Tests\test_file_eps.py:127: Ghostscript not available
SKIPPED [1] Tests\test_file_eps.py:153: Ghostscript not available
SKIPPED [1] Tests\test_file_eps.py:175: Ghostscript not available
SKIPPED [3] Tests\test_file_eps.py:197: Ghostscript not available
SKIPPED [2] Tests\test_file_eps.py:206: Ghostscript not available
SKIPPED [1] Tests\test_file_eps.py:274: Ghostscript not available
SKIPPED [1] Tests\test_file_gif.py:337: Netpbm not available
SKIPPED [1] Tests\test_file_gif.py:348: Netpbm not available
SKIPPED [1] Tests\test_file_jpeg.py:610: djpeg not available
SKIPPED [1] Tests\test_file_jpeg.py:616: cjpeg not available
SKIPPED [4] Tests\test_file_jpeg2k.py:323: Extra image files not installed
SKIPPED [1] Tests\test_file_msp.py:58: Extra image files not installed
SKIPPED [1] Tests\test_file_msp.py:72: Even More Extra image files not installed
SKIPPED [1] Tests\test_file_png.py:781: Requires Unix or macOS
SKIPPED [1] Tests\test_file_sun.py:35: Extra image files not installed
SKIPPED [1] Tests\test_file_tiff.py:840: Extra image files not installed
SKIPPED [1] Tests\test_font_leaks.py:20: Requires Unix or macOS
SKIPPED [1] Tests\test_font_leaks.py:31: Requires Unix or macOS
SKIPPED [1] Tests\test_image.py:204: Test requires opening tempfile twice
SKIPPED [1] Tests\test_image_fromqimage.py:44: Qt bindings are not installed
SKIPPED [1] Tests\test_image_fromqimage.py:49: Qt bindings are not installed
SKIPPED [1] Tests\test_image_fromqimage.py:54: Qt bindings are not installed
SKIPPED [1] Tests\test_image_fromqimage.py:59: Qt bindings are not installed
SKIPPED [1] Tests\test_image_fromqimage.py:64: Qt bindings are not installed
SKIPPED [1] Tests\test_image_quantize.py:21: libimagequant not available
SKIPPED [1] Tests\test_imagedraw.py:970: failing
SKIPPED [1] Tests\test_imagefont.py:51: raqm not available
SKIPPED [1] Tests\test_imagefont.py:79: raqm not available
SKIPPED [1] Tests\test_imagefont.py:83: raqm not available
SKIPPED [1] Tests\test_imagefont.py:101: raqm not available
SKIPPED [1] Tests\test_imagefont.py:106: raqm not available
SKIPPED [1] Tests\test_imagefont.py:115: raqm not available
SKIPPED [1] Tests\test_imagefont.py:125: raqm not available
SKIPPED [1] Tests\test_imagefont.py:139: raqm not available
SKIPPED [1] Tests\test_imagefont.py:150: raqm not available
SKIPPED [6] Tests\test_imagefont.py:162: raqm not available
SKIPPED [1] Tests\test_imagefont.py:194: raqm not available
SKIPPED [1] Tests\test_imagefont.py:210: raqm not available
SKIPPED [3] Tests\test_imagefont.py:227: raqm not available
SKIPPED [1] Tests\test_imagefont.py:238: raqm not available
SKIPPED [1] Tests\test_imagefont.py:247: raqm not available
SKIPPED [1] Tests\test_imagefont.py:254: raqm not available
SKIPPED [1] Tests\test_imagefont.py:275: raqm not available
SKIPPED [1] Tests\test_imagefont.py:293: raqm not available
SKIPPED [1] Tests\test_imagefont.py:309: raqm not available
SKIPPED [2] Tests\test_imagefont.py:317: raqm not available
SKIPPED [4] Tests\test_imagefont.py:357: raqm not available
SKIPPED [2] Tests\test_imagefont.py:401: raqm not available
SKIPPED [4] Tests\test_imagefont.py:416: raqm not available
SKIPPED [1] Tests\test_imagefont.py:437: raqm not available
SKIPPED [1] Tests\test_imagefont.py:441: raqm not available
SKIPPED [1] Tests\test_imagefont.py:449: raqm not available
SKIPPED [1] Tests\test_imagefont.py:462: raqm not available
SKIPPED [1] Tests\test_imagefont.py:504: raqm not available
SKIPPED [1] Tests\test_imagefont.py:509: raqm not available
SKIPPED [1] Tests\test_imagefont.py:527: raqm not available
SKIPPED [1] Tests\test_imagefont.py:602: raqm not available
SKIPPED [2] Tests\test_imagefont.py:635: raqm not available
SKIPPED [1] Tests\test_imagefont.py:665: raqm not available
SKIPPED [1] Tests\test_imagefont.py:735: raqm not available
SKIPPED [1] Tests\test_imagefont.py:760: raqm not available
SKIPPED [8] Tests\test_imagefont.py:790: raqm not available
SKIPPED [11] Tests\test_imagefont.py:832: raqm not available
SKIPPED [1] Tests\test_imagefont.py:869: raqm not available
SKIPPED [4] Tests\test_imagefont.py:896: raqm not available
SKIPPED [1] Tests\test_imagefont.py:914: raqm not available
SKIPPED [1] Tests\test_imagefont.py:931: raqm not available
SKIPPED [3] Tests\test_imagefont.py:943: raqm not available
SKIPPED [1] Tests\test_imagefont.py:966: raqm not available
SKIPPED [1] Tests\test_imagefont.py:983: raqm not available
SKIPPED [1] Tests\test_imagefont.py:1002: raqm not available
SKIPPED [1] Tests\test_imagefont.py:1019: raqm not available
SKIPPED [1] Tests\test_imagefont.py:1036: raqm not available
SKIPPED [1] Tests\test_imagefont.py:1052: raqm not available
SKIPPED [1] Tests\test_imagefont.py:1068: raqm not available
SKIPPED [1] Tests\test_imagefont.py:1087: raqm not available
SKIPPED [2] Tests\test_imagefont.py:545: requires Unix or macOS
SKIPPED [1] Tests\test_imagefontctl.py:13: raqm not available
SKIPPED [1] Tests\test_imagefontctl.py:21: raqm not available
SKIPPED [1] Tests\test_imagefontctl.py:32: raqm not available
SKIPPED [1] Tests\test_imagefontctl.py:43: raqm not available
SKIPPED [1] Tests\test_imagefontctl.py:63: raqm not available
SKIPPED [1] Tests\test_imagefontctl.py:74: raqm not available
SKIPPED [1] Tests\test_imagefontctl.py:85: raqm not available
SKIPPED [1] Tests\test_imagefontctl.py:96: raqm not available
SKIPPED [1] Tests\test_imagefontctl.py:111: raqm not available
SKIPPED [1] Tests\test_imagefontctl.py:134: raqm not available
SKIPPED [1] Tests\test_imagefontctl.py:147: raqm not available
SKIPPED [1] Tests\test_imagefontctl.py:158: raqm not available
SKIPPED [1] Tests\test_imagefontctl.py:175: raqm not available
SKIPPED [1] Tests\test_imagefontctl.py:186: raqm not available
SKIPPED [10] Tests\test_imagefontctl.py:197: raqm not available
SKIPPED [16] Tests\test_imagefontctl.py:224: raqm not available
SKIPPED [4] Tests\test_imagefontctl.py:250: raqm not available
SKIPPED [26] Tests\test_imagefontctl.py:304: raqm not available
SKIPPED [9] Tests\test_imagefontctl.py:324: raqm not available
SKIPPED [1] Tests\test_imagefontctl.py:356: raqm not available
SKIPPED [1] Tests\test_imagegrab.py:24: xcb not available
SKIPPED [1] Tests\test_imagegrab.py:45: xcb not available
SKIPPED [1] Tests\test_imageqt.py:20: Qt bindings are not installed
SKIPPED [1] Tests\test_imageqt.py:49: Qt bindings are not installed
SKIPPED [1] Tests\test_imageqt.py:63: Qt bindings are not installed
SKIPPED [5] Tests\test_imageshow.py:44: Only run on CIs; hangs on Windows CIs
SKIPPED [1] Tests\test_imageshow.py:82: IPython not installed
SKIPPED [1] Tests\test_imageshow.py:94: Only run on CIs; hangs on Windows CIs
SKIPPED [1] Tests\test_qt_image_qapplication.py:54: Qt bindings are not installed
SKIPPED [5] Tests\test_qt_image_toqimage.py:19: Qt bindings are not installed
SKIPPED [1] Tests\test_shell_injection.py:25: djpeg not available
SKIPPED [1] Tests\test_shell_injection.py:34: cjpeg not available
SKIPPED [1] Tests\test_shell_injection.py:39: Netpbm not available
SKIPPED [1] Tests\test_shell_injection.py:45: Netpbm not available
SKIPPED [3] Tests\test_tiff_crashes.py:50: test image not found
SKIPPED [1] Tests\test_webp_leaks.py:16: Requires Unix or macOS
XFAIL Tests/test_image_resample.py::TestCoreResampleAlphaCorrect::test_levels_rgba - Current implementation isn't precise enough
XFAIL Tests/test_image_resample.py::TestCoreResampleAlphaCorrect::test_levels_la - Current implementation isn't precise enough
XPASS Tests/test_file_palm.py::test_p_mode Palm P image is wrong
FAILED Tests/test_image_access.py::TestEmbeddable::test_embeddable - distutils.errors.LinkError: command 'C:\\Program Files\\Microsoft Visual St...
===== 1 failed, 2710 passed, 236 skipped, 2 xfailed, 1 xpassed in 38.27s ======
```

Here's the wheel:
[Pillow-9.3.0-cp311-cp311-win_arm64.whl.zip](https://github.com/python-pillow/Pillow/files/9894939/Pillow-9.3.0-cp311-cp311-win_arm64.whl.zip)


> 1. the liblzma solution is missing ARM64 target

That was just added to `build_prepare.py` in #6562.
I see there is also a CMake build that might work instead; I do not recall why I chose the VS build.

> 2. libopenjpeg `ht_dec.c` uses `popcnt`, which is not available on win-arm64.

Already fixed in a future release: https://github.com/uclouvain/openjpeg/issues/1422

Having an ARM64 Windows CI would have quickly caught both of those issues.

> passes all tests besides the usual `TestEmbeddable::test_embeddable` failure (that test should be fixed or better removed).

I've created #6703 to mark it as "known failing". It will still get run, but will no longer mark the pytest session as a fail.
> I've created https://github.com/python-pillow/Pillow/pull/6703 to mark it as "known failing"

Another issue with that test is that it leaves temporary files (obj and exe) behind. Probably better to remove the test altogether if it doesn't get maintained.
> Having an ARM64 Windows CI

One can only hope [these](https://azure.microsoft.com/en-us/blog/azure-virtual-machines-with-ampere-altra-arm-based-processors-generally-available/) will make it to GitHub as well... In the meantime, a self-hosted runner using the "Windows Dev Kit 2023" is the only option (see e.g. [the MSYS2 one](https://github.com/msys2-arm) using [the older kit](https://www.qualcomm.com/news/releases/2021/11/snapdragon-developer-kit-windows-pcs-now-available-cost-effective-resource)).
#6703 has been merged.

Is the only thing left outstanding here the OpenJPEG issue? I've created PR #6718 to patch it until the next version of OpenJPEG is released.

Resolving patch:
diff --git a/winbuild/build_prepare.py b/winbuild/build_prepare.py
--- a/winbuild/build_prepare.py
+++ b/winbuild/build_prepare.py
@@ -323,6 +323,11 @@ def cmd_msbuild(
         "filename": "openjpeg-2.5.0.tar.gz",
         "dir": "openjpeg-2.5.0",
         "license": "LICENSE",
+        "patch": {
+            r"src\lib\openjp2\ht_dec.c": {
+                "#ifdef OPJ_COMPILER_MSVC\n    return (OPJ_UINT32)__popcnt(val);": "#if defined(OPJ_COMPILER_MSVC) && (defined(_M_IX86) || defined(_M_AMD64))\n    return (OPJ_UINT32)__popcnt(val);",  # noqa: E501
+            }
+        },
         "build": [
             cmd_cmake(("-DBUILD_CODEC:BOOL=OFF", "-DBUILD_SHARED_LIBS:BOOL=OFF")),
             cmd_nmake(target="clean"),


Test patch: