Skip to content

Commit 251e2c8

Browse files
committed
use cibuildwheel to create wheels
- matrix py versions and platforms to minimize build time - emulated aarch64 builds are very slow - only build universal2 for macos - setuptools-rust ignores ARCHFLAGS when only arm64 given
1 parent e3321a9 commit 251e2c8

File tree

2 files changed

+64
-230
lines changed

2 files changed

+64
-230
lines changed

.github/workflows/ci.yml

+63-229
Original file line numberDiff line numberDiff line change
@@ -192,160 +192,68 @@ jobs:
192192
path: js/
193193
name: wasm-pkg
194194

195-
build-python-wheels-linux:
196-
# Linux wheels can't be built directly but instead need to be built
197-
# via a "manylinux" container as specified by PEPs 513, 571, and 599
198-
name: "Build Linux Wheels"
199-
needs: "test"
200-
# if: "${{ github.ref == 'refs/heads/master' }}"
195+
build-wheels:
196+
name: >
197+
Build Wheel
198+
(${{ matrix.platform.os }}, ${{ matrix.platform.name }}, ${{ matrix.py }})
199+
# needs: test
200+
runs-on: ${{ matrix.platform.os }}
201201
strategy:
202+
fail-fast: false
202203
matrix:
203-
manylinux:
204-
- arch: "manylinux2010_i686"
205-
img: "quay.io/pypa/manylinux2010_i686:2020-12-31-4928808"
206-
- arch: "manylinux2010_x86_64"
207-
img: "quay.io/pypa/manylinux2010_x86_64:2020-12-31-4928808"
208-
- arch: "manylinux2014_i686"
209-
img: "quay.io/pypa/manylinux2014_i686:2020-12-31-56195b3"
210-
- arch: "manylinux2014_x86_64"
211-
img: "quay.io/pypa/manylinux2014_x86_64:2020-12-31-56195b3"
212-
runs-on: "ubuntu-latest"
213-
steps:
214-
# Check out the code
215-
- uses: "actions/checkout@v2"
216-
# Set the current month and year (used for cache key)
217-
- name: "Get Date"
218-
id: get-date
219-
# Outputs e.g. "202007"
220-
# tbh I have yet to find the docs where this output format is
221-
# defined, but I copied this from the official cache action's README.
222-
run: |
223-
echo "::set-output name=date::$(/bin/date -u '+%Y%m')"
224-
shell: bash
225-
226-
# Generate the lockfile
227-
- name: "Generate Cargo Lockfile"
228-
run: "cargo generate-lockfile"
229-
230-
# Cache build dependencies
231-
- name: "Cache Build Fragments"
232-
id: "cache-build-fragments"
233-
uses: "actions/cache@v2"
234-
with:
235-
path: |
236-
~/.cargo/registry
237-
~/.cargo/git
238-
target
239-
# This should partial match the caches generated for the tests,
240-
# which include a python version at the end.
241-
key: "${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}-${{ matrix.manylinux.arch }}"
242-
243-
# Cache `cargo install` built binaries
244-
- name: "Cache Built Binaries"
245-
id: "cache-binaries"
246-
uses: "actions/cache@v2"
247-
with:
248-
path: "~/.cargo/bin"
249-
# In theory, this should rebuild binaries once a month
250-
key: "${{ runner.os }}-cargo-binaries-${{steps.get-date.outputs.date}}"
251-
252-
- name: "Build Wheels"
253-
run: "make build-py-wheel-manylinux"
254-
env:
255-
MANYLINUX_IMG: "${{ matrix.manylinux.img }}"
256-
257-
- uses: "actions/upload-artifact@v2"
258-
with:
259-
path: "dist/*.whl"
260-
name: "py-linux-wheels-${{ matrix.manylinux.arch }}"
204+
platform:
205+
- {os: ubuntu-latest, name: manylinux}
206+
- {os: ubuntu-latest, name: musllinux}
207+
- {os: macos-latest, name: macosx}
208+
- {os: windows-latest, name: win}
209+
py:
210+
- cp36
211+
- cp37
212+
- cp38
213+
- cp39
214+
- cp310
261215

262-
build-python-wheels-mac-windows:
263-
name: "Build MacOS and Windows Python Wheels"
264-
needs: "test"
265-
if: "${{ github.ref == 'refs/heads/master' }}"
266-
strategy:
267-
matrix:
268-
os: [macos-latest, windows-latest]
269-
python-version: ["3.6", "3.7", "3.8", "3.9", "3.10"]
270-
runs-on: "${{ matrix.os }}"
271216
steps:
272-
# Check out the code
273-
- uses: "actions/checkout@v2"
217+
- uses: actions/checkout@v2
274218

