name: Lint
on:
    push:
        paths:
            - "**.rs"
            - "**.toml"
            - "Cargo.*"
    pull_request:
    workflow_dispatch:

jobs:
    cargo-toml:
        name: Cargo.toml
        runs-on: ubuntu-24.04

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

            - name: Install taplo
              uses: uncenter/setup-taplo@v1

            - name: Run taplo lint
              run: taplo lint Cargo.toml

            - name: Run taplo fmt
              if: always()
              run: taplo fmt --check Cargo.toml

    rust:
        name: Rust (${{ matrix.feature.name }})
        runs-on: ubuntu-24.04

        strategy:
            matrix:
                feature:
                    - name: default

                    - name: minimal+mimalloc
                      flags: "--no-default-features -F mimalloc"

                    - name: minimal
                      flags: "--no-default-features"

                    - name: mimalloc
                      flags: "-F mimalloc"

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

            - name: Install build dependencies
              run: sudo apt install -y libluajit-5.1-dev mold

            - name: Set up build cache
              uses: actions/cache@v4
              with:
                  path: |
                      ~/.cargo/bin/
                      ~/.cargo/registry/index/
                      ~/.cargo/registry/cache/
                      ~/.cargo/git/db/
                      target/
                  key: lint_${{ matrix.feature.name }}_${{ hashFiles('**.toml', 'Cargo.*') }}

            - name: Switch to nightly toolchain
              run: rustup default nightly

            - name: Install components
              run: rustup component add clippy rustfmt

            - run: cargo clippy ${{ matrix.feature.flags }} -- -D warnings -D clippy::pedantic

            - if: always()
              run: cargo fmt --check