name: benchmark

on:
  pull_request:
    branches: [main]

jobs:
  benchmark:
    strategy:
      fail-fast: false
      matrix:
        os: [ubuntu-24.04, macos-15, windows-2025]
    runs-on: ${{ matrix.os }}
    defaults:
      run:
        shell: bash
    steps:
      - name: Checkout repository
        uses: actions/checkout@v4

      - uses: ./.github/actions/setup-pixi

      - name: Build scan_benchmark
        run: |
          pixi run cmake-config RelWithDebInfo ON "-DCLICE_ENABLE_BENCHMARK=ON"
          cmake --build build/RelWithDebInfo --target scan_benchmark

      - name: Clone LLVM
        run: git clone --depth 1 https://github.com/llvm/llvm-project.git

      - name: Generate CDB
        run: |
          cmake -B llvm-build -G Ninja \
            -DCMAKE_EXPORT_COMPILE_COMMANDS=ON \
            -DCMAKE_TOOLCHAIN_FILE="$(pwd)/cmake/toolchain.cmake" \
            -DLLVM_ENABLE_PROJECTS="clang;clang-tools-extra;lld;lldb;mlir;polly;flang;bolt" \
            -DLLVM_ENABLE_RUNTIMES="compiler-rt;libcxx;libcxxabi;libunwind" \
            llvm-project/llvm

      - name: Run benchmark
        run: ./build/RelWithDebInfo/bin/scan_benchmark --runs 20 llvm-build/compile_commands.json

      - name: Stop sccache server
        if: runner.os == 'Windows'
        run: pixi run -- sccache --stop-server || true
