Skip to content

Commit 505ecd0

Browse files
authored
ENH: Switch to abi3 wheels (#55)
1 parent 0337da9 commit 505ecd0

File tree

6 files changed

+55
-17
lines changed

6 files changed

+55
-17
lines changed

.github/workflows/build_wheels.yml

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,35 +14,32 @@ concurrency:
1414

1515
jobs:
1616
build_wheels:
17-
name: ${{ matrix.os }} ${{ matrix.arch }} py${{ matrix.python}} wheels
17+
name: ${{ matrix.os }} ${{ matrix.arch }} ${{ matrix.python}} wheels
1818
runs-on: ${{ matrix.os }}
1919
continue-on-error: true
2020
strategy:
2121
matrix:
2222
# macos-13 is an intel runner, macos-14 is apple silicon
2323
os: [ubuntu-latest, windows-latest, macos-13, macos-14]
2424
arch: [native]
25-
python: ["*"]
25+
python: ["{cp38,pp*}"]
2626
# Split aarch64 across jobs because it uses emulation (slow)
2727
include:
2828
- os: ubuntu-latest
2929
arch: i686
30-
python: "*"
30+
python: "{cp38,pp*}"
3131
- os: ubuntu-latest
3232
arch: aarch64
33-
python: "38"
33+
python: "cp38"
3434
- os: ubuntu-latest
3535
arch: aarch64
36-
python: "39"
36+
python: "pp38"
3737
- os: ubuntu-latest
3838
arch: aarch64
39-
python: "310"
39+
python: "pp39"
4040
- os: ubuntu-latest
4141
arch: aarch64
42-
python: "311"
43-
- os: ubuntu-latest
44-
arch: aarch64
45-
python: "312"
42+
python: "pp310"
4643
steps:
4744
- uses: actions/checkout@v4
4845
with:
@@ -55,17 +52,19 @@ jobs:
5552
if: runner.os == 'Linux' && matrix.arch == 'aarch64'
5653
- uses: pypa/[email protected]
5754
env:
58-
CIBW_BUILDING: "true"
59-
CIBW_ARCHS: ${{ matrix.arch }} # simplest for now
60-
CIBW_BUILD: "{c,p}p${{ matrix.python }}-*"
61-
CIBW_SKIP: "{c,p}p3{6,7}-*"
55+
CIBW_ARCHS: "${{ matrix.arch }}"
56+
CIBW_BUILD: "${{ matrix.python }}-*"
6257
CIBW_TEST_COMMAND: "python -c \"import rtmixer; print(rtmixer.__version__)\""
6358
# No portaudio on these platforms:
6459
CIBW_TEST_SKIP: "*_i686 *-musllinux_* *_aarch64"
6560
# To enable testing we'd have to bump up to the Almalinux 8-based image:
6661
# CIBW_MANYLINUX_AARCH64_IMAGE: "manylinux_2_28"
6762
CIBW_BUILD_VERBOSITY: "3"
6863
CIBW_BEFORE_TEST_LINUX: "bash {project}/tools/cibw_before_test_linux.sh"
64+
# Use abi3audit to catch issues with Limited API wheels
65+
CIBW_REPAIR_WHEEL_COMMAND: "bash ./tools/cibw_repair_wheel_command.sh {dest_dir} {wheel} {delocate_archs}"
66+
CIBW_ENVIRONMENT_PASS_LINUX: "RUNNER_OS"
67+
CIBW_PROJECT_REQUIRES_PYTHON: ">=3.8"
6968
- uses: actions/upload-artifact@v4
7069
with:
7170
name: cibw-wheels-${{ matrix.os }}-${{ matrix.arch}}-${{ strategy.job-index }}

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ src/*.so
44
src/*.egg-info
55
__pycache__
66
.eggs
7+
/dist/

pyproject.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[build-system]
2+
requires = ["setuptools", "wheel"]
3+
build-backend = "setuptools.build_meta"

setup.py

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
from setuptools import setup
1+
from setuptools import setup, Extension
2+
from wheel.bdist_wheel import bdist_wheel
23

34
__version__ = 'unknown'
45

@@ -8,12 +9,27 @@
89
exec(line)
910
break
1011

12+
13+
# Adapted from
14+
# https://github.com/joerick/python-abi3-package-sample/blob/main/setup.py
15+
class bdist_wheel_abi3(bdist_wheel):
16+
def get_tag(self):
17+
python, abi, plat = super().get_tag()
18+
19+
if python.startswith("cp"):
20+
# on CPython, our wheels are abi3 and compatible back to 3.2,
21+
# but let's set it to our min version anyway
22+
return "cp38", "abi3", plat
23+
24+
return python, abi, plat
25+
26+
1127
setup(
1228
name='rtmixer',
1329
version=__version__,
1430
package_dir={'': 'src'},
1531
py_modules=['rtmixer'],
16-
cffi_modules=['rtmixer_build.py:ffibuilder'],
32+
cffi_modules=['rtmixer_build.py:ffibuilder'], # sets Py_LIMITED_API for us
1733
python_requires='>=3.6',
1834
setup_requires=[
1935
'CFFI>=1.4.0',
@@ -39,4 +55,5 @@
3955
'Programming Language :: Python :: 3',
4056
'Topic :: Multimedia :: Sound/Audio',
4157
],
58+
cmdclass={"bdist_wheel": bdist_wheel_abi3},
4259
)

src/rtmixer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
https://python-rtmixer.readthedocs.io/
44
55
"""
6-
__version__ = '0.1.5'
6+
__version__ = '0.1.6'
77

88
import sounddevice as _sd
99
from pa_ringbuffer import init as _init_ringbuffer

tools/cibw_repair_wheel_command.sh

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/bin/bash
2+
3+
set -xeo pipefail
4+
5+
DEST_DIR=$1
6+
WHEEL=$2
7+
DELOCATE_ARCHS=$3
8+
if [[ "$RUNNER_OS" == "Linux" ]]; then
9+
auditwheel repair -w $DEST_DIR $WHEEL
10+
elif [[ "$RUNNER_OS" == "macOS" ]]; then
11+
delocate-wheel --require-archs $DELOCATE_ARCHS -w $DEST_DIR -v $WHEEL
12+
else
13+
cp $WHEEL $DEST_DIR
14+
fi
15+
16+
if [[ "$(python -c 'import platform; print(platform.python_implementation())')" == "CPython" ]]; then
17+
pipx run abi3audit --strict --report $WHEEL
18+
fi

0 commit comments

Comments
 (0)