Skip to content

Commit

Permalink
ENH: Switch to abi3 wheels (#55)
Browse files Browse the repository at this point in the history
  • Loading branch information
larsoner authored Jul 2, 2024
1 parent 0337da9 commit 505ecd0
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 17 deletions.
27 changes: 13 additions & 14 deletions .github/workflows/build_wheels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,35 +14,32 @@ concurrency:

jobs:
build_wheels:
name: ${{ matrix.os }} ${{ matrix.arch }} py${{ matrix.python}} wheels
name: ${{ matrix.os }} ${{ matrix.arch }} ${{ matrix.python}} wheels
runs-on: ${{ matrix.os }}
continue-on-error: true
strategy:
matrix:
# macos-13 is an intel runner, macos-14 is apple silicon
os: [ubuntu-latest, windows-latest, macos-13, macos-14]
arch: [native]
python: ["*"]
python: ["{cp38,pp*}"]
# Split aarch64 across jobs because it uses emulation (slow)
include:
- os: ubuntu-latest
arch: i686
python: "*"
python: "{cp38,pp*}"
- os: ubuntu-latest
arch: aarch64
python: "38"
python: "cp38"
- os: ubuntu-latest
arch: aarch64
python: "39"
python: "pp38"
- os: ubuntu-latest
arch: aarch64
python: "310"
python: "pp39"
- os: ubuntu-latest
arch: aarch64
python: "311"
- os: ubuntu-latest
arch: aarch64
python: "312"
python: "pp310"
steps:
- uses: actions/checkout@v4
with:
Expand All @@ -55,17 +52,19 @@ jobs:
if: runner.os == 'Linux' && matrix.arch == 'aarch64'
- uses: pypa/[email protected]
env:
CIBW_BUILDING: "true"
CIBW_ARCHS: ${{ matrix.arch }} # simplest for now
CIBW_BUILD: "{c,p}p${{ matrix.python }}-*"
CIBW_SKIP: "{c,p}p3{6,7}-*"
CIBW_ARCHS: "${{ matrix.arch }}"
CIBW_BUILD: "${{ matrix.python }}-*"
CIBW_TEST_COMMAND: "python -c \"import rtmixer; print(rtmixer.__version__)\""
# No portaudio on these platforms:
CIBW_TEST_SKIP: "*_i686 *-musllinux_* *_aarch64"
# To enable testing we'd have to bump up to the Almalinux 8-based image:
# CIBW_MANYLINUX_AARCH64_IMAGE: "manylinux_2_28"
CIBW_BUILD_VERBOSITY: "3"
CIBW_BEFORE_TEST_LINUX: "bash {project}/tools/cibw_before_test_linux.sh"
# Use abi3audit to catch issues with Limited API wheels
CIBW_REPAIR_WHEEL_COMMAND: "bash ./tools/cibw_repair_wheel_command.sh {dest_dir} {wheel} {delocate_archs}"
CIBW_ENVIRONMENT_PASS_LINUX: "RUNNER_OS"
CIBW_PROJECT_REQUIRES_PYTHON: ">=3.8"
- uses: actions/upload-artifact@v4
with:
name: cibw-wheels-${{ matrix.os }}-${{ matrix.arch}}-${{ strategy.job-index }}
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ src/*.so
src/*.egg-info
__pycache__
.eggs
/dist/
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[build-system]
requires = ["setuptools", "wheel"]
build-backend = "setuptools.build_meta"
21 changes: 19 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from setuptools import setup
from setuptools import setup, Extension
from wheel.bdist_wheel import bdist_wheel

__version__ = 'unknown'

Expand All @@ -8,12 +9,27 @@
exec(line)
break


# Adapted from
# https://github.com/joerick/python-abi3-package-sample/blob/main/setup.py
class bdist_wheel_abi3(bdist_wheel):
def get_tag(self):
python, abi, plat = super().get_tag()

if python.startswith("cp"):
# on CPython, our wheels are abi3 and compatible back to 3.2,
# but let's set it to our min version anyway
return "cp38", "abi3", plat

return python, abi, plat


setup(
name='rtmixer',
version=__version__,
package_dir={'': 'src'},
py_modules=['rtmixer'],
cffi_modules=['rtmixer_build.py:ffibuilder'],
cffi_modules=['rtmixer_build.py:ffibuilder'], # sets Py_LIMITED_API for us
python_requires='>=3.6',
setup_requires=[
'CFFI>=1.4.0',
Expand All @@ -39,4 +55,5 @@
'Programming Language :: Python :: 3',
'Topic :: Multimedia :: Sound/Audio',
],
cmdclass={"bdist_wheel": bdist_wheel_abi3},
)
2 changes: 1 addition & 1 deletion src/rtmixer.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
https://python-rtmixer.readthedocs.io/
"""
__version__ = '0.1.5'
__version__ = '0.1.6'

import sounddevice as _sd
from pa_ringbuffer import init as _init_ringbuffer
Expand Down
18 changes: 18 additions & 0 deletions tools/cibw_repair_wheel_command.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/bash

set -xeo pipefail

DEST_DIR=$1
WHEEL=$2
DELOCATE_ARCHS=$3
if [[ "$RUNNER_OS" == "Linux" ]]; then
auditwheel repair -w $DEST_DIR $WHEEL
elif [[ "$RUNNER_OS" == "macOS" ]]; then
delocate-wheel --require-archs $DELOCATE_ARCHS -w $DEST_DIR -v $WHEEL
else
cp $WHEEL $DEST_DIR
fi

if [[ "$(python -c 'import platform; print(platform.python_implementation())')" == "CPython" ]]; then
pipx run abi3audit --strict --report $WHEEL
fi

0 comments on commit 505ecd0

Please sign in to comment.