-
Notifications
You must be signed in to change notification settings - Fork 100
453 lines (407 loc) · 15.2 KB
/
ci.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
name: CI
on:
push:
branches:
- main
pull_request:
concurrency:
group: ${{ github.workflow }}-${{ github.ref_name }}-${{ github.event.pull_request.number || github.sha }}
cancel-in-progress: true
jobs:
fmt:
runs-on: "ubuntu-latest"
steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: "3.x"
- run: pip install black
- run: black --check .
mypy:
runs-on: "ubuntu-latest"
steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: "3.x"
- run: pip install nox
- run: nox -s mypy
pytest:
runs-on: "ubuntu-latest"
steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: "3.x"
- name: Install Rust toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: stable
profile: minimal
default: true
- run: pip install nox
- run: nox -s test
build:
name: ${{ matrix.python-version }} ${{ matrix.platform.os }}-${{ matrix.platform.python-architecture }}
runs-on: ${{ matrix.platform.os }}
strategy:
# If one platform fails, allow the rest to keep testing if `CI-no-fail-fast` label is present
fail-fast: ${{ !contains(github.event.pull_request.labels.*.name, 'CI-no-fail-fast') }}
matrix:
python-version: ["3.7", "3.8", "3.9", "3.10", pypy-3.7, pypy-3.8]
platform: [
{ os: "macos-latest", python-architecture: "x64", rust-target: "x86_64-apple-darwin" },
{ os: "ubuntu-latest", python-architecture: "x64", rust-target: "x86_64-unknown-linux-gnu" },
{ os: "windows-latest", python-architecture: "x64", rust-target: "x86_64-pc-windows-msvc" },
{ os: "windows-latest", python-architecture: "x86", rust-target: "i686-pc-windows-msvc" },
]
exclude:
# No 32-bit pypy 3.7 on Windows
- python-version: pypy-3.7
platform: { os: "windows-latest", python-architecture: "x86" }
# No 32-bit pypy 3.8 on Windows
- python-version: pypy-3.8
platform: { os: "windows-latest", python-architecture: "x86" }
steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
architecture: ${{ matrix.platform.python-architecture }}
- name: Install Rust toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: stable
target: ${{ matrix.platform.rust-target }}
profile: minimal
default: true
- name: Install Rust aarch64-apple-darwin target
if: matrix.platform.os == 'macos-latest'
run: rustup target add aarch64-apple-darwin
- name: Install test dependencies
run: pip install --upgrade nox
- name: Build package
run: pip install -e .
- name: Test examples
shell: bash
env:
PYTHON: ${{ matrix.python-version }}
run: nox -s test-examples
- name: Test macOS universal2
if: matrix.platform.os == 'macos-latest' && !startsWith(matrix.python-version, 'pypy')
shell: bash
env:
DEVELOPER_DIR: /Applications/Xcode.app/Contents/Developer
MACOSX_DEPLOYMENT_TARGET: '10.9'
ARCHFLAGS: -arch x86_64 -arch arm64
PYO3_CROSS_LIB_DIR: /Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.8/lib
run: |
cd examples/namespace_package
pip install wheel
python setup.py bdist_wheel
ls -l dist/
pip install --force-reinstall dist/namespace_package*_universal2.whl
cd -
python -c "from namespace_package import rust; assert rust.rust_func() == 14"
python -c "from namespace_package import python; assert python.python_func() == 15"
- name: Test sdist vendor Rust crates
shell: bash
run: nox -s test-sdist-vendor
env:
CARGO_BUILD_TARGET: ${{ matrix.platform.rust-target }}
test-abi3:
runs-on: ${{ matrix.os }}
strategy:
# If one platform fails, allow the rest to keep testing if `CI-no-fail-fast` label is present
fail-fast: ${{ !contains(github.event.pull_request.labels.*.name, 'CI-no-fail-fast') }}
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
steps:
- uses: actions/checkout@master
- name: Setup python
uses: actions/setup-python@v2
with:
python-version: 3.9
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
- name: Install Rust aarch64-apple-darwin target
if: matrix.os == 'macos-latest'
run: rustup target add aarch64-apple-darwin
- name: Build package
run: pip install -e .
- name: Build an abi3 wheel
shell: bash
run: |
cd examples/rust_with_cffi/
python --version
pip install -U wheel
python setup.py bdist_wheel --py-limited-api=cp39
ls -la dist/
env:
# https://github.com/actions/setup-python/issues/26
MACOSX_DEPLOYMENT_TARGET: 10.9
# Now we switch to a differnet Python version and ensure we can install
# the wheel we just built.
- name: Setup python
uses: actions/setup-python@v2
with:
python-version: "3.10"
- name: Install abi3 wheel and run tests
shell: bash
run: |
cd examples/
pip install -U wheel
python --version
pip install rust_with_cffi/dist/rust_with_cffi*.whl
python -c "from rust_with_cffi import rust; assert rust.rust_func() == 14"
python -c "from rust_with_cffi.cffi import lib; assert lib.cffi_func() == 15"
test-crossenv:
runs-on: ubuntu-latest
strategy:
# If one platform fails, allow the rest to keep testing if `CI-no-fail-fast` label is present
fail-fast: ${{ !contains(github.event.pull_request.labels.*.name, 'CI-no-fail-fast') }}
matrix:
platform: [
{ target: "aarch64-unknown-linux-gnu", arch: "aarch64" },
{ target: "armv7-unknown-linux-gnueabihf", arch: "armv7" },
]
steps:
- uses: actions/checkout@master
- name: Build wheels
run: |
echo 'set -ex
curl -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain stable
source ~/.cargo/env
rustup target add ${{ matrix.platform.target }}
# https://github.com/pypa/setuptools_scm/issues/707
git config --global --add safe.directory /io
cd examples/rust_with_cffi/
python3.9 -m pip install crossenv
python3.9 -m crossenv "/opt/python/cp39-cp39/bin/python3" --cc $TARGET_CC --cxx $TARGET_CXX --sysroot $TARGET_SYSROOT --env LIBRARY_PATH= --manylinux manylinux1 venv
. venv/bin/activate
build-pip install cffi wheel "setuptools>=62.4"
cross-expose cffi
pip install wheel
pip install -e ../../
python setup.py bdist_wheel --py-limited-api=cp37
ls -la dist/
' > build-wheels.sh
docker run --rm -v "$PWD":/io -w /io messense/manylinux2014-cross:${{ matrix.platform.arch }} bash build-wheels.sh
- name: Install abi3 wheel and run tests
uses: uraimo/[email protected]
with:
arch: ${{ matrix.platform.arch }}
distro: ubuntu20.04
dockerRunArgs: |
--volume "${PWD}/examples:/examples"
install: |
apt-get update
apt-get install -y --no-install-recommends python3 python3-dev python3-pip build-essential libffi-dev
run: |
cd /examples
python3 --version
pip3 install rust_with_cffi/dist/rust_with_cffi*.whl
python3 -c "from rust_with_cffi import rust; assert rust.rust_func() == 14"
python3 -c "from rust_with_cffi.cffi import lib; assert lib.cffi_func() == 15"
test-cross:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Setup python
uses: actions/setup-python@v2
with:
python-version: 3.8
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
- name: Install cross
uses: taiki-e/install-action@v1
with:
tool: cross
- name: Build package
run: pip install -e .
- name: Build wheel using cross
shell: bash
env:
CARGO: cross
CARGO_BUILD_TARGET: aarch64-unknown-linux-gnu
PYO3_CROSS_LIB_DIR: /opt/python/cp38-cp38/lib
run: |
cd examples/namespace_package
docker build -t cross-pyo3:aarch64-unknown-linux-gnu .
python -m pip install wheel
python setup.py bdist_wheel --plat-name manylinux2014_aarch64
ls -la dist/
- uses: uraimo/[email protected]
name: Install built wheel
with:
arch: aarch64
distro: ubuntu20.04
dockerRunArgs: |
--volume "${PWD}/examples/namespace_package:/io"
install: |
apt-get update
apt-get install -y --no-install-recommends python3 python3-pip
pip3 install -U pip
run: |
pip3 install namespace_package --no-index --find-links /io/dist/ --force-reinstall
python3 -c "from namespace_package import rust; assert rust.rust_func() == 14"
python3 -c "from namespace_package import python; assert python.python_func() == 15"
test-zigbuild:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Setup python
uses: actions/setup-python@v2
with:
python-version: 3.8
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
target: aarch64-unknown-linux-gnu
override: true
- name: Install cargo-zigbuild
run: |
python3 -m pip install cargo-zigbuild
- name: Build package
run: pip install -e .
- name: Build wheel using cargo-zigbuild
shell: bash
env:
CARGO: cargo-zigbuild
CARGO_BUILD_TARGET: aarch64-unknown-linux-gnu
PYO3_CROSS_LIB_DIR: /opt/python/cp38-cp38/lib
run: |
mkdir -p $PYO3_CROSS_LIB_DIR
docker cp -L $(docker create --rm quay.io/pypa/manylinux2014_aarch64:latest):/opt/python/cp38-cp38 /opt/python
cd examples/namespace_package
python -m pip install wheel
python setup.py bdist_wheel --plat-name manylinux2014_aarch64
ls -la dist/
- uses: uraimo/[email protected]
name: Install built wheel
with:
arch: aarch64
distro: ubuntu20.04
dockerRunArgs: |
--volume "${PWD}/examples/namespace_package:/io"
install: |
apt-get update
apt-get install -y --no-install-recommends python3 python3-pip
pip3 install -U pip
run: |
pip3 install namespace_package --no-index --find-links /io/dist/ --force-reinstall
python3 -c "from namespace_package import rust; assert rust.rust_func() == 14"
python3 -c "from namespace_package import python; assert python.python_func() == 15"
test-cibuildwheel:
runs-on: macos-latest
steps:
- uses: actions/checkout@v3
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
target: aarch64-apple-darwin
override: true
- uses: pypa/[email protected]
env:
CIBW_BUILD: cp39-*
CIBW_BEFORE_BUILD: pip install -e .
CIBW_ARCHS_MACOS: "x86_64 universal2 arm64"
CIBW_BUILD_VERBOSITY: 1
with:
package-dir: examples/namespace_package
test-mingw:
runs-on: windows-latest
name: ${{ matrix.python-version }} mingw-${{ matrix.arch }}
strategy:
fail-fast: false
matrix:
include: [
{ msystem: MINGW64, arch: x86_64, path: mingw64, rust_target: x86_64-pc-windows-gnu },
{ msystem: MINGW32, arch: i686, path: mingw32, rust_target: i686-pc-windows-gnu }
]
steps:
- uses: actions/checkout@v2
- name: Install MSys2 and dependencies
uses: msys2/setup-msys2@v2
with:
update: true
msystem: ${{ matrix.msystem }}
install: >-
git
mingw-w64-${{ matrix.arch }}-python
mingw-w64-${{ matrix.arch }}-python-pip
mingw-w64-${{ matrix.arch }}-openssl
mingw-w64-${{ matrix.arch }}-toolchain
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable-${{ matrix.rust_target }}
default: true
- name: Install test dependencies
shell: msys2 {0}
run: python -m pip install --upgrade nox pip wheel
- name: Create libpython symlink
shell: msys2 {0}
run: ln -s /${{ matrix.path }}/lib/libpython3.10.dll.a /${{ matrix.path }}/lib/libpython310.dll.a
- name: Test examples
shell: msys2 {0}
run: |
PATH="$PATH:/c/Users/runneradmin/.cargo/bin" nox -s test-mingw
test-emscripten:
name: Test Emscripten
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 18
- run: |
PYODIDE_VERSION=0.21.0
cd emscripten
npm i [email protected] prettier
cd node_modules/pyodide/
node ../prettier/bin-prettier.js -w pyodide.asm.js
EMSCRIPTEN_VERSION=$(node -p "require('./repodata.json').info.platform.split('_').slice(1).join('.')")
PYTHON_VERSION=3.10.2
echo "PYODIDE_VERSION=$PYODIDE_VERSION" >> $GITHUB_ENV
echo "EMSCRIPTEN_VERSION=$EMSCRIPTEN_VERSION" >> $GITHUB_ENV
echo "PYTHON_VERSION=$PYTHON_VERSION" >> $GITHUB_ENV
echo "ORIG_PATH=$PATH" >> $GITHUB_ENV
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: nightly
components: rust-src
target: wasm32-unknown-emscripten
override: true
- uses: mymindstorm/setup-emsdk@v11
with:
version: ${{env.EMSCRIPTEN_VERSION}}
actions-cache-folder: emsdk-cache
- uses: actions/setup-python@v2
id: setup-python
with:
python-version: ${{env.PYTHON_VERSION}}
- run: pip install nox
- uses: actions/cache@v3
with:
path: |
tests/pyodide
key: ${{ hashFiles('tests/*.js') }} - ${{ hashFiles('noxfile.py') }} - ${{ steps.setup-python.outputs.python-path }}
- uses: Swatinem/rust-cache@v1
- name: Test
run: |
export PATH=$ORIG_PATH:$PATH
nox -s test-examples-emscripten