name: Rust

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

env:
  CARGO_TERM_COLOR: always

jobs:
  fmt:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v6
      with:
        submodules: recursive
    - name: Check formatting
      run: cargo fmt --check

  clippy:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v6
      with:
        submodules: recursive
    - name: Clippy
      run: cargo clippy --all-targets -- -D warnings

  doc:
    runs-on: ubuntu-latest
    env:
      RUSTDOCFLAGS: -Dwarnings
    steps:
    - uses: actions/checkout@v6
      with:
        submodules: recursive
    - name: Build docs
      run: cargo doc --no-deps

  test:
    strategy:
      fail-fast: false
      matrix:
        os: [ubuntu-latest, macos-latest, windows-latest]
        rust: [stable, "1.93"]
    runs-on: ${{ matrix.os }}
    steps:
    - uses: actions/checkout@v6
      with:
        submodules: recursive
    - name: Install Rust ${{ matrix.rust }}
      run: rustup toolchain install ${{ matrix.rust }} --profile minimal && rustup default ${{ matrix.rust }}
    - name: Test
      run: cargo test --verbose

  test-release:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v6
      with:
        submodules: recursive
    - name: Install Rust stable
      run: rustup toolchain install stable --profile minimal && rustup default stable
    - name: Test (release profile)
      run: cargo test --release --verbose
