Skip to content

Build binary wheels and upload to PyPI #671

Build binary wheels and upload to PyPI

Build binary wheels and upload to PyPI #671

name: Build binary wheels and upload to PyPI
on:
release:
types: [created]
schedule:
# Build nightly at 05:43 UTC
- cron: '43 5 * * *'
workflow_dispatch: # allow running manually from 'Actions' tab
jobs:
build-source-distribution:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
- name: Build
run: python setup.py sdist
- uses: actions/upload-artifact@v3
with:
name: python-package-distributions
path: dist/
build-wheels-manylinux1:
# Note: the 'manylinux1' image will no longer be supported by PyPA
# after 2022-01-01.
# See: https://github.com/pypa/manylinux/issues/994
name: Build wheels on ubuntu-20.04 - x86_64 - manylinux1
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v3
with:
submodules: 'recursive'
- name: Build Wheels
uses: pypa/[email protected]
env:
CIBW_ARCHS_LINUX: x86_64
CIBW_MANYLINUX_X86_64_IMAGE: manylinux1
CIBW_BUILD: "cp3[6-9]-manylinux*" # manylinux1 has no support for 3.10+ Python or PyPy
CIBW_ENVIRONMENT: >
CRC32C_PURE_PYTHON="0"
CRC32C_INSTALL_PREFIX="$(pwd)/usr"
CIBW_BUILD_VERBOSITY: 1
# Build the C library inside CIBW so that the manylinux image is
# used to link the share library; otherwise, our extension wouldn't
# be able to link with it.
CIBW_BEFORE_BUILD: >
python -m pip install --only-binary --require-hashes -r scripts/requirements.txt &&
cmake -S google_crc32c -B build \
-DCMAKE_BUILD_TYPE=Release \
-DCRC32C_BUILD_TESTS=no \
-DCRC32C_BUILD_BENCHMARKS=no \
-DBUILD_SHARED_LIBS=yes \
-DCMAKE_INSTALL_PREFIX:PATH=$(pwd)/usr &&
make -C build all install
CIBW_TEST_REQUIRES: pytest
CIBW_TEST_COMMAND: py.test -v {project}/tests/
- uses: actions/upload-artifact@v3
with:
name: python-package-distributions
path: wheelhouse/
build-wheels-linux:
name: Build wheels on ${{ matrix.os }} - ${{ matrix.arch }}
strategy:
matrix:
os:
- ubuntu-20.04
arch:
- x86_64
- i686
- aarch64
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
with:
submodules: 'recursive'
- name: Set up QEMU for ARM64 cross compile
if: ${{ matrix.arch }} == 'aarch64'
id: qemu
uses: docker/setup-qemu-action@v2
- name: Build Wheels
uses: pypa/[email protected]
env:
CIBW_ARCHS_LINUX: ${{ matrix.arch }}
CIBW_ENVIRONMENT: >
CRC32C_PURE_PYTHON="0"
CRC32C_INSTALL_PREFIX="$(pwd)/usr"
CIBW_BUILD_VERBOSITY: 1
# Build the C library inside CIBW so that the manylinux image is
# used to link the share library; otherwise, our extension wouldn't
# be able to link with it.
CIBW_BEFORE_BUILD: >
python -m pip install --require-hashes -r scripts/requirements.txt &&
cmake -S google_crc32c -B build \
-DCMAKE_BUILD_TYPE=Release \
-DCRC32C_BUILD_TESTS=no \
-DCRC32C_BUILD_BENCHMARKS=no \
-DBUILD_SHARED_LIBS=yes \
-DCMAKE_INSTALL_PREFIX:PATH=$(pwd)/usr &&
make -C build all install
CIBW_TEST_REQUIRES: pytest
CIBW_TEST_COMMAND: py.test -v {project}/tests/
- uses: actions/upload-artifact@v3
with:
name: python-package-distributions
path: wheelhouse/
build-wheels-macos:
name: Build wheels on ${{ matrix.os }} - ${{ matrix.arch }}
strategy:
matrix:
os:
- macos-10.15
#- macos-11
arch:
- x86_64
- universal2
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
with:
submodules: 'recursive'
- name: Get C library hash
id: get-c-lib-hash
run:
echo "::set-output name=hash::$(git -C google_crc32c log -n 1 --pretty=%H)"
- id: load-cache
name: Load cached C library
uses: actions/cache@v3
with:
path: ${{ github.workspace }}/usr
key:
libcrc32c-${{ matrix.os }}-${{ steps.get-c-lib-hash.outputs.hash }}
- name: Build C Library
if: steps.load-cache.outputs.cache-hit != 'true'
run: >
python -m pip install --require-hashes -r scripts/requirements.txt &&
cmake -S google_crc32c -B build \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_OSX_DEPLOYMENT_TARGET=10.9 \
-DCMAKE_OSX_ARCHITECTURES="arm64;x86_64" \
-DCRC32C_BUILD_TESTS=no \
-DCRC32C_BUILD_BENCHMARKS=no \
-DBUILD_SHARED_LIBS=yes \
-DCMAKE_INSTALL_PREFIX:PATH=${{ github.workspace }}/usr \
-DCMAKE_INSTALL_NAME_DIR:PATH=${{ github.workspace }}/usr/lib &&
make -C build all install
- name: Build Wheels
uses: pypa/[email protected]
env:
CIBW_ARCHS_MACOS: ${{ matrix.arch }}
CIBW_ENVIRONMENT: >
CRC32C_PURE_PYTHON="0"
CRC32C_INSTALL_PREFIX="$(pwd)/usr"
CIBW_BUILD_VERBOSITY: 1
CIBW_TEST_REQUIRES: pytest
CIBW_TEST_COMMAND: py.test -v {project}/tests/
- uses: actions/upload-artifact@v3
with:
name: python-package-distributions
path: wheelhouse/
build-wheels-windows:
name: Build wheels on ${{ matrix.os }} ( ${{ matrix.platform }} )
strategy:
matrix:
os:
- windows-2019
platform:
- x64
- Win32
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
with:
submodules: 'recursive'
- name: Get C library hash
id: get-c-lib-hash
run:
echo "::set-output name=hash::$(git -C google_crc32c log -n 1 --pretty=%H)"
- id: load-cache
name: Load cached C library
uses: actions/cache@v3
with:
path: ${{ github.workspace }}\usr
key:
libcrc32c-${{ matrix.os }}-${{ matrix.platform }}-${{ steps.get-c-lib-hash.outputs.hash }}
- name: Build C Library
if: steps.load-cache.outputs.cache-hit != 'true'
run: |
python -m pip install --require-hashes -r scripts/requirements.txt
cmake -S google_crc32c -B build -G "Visual Studio 16 2019" -A ${{ matrix.platform }} -DCRC32C_BUILD_BENCHMARKS=no -DCRC32C_BUILD_TESTS=no -DBUILD_SHARED_LIBS=no -DCMAKE_WINDOWS_EXPORT_ALL_SYMBOLS=yes -DCRC32C_USE_GLOG=0
cmake --build build --verbose --config Release
cmake --install build --verbose --config Release --prefix=${{ github.workspace }}\usr\
# Passing through ${{ github.workspace }} to CIBW_ENVIRONMENT mangles
# backslashes: compute a variant which uses only forward-slashses.
- id: crc32c-install-prefix
name: Dead-reckon a CIBW-compatible install prefix
shell: bash
run: |
python -c "import os; workspace = '/'.join(os.getenv('GITHUB_WORKSPACE').split(os.sep)); pfx = f'{workspace}/usr'; print(f'::set-output name=prefix::{pfx}')"
- id: platform-arch
name: Map platform -> wheel arch
shell: bash
run: |
if [[ "${{ matrix.platform }}" == "Win32" ]]; then
echo "::set-output name=arch::x86"
else
echo "::set-output name=arch::AMD64"
fi
- name: Build Wheels
uses: pypa/[email protected]
env:
CIBW_ARCHS_WINDOWS: ${{ steps.platform-arch.outputs.arch }}
CIBW_ENVIRONMENT: >
CRC32C_INSTALL_PREFIX="${{ steps.crc32c-install-prefix.outputs.prefix }}"
CRC32C_PURE_PYTHON="0"
CIBW_BUILD_VERBOSITY: 1
CIBW_TEST_REQUIRES: pytest
CIBW_TEST_COMMAND: py.test -v {project}/tests
- uses: actions/upload-artifact@v3
with:
name: python-package-distributions
path: wheelhouse/
publish:
if: github.event_name == 'release'
needs:
- build-source-distribution
- build-wheels-manylinux1
- build-wheels-linux
- build-wheels-macos
- build-wheels-windows
runs-on: ubuntu-latest
steps:
- name: Download all the dists
uses: actions/download-artifact@v3
with:
name: python-package-distributions
path: dist/
- name: Download all the wheels
uses: actions/download-artifact@v3
with:
name: python-package-distributions
path: wheelhouse/
- name: What will we publish?
run: ls wheelhouse/
- name: Publish Source Distribution
uses: pypa/gh-action-pypi-publish@master
with:
user: __token__
password: ${{ secrets.PYPI_API_TOKEN }}
packages_dir: dist/
skip_existing: true
# repository_url: https://test.pypi.org/legacy/
- name: Publish Wheels
uses: pypa/gh-action-pypi-publish@master
with:
user: __token__
password: ${{ secrets.PYPI_API_TOKEN }}
packages_dir: wheelhouse/
skip_existing: true
# repository_url: https://test.pypi.org/legacy/