Skip to content

Commit 3d96435

Browse files
authored
fix: make abi3 support conditional on Python version (#344)
This makes it much easier to support setting something in the middle of your supported range (like `"cp312"` for nanobind). Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
1 parent 43fadc3 commit 3d96435

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

docs/cmakelists.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,21 @@ configuration, with the variables:
6767
- `${SKBUILD_NULL_DIR}`: Anything installed here will not be placed in the
6868
wheel.
6969

70+
## Limited API / Stable ABI
71+
72+
You can activate the limited ABI by setting When you do that,
73+
`${SKBUILD_SABI_COMPONENT}` will be set to `Development.SABIModule` if you can
74+
target this (new enough CPython), and will remain an empty string otherwise
75+
(PyPy). This allows the following idiom:
76+
77+
```cmake
78+
find_package(Python REQUIRED COMPONENTS Interpreter Development.Module ${SKBUILD_SABI_COMPONENT})
79+
```
80+
81+
This will add this only if scikit-build-core is driving the compilation and is
82+
targeting ABI3. If you want to support limited ABI from outside
83+
scikit-build-core, look into the `OPTIONAL_COMPONENTS` flag for `find_package`.
84+
7085
## Future additions
7186

7287
Scikit-build-core does not include helpers for F2Py or Cython like scikit-build

docs/configuration.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,10 @@ the wheel tags for the version you support:
198198
wheel.py-api = "cp37"
199199
```
200200

201+
Scikit-build-core will only target ABI3 if the version of Python is equal to or
202+
newer than the one you set. `${SKBUILD_SABI_COMPONENT}` is set to
203+
`Development.SABIModule` when targeting ABI3, and is an empty string otherwise.
204+
201205
If you are not using CPython at all, you can specify any version of Python is
202206
fine:
203207

src/scikit_build_core/builder/builder.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,11 @@ def configure(
127127
cache_config["SKBUILD_PROJECT_VERSION"] = str(version)
128128

129129
if limited_abi is None:
130-
limited_abi = self.settings.wheel.py_api.startswith("cp3")
130+
if self.settings.wheel.py_api.startswith("cp3"):
131+
target_minor_version = int(self.settings.wheel.py_api[3:])
132+
limited_abi = target_minor_version >= sys.version_info.minor
133+
else:
134+
limited_abi = False
131135

132136
python_library = get_python_library(self.config.env, abi3=limited_abi)
133137
python_include_dir = get_python_include_dir()

0 commit comments

Comments
 (0)