php-tokio 0.2.2

Use any async Rust library from PHP!
Documentation
name: CI

on:
  push:
    branches: [master]
  pull_request:

jobs:
  # ubuntu-24.04, not ubuntu-latest (26.04, x86_64): there, ext-php-rs's bindgen fails to generate the bindings,
  # with errors in clang 21's xmmintrin.h and emmintrin.h.
  lint:
    name: rustfmt and clippy
    runs-on: ubuntu-24.04
    steps:
      - uses: actions/checkout@v4
      - uses: shivammathur/setup-php@v2
        with:
          php-version: "8.4"
          coverage: none
      - uses: dtolnay/rust-toolchain@stable
        with:
          components: rustfmt, clippy
      - uses: Swatinem/rust-cache@v2
      - run: cargo fmt --all --check
      - run: cargo clippy --workspace --all-targets -- -D warnings

  test:
    name: ${{ matrix.os }}, PHP ${{ matrix.php }} ${{ matrix.ts }}
    runs-on: ${{ matrix.os }}
    strategy:
      fail-fast: false
      matrix:
        os: [ubuntu-24.04, macos-latest, windows-latest]
        php: ["8.2", "8.5", "8.6"]
        ts: [nts]
        include:
          # thread-safe PHP too (docker-library's images of PHP 8.6 are only ZTS)
          - { os: ubuntu-24.04, php: "8.6", ts: ts }
    defaults:
      run:
        shell: bash
    steps:
      - uses: actions/checkout@v4

      - uses: shivammathur/setup-php@v2
        with:
          php-version: ${{ matrix.php }}
          coverage: none
          tools: composer
        env:
          phpts: ${{ matrix.ts }}

      # ext-php-rs needs nightly on Windows, for the vectorcall calling convention.
      - uses: dtolnay/rust-toolchain@master
        with:
          toolchain: ${{ runner.os == 'Windows' && 'nightly' || 'stable' }}
      - uses: Swatinem/rust-cache@v2
        with:
          key: php-${{ matrix.php }}-${{ matrix.ts }}

      - name: Build the extensions
        run: cargo build --release --workspace

      - name: Install the test suite's dependencies
        working-directory: tests
        run: composer install --no-interaction --no-progress

      - name: Run the test suite
        working-directory: tests
        run: |
          case "$RUNNER_OS" in
            Linux) extension=../target/release/libphp_tokio_test_extension.so ;;
            macOS) extension=../target/release/libphp_tokio_test_extension.dylib ;;
            Windows) extension=../target/release/php_tokio_test_extension.dll ;;
          esac
          # ShutdownTest starts PHP processes of its own with the extension.
          PHP_TOKIO_TEST_EXTENSION="$extension" php -d "extension=$extension" vendor/bin/phpunit

  coverage:
    # Every line and function of php-tokio's Rust code covered: tests/coverage.sh fails otherwise.
    name: coverage, ${{ matrix.os }}
    runs-on: ${{ matrix.os }}
    strategy:
      fail-fast: false
      matrix:
        os: [ubuntu-24.04, macos-latest, windows-latest]
    defaults:
      run:
        shell: bash
    steps:
      - uses: actions/checkout@v4

      - uses: shivammathur/setup-php@v2
        with:
          php-version: "8.5"
          coverage: none
          tools: composer

      - uses: dtolnay/rust-toolchain@master
        with:
          toolchain: ${{ runner.os == 'Windows' && 'nightly' || 'stable' }}
          components: llvm-tools-preview
      - uses: taiki-e/install-action@cargo-llvm-cov
      - uses: Swatinem/rust-cache@v2
        with:
          key: coverage

      - name: Install the test suite's dependencies
        working-directory: tests
        run: composer install --no-interaction --no-progress

      - run: tests/coverage.sh

  mutants:
    # Every mutant of php-tokio's Rust code caught by the tests: cargo mutants fails otherwise.
    # Windows-only code is only compiled, so mutated, on Windows.
    name: mutation testing, ${{ matrix.os }}
    runs-on: ${{ matrix.os }}
    strategy:
      fail-fast: false
      matrix:
        include:
          - os: ubuntu-24.04
            mutants: --exclude src/notify/windows.rs
          - os: windows-latest
            mutants: --file src/notify/windows.rs
    defaults:
      run:
        shell: bash
    steps:
      - uses: actions/checkout@v4

      - uses: shivammathur/setup-php@v2
        with:
          php-version: "8.5"
          coverage: none
          tools: composer

      - uses: dtolnay/rust-toolchain@master
        with:
          toolchain: ${{ runner.os == 'Windows' && 'nightly' || 'stable' }}
      - uses: taiki-e/install-action@cargo-mutants
      - uses: Swatinem/rust-cache@v2
        with:
          key: mutants

      - name: Install the test suite's dependencies
        working-directory: tests
        run: composer install --no-interaction --no-progress

      - name: Test the mutants
        run: PHP_TOKIO_TESTS="$PWD/tests" cargo mutants --jobs 2 --timeout 300 ${{ matrix.mutants }}

      - uses: actions/upload-artifact@v4
        if: failure()
        with:
          name: mutants.out-${{ matrix.os }}
          path: mutants.out