Skip to content

Commit a4557b9

Browse files
henryiiiwjakob
authored andcommitted
Switch to scikit-build-core (#20)
This commit switches from scikit-build to scikit-build-core, which significantly simplifies the example build system and brings other benefits like a stable ABI3 wheels.
1 parent 4df3213 commit a4557b9

File tree

4 files changed

+29
-57
lines changed

4 files changed

+29
-57
lines changed

.github/workflows/wheels.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ on:
1212

1313
env:
1414
# Python 3.12+ is handled using the stable ABI, no need to build later versions
15-
CIBW_PROJECT_REQUIRES_PYTHON: ">=3.8, <=3.12"
1615
# Only build for PyPy 3.9
1716
CIBW_SKIP: "pp37* pp38*"
1817
# Target 64 bit architectures (x86_64, and arm64 on macOS)
@@ -66,7 +65,7 @@ jobs:
6665
with:
6766
submodules: true
6867

69-
- uses: pypa/cibuildwheel@v2.12.0
68+
- uses: pypa/cibuildwheel@v2.13.0
7069

7170
- name: Verify clean directory
7271
run: git diff --exit-code

CMakeLists.txt

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
cmake_minimum_required(VERSION 3.18...3.22)
1+
cmake_minimum_required(VERSION 3.15...3.26)
22

33
project(nanobind_example LANGUAGES CXX)
44

@@ -17,28 +17,14 @@ if (NOT SKBUILD)
1717
in your environment once and use the following command that avoids
1818
a costly creation of a new virtual environment at every compilation:
1919
=====================================================================
20-
$ python setup.py install
20+
$ pip install --no-build-isolation -v .
2121
=====================================================================")
2222
endif()
2323

24-
# Perform a release build by default
25-
if (NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
26-
set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build." FORCE)
27-
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "MinSizeRel" "RelWithDebInfo")
28-
endif()
29-
30-
# Create CMake targets for all Python components needed by nanobind
31-
if (CMAKE_VERSION VERSION_GREATER_EQUAL 3.26 AND Python_INTERPRETER_ID STREQUAL "Python")
32-
find_package(Python 3.8 COMPONENTS Interpreter Development.Module Development.SABIModule REQUIRED)
33-
else()
34-
find_package(Python 3.8 COMPONENTS Interpreter Development.Module REQUIRED)
35-
endif()
36-
37-
# Determine the nanobind CMake include path and register it
38-
execute_process(
39-
COMMAND "${Python_EXECUTABLE}" -m nanobind --cmake_dir
40-
OUTPUT_STRIP_TRAILING_WHITESPACE OUTPUT_VARIABLE NB_DIR)
41-
list(APPEND CMAKE_PREFIX_PATH "${NB_DIR}")
24+
# Try to import all Python components potentially needed by nanobind
25+
find_package(Python 3.8
26+
REQUIRED COMPONENTS Interpreter Development.Module
27+
OPTIONAL_COMPONENTS Development.SABIModule)
4228

4329
# Import nanobind through CMake's find_package mechanism
4430
find_package(nanobind CONFIG REQUIRED)
@@ -66,4 +52,4 @@ nanobind_add_module(
6652
)
6753

6854
# Install directive for scikit-build
69-
install(TARGETS nanobind_example_ext LIBRARY DESTINATION .)
55+
install(TARGETS nanobind_example_ext LIBRARY DESTINATION nanobind_example)

pyproject.toml

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,24 @@
11
[build-system]
2-
requires = [
3-
"setuptools>=42",
4-
"wheel",
5-
"scikit-build>=0.16.7",
6-
"cmake>=3.18",
7-
"nanobind>=1.1.0",
8-
"ninja; platform_system!='Windows'"
2+
requires = ["scikit-build-core >=0.4.3", "nanobind >=1.3.1"]
3+
build-backend = "scikit_build_core.build"
4+
5+
[project]
6+
name = "nanobind-example"
7+
version = "0.0.1"
8+
description = "An example minimal project that compiles bindings using nanobind and scikit-build"
9+
readme = "README.md"
10+
requires-python = ">=3.8"
11+
authors = [
12+
{ name = "Wenzel Jakob", email = "[email protected]" },
13+
]
14+
classifiers = [
15+
"License :: BSD",
916
]
1017

11-
build-backend = "setuptools.build_meta"
18+
[project.urls]
19+
Homepage = "https://github.com/wjakob/nanobind_example"
20+
21+
22+
[tool.scikit-build]
23+
# Build stable ABI wheels for CPython 3.12+
24+
wheel.py-api = "cp312"

setup.py

Lines changed: 0 additions & 26 deletions
This file was deleted.

0 commit comments

Comments
 (0)