Skip to content

Commit f024625

Browse files
committed
wip: limited api wheels
1 parent 7ba9349 commit f024625

File tree

6 files changed

+58
-12
lines changed

6 files changed

+58
-12
lines changed

.github/workflows/wheels.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ jobs:
6464
env:
6565
MACOSX_DEPLOYMENT_TARGET: "10.9"
6666
CIBW_BUILD: "${{ matrix.cibw.build || '*' }}"
67-
CIBW_SKIP: "${{ matrix.cibw.skip || '' }}"
67+
CIBW_SKIP: "cp38-* cp39-* cp310-* cp311-* cp313-* ${{ matrix.cibw.skip || '' }}"
6868
CIBW_ARCHS: "${{ matrix.cibw.arch || 'auto' }}"
6969
CIBW_MANYLINUX_X86_64_IMAGE: "${{ matrix.cibw.manylinux_x86_64_image || '' }}"
7070

CMakeLists.txt

+12-2
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ set(CMAKE_POLICY_DEFAULT_CMP0077 NEW)
55
list(PREPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
66
find_package(
77
Python
8-
COMPONENTS Interpreter Development.Module
8+
COMPONENTS Interpreter Development.Module ${SKBUILD_SABI_COMPONENT}
99
REQUIRED)
1010

1111
# Python_SOABI isn't always right when cross-compiling
1212
# SKBUILD_SOABI seems to be
1313
if (DEFINED SKBUILD_SOABI AND NOT "${SKBUILD_SOABI}" STREQUAL "${Python_SOABI}")
14-
message(WARNING "SKBUILD_SOABI=${SKBUILD_SOABI} != Python_SOABI=${Python_SOABI}; likely cross-compiling, using SOABI=${SKBUILD_SOABI} from scikit-build")
14+
message(WARNING "SKBUILD_SOABI=${SKBUILD_SOABI} != Python_SOABI=${Python_SOABI}; likely cross-compiling or Limited API, using SOABI=${SKBUILD_SOABI} from scikit-build")
1515
set(Python_SOABI "${SKBUILD_SOABI}")
1616
endif()
1717

@@ -404,9 +404,19 @@ endif()
404404

405405
file(MAKE_DIRECTORY ${ZMQ_BACKEND_DEST})
406406

407+
if(NOT "${SKBUILD_SABI_COMPONENT}" STREQUAL "")
408+
# set stable API
409+
# assume we are targeting >= current Python version
410+
# this isn't required, but we can't seem to get `wheel.py-api
411+
message("SKBUILD_LIMITED_API=${SKBUILD_LIMITED_API}")
412+
set(SABI_ARG "USE_SABI;${Python_VERSION_MAJOR}.${Python_VERSION_MINOR}")
413+
message("Building with stable API ${SABI_ARG} for ${Python_SOABI}")
414+
endif()
415+
407416
python_add_library(
408417
${ZMQ_EXT_NAME} MODULE
409418
WITH_SOABI
419+
${SABI_ARG}
410420
${ZMQ_C}
411421
)
412422

pyproject.toml

+16-3
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
[build-system]
33
requires = [
44
"cffi; implementation_name == 'pypy'",
5-
"cython>=3.0.0; implementation_name != 'pypy'",
5+
"cython>=3.1.0a1; implementation_name != 'pypy'",
66
"packaging",
7-
"scikit-build-core",
7+
"scikit-build-core>=0.10",
88
]
99
build-backend = "scikit_build_core.build"
1010

@@ -56,7 +56,7 @@ wheel.license-files = ["licenses/LICENSE*"]
5656
# 3.15 is required by scikit-build-core
5757
cmake.version = ">=3.15"
5858
# only build/install the pyzmq component
59-
cmake.targets = ["pyzmq"]
59+
build.targets = ["pyzmq"]
6060
install.components = ["pyzmq"]
6161

6262
[tool.ruff]
@@ -202,6 +202,19 @@ select = "cp3{7,8,9}-* pp3{7,8}-*"
202202
manylinux-x86_64-image = "manylinux2010"
203203
manylinux-i686-image = "manylinux2010"
204204

205+
# build limited-api wheels for 3.7, 3.12
206+
[[tool.cibuildwheel.overrides]]
207+
select = "cp312-*"
208+
config-settings = {
209+
wheel = {py-api = "cp312"},
210+
}
211+
212+
[[tool.cibuildwheel.overrides]]
213+
select = "cp37-*"
214+
config-settings = {
215+
wheel = {py-api = "cp37"},
216+
}
217+
205218
# note: manylinux_2_28 builds are added
206219
# in .github/workflows/wheels.yml
207220

zmq/backend/cython/_cpython.pxd

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# These should be cimported from cpython.bytes
2+
# but that has a transitive import of cpython.type
3+
# which currently conflicts with limited API
4+
cdef extern from "Python.h":
5+
# cpython.bytes
6+
char* PyBytes_AsString(object string) except NULL
7+
bytes PyBytes_FromStringAndSize(char *v, Py_ssize_t len)
8+
Py_ssize_t PyBytes_Size(object string) except -1
9+
# cpython.exc
10+
int PyErr_CheckSignals() except -1

zmq/backend/cython/_zmq.py

+17-6
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,15 @@
5656
size_t,
5757
sizeof,
5858
)
59-
from cython.cimports.cpython import (
60-
PyBytes_AsString,
61-
PyBytes_FromStringAndSize,
62-
PyBytes_Size,
63-
PyErr_CheckSignals,
64-
)
59+
60+
# Cannot cimport these with Limited API yet
61+
# see https://github.com/cython/cython/issues/5634
62+
# from cython.cimports.cpython.bytes import (
63+
# PyBytes_AsString,
64+
# PyBytes_FromStringAndSize,
65+
# PyBytes_Size,
66+
# )
67+
# from cython.cimports.cpython.exc import PyErr_CheckSignals
6568
from cython.cimports.libc.errno import EAGAIN, EINTR, ENAMETOOLONG, ENOENT, ENOTSOCK
6669

6770
# cimports require Cython 3
@@ -70,6 +73,14 @@
7073
from cython.cimports.libc.stdio import stderr as cstderr
7174
from cython.cimports.libc.stdlib import free, malloc
7275
from cython.cimports.libc.string import memcpy
76+
77+
# these should be from cython.cimports.cpython
78+
from cython.cimports.zmq.backend.cython._cpython import (
79+
PyBytes_AsString,
80+
PyBytes_FromStringAndSize,
81+
PyBytes_Size,
82+
PyErr_CheckSignals,
83+
)
7384
from cython.cimports.zmq.backend.cython._externs import (
7485
get_ipc_path_max_len,
7586
getpid,

zmq/utils/mutex.h

+2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99

1010
#pragma once
1111

12+
#include <stdlib.h>
13+
1214
#if defined(_WIN32)
1315
# include <windows.h>
1416
#else

0 commit comments

Comments
 (0)