Skip to content

Commit f657fdd

Browse files
committed
allow selecting backend with PYZMQ_BACKEND at build time
1 parent dc0c1c1 commit f657fdd

File tree

3 files changed

+35
-4
lines changed

3 files changed

+35
-4
lines changed

.github/workflows/test.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,10 @@ jobs:
8282
- os: ubuntu-24.04
8383
python: "3.12"
8484

85+
- os: ubuntu-24.04
86+
python: "3.13"
87+
backend: cffi
88+
8589
- os: ubuntu-24.04
8690
python: "3.13"
8791

@@ -193,6 +197,11 @@ jobs:
193197
run: |
194198
echo "ZMQ_PREFIX=${{ matrix.zmq }}" >> "$GITHUB_ENV"
195199
200+
- name: set $PYZMQ_BACKEND
201+
if: matrix.backend
202+
run: |
203+
echo "PYZMQ_BACKEND=${{ matrix.backend }}" >> "$GITHUB_ENV"
204+
196205
- name: install libzmq-dev
197206
if: matrix.zmq == 'head'
198207
run: |

CMakeLists.txt

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ set(PYZMQ_LIBSODIUM_URL "" CACHE STRING "full URL to download bundled libsodium"
2929
set(PYZMQ_LIBSODIUM_CONFIGURE_ARGS "" CACHE STRING "semicolon-separated list of arguments to pass to ./configure for bundled libsodium")
3030
set(PYZMQ_LIBSODIUM_MSBUILD_ARGS "" CACHE STRING "semicolon-separated list of arguments to pass to msbuild for bundled libsodium")
3131
set(PYZMQ_LIBSODIUM_VS_VERSION "" CACHE STRING "Visual studio solution version for bundled libsodium (default: detect from MSVC_VERSION)")
32+
set(PYZMQ_BACKEND "" CACHE STRING "pyzmq backend to build ('cffi' or 'cython'). Default: cffi on PyPy, else Cython.")
3233

3334
if (NOT CMAKE_BUILD_TYPE)
3435
# default to Release
@@ -57,6 +58,7 @@ foreach(_optname
5758
PYZMQ_LIBSODIUM_CONFIGURE_ARGS
5859
PYZMQ_LIBSODIUM_MSBUILD_ARGS
5960
PYZMQ_LIBSODIUM_VS_VERSION
61+
PYZMQ_BACKEND
6062
)
6163
if (DEFINED ENV{${_optname}})
6264
if (_optname MATCHES ".*_ARGS")
@@ -367,8 +369,19 @@ set(EXT_SRC_DIR "${CMAKE_CURRENT_BINARY_DIR}/_src")
367369
set(ZMQ_BUILDUTILS "${CMAKE_CURRENT_SOURCE_DIR}/buildutils")
368370
file(MAKE_DIRECTORY "${EXT_SRC_DIR}")
369371

370-
if(Python_INTERPRETER_ID STREQUAL "PyPy")
372+
if (NOT PYZMQ_BACKEND)
373+
if(Python_INTERPRETER_ID STREQUAL "PyPy")
374+
set(PYZMQ_BACKEND "cffi")
375+
else()
376+
set(PYZMQ_BACKEND "cython")
377+
endif()
378+
endif()
379+
380+
if(PYZMQ_BACKEND STREQUAL "cffi")
371381
message(STATUS "Building CFFI backend")
382+
if(NOT Python_INTERPRETER_ID STREQUAL "PyPy")
383+
message(WARNING "Building CFFI backend on ${Python_INTERPRETER_ID}, not PyPy. This is not supported and may not work.")
384+
endif()
372385
set(ZMQ_EXT_NAME "_cffi")
373386

374387
set(ZMQ_BACKEND_DEST "zmq/backend/cffi")
@@ -381,8 +394,11 @@ if(Python_INTERPRETER_ID STREQUAL "PyPy")
381394
"${ZMQ_BUILDUTILS}/build_cffi.py"
382395
"${ZMQ_C}"
383396
)
384-
else()
397+
elseif(PYZMQ_BACKEND STREQUAL "cython")
385398
message(STATUS "Building Cython backend")
399+
if(NOT Python_INTERPRETER_ID STREQUAL "Python")
400+
message(WARNING "Building Cython backend on ${Python_INTERPRETER_ID}, not CPython. This is not supported and may not work.")
401+
endif()
386402
find_program(CYTHON "cython")
387403

388404
set(ZMQ_BACKEND_DEST "zmq/backend/cython")
@@ -400,6 +416,8 @@ else()
400416
--module-name "zmq.backend.cython._zmq"
401417
${ZMQ_PYX}
402418
)
419+
else()
420+
message(FATAL_ERROR "Unsupported PYZMQ_BACKEND=${PYZMQ_BACKEND}. Must be 'cffi' or 'cython'.")
403421
endif()
404422

405423
file(MAKE_DIRECTORY ${ZMQ_BACKEND_DEST})

pyproject.toml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ requires = [
44
"cffi; implementation_name == 'pypy'",
55
"cython>=3.0.0; implementation_name != 'pypy'",
66
"packaging",
7-
"scikit-build-core",
7+
"scikit-build-core>=0.10",
88
]
99
build-backend = "scikit_build_core.build"
1010

@@ -55,9 +55,13 @@ wheel.license-files = ["licenses/LICENSE*"]
5555
# 3.15 is required by scikit-build-core
5656
cmake.version = ">=3.15"
5757
# only build/install the pyzmq component
58-
cmake.targets = ["pyzmq"]
58+
build.targets = ["pyzmq"]
5959
install.components = ["pyzmq"]
6060

61+
[[tool.scikit-build.overrides]]
62+
if.env.PYZMQ_BACKEND = "cffi"
63+
build.requires = ["cffi"]
64+
6165
[tool.ruff]
6266

6367
[tool.ruff.format]

0 commit comments

Comments
 (0)