Debian Codegraph @

.github/workflows/test.yml

raw
1 name: Test
2
3 on:
4 pull_request:
5 paths-ignore:
6 - "guide/**"
7 - "sysconfig/**"
8 - "**.md"
9 - ".cirrus.yml"
10 - ".github/ISSUE_TEMPLATE/**"
11 - ".github/dependabot.yml"
12 workflow_dispatch:
13
14 concurrency:
15 group: ${{ github.workflow }}-${{ github.ref_name }}-${{ github.event.pull_request.number }}
16 cancel-in-progress: true
17
18 jobs:
19 lint:
20 name: Lint
21 runs-on: ubuntu-latest
22 steps:
23 - uses: actions/checkout@v4
24 - run: |
25 rustup component add rustfmt
26 rustup component add clippy
27 - name: cargo fmt
28 run: cargo fmt --all -- --check
29 - uses: EmbarkStudios/cargo-deny-action@v2
30 with:
31 arguments: --all-features
32 - name: cargo clippy
33 run: cargo clippy --tests --all-features -- -D warnings
34
35 test:
36 name: Test
37 strategy:
38 fail-fast: false
39 matrix:
40 os:
41 - ubuntu-latest
42 - ubuntu-22.04-arm
43 - macos-13
44 - macos-14
45 - windows-latest
46 python-version:
47 - "3.9"
48 - "3.13"
49 - "3.13t"
50 - "pypy3.11"
51 include:
52 - os: windows-11-arm
53 python-version: "3.13"
54 exclude:
55 # Skip PyPy on macOS M1 runner because they are built for x86_64
56 - os: macos-14
57 python-version: pypy3.11
58 # TODO: Tests are getting stuck
59 - os: ubuntu-latest
60 python-version: pypy3.11
61 # macOS M1 runner only have Python 3.11+
62 - os: macos-14
63 python-version: 3.9
64 # PyPy on ARM is not supported in setup-python action
65 - os: ubuntu-22.04-arm
66 python-version: pypy3.11
67 runs-on: ${{ matrix.os }}
68 env:
69 RUST_BACKTRACE: "1"
70 steps:
71 - name: Enable long paths
72 if: startsWith(matrix.os, 'windows')
73 run: |
74 reg add HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\FileSystem /v LongPathsEnabled /t REG_DWORD /d 1 /f
75 - name: Cleanup Disk
76 if: ${{ !startsWith(matrix.os, 'windows') }}
77 run: |
78 sudo rm -rf /usr/share/dotnet
79 sudo rm -rf /opt/ghc
80 - name: sccache setup
81 if: ${{ matrix.os != 'windows-11-arm' }}
82 uses: mozilla-actions/[email protected]
83 with:
84 version: "v0.10.0"
85 - name: Enable sccache
86 if: ${{ matrix.os != 'windows-11-arm' }}
87 run: |
88 echo "SCCACHE_GHA_ENABLED=true" >> $GITHUB_ENV
89 echo "RUSTC_WRAPPER=sccache" >> $GITHUB_ENV
90 - uses: actions/checkout@v4
91 - uses: astral-sh/setup-uv@v6
92 - name: Install python packages
93 run: |
94 uv tool install virtualenv
95 uv tool install twine
96 uv tool install uniffi-bindgen==0.28.0
97 - uses: conda-incubator/setup-miniconda@v3
98 if: ${{ matrix.os != 'windows-11-arm' }}
99 with:
100 auto-activate-base: "false"
101 activate-environment: ""
102 miniconda-version: "latest"
103 - uses: actions/setup-python@v5
104 with:
105 python-version: ${{ matrix.python-version }}
106 - name: Set PYTHON_VERSION env var
107 shell: bash
108 run: |
109 set -ex
110 # remove -dev suffix
111 python_version=$(echo ${{ matrix.python-version }} | sed -e s/-dev//)
112 echo "PYTHON_VERSION=$python_version" >> "${GITHUB_ENV}"
113 - uses: mlugg/setup-zig@v2
114 if: ${{ matrix.os != 'windows-11-arm' }}
115 with:
116 version: 0.12.1
117 - uses: dtolnay/rust-toolchain@stable
118 id: rustup
119 with:
120 targets: wasm32-wasip1 # Used by the test suite
121 - name: Install cargo-nextest
122 uses: taiki-e/install-action@nextest
123 - name: Install additional Rust target
124 if: startsWith(matrix.os, 'macos')
125 run: rustup target add aarch64-apple-darwin x86_64-apple-darwin
126 - name: Setup Xcode env
127 if: startsWith(matrix.os, 'macos')
128 shell: bash
129 run: |
130 set -ex
131 sudo xcode-select -s /Applications/Xcode.app
132 bindir="$(xcode-select --print-path)/Toolchains/XcodeDefault.xctoolchain/usr/bin"
133 echo "CC=${bindir}/clang" >> "${GITHUB_ENV}"
134 echo "CXX=${bindir}/clang++" >> "${GITHUB_ENV}"
135 echo "SDKROOT=$(xcrun --sdk macosx --show-sdk-path)" >> "${GITHUB_ENV}"
136
137 # Caching
138 - name: Set MATURIN_TEST_PYTHON for PyPy
139 shell: bash
140 if: contains(matrix.python-version, 'pypy')
141 run: echo "MATURIN_TEST_PYTHON=pypy3" >> $GITHUB_ENV
142 # To save disk space
143 - name: Disable debuginfo on Windows
144 if: startsWith(matrix.os, 'windows')
145 run: echo "RUSTFLAGS="-C debuginfo=0"" >> $GITHUB_ENV
146 - name: cargo test
147 run: cargo nextest run --features password-storage
148 # TODO: https://github.com/PyO3/maturin/issues/2263
149 #- name: test cross compiling with zig
150 # if: ${{ !contains(matrix.python-version, '-dev') }}
151 # shell: bash
152 # run: |
153 # set -ex
154 # rustup target add aarch64-unknown-linux-gnu
155 # rustup target add aarch64-unknown-linux-musl
156 # rustup target add aarch64-apple-darwin
157 #
158 # # abi3
159 # cargo run build -i $PYTHON_VERSION -m test-crates/pyo3-pure/Cargo.toml --target aarch64-unknown-linux-gnu --zig
160 # cargo run build -i $PYTHON_VERSION -m test-crates/pyo3-pure/Cargo.toml --target aarch64-unknown-linux-musl --zig
161 # if [[ "$PYTHON_VERSION" != "pypy"* ]]; then
162 # cargo run build -i $PYTHON_VERSION -m test-crates/pyo3-pure/Cargo.toml --target aarch64-apple-darwin --zig
163 # fi
164 #
165 # if [[ "$PYTHON_VERSION" == "3.1"* ]]; then
166 # # Check abi3 wheels with abi3audit on CPython only
167 # pip install abi3audit
168 # abi3audit test-crates/pyo3-pure/target/wheels/*.whl
169 # fi
170 # # Check wheels with twine
171 # twine check --strict test-crates/pyo3-pure/target/wheels/*.whl
172 #
173 # # non-abi3
174 # cargo run build -i $PYTHON_VERSION -m test-crates/pyo3-mixed/Cargo.toml --target aarch64-unknown-linux-gnu --zig
175 # if [[ "$PYTHON_VERSION" != "pypy"* ]]; then
176 # cargo run build -i $PYTHON_VERSION -m test-crates/pyo3-mixed/Cargo.toml --target aarch64-apple-darwin --zig
177 # fi
178 # # Check wheels with twine
179 # twine check --strict test-crates/pyo3-mixed/target/wheels/*.whl
180 - name: test compiling with PYO3_CONFIG_FILE
181 if: ${{ matrix.os != 'windows-11-arm' }}
182 shell: bash
183 run: |
184 set -ex
185 rustup target add x86_64-unknown-linux-gnu
186 export PYO3_CONFIG_FILE=$(pwd)/test-crates/pyo3-mixed/pyo3-config.txt
187 target/debug/maturin build -m test-crates/pyo3-mixed/Cargo.toml --target x86_64-unknown-linux-gnu --zig
188 - name: test maturin new
189 shell: bash
190 run: |
191 set -ex
192 target/debug/maturin new -b pyo3 test-crates/pyo3-new
193 target/debug/maturin build -m test-crates/pyo3-new/Cargo.toml --target-dir test-crates/targets/
194 target/debug/maturin new --mixed -b pyo3 test-crates/pyo3-new-mixed
195 target/debug/maturin build -m test-crates/pyo3-new-mixed/Cargo.toml --target-dir test-crates/targets/
196
197 build-maturin:
198 name: Build maturin
199 runs-on: ubuntu-latest
200 steps:
201 - uses: actions/checkout@v4
202 - run: rustup show
203 - run: rustup target add x86_64-unknown-linux-musl
204 - run: sudo apt-get install musl-tools
205 - uses: Swatinem/rust-cache@v2
206 - run: cargo build --target x86_64-unknown-linux-musl --release
207 - uses: actions/upload-artifact@v4
208 with:
209 name: maturin-build
210 path: target/x86_64-unknown-linux-musl/release/maturin
211
212 test-windows-cross:
213 name: Test windows cross
214 needs: build-maturin
215 runs-on: ubuntu-latest
216 env:
217 RUST_BACKTRACE: "1"
218 SCCACHE_GHA_ENABLED: "true"
219 RUSTC_WRAPPER: "sccache"
220 steps:
221 - uses: actions/checkout@v4
222 - name: Sccache Setup
223 uses: mozilla-actions/[email protected]
224 with:
225 version: "v0.10.0"
226 - uses: actions/setup-python@v5
227 with:
228 python-version: 3.12
229 - uses: actions/download-artifact@v4
230 with:
231 name: maturin-build
232 path: bin
233 - run: chmod +x bin/maturin
234 - name: test cross compiling windows wheel
235 run: |
236 set -ex
237 sudo apt-get install -y mingw-w64
238 rustup component add llvm-tools-preview
239 rustup target add x86_64-pc-windows-gnu
240 rustup target add x86_64-pc-windows-msvc
241
242 # abi3
243 bin/maturin build -m test-crates/pyo3-pure/Cargo.toml --target x86_64-pc-windows-gnu
244 bin/maturin build -m test-crates/pyo3-pure/Cargo.toml --target x86_64-pc-windows-msvc
245
246 # no-abi3
247 bin/maturin build -i python3.12 -m test-crates/pyo3-mixed/Cargo.toml --target x86_64-pc-windows-msvc
248
249 test-emscripten:
250 name: Test Emscripten
251 runs-on: ubuntu-latest
252 env:
253 PYODIDE_VERSION: "0.23.4"
254 PYTHON_VERSION: "3.11.2"
255 NODE_VERSION: 18
256 steps:
257 - uses: actions/checkout@v4
258 - uses: actions/setup-python@v5
259 id: setup-python
260 with:
261 python-version: ${{ env.PYTHON_VERSION }}
262 - uses: actions/setup-node@v4
263 with:
264 node-version: ${{ env.NODE_VERSION }}
265 - uses: dtolnay/rust-toolchain@nightly
266 with:
267 components: rust-src
268 targets: wasm32-unknown-emscripten
269 - uses: Swatinem/rust-cache@v2
270 with:
271 shared-key: maturin-build
272 - uses: astral-sh/setup-uv@v6
273 - run: uv tool install nox
274 - name: Setup Pyodide
275 run: nox -s setup-pyodide
276 - uses: mymindstorm/setup-emsdk@v14
277 with:
278 version: ${{ env.EMSCRIPTEN_VERSION }}
279 actions-cache-folder: emsdk-cache
280 - uses: actions/setup-node@v4
281 with:
282 node-version: ${{ env.NODE_VERSION }}
283 - name: Run tests
284 run: nox -s test-emscripten
285
286 test-alpine:
287 name: Test Alpine Linux
288 runs-on: ubuntu-latest
289 env:
290 RUST_BACKTRACE: "1"
291 CARGO_INCREMENTAL: "0"
292 CARGO_TERM_COLOR: always
293 container: alpine:latest
294 steps:
295 - name: Install build requirements
296 run: |
297 set -ex
298 apk add cargo python3-dev libffi-dev py3-pip curl \
299 bash tar zstd git patchelf py3-virtualenv
300 - uses: actions/checkout@v4
301 - name: Fix git permissions
302 run: git config --global --add safe.directory $GITHUB_WORKSPACE
303 - name: Cache cargo build
304 uses: Swatinem/rust-cache@v2
305 with:
306 shared-key: maturin-build
307 - name: Install cargo-nextest
308 uses: taiki-e/install-action@nextest
309 - name: cargo test
310 run: |
311 # unset GITHUB_ACTIONS env var to disable zig related tests
312 env -u GITHUB_ACTIONS cargo nextest run --features password-storage
313
314 test-auditwheel:
315 name: Test Auditwheel
316 needs: build-maturin
317 runs-on: ubuntu-latest
318 strategy:
319 fail-fast: false
320 matrix:
321 manylinux: ["manylinux_2_28"]
322 container: quay.io/pypa/${{ matrix.manylinux }}_x86_64
323 steps:
324 - uses: actions/checkout@v4
325 - uses: dtolnay/rust-toolchain@stable
326 - uses: actions/download-artifact@v4
327 with:
328 name: maturin-build
329 path: bin
330 - run: chmod +x bin/maturin
331 - name: Compliant Build
332 run: tests/manylinux_compliant.sh bin/maturin ${{ matrix.manylinux }}
333 - name: Incompliant Build
334 if: matrix.manylinux == 'manylinux_2_28'
335 run: tests/manylinux_incompliant.sh bin/maturin
336
337 test-docker:
338 name: Test Docker
339 runs-on: ubuntu-latest
340 env:
341 CARGO_INCREMENTAL: "0"
342 CARGO_TERM_COLOR: always
343 steps:
344 - uses: actions/checkout@v4
345 - uses: actions/setup-python@v5
346 with:
347 python-version: "3.11"
348 - name: Login to GitHub Container Registry
349 uses: docker/login-action@v3
350 with:
351 registry: ghcr.io
352 username: ${{ github.actor }}
353 password: ${{ secrets.GITHUB_TOKEN }}
354 - uses: docker/setup-buildx-action@v3
355 - name: Build
356 uses: docker/build-push-action@v6
357 with:
358 context: .
359 push: false
360 tags: maturin
361 load: true
362 cache-from: type=registry,ref=ghcr.io/pyo3/maturin:buildcache
363 - name: Test the Docker container
364 run: ./test-dockerfile.sh
365
366 test-cross-compile:
367 name: Test Cross Compile
368 needs: build-maturin
369 runs-on: ubuntu-latest
370 container: ${{ matrix.platform.container }}
371 strategy:
372 fail-fast: false
373 matrix:
374 platform:
375 # CPython
376 - target: aarch64-unknown-linux-gnu
377 abi: cp39-cp39
378 python: python3.9
379 container: ghcr.io/rust-cross/manylinux2014-cross:aarch64
380 - target: armv7-unknown-linux-gnueabihf
381 abi: cp39-cp39
382 python: python3.9
383 container: ghcr.io/rust-cross/manylinux2014-cross:armv7
384 - target: s390x-unknown-linux-gnu
385 abi: cp310-cp310
386 python: python3.10
387 container: ghcr.io/rust-cross/manylinux2014-cross:s390x
388 - target: loongarch64-unknown-linux-gnu
389 abi: cp310-cp310
390 python: python3.10
391 container: ghcr.io/rust-cross/manylinux_2_36-cross:loongarch64
392 - target: riscv64gc-unknown-linux-gnu
393 abi: cp310-cp310
394 python: python3.10
395 container: ghcr.io/rust-cross/manylinux_2_31-cross:riscv64
396 extra-args: --manylinux 2_31
397 # PyPy
398 - target: aarch64-unknown-linux-gnu
399 abi: pp310-pypy310_pp73
400 python: pypy3.10
401 container: ghcr.io/rust-cross/manylinux2014-cross:aarch64
402 steps:
403 - uses: actions/checkout@v4
404 - uses: actions/download-artifact@v4
405 with:
406 name: maturin-build
407 path: bin
408 - run: chmod +x bin/maturin
409 - uses: dtolnay/rust-toolchain@stable
410 with:
411 targets: ${{ matrix.platform.target }}
412 - name: Build wheels
413 run: |
414 set -ex
415 # Use bundled sysconfig
416 bin/maturin build -i ${{ matrix.platform.python }} --release --out dist --target ${{ matrix.platform.target }} -m test-crates/pyo3-mixed/Cargo.toml ${{ matrix.platform.extra-args }}
417
418 # Use PYO3_CROSS_LIB_DIR
419 export PYO3_CROSS_LIB_DIR=/opt/python/${{ matrix.platform.abi }}
420 bin/maturin build -i python3.9 --release --out dist --target ${{ matrix.platform.target }} -m test-crates/pyo3-mixed/Cargo.toml ${{ matrix.platform.extra-args }}
421 unset PYO3_CROSS_LIB_DIR
422
423 # Test abi3
424 bin/maturin build -i ${{ matrix.platform.python }} --release --out dist --target ${{ matrix.platform.target }} -m test-crates/pyo3-pure/Cargo.toml ${{ matrix.platform.extra-args }}
425
426 # --find-interpreter
427 bin/maturin build --find-interpreter --release --out dist --target ${{ matrix.platform.target }} -m test-crates/pyo3-mixed/Cargo.toml ${{ matrix.platform.extra-args }}
428
429 test-bootstrap:
430 name: Test Bootstrap
431 runs-on: ${{ matrix.os }}
432 env:
433 SCCACHE_GHA_ENABLED: "true"
434 RUSTC_WRAPPER: "sccache"
435 strategy:
436 fail-fast: false
437 matrix:
438 os: [ubuntu-latest, macos-14, windows-latest]
439 steps:
440 - uses: actions/checkout@v4
441 - uses: dorny/paths-filter@v3
442 id: changes
443 with:
444 filters: |
445 changed:
446 - 'maturin/**'
447 - 'pyproject.toml'
448 - 'setup.py'
449 - 'MANIFEST.in'
450 - 'Cargo.toml'
451 - '.github/workflows/test.yml'
452 - uses: astral-sh/setup-uv@v6
453 # Caching
454 - name: Sccache Setup
455 if: ${{ steps.changes.outputs.changed == 'true' || contains(github.event.pull_request.labels.*.name, 'release') }}
456 uses: mozilla-actions/[email protected]
457 with:
458 version: "v0.10.0"
459 - uses: actions/setup-python@v5
460 if: ${{ steps.changes.outputs.changed == 'true' || contains(github.event.pull_request.labels.*.name, 'release') }}
461 with:
462 python-version: "3.10"
463 - name: Build and install
464 shell: bash
465 run: |
466 set -ex
467 cargo run sdist -o dist
468 uv pip install --system -v dist/maturin-*.tar.gz
469 if: ${{ steps.changes.outputs.changed == 'true' || contains(github.event.pull_request.labels.*.name, 'release') }}
470 - run: maturin --version
471 if: ${{ steps.changes.outputs.changed == 'true' || contains(github.event.pull_request.labels.*.name, 'release') }}
472 - run: python3 -m maturin --version
473 if: ${{ steps.changes.outputs.changed == 'true' || contains(github.event.pull_request.labels.*.name, 'release') }}
474 - name: Upload wheel artifacts
475 if: ${{ steps.changes.outputs.changed == 'true' || contains(github.event.pull_request.labels.*.name, 'release') }}
476 uses: actions/upload-artifact@v4
477 with:
478 name: wheels-${{ runner.os }}
479 path: dist
480
481 test-msrv:
482 name: Test MSRV
483 runs-on: ubuntu-latest
484 steps:
485 - uses: actions/checkout@v4
486 - uses: dtolnay/[email protected]
487 # Caching
488 - name: Cache cargo build
489 uses: Swatinem/rust-cache@v2
490 - run: cargo build --no-default-features
491 - name: cargo build
492 run: cargo build --all
493
494 test-downstream:
495 name: Test downstream - ${{ matrix.downstream.repository }}
496 if: ${{ contains(github.event.pull_request.labels.*.name, 'sdist') && github.event_name == 'pull_request' }}
497 uses: ./.github/workflows/downstream.yml
498 with:
499 repository: ${{ matrix.downstream.repository }}
500 manifest-dir: ${{ matrix.downstream.manifest-dir }}
501 strategy:
502 fail-fast: false
503 matrix:
504 downstream:
505 - repository: "pola-rs/polars"
506 manifest-dir: "py-polars"
507 - repository: "astral-sh/ruff"
508 manifest-dir: "crates/ruff_cli"
509 - repository: "crate-ci/typos"
510 manifest-dir: "crates/typos-cli"
511 - repository: "ast-grep/ast-grep"
512 manifest-dir: "crates/pyo3"
513 - repository: "oxigraph/oxigraph"
514 manifest-dir: "python"
515
516 check:
517 name: Check ${{ matrix.platform.target }}
518 strategy:
519 fail-fast: false
520 matrix:
521 platform:
522 - target: armv5te-unknown-linux-gnueabi
523 apt-packages: gcc-arm-linux-gnueabi
524 runs-on: ubuntu-latest
525 steps:
526 - uses: actions/checkout@v4
527 - name: Install packages
528 run: |
529 sudo apt-get update
530 sudo apt-get install -y ${{ matrix.platform.apt-packages }}
531 - run: rustup target add ${{ matrix.platform.target }}
532 - name: Cache cargo build
533 uses: Swatinem/rust-cache@v2
534 - name: cargo check
535 run: cargo check --target ${{ matrix.platform.target }}
536
537 conclusion:
538 needs:
539 - test
540 - test-emscripten
541 - test-alpine
542 - test-auditwheel
543 - test-docker
544 - test-cross-compile
545 - test-bootstrap
546 - test-msrv
547 - test-downstream
548 - check
549 runs-on: ubuntu-latest
550 steps:
551 - name: Result
552 run: |
553 jq -C <<< "${needs}"
554 # Check if all needs were successful or skipped.
555 "$(jq -r 'all(.result as $result | (["success", "skipped"] | contains([$result])))' <<< "${needs}")"
556 env:
557 needs: ${{ toJson(needs) }}