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

jobs:
    errornowatcher:
        name: errornowatcher (${{ matrix.os }}, ${{ matrix.feature.name }})
        runs-on: ${{ matrix.os }}

        strategy:
            matrix:
                os: [ubuntu-24.04, ubuntu-24.04-arm]
                feature:
                    - name: default

                    - 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: build_${{ matrix.os }}_${{ matrix.feature.name }}_${{ hashFiles('**.toml', 'Cargo.*') }}

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

            - run: cargo build --release ${{ matrix.feature.flags }}

            - name: Upload build artifacts
              uses: actions/upload-artifact@v4
              with:
                  name: errornowatcher_${{ matrix.feature.name }}_${{ matrix.os }}
                  path: target/release/errornowatcher