name: 🧩 Backends
on:
  push:
    paths:
      - '.github/workflows/backends.yml'
      - 'src/**/*.rs'
      - 'backends/**/*.rs'
      - 'ort-sys/src/lib.rs'
      - 'Cargo.toml'
  pull_request:
    types: [ opened, synchronize, reopened ]
    paths:
      - '.github/workflows/backends.yml'
      - 'src/**/*.rs'
      - 'backends/**/*.rs'
      - 'ort-sys/src/lib.rs'
      - 'Cargo.toml'
permissions:
  contents: read
concurrency:
  group: '${{ github.workflow }} @ ${{ github.event.pull_request.head.label || github.head_ref || github.ref }}'
  cancel-in-progress: true
env:
  RUST_BACKTRACE: 1
jobs:
  candle:
    name: Candle
    runs-on: ${{ matrix.platform.os }}
    strategy:
      fail-fast: false
      matrix:
        platform:
          - os: ubuntu-latest
          - os: macos-15
    steps:
      - uses: actions/checkout@v5
      - name: Install protoc
        run: |
          if [ "$RUNNER_OS" == "Linux" ]; then
            sudo apt-get update && sudo apt-get install protobuf-compiler -y
          elif [ "$RUNNER_OS" == "macOS" ]; then
            brew install protobuf
          fi
      - name: Install stable Rust toolchain
        uses: dtolnay/rust-toolchain@stable
        with:
          toolchain: stable
      - uses: Swatinem/rust-cache@v2.7.8
      - name: Run tests
        run: |
          cargo test --manifest-path backends/candle/Cargo.toml -p ort-candle --verbose -- --test-threads 1
  tract:
    name: Tract
    runs-on: ${{ matrix.platform.os }}
    strategy:
      fail-fast: false
      matrix:
        platform:
          - os: ubuntu-latest
          - os: windows-latest
          - os: macos-15
    steps:
      - uses: actions/checkout@v5
      - name: Install stable Rust toolchain
        uses: dtolnay/rust-toolchain@stable
        with:
          toolchain: stable
      - uses: Swatinem/rust-cache@v2.7.8
      - name: Run tests
        run: |
          cargo test --manifest-path backends/tract/Cargo.toml -p ort-tract --verbose -- --test-threads 1
  web:
    name: Web
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v5
      - name: Install stable Rust toolchain
        uses: dtolnay/rust-toolchain@stable
        with:
          toolchain: stable
          targets: wasm32-unknown-unknown
      - uses: Swatinem/rust-cache@v2.7.8
      - name: Run tests
        run: |
          cargo check --manifest-path backends/web/Cargo.toml -p ort-web --target wasm32-unknown-unknown
