Python Package #19
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Python Package | |
on: | |
release: | |
types: | |
- published | |
branches: | |
- main | |
# Allows us run the action manually. | |
workflow_dispatch: | |
jobs: | |
build-wheels: | |
name: Build wheels for ${{ matrix.os }} | |
runs-on: ${{ matrix.os }} | |
strategy: | |
matrix: | |
os: | |
- ubuntu-latest | |
- windows-latest | |
- macos-13 # x86_64 | |
- macos-14 # aarch64 | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
submodules: recursive | |
# On Linux, use QEMU to build multiple platforms. | |
- name: Setup QEMU | |
if: runner.os == 'Linux' | |
uses: docker/setup-qemu-action@v3 | |
with: | |
platforms: all | |
# Need this for macos-14, which doesn't come with python for some reason. | |
- name: Setup Python | |
uses: actions/setup-python@v4 | |
with: | |
python-version: '3.10' | |
# Need this to get cl.exe on the path. | |
- name: Set up Visual Studio shell | |
if: runner.os == 'Windows' | |
uses: egor-tensin/vs-shell@v2 | |
- name: Install cibuildwheel | |
run: python -m pip install cibuildwheel | |
- name: Build wheels | |
run: python -m cibuildwheel --output-dir wheelhouse | |
env: | |
# We have QEMU setup and can build everything. | |
CIBW_ARCHS_LINUX: x86_64 i686 aarch64 | |
# For some reason these don't use the same distro. | |
# musllinux uses apk & manylinux uses yum. | |
CIBW_BEFORE_BUILD_LINUX: | | |
if command -v apk > /dev/null; then | |
apk add --update clang && make -C src blst | |
elif command -v yum > /dev/null; then | |
yum install -y clang && make -C src blst | |
fi | |
# Building x86 (32-bit) package is difficult. | |
# We're missing the 32-bit Python library. | |
CIBW_ARCHS_WINDOWS: AMD64 | |
# We need blst.lib (via MSVC) which our Makefile doesn't support. | |
CIBW_BEFORE_BUILD_WINDOWS: | | |
cd blst && build.bat && cp blst.lib ../lib && cp bindings/*.h ../inc | |
CIBW_BEFORE_BUILD_MACOS: | | |
make -C src blst | |
- name: Upload wheels as artifacts | |
uses: actions/upload-artifact@v2 | |
with: | |
name: wheels | |
path: wheelhouse/* | |
# Build the source distribution under Linux | |
build-sdist: | |
name: Source distribution | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
submodules: recursive | |
- name: Setup Python | |
uses: actions/setup-python@v4 | |
with: | |
python-version: '3.10' | |
- name: Build source distribution | |
run: python setup.py sdist | |
- name: Store artifacts | |
uses: actions/upload-artifact@v3 | |
with: | |
path: dist/*.tar.gz | |
name: wheels | |
publish: | |
needs: [build-wheels, build-sdist] | |
runs-on: ubuntu-latest | |
steps: | |
- name: Download artifacts | |
uses: actions/download-artifact@v2 | |
with: | |
name: wheels | |
path: wheelhouse | |
- name: Publish to PyPI | |
uses: pypa/gh-action-pypi-publish@release/v1 | |
with: | |
password: ${{ secrets.PYPI_PASSWORD }} | |
packages-dir: wheelhouse | |