co3 0.4.0

Build C API from Rust
Documentation
name: CI

on:
  push:
    branches: [main]
  pull_request:
    branches: [main]

permissions:
  contents: read

concurrency:
  group: ${{ github.workflow }}-${{ github.head_ref || github.ref }}
  cancel-in-progress: true

jobs:
  static-analysis:
    runs-on: ubuntu-latest
    timeout-minutes: 5

    steps:
    - uses: actions/checkout@v7
    - uses: dtolnay/rust-toolchain@stable
      with:
        components: rustfmt, clippy
    - uses: Swatinem/rust-cache@v2

    - name: Check formatting
      run: cargo fmt --all --check

    - name: Check documentation
      env:
        RUSTDOCFLAGS: -D warnings
      run: cargo doc --workspace --no-deps

    - name: Lint workspace
      run: cargo clippy --workspace --benches --tests --examples -- --deny warnings

    - name: Lint workspace (no default features)
      run: cargo clippy --workspace --benches --tests --examples --no-default-features -- --deny warnings

    - name: Lint workspace (alloc only)
      run: cargo clippy --workspace --benches --tests --examples --no-default-features --features alloc -- --deny warnings

    - name: Lint workspace (derive only)
      run: cargo clippy --workspace --benches --tests --examples --no-default-features --features derive -- --deny warnings

  #allocator-api:
  #  runs-on: ubuntu-latest
  #  timeout-minutes: 5

  #  steps:
  #  - uses: actions/checkout@v7
  #  - uses: dtolnay/rust-toolchain@nightly
  #    with:
  #      components: clippy
  #  - uses: Swatinem/rust-cache@v2
  #    with:
  #      key: allocator-api

  #  - name: Lint workspace
  #    run: cargo +nightly clippy --workspace --benches --tests --examples --features allocator-api -- --deny warnings --allow unused-features

  #  - name: Lint workspace (alloc only)
  #    run: cargo +nightly clippy --workspace --benches --tests --examples --no-default-features --features allocator-api,alloc -- --deny warnings --allow unused-features

  #  - name: Lint workspace (derive only)
  #    run: cargo +nightly clippy --workspace --benches --tests --examples --no-default-features --features allocator-api,derive -- --deny warnings --allow unused-features

  test:
    runs-on: ${{ matrix.os }}
    timeout-minutes: 5

    strategy:
      matrix:
        os: [ubuntu-latest, macos-latest, windows-latest]

    steps:
    - uses: actions/checkout@v7
    - uses: dtolnay/rust-toolchain@stable
      with:
        components: rust-src
    - uses: Swatinem/rust-cache@v2
      with:
        key: test-${{ matrix.os }}

    - name: Run Tests
      env:
        RUSTFLAGS: -D warnings
      run: cargo test --workspace

  miri:
    runs-on: ubuntu-latest
    timeout-minutes: 15

    steps:
    - uses: actions/checkout@v7
    - uses: dtolnay/rust-toolchain@nightly
      with:
        components: miri
    - uses: Swatinem/rust-cache@v2
      with:
        key: miri

    - name: Prepare Miri
      run: cargo miri setup

    - name: Run Miri with leak checking
      run: |
        cargo miri test --all-features --lib -- \
          --skip tests::encode_stored_mut_box_allows_pointer_replacement
        cargo miri test --all-features --test export

    # Stable opaque types use ZST stand-ins. These tests form Rust references to those stand-ins
    # before passing their pointers back to the provider. Stacked Borrows rejects the resulting
    # zero-byte-to-full-allocation access; Tree Borrows, which has no subobject provenance, accepts
    # it. Rust's final aliasing rules for this pattern are not yet settled.
    - name: Run ABI integration tests under Tree Borrows
      env:
        MIRIFLAGS: -Zmiri-tree-borrows
      run: cargo miri test --all-features --test abi

    - name: Run known leak case with leak checking disabled
      env:
        MIRIFLAGS: -Zmiri-ignore-leaks
      run: cargo miri test --all-features --lib tests::encode_stored_mut_box_allows_pointer_replacement -- --exact

  wasm-test:
    runs-on: ubuntu-latest
    timeout-minutes: 10

    steps:
      - uses: actions/checkout@v7
      - uses: dtolnay/rust-toolchain@stable
        with:
          targets: wasm32-wasip1
      - uses: Swatinem/rust-cache@v2

      - name: Install wasmtime
        run: |
          curl -fsSL https://wasmtime.dev/install.sh | bash
          echo "$HOME/.wasmtime/bin" >> $GITHUB_PATH

      - name: Run Tests (WASIp1)
        # `trybuild` invokes Cargo for each fixture, which WASI cannot support.
        run: cargo test --workspace --target wasm32-wasip1 --lib --test abi --test export --test import