Skip to content

Commit

Permalink
ENH: Update CI for nanobind build (#628)
Browse files Browse the repository at this point in the history
Some changes to make the builds work:

* MACOSX_DEPLOYMENT_TARGET is now set to the runner OS version. This might require Intel Mac users to set the variable SYSTEM_VERSION_COMPAT=0 before installing. 

* Removed Python 3.8 wheels for Windows and Mac because of various build issues
  • Loading branch information
cookpa committed May 15, 2024
1 parent 9266f2f commit 75f7392
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 32 deletions.
35 changes: 16 additions & 19 deletions .github/workflows/wheels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@ jobs:
# Need to quote decimal versions as string to avoid the "Norway problem"

# Windows 64-bit
- os: windows-latest
python: '3.8'
cibw_python: 38
platform_id: win_amd64
- os: windows-latest
python: '3.9'
cibw_python: 39
Expand Down Expand Up @@ -63,11 +59,6 @@ jobs:
platform_id: manylinux_x86_64

# macOS on Intel 64-bit
- os: macos-12
python: '3.8'
cibw_python: 38
arch: x86_64
platform_id: macosx_x86_64
- os: macos-12
python: '3.9'
cibw_python: 39
Expand Down Expand Up @@ -122,23 +113,28 @@ jobs:
uses: ilammy/msvc-dev-cmd@v1

- name: Install cibuildwheel
run: python -m pip install cibuildwheel==2.16.2 setuptools
run: python -m pip install cibuildwheel==2.16.2 setuptools toml

- name: Get package name and version (Linux / Mac)
if: ${{ ! startsWith(matrix.os, 'windows-') }}
run: |
echo PACKAGE_NAME=$( python setup.py --name ) >> $GITHUB_ENV
echo PACKAGE_VERSION=$( python setup.py --version ) >> $GITHUB_ENV
echo "PACKAGE_NAME=$( python -c "import toml; print(toml.load('pyproject.toml')['project']['name'])" )" >> $GITHUB_ENV
echo "PACKAGE_VERSION=$( python -c "import toml; print(toml.load('pyproject.toml')['project']['version'])" )" >> $GITHUB_ENV
# Some shells require "-Encoding utf8" to append to GITHUB_ENV
# https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions?tool=powershell#environment-files
- name: Get package name and version (Windows)
if: startsWith(matrix.os, 'windows-')
run: |
echo "PACKAGE_NAME=$( python setup.py --name )" | Out-File -FilePath $env:GITHUB_ENV `
-Append
echo "PACKAGE_VERSION=$( python setup.py --version )" | Out-File -FilePath $env:GITHUB_ENV `
-Append
echo "PACKAGE_NAME=$( python -c "import toml; print(toml.load('pyproject.toml')['project']['name'])" )" | Out-File -FilePath $env:GITHUB_ENV ` -Append
echo "PACKAGE_VERSION=$( python -c "import toml; print(toml.load('pyproject.toml')['project']['version'])" )" | Out-File -FilePath $env:GITHUB_ENV ` -Append
- name: Determine macOS version
if: startsWith(matrix.os, 'macos-')
run: |
macos_version=$(sw_vers -productVersion | awk -F '.' '{print $1".0"}')
echo "MACOSX_DEPLOYMENT_TARGET=${macos_version}" >> $GITHUB_ENV
- name: Build wheels
env:
CIBW_MANYLINUX_X86_64_IMAGE: manylinux2014
Expand All @@ -158,16 +154,17 @@ jobs:
python -m pip install cmake ninja setuptools
CIBW_ARCHS_MACOS: ${{ matrix.arch }}

CIBW_ENVIRONMENT_MACOS: |
CMAKE_OSX_ARCHITECTURES=${{ matrix.arch }} CMAKE_PREFIX_PATH=/usr/local
CIBW_BEFORE_ALL_MACOS: |
python -m pip install cmake ninja setuptools
brew update
if ! brew list libpng &>/dev/null; then
HOMEBREW_NO_AUTO_UPDATE=1 brew install libpng
fi
CIBW_ENVIRONMENT_MACOS: |
CMAKE_OSX_ARCHITECTURES=${{ matrix.arch }} CMAKE_PREFIX_PATH=/usr/local
run: python -m cibuildwheel --output-dir wheelhouse/cp${{ matrix.cibw_python }}-${{matrix.platform_id }}

- name: Install and test (Linux / Mac)
Expand Down
6 changes: 2 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ set(CMAKE_POSITION_INDEPENDENT_CODE ON)

# Try to import all Python components potentially needed by nanobind
find_package(Python 3.8
REQUIRED COMPONENTS Interpreter Development.Module
OPTIONAL_COMPONENTS Development.SABIModule)
REQUIRED COMPONENTS Interpreter Development.Module)

# Import nanobind through CMake's find_package mechanism
find_package(nanobind CONFIG REQUIRED)
Expand Down Expand Up @@ -40,10 +39,9 @@ add_library(imageMathUtilities STATIC src/antscore/ImageMathHelper2D.cxx src/an
target_link_libraries(antsUtilities ${ITK_LIBRARIES})
target_link_libraries(registrationUtilities ${ITK_LIBRARIES})
target_link_libraries(imageMathUtilities ${ITK_LIBRARIES})

nanobind_add_module(
lib
STABLE_ABI
NB_STATIC
src/main.cpp
src/antscore/antsAffineInitializer.cxx
Expand Down
9 changes: 0 additions & 9 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,6 @@ minimum-version = "0.4"
# Setuptools-style build caching in a local directory
build-dir = "build/{wheel_tag}"

# Build stable ABI wheels for CPython 3.12+
wheel.py-api = "cp311"

cmake.args = []

wheel.packages = ["ants"]
Expand All @@ -54,9 +51,3 @@ build-verbosity = 1
test-command = "pytest {project}/tests"
test-requires = "pytest"

# Don't test Python 3.8 wheels on macOS/arm64
test-skip="cp38-macosx_*:arm64"

# Needed for full C++17 support
[tool.cibuildwheel.macos.environment]
MACOSX_DEPLOYMENT_TARGET = "10.14"

0 comments on commit 75f7392

Please sign in to comment.