name: ci

on:
  push:
    branches: [main]
  pull_request:

jobs:
  lint:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      - uses: dtolnay/rust-toolchain@stable
        with:
          components: rustfmt, clippy

      - name: Install native build dependencies
        run: |
          sudo apt-get update
          sudo apt-get install -y cmake build-essential zlib1g-dev nasm

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

      - name: Clippy
        run: cargo clippy --all-targets -- -D warnings

  test:
    strategy:
      fail-fast: false
      matrix:
        include:
          - os: ubuntu-latest
            kind: test
          - os: ubuntu-24.04-arm
            kind: test
          - os: macos-15-intel
            kind: test
          - os: macos-15
            kind: test
          - os: windows-latest
            kind: test
          - os: windows-11-arm
            kind: build
    runs-on: ${{ matrix.os }}

    steps:
      - name: Checkout repository
        uses: actions/checkout@v4

      - name: Install Rust
        uses: dtolnay/rust-toolchain@stable

      - name: Install native build dependencies
        shell: bash
        run: |
          set -euxo pipefail
          case "$RUNNER_OS" in
            Linux)
              sudo apt-get update
              sudo apt-get install -y cmake build-essential zlib1g-dev nasm
              ;;
            macOS)
              brew install -q nasm
              ;;
            Windows)
              choco install -y nasm
              echo "C:\Program Files\NASM" >> "$GITHUB_PATH"
              ;;
          esac

      - name: Run CLI tests
        if: matrix.kind == 'test'
        run: cargo test

      - name: Smoke build release binary
        if: matrix.kind == 'build'
        run: cargo build --release
