From 9e9f2cbe90872715610bfd0c6318dbbcaf1d08fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Sok=C3=B3=C5=82?= <8431159+mtsokol@users.noreply.github.com> Date: Mon, 3 Feb 2025 10:32:43 +0100 Subject: [PATCH] BLD: Update CI jobs to the newer LLVM git hash (#15) --- .github/workflows/ci.yml | 2 +- CMakeLists.txt | 7 +++++-- pyproject.toml | 1 + requirements/requirements.txt | 1 + setup.py | 25 +++++++++++++++++++++++-- 5 files changed, 31 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 384c04e..25949f9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -41,7 +41,7 @@ jobs: uses: actions/checkout@v4 with: repository: llvm/llvm-project - ref: '4091bc61e315f187829dca877dd908a07ba9cb91' # Latest commit as of 2024-10-17 + ref: 'bb59eb8ed534da2bd03117cfde594321add4d60c' # Latest commit as of 2025-01-22 path: 'llvm-project' - name: Setup Developer Command Prompt diff --git a/CMakeLists.txt b/CMakeLists.txt index 295240d..d6f7800 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,8 +6,11 @@ set(CMAKE_BUILD_WITH_INSTALL_NAME_DIR ON) set(CMAKE_CXX_STANDARD 17 CACHE STRING "C++ standard to conform to") # https://github.com/iree-org/iree/blob/c96372348654eea8548509d38df5c8e8b179aef3/CMakeLists.txt#L275-L280 -find_package(Python3 COMPONENTS Interpreter Development) -find_package(Python3 COMPONENTS Interpreter Development.Module REQUIRED) +find_package(Python3 COMPONENTS Interpreter Development NumPy) +find_package(Python3 COMPONENTS Interpreter Development.Module NumPy REQUIRED) +# nanobind uses Python_EXECUTABLE +find_package(Python COMPONENTS Interpreter Development.Module NumPy REQUIRED) + if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) find_package(MLIR REQUIRED CONFIG) diff --git a/pyproject.toml b/pyproject.toml index c038215..24f89fe 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -7,6 +7,7 @@ requires = [ "pybind11>=2.10.4", "numpy", "PyYAML", + "nanobind", ] [tool.cibuildwheel] diff --git a/requirements/requirements.txt b/requirements/requirements.txt index eb98001..d81173c 100644 --- a/requirements/requirements.txt +++ b/requirements/requirements.txt @@ -5,3 +5,4 @@ cmake>=3.12 pybind11>=2.10.4 numpy PyYAML +nanobind diff --git a/setup.py b/setup.py index d626617..ed087d9 100644 --- a/setup.py +++ b/setup.py @@ -4,6 +4,7 @@ import sys import subprocess from pathlib import Path +from sysconfig import get_paths import ninja from setuptools import Extension, setup @@ -29,9 +30,14 @@ def build_extension(self, ext: CMakeExtension) -> None: install_dir = extdir ninja_executable_path = Path(ninja.BIN_DIR) / "ninja" PYTHON_EXECUTABLE = str(Path(sys.executable)) + include_path = get_paths()["include"] - - extra_flags = [] + extra_flags = [ + # pybind11 and nanobind use different names + f"-DPython_INCLUDE_DIR={include_path}", + f"-DPython3_INCLUDE_DIR={include_path}", + f"-DPYTHON_INCLUDE_DIR={include_path}", + ] if sys.platform.startswith("darwin"): extra_flags.append("-DCMAKE_OSX_DEPLOYMENT_TARGET=11.0") elif platform.system() == "Windows": @@ -42,6 +48,13 @@ def build_extension(self, ext: CMakeExtension) -> None: "-DCMAKE_C_FLAGS=/MT", "-DCMAKE_CXX_FLAGS=/MT", ] + libs_path = Path(include_path).parent / "libs" + library_path = libs_path / f"python3{sys.version_info.minor}.lib" + for python_name in ["Python", "Python3", "PYTHON"]: + extra_flags += [ + f"-D{python_name}_LIBRARY={library_path}", + f"-D{python_name}_LIBRARY_DIRS={libs_path}", + ] # BUILD LLVM llvm_cmake_args = [ @@ -51,6 +64,10 @@ def build_extension(self, ext: CMakeExtension) -> None: "-DLLVM_TARGETS_TO_BUILD=Native", "-DMLIR_ENABLE_BINDINGS_PYTHON=ON", f"-DPython3_EXECUTABLE={PYTHON_EXECUTABLE}", + f"-DPython_EXECUTABLE={PYTHON_EXECUTABLE}", + f"-DPYTHON_EXECUTABLE={PYTHON_EXECUTABLE}", + f"-UNB_SUFFIX", + f"-UNB_SUFFIX_S", "-DLLVM_INSTALL_UTILS=ON", "-DLLVM_CCACHE_BUILD=ON", "-DCMAKE_BUILD_TYPE=Release", @@ -86,6 +103,10 @@ def build_extension(self, ext: CMakeExtension) -> None: "-DLLVM_ENABLE_ZLIB=OFF", "-DLLVM_ENABLE_ZSTD=OFF", f"-DPython3_EXECUTABLE={PYTHON_EXECUTABLE}", + f"-DPython_EXECUTABLE={PYTHON_EXECUTABLE}", + f"-DPYTHON_EXECUTABLE={PYTHON_EXECUTABLE}", + f"-UNB_SUFFIX", + f"-UNB_SUFFIX_S", *extra_flags, ]