275-
# Install python
276-
- name: "Set up python"
277-
uses: "actions/setup-python@v2"
219+
- uses: actions/setup-python@v2
220+
name: Install Python
278221
with:
279-
python-version: "${{ matrix.python-version }}"
280-
281-
- name: "Get Python Path"
282-
id: get-py-path
283-
shell: bash
284-
run: |
285-
echo "::set-output name=path::$(which python)"
286-
287-
# Set the current month and year (used for cache key)
288-
- name: "Get Date"
289-
id: get-date
290-
# Outputs e.g. "202007"
291-
# tbh I have yet to find the docs where this output format is
292-
# defined, but I copied this from the official cache action's README.
293-
run: |
294-
echo "::set-output name=date::$(/bin/date -u '+%Y%m')"
295-
shell: bash
296-
297-
# Generate the lockfile
298-
- name: "Generate Cargo Lockfile"
299-
run: "cargo generate-lockfile"
300-
301-
# Cache build dependencies
302-
- name: "Cache Build Fragments"
303-
id: "cache-build-fragments"
304-
uses: "actions/cache@v2"
305-
with:
306-
path: |
307-
~/.cargo/registry
308-
~/.cargo/git
309-
target
310-
# Use the OS, the python version, and the hashed cargo lockfile as the
311-
# cache key. The Python version shouldn't be necessary, but I have
312-
# seen some weird failures in Windows CI where it gets the built
313-
# python targets confused. The Python version is included at the
314-
# end so it can be partially matched by cache keys in contexts
315-
# where we're not iterating over python envs.
316-
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}-${{ matrix.python-version }}
222+
python-version: '3.10'
317223

318-
# Cache `cargo install` built binaries
319-
- name: "Cache Built Binaries"
320-
id: "cache-binaries"
321-
uses: "actions/cache@v2"
224+
- name: Set up QEMU
225+
if: runner.os == 'Linux'
226+
uses: docker/setup-qemu-action@v1
322227
with:
323-
path: "~/.cargo/bin"
324-
# In theory, this should rebuild binaries once a month
325-
key: "${{ runner.os }}-cargo-binaries-${{steps.get-date.outputs.date}}"
326-
327-
- name: "Perform Setup"
328-
run: "make setup"
329-
shell: bash
330-
env:
331-
WINDOWS: "${{ contains(runner.os, 'windows') }}"
332-
PYTHON: ${{ steps.get-py-path.outputs.path }}
228+
platforms: all
333229

