Skip to content

Commit 5b3635a

Browse files
committed
MAINT: Build abi3 wheels and use native arm64 Linux
1 parent baa9d6e commit 5b3635a

File tree

4 files changed

+70
-30
lines changed

4 files changed

+70
-30
lines changed

.github/workflows/wheels.yml

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,10 @@ jobs:
5959
matrix:
6060
buildplat:
6161
- [ubuntu-latest, musllinux_x86_64]
62-
- [ubuntu-latest, manylinux_aarch64]
62+
- [ubuntu-24.04-arm64, manylinux_aarch64]
6363
- [macos-15-intel, macosx_x86_64] # native Intel hardware
6464
- [windows-latest, win_amd64]
65-
python: ["cp310", "cp311", "cp312", "cp313", "cp314"]
65+
python: ["cp310", "cp311"]
6666
include:
6767
# Manylinux and arm64 builds (on native hardware) are cheap, do all in one
6868
- { buildplat: ["ubuntu-latest", "manylinux_x86_64"], python: "*" }
@@ -76,13 +76,6 @@ jobs:
7676
- name: Install the latest version of uv
7777
uses: astral-sh/setup-uv@v6
7878

79-
# For aarch64 support
80-
# https://cibuildwheel.pypa.io/en/stable/faq/#emulation
81-
- uses: docker/setup-qemu-action@v3
82-
with:
83-
platforms: all
84-
if: runner.os == 'Linux' && endsWith(matrix.buildplat[1], 'aarch64')
85-
8679
- name: Build wheel(s)
8780
run: uvx cibuildwheel
8881
env:

pyproject.toml

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,19 +64,37 @@ test = [
6464
[tool.cibuildwheel]
6565
# Disable PyPy
6666
skip = "pp*"
67-
67+
# 3.11 is abi3
68+
build = "cp310-* cp311-*"
6869
# 64-bit builds only; 32-bit builds seem pretty niche these days, so
6970
# don't bother unless someone asks
7071
archs = ["native"]
71-
72+
before-build = "pip install auditwheel"
7273
test-requires = [
7374
"pytest",
7475
"nitime[full]", # Enable all optional behavior
7576
]
7677
test-command = "pytest -rsx --pyargs nitime"
7778

7879
[tool.cibuildwheel.linux]
79-
archs = ["x86_64", "aarch64"]
80+
repair-wheel-command = [
81+
"auditwheel repair -w {dest_dir} {wheel}",
82+
"bash tools/audit_wheel.sh {wheel}",
83+
]
84+
85+
[tool.cibuildwheel.macos]
86+
archs = ["native"]
87+
repair-wheel-command = [
88+
"delocate-wheel --require-archs {delocate_archs} -w {dest_dir} -v {wheel}",
89+
"bash tools/audit_wheel.sh {wheel}",
90+
]
91+
92+
[tool.cibuildwheel.windows]
93+
before-build = "pip install delvewheel abi3audit"
94+
repair-wheel-command = [
95+
"delvewheel repair -w {dest_dir} {wheel}",
96+
"bash tools/audit_wheel.sh {wheel}",
97+
]
8098

8199
[tool.pytest.ini_options]
82100
minversion = "8"

setup.py

Lines changed: 38 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,46 @@
44
This file only contains cython components.
55
See pyproject.toml for the remaining configuration.
66
"""
7+
import platform
8+
import sys
9+
710
from setuptools import setup
11+
from setuptools import Extension
12+
from Cython.Build import cythonize
13+
from numpy import get_include
14+
15+
# add Cython extensions to the setup options
16+
17+
18+
# https://github.com/joerick/python-abi3-package-sample/blob/main/setup.py
19+
class bdist_wheel_abi3(bdist_wheel): # noqa: D101
20+
def get_tag(self): # noqa: D102
21+
python, abi, plat = super().get_tag()
22+
23+
if python.startswith("cp"):
24+
return "cp311", "abi3", plat
25+
26+
return python, abi, plat
27+
28+
macros = [('NPY_NO_DEPRECATED_API', 'NPY_1_7_API_VERSION')]
29+
ext_kwargs = {}
30+
setup_kwargs = {}
31+
if sys.version_info.minor >= 11 and platform.python_implementation() == "CPython":
32+
# Can create an abi3 wheel (typed memoryviews first available in 3.11)!
33+
macros.append(("Py_LIMITED_API", "0x030B0000"))
34+
ext_kwargs["py_limited_api"] = True
35+
setup_kwargs["cmdclass"] = {"bdist_wheel": bdist_wheel_abi3}
36+
837

9-
try:
10-
from setuptools import Extension
11-
from Cython.Build import cythonize
12-
from numpy import get_include
13-
14-
# add Cython extensions to the setup options
15-
exts = [
16-
Extension(
17-
'nitime._utils',
18-
['nitime/_utils.pyx'],
19-
include_dirs=[get_include()],
20-
define_macros=[('NPY_NO_DEPRECATED_API', 'NPY_1_7_API_VERSION')],
21-
)
22-
]
23-
opts = {'ext_modules': cythonize(exts, language_level='3')}
24-
except ImportError:
25-
# no loop for you!
26-
opts = {}
38+
exts = [
39+
Extension(
40+
'nitime._utils',
41+
['nitime/_utils.pyx'],
42+
include_dirs=[get_include()],
43+
define_macros=macros,
44+
)
45+
]
46+
opts = {'ext_modules': cythonize(exts, language_level='3'), **setup_kwargs}
2747

2848
# Now call the actual setup function
2949
if __name__ == '__main__':

tools/audit_wheel.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/bin/bash -eo pipefail
2+
set -x
3+
4+
PY_MINOR=$(python -c "import sys; print(sys.version_info.minor)")
5+
if [ "$PY_MINOR" -lt 11 ]; then
6+
echo "Not checking abi3audit for Python $PY_MINOR < 3.11"
7+
exit 0
8+
fi
9+
abi3audit --strict --report --verbose "$1"

0 commit comments

Comments
 (0)