|
8 | 8 |
|
9 | 9 | # Compile Commands: |
10 | 10 | # [windows] |
11 | | -# Set QNN_SDK_ROOT=C:/Qualcomm/AIStack/QAIRT/2.40.0.251030/ |
| 11 | +# Set QNN_SDK_ROOT=C:/Qualcomm/AIStack/QAIRT/2.42.0.251225/ |
12 | 12 | # Set QNN_SDK_ROOT=C:/Qualcomm/AIStack/QAIRT/2.38.0.250901/ |
13 | 13 | # python setup.py bdist_wheel |
14 | 14 | # [linux] |
15 | 15 | # export QNN_SDK_ROOT=~/QAIRT/2.38.0.250901/ |
16 | | -# python setup.py bdist_wheel |
| 16 | +# python setup.py bdist_wheel --hexagonarch 81 |
| 17 | +# python setup.py bdist_wheel --hexagonarch 81 --toolchains aarch64-windows-msvc |
17 | 18 |
|
18 | 19 | import os |
19 | 20 | import platform |
|
23 | 24 | from pathlib import Path |
24 | 25 | import shutil |
25 | 26 | import zipfile |
| 27 | +from shlex import quote |
26 | 28 |
|
27 | 29 | from setuptools import Extension, setup, find_packages |
28 | 30 | from setuptools.command.build_ext import build_ext |
|
35 | 37 | sysinfo = sys.version |
36 | 38 |
|
37 | 39 | generate = "-G \"Visual Studio 17 2022\"" |
| 40 | + |
| 41 | +# ----------------------------------------------------------------------------- |
| 42 | +# For "x64 Python + ARM64EC extension" builds: |
| 43 | +# - CMake FindPython (new mode) enforces interpreter architecture == target arch |
| 44 | +# when both Interpreter and Development are requested, which fails here. |
| 45 | +# (ARM64EC target + x64 python.exe => "Wrong architecture"). |
| 46 | +# (https://learn.arm.com/learning-paths/laptops-and-desktops/win_arm64ec_porting/how-to-2/)[5](https://getdocs.org/Cmake/docs/3.21/module/findpython) |
| 47 | +# - pybind11 provides a compat/classic mode to avoid the new FindPython path, |
| 48 | +# selectable via PYBIND11_FINDPYTHON=COMPAT. |
| 49 | +# (https://stackoverflow.com/questions/64632484/cmake-python-cannot-use-the-interpreter)[4](https://github.com/msys2/MINGW-packages/issues/20569) |
| 50 | +# - We also pass multiple Python executable variables to satisfy different |
| 51 | +# discovery code paths (Python_EXECUTABLE / Python3_EXECUTABLE / PYTHON_EXECUTABLE). |
| 52 | +# (https://learn.arm.com/learning-paths/laptops-and-desktops/win_arm64ec_porting/how-to-2/) |
| 53 | +# ----------------------------------------------------------------------------- |
| 54 | +def _cmake_python_hints(): |
| 55 | + py = os.environ.get("PYTHON_X64_EXECUTABLE", sys.executable) |
| 56 | + # Quote for safety when paths include spaces. |
| 57 | + pyq = quote(py) |
| 58 | + # Force pybind11 to use classic/compat mode (avoid FindPython arch check). |
| 59 | + # See pybind11 CMake docs for PYBIND11_FINDPYTHON=COMPAT. [3](https://stackoverflow.com/questions/64632484/cmake-python-cannot-use-the-interpreter)[4](https://github.com/msys2/MINGW-packages/issues/20569) |
| 60 | + hints = [] |
| 61 | + hints.append(f" -DPYBIND11_FINDPYTHON=COMPAT") |
| 62 | + # Make sure pybind11 classic mode finds the right version when multiple Pythons exist. |
| 63 | + hints.append(f" -DPYBIND11_PYTHON_VERSION={sys.version_info.major}.{sys.version_info.minor}") |
| 64 | + # Provide Python executable under both "new" and "old" variable names. |
| 65 | + hints.append(f" -DPython_EXECUTABLE={pyq}") |
| 66 | + hints.append(f" -DPython3_EXECUTABLE={pyq}") |
| 67 | + hints.append(f" -DPYTHON_EXECUTABLE={pyq}") |
| 68 | + return "".join(hints) |
| 69 | + |
| 70 | + |
38 | 71 | arch = "ARM64" |
39 | 72 |
|
40 | 73 | if machine == "AMD64" or "AMD64" in sysinfo: |
@@ -121,7 +154,10 @@ def build_cmake(): |
121 | 154 | os.mkdir("build") |
122 | 155 | os.chdir("build") |
123 | 156 |
|
124 | | - subprocess.run("cmake .. " + generate, shell=True) |
| 157 | + # subprocess.run("cmake .. " + generate, shell=True) |
| 158 | + # Pass Python/pybind11 hints to avoid FindPython arch mismatch for x64 python + ARM64EC target. |
| 159 | + subprocess.run("cmake .. " + generate + _cmake_python_hints(), shell=True) |
| 160 | + |
125 | 161 | subprocess.run("cmake --build ./ --config " + CONFIG, shell=True) |
126 | 162 | os.chdir("../") |
127 | 163 |
|
@@ -253,7 +289,11 @@ def build_extension(self, ext: CMakeExtension) -> None: |
253 | 289 |
|
254 | 290 | cmake_generator = os.environ.get("CMAKE_GENERATOR", "") |
255 | 291 |
|
256 | | - cmake_args = f" -DCMAKE_LIBRARY_OUTPUT_DIRECTORY={extdir}{os.sep}" + f" -DPYTHON_EXECUTABLE={sys.executable}" + f" -DCMAKE_BUILD_TYPE={cfg}" # not used on MSVC, but no harm |
| 292 | + # cmake_args = f" -DCMAKE_LIBRARY_OUTPUT_DIRECTORY={extdir}{os.sep}" + f" -DPYTHON_EXECUTABLE={sys.executable}" + f" -DCMAKE_BUILD_TYPE={cfg}" # not used on MSVC, but no harm |
| 293 | + # IMPORTANT: |
| 294 | + # - Do NOT rely on FindPython (new) here: it rejects x64 interpreter for ARM64EC target when Development is requested. |
| 295 | + # - Force pybind11 compat mode and pass x64 python executable via multiple variables. |
| 296 | + cmake_args = f" -DCMAKE_LIBRARY_OUTPUT_DIRECTORY={extdir}{os.sep}" + f" -DCMAKE_BUILD_TYPE={cfg}" + _cmake_python_hints() # not used on MSVC, but no harm |
257 | 297 |
|
258 | 298 | build_args = "" |
259 | 299 |
|
|
0 commit comments