334-
- name: "Build Python Wheel"
335-
run: "make build-py-wheel"
230+
- name: Build wheels
231+
uses: pypa/[email protected]
336232
env:
337-
WINDOWS: "${{ contains(runner.os, 'windows') }}"
338-
PYTHON: ${{ steps.get-py-path.outputs.path }}
339-
340-
- uses: "actions/upload-artifact@v2"
233+
# configure cibuildwheel to build native archs ('auto'), and some
234+
# emulated ones
235+
CIBW_ARCHS_LINUX: x86_64 aarch64
236+
# cross-compiling wheels for discrete architectures not working OOTB
237+
# see: https://github.com/PyO3/setuptools-rust/issues/206
238+
CIBW_ARCHS_MACOS: x86_64 universal2
239+
CIBW_ARCHS_WINDOWS: AMD64
240+
CIBW_BEFORE_ALL_LINUX: >
241+
curl https://sh.rustup.rs -sSf | sh -s -- --default-toolchain stable -y
242+
CIBW_BEFORE_ALL_MACOS: >
243+
rustup target add aarch64-apple-darwin
244+
CIBW_ENVIRONMENT_LINUX: PATH=/root/.cargo/bin:$PATH
245+
CIBW_BUILD: ${{ matrix.py }}-${{ matrix.platform.name }}_*
246+
CIBW_TEST_COMMAND: python {project}/tests/test_py.py
247+
248+
- uses: actions/upload-artifact@v2
341249
with:
342-
path: "dist/*.whl"
343-
name: "py-${{ matrix.python-version }}-${{ runner.os }}-wheels"
250+
name: py-wheels
251+
path: ./wheelhouse/*.whl
344252

345253
distribute:
346254
name: "Distribute Cargo, WASM, and Python Sdist Packages"
347255
needs:
348-
["build", "build-python-wheels-mac-windows", "build-python-wheels-linux"]
256+
["build", "build-wheels"]
349257
runs-on: ubuntu-latest
350258
if: "${{ github.ref == 'refs/heads/master' }}"
351259
steps:
@@ -478,99 +386,25 @@ jobs:
478386
}
479387
})
480388
481-
distribute-py-wheels-mac-windows:
482-
name: "Distribute Mac and Windows Python Wheels"
483-
needs: ["distribute", "build-python-wheels-mac-windows"]
389+
distribute-py-wheels:
390+
name: "Distribute Python Wheels"
391+
needs: ["distribute"]
484392
if: "${{ github.ref == 'refs/heads/master' }}"
485-
strategy:
486-
matrix:
487-
os: [macos-latest, windows-latest]
488-
python-version: ["3.6", "3.7", "3.8", "3.9", "3.10"]
489-
runs-on: "${{ matrix.os }}"
490-
steps:
491-
# Check out the code
492-
- uses: "actions/checkout@v2"
493-
494-
# Install python
495-
- name: "Set up python"
496-
uses: "actions/setup-python@v2"
497-
with:
498-
python-version: "3.8"
499-
500-
- name: "Pull cargo version tracking file"
501-
uses: "actions/download-artifact@v1"
502-
with:
503-
name: "new-cargo"
504-
505-
- name: "Check for new cargo version"
506-
id: cargo-version
507-
shell: bash
508-
run: |
509-
echo "::set-output name=new::$(cat ./new-cargo/tmp-new-cargo-ver)"
510-
511-
- name: "Pull Python Wheels"
512-
if: "${{ steps.cargo-version.outputs.new == 'true' }}"
513-
uses: "actions/download-artifact@v1"
514-
with:
515-
name: "py-${{ matrix.python-version }}-${{ runner.os }}-wheels"
516-
path: dist-py
517-
518-
- name: "Publish Wheels"
519-
if: "${{ steps.cargo-version.outputs.new == 'true' }}"
520-
shell: bash
521-
run: |
522-
pip install twine
523-
twine upload --skip-existing dist-py/*
524-
env:
525-
TWINE_USERNAME: "__token__"
526-
TWINE_PASSWORD: "${{ secrets.PYPI_TOKEN }}"
527-
528-
distribute-py-wheels-linux:
529-
name: "Distribute Linux Python Wheels"
530-
needs: ["distribute", "build-python-wheels-linux"]
393+
# needs: [build_wheels, build_sdist]
531394
runs-on: ubuntu-latest
532-
if: "${{ github.ref == 'refs/heads/master' }}"
533-
strategy:
534-
matrix:
535-
manylinux:
536-
- arch: "manylinux2010_i686"
537-
- arch: "manylinux2010_x86_64"
538-
- arch: "manylinux2014_i686"
539-
- arch: "manylinux2014_x86_64"
395+
# upload to PyPI on every tag starting with 'v'
396+
# if: github.event_name == 'push' && startsWith(github.event.ref, 'refs/tags/v')
397+
# alternatively, to publish when a GitHub Release is created, use the following rule:
398+
# if: github.event_name == 'release' && github.event.action == 'published'
540399
steps:
541-
# Check out the code
542-
- uses: "actions/checkout@v2"
543-
544-
# Install python
545-
- name: "Set up python"
546-
uses: "actions/setup-python@v2"
400+
- uses: actions/download-artifact@v2
547401
with:
548-
python-version: "3.10"
402+
name: py-wheels
403+
path: dist
549404

550-
- name: "Pull cargo version tracking file"
551-
uses: "actions/download-artifact@v1"
405+
- uses: pypa/[email protected]
552406
with:
553-
name: "new-cargo"
554-
555-
- name: "Check for new cargo version"
556-
id: cargo-version
557-
shell: bash
558-
run: |
559-
echo "::set-output name=new::$(cat ./new-cargo/tmp-new-cargo-ver)"
560-
561-
- name: "Pull Python Wheel"
562-
if: "${{ steps.cargo-version.outputs.new == 'true' }}"
563-
uses: "actions/download-artifact@v1"
564-
with:
565-
name: "py-linux-wheels-${{ matrix.manylinux.arch }}"
566-
path: dist-py
567-
568-
- name: "Publish Python Wheels"
569-
if: "${{ steps.cargo-version.outputs.new == 'true' }}"
570-
shell: bash
571-
run: |
572-
pip install twine
573-
twine upload --skip-existing dist-py/*manylinux*
574-
env:
575-
TWINE_USERNAME: "__token__"
576-
TWINE_PASSWORD: "${{ secrets.PYPI_TOKEN }}"
407+
user: __token__
408+
password: ${{ secrets.pypi_password }}
409+
skip_existing: true
410+
# To test: repository_url: https://test.pypi.org/legacy/

pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[build-system]
2-
requires = ["setuptools", "wheel", "setuptools-rust"]
2+
requires = ["setuptools", "wheel", "setuptools-rust>=1.1.2"]
33

44
[tool.black]
55
line-length = 80

0 commit comments

Comments
 (0)