name: Test

on:
  push:
  pull_request:
    branches: [ main ]

env:
  CARGO_TERM_COLOR: always

jobs:
  build:
    name: Build and test
    strategy:
      matrix:
        os:
          - ubuntu-latest
          - windows-latest
    runs-on: ${{ matrix.os }}
    steps:
    - uses: actions/checkout@v4
    - name: Install the MinGW and LLVM toolchains
      if: matrix.os == 'ubuntu-latest'
      run: sudo apt-get install -y gcc-mingw-w64 llvm
    - name: Build
      run: cargo build --verbose
    - name: Run tests
      run: cargo test --verbose -- --test-threads=1
  zigbuild:
    name: Test zig dlltool
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v4
    - uses: goto-bus-stop/setup-zig@v2
    - name: Run tests with zig
      run: ZIG_COMMAND=zig cargo test --verbose
  zigwheel:
    name: Test python -m ziglang dlltool
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v4
    - uses: actions/setup-python@v5
      with:
        python-version: "3.12"
    - name: Install ziglang package
      run: pip install ziglang
    - name: Run tests with python -m ziglang
      run: ZIG_COMMAND="python -m ziglang" cargo test --verbose
  fmt:
    name: Check code formatting
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v4
    - name: Run cargo fmt
      run: cargo fmt -- --check
  clippy:
    name: Clippy lints
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v4
    - name: Run cargo clippy
      run: cargo clippy --all-targets -- --deny warnings
