Skip to content

Commit 37c96c2

Browse files
authored
Add wheels for 313t (#257)
Signed-off-by: Andreas Fehlner <fehlner@arcor.de>
1 parent e3bb42a commit 37c96c2

File tree

2 files changed

+32
-10
lines changed

2 files changed

+32
-10
lines changed

.github/workflows/build-and-test.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#
33
# SPDX-License-Identifier: Apache-2.0
44

5-
name: Build and Test, (Release)
5+
name: Build and Test, Release
66

77
on:
88
push:
@@ -24,6 +24,7 @@ jobs:
2424
CIBW_BEFORE_BUILD_LINUX: pip install protobuf
2525
CIBW_BEFORE_BUILD_WINDOWS: python -m pip install protobuf
2626
CIBW_BEFORE_BUILD_MACOS: pip install protobuf
27+
CIBW_ENABLE: "cpython-freethreading"
2728
CIBW_TEST_REQUIRES_LINUX: pytest pytest-xdist ruff mypy onnxruntime onnxscript
2829
CIBW_TEST_REQUIRES_MACOS: pytest pytest-xdist
2930
CIBW_TEST_REQUIRES_WINDOWS: pytest pytest-xdist
@@ -40,7 +41,7 @@ jobs:
4041
fail-fast: false
4142
matrix:
4243
os: [ubuntu-24.04, windows-2022, macos-15]
43-
python: ["cp312", "cp311", "cp310"] # because of abi3 we don't need to build separate whls for python 3.13, 3.14
44+
python: ["cp313t", "cp312", "cp311", "cp310"] # because of abi3 we don't need to build separate whls for python 3.13, 3.14
4445
steps:
4546
- uses: actions/checkout@v6.0.1
4647
with:

setup.py

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -291,17 +291,30 @@ def run(self):
291291
# Extensions
292292
################################################################################
293293

294-
py_limited_api = sys.version_info >= (3, 12)
295-
if py_limited_api:
296-
setup_opts = {
297-
"bdist_wheel": {"py_limited_api": "cp312"},
298-
}
299-
else:
300-
setup_opts = {}
294+
################################################################################
295+
# Extensions
296+
################################################################################
297+
298+
# Enable limited ABI build
299+
# nanobind supports limited ABI for Python 3.12 and later.
300+
# https://blog.trailofbits.com/2022/11/15/python-wheels-abi-abi3audit/
301+
# 1. The Py_LIMITED_API macro is defined in the extension
302+
# 2. py_limited_api in Extension tags the extension as abi3
303+
# 3. bdist_wheel options tag the wheel as abi3
304+
NO_GIL = hasattr(sys, "_is_gil_enabled") and not sys._is_gil_enabled()
305+
PY_312_OR_NEWER = sys.version_info >= (3, 12)
306+
USE_LIMITED_API = not NO_GIL and PY_312_OR_NEWER and platform.system() != "FreeBSD"
307+
308+
macros = []
309+
if USE_LIMITED_API:
310+
macros.append(("Py_LIMITED_API", "0x030C0000"))
301311

302312
ext_modules = [
303313
setuptools.Extension(
304-
name="onnxoptimizer.onnx_opt_cpp2py_export", sources=[], py_limited_api=py_limited_api
314+
name="onnxoptimizer.onnx_opt_cpp2py_export",
315+
sources=[],
316+
py_limited_api=USE_LIMITED_API,
317+
define_macros=macros,
305318
)
306319
]
307320

@@ -316,6 +329,14 @@ def run(self):
316329
# Test
317330
################################################################################
318331

332+
bdist_wheel_options = {}
333+
if USE_LIMITED_API:
334+
bdist_wheel_options["py_limited_api"] = "cp312"
335+
336+
setup_opts = {}
337+
if bdist_wheel_options:
338+
setup_opts["bdist_wheel"] = bdist_wheel_options
339+
319340
setuptools.setup(
320341
version=version_info.version,
321342
ext_modules=ext_modules,

0 commit comments

Comments
 (0)