Skip to content

Commit 6a72786

Browse files
davnnkno10
authored andcommitted
Improve platform support of wheels
1 parent df7d643 commit 6a72786

2 files changed

Lines changed: 84 additions & 61 deletions

File tree

.github/workflows/build-wheels.sh

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/bin/bash
2+
set -e -x
3+
4+
# build wheels
5+
for PYBIN in /opt/python/cp3[891]*/bin; do
6+
"${PYBIN}/pip" install -r requirements.txt -r requirements-dev.txt
7+
"${PYBIN}/maturin" build -i "${PYBIN}/python" --release --strip
8+
done
9+
10+
# check/repair wheels
11+
for wheel in target/wheels/*.whl; do
12+
auditwheel repair "${wheel}"
13+
done
14+
15+
# test wheels
16+
for PYBIN in /opt/python/cp3[891]*/bin; do
17+
"${PYBIN}/pip" install kmedoids --no-index --find-links wheelhouse
18+
cd tests && "${PYBIN}/python" -m unittest discover && cd ..
19+
done

.github/workflows/wheels.yml

Lines changed: 65 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -7,89 +7,94 @@ on:
77
workflow_dispatch:
88

99
jobs:
10-
build-wheels:
11-
name: Build wheels for PyPI
10+
linux-wheels:
11+
runs-on: ubuntu-latest
1212
strategy:
1313
matrix:
14-
os: [ ubuntu-latest, macos-latest, windows-latest ]
15-
python-version: [ "3.8", "3.9", "3.10" ]
16-
runs-on: ${{ matrix.os }}
17-
14+
container:
15+
- "quay.io/pypa/manylinux2014_x86_64"
16+
- "quay.io/pypa/manylinux_2_28_x86_64"
17+
container: ${{ matrix.container }}
1818
steps:
19-
- name: Checkout code
20-
uses: actions/checkout@v2
21-
- name: Setup python
22-
uses: actions/setup-python@v2
19+
- uses: actions/checkout@v3
20+
- name: Build wheels
21+
run: |
22+
curl https://sh.rustup.rs -sSf | sh -s -- -y
23+
source $HOME/.cargo/env
24+
rustup default stable
25+
bash .github/workflows/build-wheels.sh
26+
- uses: actions/upload-artifact@v3
2327
with:
24-
python-version: ${{ matrix.python-version }}
25-
- name: Install prerequisites cffi and virtualenv
26-
run: pip install cffi virtualenv
27-
- name: install Rust toolchain
28-
uses: actions-rs/toolchain@v1
29-
id: rustup
28+
name: wheels
29+
path: wheelhouse
30+
if-no-files-found: error
31+
32+
osx-wheels:
33+
runs-on: macos-latest
34+
strategy:
35+
matrix:
36+
python-version: ["3.8", "3.9", "3.10"]
37+
steps:
38+
- uses: actions/checkout@v3
39+
- uses: actions-rs/toolchain@v1
3040
with:
31-
profile: minimal
3241
toolchain: stable
33-
override: true
34-
35-
# setup macOS as in the maturin tests, see:
36-
# https://github.com/PyO3/maturin/blob/main/.github/workflows/test.yml
37-
- name: Install aarch64-apple-darwin Rust target
38-
if: matrix.os == 'macos-latest'
39-
run: rustup target add aarch64-apple-darwin
40-
- name: Setup Xcode env
41-
if: matrix.os == 'macos-latest'
42-
shell: bash
42+
default: true
43+
- uses: actions/setup-python@v4
44+
with:
45+
python-version: ${{ matrix.python-version }}
46+
- name: Build wheels
4347
run: |
44-
sudo xcode-select -s /Applications/Xcode.app
45-
bindir="$(xcode-select --print-path)/Toolchains/XcodeDefault.xctoolchain/usr/bin"
46-
echo "CC=${bindir}/clang" >> "${GITHUB_ENV}"
47-
echo "CXX=${bindir}/clang++" >> "${GITHUB_ENV}"
48-
echo "SDKROOT=$(xcrun --sdk macosx --show-sdk-path)" >> "${GITHUB_ENV}"
48+
rustup target add aarch64-apple-darwin
49+
python3 -m pip install -r requirements.txt -r requirements-dev.txt
50+
maturin build --release --strip
51+
maturin build --release --strip --universal2
52+
python3 -m pip install kmedoids --no-index --find-links target/wheels
53+
cd tests && python3 -m unittest discover && cd ..
54+
- uses: actions/upload-artifact@v3
55+
with:
56+
name: wheels
57+
path: target/wheels
58+
if-no-files-found: error
4959

50-
- name: Install Python dependencies
51-
run: pip install maturin
60+
windows-wheels:
61+
runs-on: windows-latest
62+
strategy:
63+
matrix:
64+
python-version: ["3.8", "3.9", "3.10"]
65+
steps:
66+
- uses: actions/checkout@v3
67+
- uses: actions-rs/toolchain@v1
68+
with:
69+
toolchain: stable
70+
default: true
71+
- uses: actions/setup-python@v4
72+
with:
73+
python-version: ${{ matrix.python-version }}
5274
- name: Build wheels
53-
if: matrix.os != 'macos-latest'
54-
run: maturin build --release --strip
55-
- name: Build wheels universal2
56-
if: matrix.os == 'macos-latest'
57-
# OSX: universal2 binaries, also for M1
58-
run: maturin build --release --strip --universal2
59-
- name: Run unit tests on Unix
60-
if: matrix.os != 'windows-latest'
61-
# TODO: can we install the wheel built above instead?
6275
run: |
63-
python -m venv venv
64-
source venv/bin/activate
65-
maturin develop --release
66-
python -m unittest discover tests
67-
- name: Run unit tests on Windows
68-
if: matrix.os == 'windows-latest'
69-
# TODO: can we install the wheel built above instead?
70-
run: |
71-
python -m venv venv
72-
venv/Scripts/activate.ps1
73-
maturin develop --release
74-
python -m unittest discover tests
75-
- name: Collect artifacts
76-
uses: actions/upload-artifact@v3
76+
rustup target add
77+
python -m pip install -r requirements.txt -r requirements-dev.txt
78+
maturin build --release --strip
79+
python -m pip install kmedoids --no-index --find-links target/wheels
80+
cd tests && python -m unittest discover && cd ..
81+
- uses: actions/upload-artifact@v3
7782
with:
7883
name: wheels
79-
path: target/wheels/
84+
path: target/wheels
8085
if-no-files-found: error
8186

8287
upload-wheels:
8388
name: Upload wheels to PyPI
84-
needs: build-wheels
89+
needs: [linux-wheels, osx-wheels, windows-wheels]
8590
runs-on: ubuntu-latest
8691
steps:
8792
- name: Collect artifacts
8893
uses: actions/download-artifact@v3
8994
with:
9095
name: wheels
9196
path: wheels/
92-
- name: list contents
97+
- name: List contents
9398
run: ls -R
9499
working-directory: wheels/
95100
- name: Publish to PyPI
@@ -100,4 +105,3 @@ jobs:
100105
packages_dir: wheels/
101106
skip_existing: true
102107
verbose: true
103-

0 commit comments

Comments
 (0)