pyo3/.github/workflows/ci.yml

309 lines
11 KiB
YAML
Raw Normal View History

name: CI
2019-11-16 12:39:59 +00:00
2020-08-16 13:36:15 +00:00
on:
push:
branches:
2021-03-16 22:14:57 +00:00
- main
2020-08-16 13:36:15 +00:00
pull_request:
2019-11-16 12:39:59 +00:00
2020-09-01 19:59:28 +00:00
env:
CARGO_TERM_COLOR: always
2019-11-16 12:39:59 +00:00
jobs:
2020-08-08 17:03:16 +00:00
fmt:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
2020-08-16 13:36:15 +00:00
- uses: actions/setup-python@v2
- run: pip install black==20.8b1
2020-08-08 17:03:16 +00:00
- uses: actions-rs/toolchain@v1
with:
toolchain: stable
2020-08-16 13:36:15 +00:00
profile: minimal
components: rustfmt
2020-08-08 17:03:16 +00:00
- name: Check python formatting (black)
run: black --check .
- name: Check rust formatting (rustfmt)
run: cargo fmt --all -- --check
clippy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
toolchain: stable
2020-08-16 13:36:15 +00:00
profile: minimal
components: clippy
2020-08-08 17:03:16 +00:00
- run: make clippy
2021-08-30 08:13:43 +00:00
check-target:
needs: [fmt]
runs-on: ubuntu-latest
strategy:
fail-fast: false # If one platform fails, allow the rest to keep testing.
matrix:
target: [powerpc64le-unknown-linux-gnu, s390x-unknown-linux-gnu, wasm32-wasi]
name: check-${{ matrix.target }}
steps:
- uses: actions/checkout@v2
- name: Install Rust toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: stable
target: ${{ matrix.target }}
profile: minimal
default: true
- name: Run cargo checks
run: |
set -x
2021-11-19 10:45:27 +00:00
VERSIONS=("3.7" "3.8" "3.9" "3.10")
2021-08-30 08:13:43 +00:00
for VERSION in ${VERSIONS[@]}; do
echo "version=$VERSION" > config.txt
echo "suppress_build_script_link_lines=true" >> config.txt
PYO3_BUILD_CONFIG=$(pwd)/config.txt cargo check --all-targets --no-default-features
PYO3_BUILD_CONFIG=$(pwd)/config.txt cargo check --all-targets --no-default-features --features "abi3"
PYO3_BUILD_CONFIG=$(pwd)/config.txt cargo check --all-targets --no-default-features --features "$(make list_all_additive_features)"
PYO3_BUILD_CONFIG=$(pwd)/config.txt cargo check --all-targets --no-default-features --features "abi3 $(make list_all_additive_features)"
2021-08-30 08:13:43 +00:00
done
2019-11-16 12:39:59 +00:00
build:
2020-08-08 17:03:16 +00:00
needs: [fmt] # don't wait for clippy as fails rarely and takes longer
2020-08-16 13:36:15 +00:00
name: python${{ matrix.python-version }}-${{ matrix.platform.python-architecture }} ${{ matrix.platform.os }} ${{ matrix.msrv }}
runs-on: ${{ matrix.platform.os }}
2019-11-16 12:39:59 +00:00
strategy:
fail-fast: false # If one platform fails, allow the rest to keep testing.
2019-11-16 12:39:59 +00:00
matrix:
2020-08-16 13:36:15 +00:00
rust: [stable]
2021-11-19 10:45:27 +00:00
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:
2021-11-19 10:45:27 +00:00
# PyPy doesn't release 32-bit Windows builds any more
2021-04-02 09:39:47 +00:00
- python-version: pypy-3.7
platform: { os: "windows-latest", python-architecture: "x86" }
2021-10-24 20:34:57 +00:00
- python-version: pypy-3.8
platform: { os: "windows-latest", python-architecture: "x86" }
2020-08-16 13:36:15 +00:00
include:
# Test minimal supported Rust version
2021-11-18 11:38:47 +00:00
- rust: 1.48.0
2021-10-24 10:21:23 +00:00
python-version: "3.10"
platform:
{
os: "ubuntu-latest",
python-architecture: "x64",
rust-target: "x86_64-unknown-linux-gnu",
}
2020-08-16 13:36:15 +00:00
msrv: "MSRV"
2019-11-16 12:39:59 +00:00
steps:
2020-03-25 02:28:33 +00:00
- uses: actions/checkout@v2
2021-04-11 22:10:23 +00:00
# macos: install gnu-tar because BSD tar is buggy for github actions
2021-04-11 17:37:35 +00:00
# https://github.com/actions/cache/issues/403
2021-04-11 22:10:23 +00:00
- name: Install GNU tar (macOS only)
if: matrix.platform.os == 'macos-latest'
2021-04-11 17:37:35 +00:00
run: |
brew install gnu-tar
echo "/usr/local/opt/gnu-tar/libexec/gnubin" >> $GITHUB_PATH
2021-04-03 20:59:03 +00:00
- uses: actions/cache@v2
with:
path: |
~/.cargo/registry
~/.cargo/git
target
2021-04-11 22:10:23 +00:00
key: cargo-${{ matrix.python-version }}-${{ matrix.platform.python-architecture }}-${{ matrix.platform.os }}-${{ matrix.msrv }}-${{ hashFiles('**/Cargo.toml') }}
2021-04-18 06:08:16 +00:00
continue-on-error: true
2021-04-03 20:59:03 +00:00
- 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:
2020-08-16 13:36:15 +00:00
toolchain: ${{ matrix.rust }}
target: ${{ matrix.platform.rust-target }}
2020-08-16 13:36:15 +00:00
profile: minimal
default: true
# needed to correctly format errors, see #1865
components: rust-src
2020-08-16 13:36:15 +00:00
- if: matrix.platform.os == 'ubuntu-latest'
name: Prepare LD_LIBRARY_PATH (Ubuntu only)
run: echo LD_LIBRARY_PATH=${pythonLocation}/lib >> $GITHUB_ENV
2021-03-02 22:48:43 +00:00
- name: Prepare workflow settings
id: settings
shell: bash
run: |
echo "::set-output name=all_additive_features::$(make list_all_additive_features)"
2021-03-02 22:48:43 +00:00
2021-03-24 22:29:00 +00:00
- if: matrix.msrv == 'MSRV'
name: Prepare minimal package versions (MSRV only)
run: |
cargo update -p indexmap --precise 1.6.2
cargo update -p hashbrown:0.11.2 --precise 0.9.1
2021-03-24 22:29:00 +00:00
2020-12-17 03:00:48 +00:00
- name: Build docs
2021-04-03 20:59:03 +00:00
run: cargo doc --no-deps --no-default-features --features "${{ steps.settings.outputs.all_additive_features }}"
2020-12-17 03:00:48 +00:00
- name: Build (no features)
2021-03-02 22:48:43 +00:00
run: cargo build --lib --tests --no-default-features
# --no-default-features when used with `cargo build/test -p` doesn't seem to work!
- name: Build pyo3-build-config (no features)
run: |
cd pyo3-build-config
cargo build --no-default-features
2021-03-02 22:48:43 +00:00
# Run tests (except on PyPy, because no embedding API).
2021-04-02 09:39:47 +00:00
- if: ${{ !startsWith(matrix.python-version, 'pypy') }}
2021-03-02 22:48:43 +00:00
name: Test (no features)
run: cargo test --no-default-features
# --no-default-features when used with `cargo build/test -p` doesn't seem to work!
- name: Test pyo3-build-config (no features)
run: |
cd pyo3-build-config
cargo test --no-default-features
- name: Build (all additive features)
2021-03-02 22:48:43 +00:00
run: cargo build --lib --tests --no-default-features --features "${{ steps.settings.outputs.all_additive_features }}"
2021-11-15 04:11:30 +00:00
- if: ${{ startsWith(matrix.python-version, 'pypy') }}
2021-11-19 10:45:27 +00:00
name: Build PyPy (abi3-py37)
run: cargo build --lib --tests --no-default-features --features "abi3-py37 ${{ steps.settings.outputs.all_additive_features }}"
2021-11-15 04:11:30 +00:00
# Run tests (except on PyPy, because no embedding API).
2021-04-02 09:39:47 +00:00
- if: ${{ !startsWith(matrix.python-version, 'pypy') }}
name: Test
2021-03-02 22:48:43 +00:00
run: cargo test --no-default-features --features "${{ steps.settings.outputs.all_additive_features }}"
2020-09-19 15:27:06 +00:00
# Run tests again, but in abi3 mode
2021-04-02 09:39:47 +00:00
- if: ${{ !startsWith(matrix.python-version, 'pypy') }}
name: Test (abi3)
2021-03-02 22:48:43 +00:00
run: cargo test --no-default-features --features "abi3 ${{ steps.settings.outputs.all_additive_features }}"
2021-11-19 10:45:27 +00:00
# Run tests again, for abi3-py37 (the minimal Python version)
- if: ${{ (!startsWith(matrix.python-version, 'pypy')) && (matrix.python-version != '3.7') }}
name: Test (abi3-py37)
run: cargo test --no-default-features --features "abi3-py37 ${{ steps.settings.outputs.all_additive_features }}"
2020-12-15 13:57:09 +00:00
- name: Test proc-macro code
2021-03-02 22:48:43 +00:00
run: cargo test --manifest-path=pyo3-macros-backend/Cargo.toml
- name: Test build config
run: cargo test --manifest-path=pyo3-build-config/Cargo.toml
- name: Install python test dependencies
run: python -m pip install -U pip tox
- name: Test example extension modules
shell: bash
run: |
2021-08-02 21:29:37 +00:00
for example_dir in examples/*/; do
tox -c $example_dir -e py
done
2021-03-02 22:48:43 +00:00
env:
TOX_TESTENV_PASSENV: "CARGO_BUILD_TARGET"
2021-06-27 07:08:41 +00:00
- name: Test cross compilation
if: ${{ matrix.platform.os == 'ubuntu-latest' && matrix.python-version == '3.9' }}
uses: messense/maturin-action@v1
env:
PYO3_CROSS_LIB_DIR: /opt/python/cp39-cp39/lib
with:
target: aarch64-unknown-linux-gnu
manylinux: auto
args: --release -i python3.9 --no-sdist -m examples/maturin-starter/Cargo.toml
2020-01-12 14:33:34 +00:00
env:
2021-03-02 22:48:43 +00:00
CARGO_TERM_VERBOSE: true
CARGO_BUILD_TARGET: ${{ matrix.platform.rust-target }}
2020-01-12 14:33:34 +00:00
RUST_BACKTRACE: 1
2020-12-26 08:11:19 +00:00
RUSTFLAGS: "-D warnings"
2021-03-04 19:41:11 +00:00
RUSTDOCFLAGS: "-D warnings"
# TODO: this is a hack to workaround compile_error! warnings about auto-initialize on PyPy
# Once cargo's `resolver = "2"` is stable (~ MSRV Rust 1.52), remove this.
PYO3_CI: 1
coverage:
needs: [fmt]
name: coverage-${{ matrix.os }}
strategy:
matrix:
os: ["windows", "macos", "ubuntu"]
runs-on: ${{ matrix.os }}-latest
steps:
2020-08-16 13:36:15 +00:00
- uses: actions/checkout@v2
2021-10-24 10:25:10 +00:00
- uses: actions/setup-python@v2
with:
python-version: "3.10"
2021-04-04 07:49:27 +00:00
- uses: actions/cache@v2
with:
path: |
~/.cargo/registry
~/.cargo/git
2021-09-01 19:35:53 +00:00
target
2021-04-04 07:49:27 +00:00
key: coverage-cargo-${{ hashFiles('**/Cargo.toml') }}
2021-04-19 08:50:25 +00:00
continue-on-error: true
- uses: actions-rs/toolchain@v1
with:
toolchain: nightly
override: true
profile: minimal
components: llvm-tools-preview
2021-08-07 22:24:53 +00:00
- name: install cargo-llvm-cov
shell: bash
2021-04-04 07:49:27 +00:00
run: |
host=$(rustc -Vv | grep host | sed 's/host: //')
curl -fsSL https://github.com/taiki-e/cargo-llvm-cov/releases/download/v${CARGO_LLVM_COV_VERSION}/cargo-llvm-cov-"$host".tar.gz | tar xzf - -C ~/.cargo/bin
2021-04-04 07:49:27 +00:00
env:
CARGO_LLVM_COV_VERSION: 0.1.11
- uses: actions-rs/toolchain@v1
with:
toolchain: nightly
override: true
2020-08-16 13:36:15 +00:00
profile: minimal
2021-04-04 07:49:27 +00:00
components: llvm-tools-preview
2021-08-07 22:24:53 +00:00
- run: |
2021-09-01 19:35:53 +00:00
cargo llvm-cov clean --workspace
2021-08-15 21:47:18 +00:00
cargo llvm-cov --package $ALL_PACKAGES --no-report
cargo llvm-cov --package $ALL_PACKAGES --no-report --features abi3
cargo llvm-cov --package $ALL_PACKAGES --no-report --features $(make list_all_additive_features)
cargo llvm-cov --package $ALL_PACKAGES --no-report --features abi3 $(make list_all_additive_features)
2021-08-15 21:47:18 +00:00
cargo llvm-cov --package $ALL_PACKAGES --no-run --lcov --output-path coverage.lcov
shell: bash
2021-08-15 21:47:18 +00:00
env:
ALL_PACKAGES: pyo3 pyo3-build-config pyo3-macros-backend pyo3-macros
2021-10-24 07:15:20 +00:00
- uses: codecov/codecov-action@v2
with:
2021-04-04 07:49:27 +00:00
file: coverage.lcov
name: ${{ matrix.os }}