glam 0.33.7

A simple and fast 3D math library for games and graphics
Documentation
name: Update bench baselines

# Saves instruction-count baselines from this repo into the shared
# bitshifter/glam-bench-baselines repo, which the Bench workflow compares
# against.
#
# Triggers:
# - workflow_dispatch: manual run on main.
# - pull_request_target (closed): merged PR labeled `bench-update`. Used
#   instead of `pull_request` so the baselines push secret works for fork
#   PRs. Only the merged commit (merge_commit_sha, already on main) is ever
#   checked out, never the PR head, so it has the same trust level as a manual
#   run on main. Only maintainers can apply the label, so PR authors can't
#   trigger this.
on:
  workflow_dispatch:
  pull_request_target:
    branches: [main]
    types: [closed]

concurrency:
  group: ${{ github.workflow }}

env:
  # Keep in sync with BENCH_TOOLCHAIN in bench.yml.
  BENCH_TOOLCHAIN: 1.98.0

permissions:
  contents: read # checkout; pushes to the baselines repo use the PAT below
  actions: write # upload artifacts (save job), not otherwise used

jobs:
  save:
    name: save (${{ matrix.os }})
    # Only save from main's code: a manual dispatch on main, or a merged PR
    # labeled `bench-update` (base main; the checked-out merge_commit_sha is
    # then on main).
    if: |
      (github.event_name == 'workflow_dispatch' && github.ref == 'refs/heads/main') ||
      (github.event_name == 'pull_request_target' && github.event.action == 'closed' &&
       github.event.pull_request.merged && github.event.pull_request.base.ref == 'main' &&
       contains(github.event.pull_request.labels.*.name, 'bench-update'))
    strategy:
      fail-fast: false
      matrix:
        # The ci tool saves SSE2, scalar-math, and core-simd baselines on
        # x86_64 Linux and NEON, scalar-math, and core-simd baselines on
        # aarch64 Linux. Valgrind doesn't support macOS, so there are no
        # macOS baselines.
        os: [ubuntu-latest, ubuntu-24.04-arm]
    runs-on: ${{ matrix.os }}
    steps:
      - uses: actions/checkout@v7
        with:
          submodules: true
          # workflow_dispatch: HEAD of main; pull_request_target: the merged
          # commit on main. Never the PR head (github.sha on PR events).
          ref: ${{ github.event.pull_request.merge_commit_sha || github.sha }}
      - uses: actions/checkout@v7
        with:
          repository: bitshifter/glam-bench-baselines
          path: benches/gungraun-baselines
          token: ${{ secrets.GLAM_BENCH_BASELINES_TOKEN }}
      - name: Remove baselines saved by other runners
        run: |
          find benches/gungraun-baselines -type f -name '*.base@*' -delete
          rm -f benches/gungraun-baselines/x86_64.md benches/gungraun-baselines/aarch64.md
          find benches/gungraun-baselines -type d -empty -delete
      - uses: Swatinem/rust-cache@v2
      - run: rustup update --no-self-update ${{ env.BENCH_TOOLCHAIN }}
      - run: rustup default ${{ env.BENCH_TOOLCHAIN }}
      - run: rustup update --no-self-update nightly
      # Needed for full source annotations from `cargo asm --rust` (std/core
      # sources); glam and bench sources annotate without it.
      - run: rustup component add rust-src
      - run: rustup component add rust-src --toolchain nightly
      - name: Install valgrind
        run: sudo apt-get update && sudo apt-get install -y valgrind
      # cargo-asm (cargo-show-asm) powers `--save --asm`; pinned version so
      # output/CLI can't drift.
      - name: Install cargo-asm
        run: cargo install cargo-show-asm --version 0.2.62 --locked
      - run: cargo run --release -p ci -- bench --save --asm
      - name: Keep only baseline and asm files
        run: |
          find benches/gungraun-baselines -type f \
            ! -name '*.base@*' ! -name 'Cargo.lock' \
            ! -name 'x86_64.md' ! -name 'aarch64.md' \
            ! -path 'benches/gungraun-baselines/asm/*' -delete
          find benches/gungraun-baselines -type d -empty -delete
      - uses: actions/upload-artifact@v7
        with:
          name: baselines-${{ matrix.os }}
          path: benches/gungraun-baselines
          if-no-files-found: error

  commit:
    name: Commit baselines
    needs: save
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v7
        with:
          repository: bitshifter/glam-bench-baselines
          path: baselines
          token: ${{ secrets.GLAM_BENCH_BASELINES_TOKEN }}
      - name: Clear previous baselines
        run: |
          cd baselines
          rm -rf glam Cargo.lock x86_64.md aarch64.md asm
      - uses: actions/download-artifact@v8
        with:
          pattern: baselines-*
          path: baselines
          merge-multiple: true
      - name: Commit baselines
        run: |
          cd baselines
          git config user.name "github-actions[bot]"
          git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
          git add -A
          if git diff --cached --quiet; then
            echo "no baseline changes"
            exit 0
          fi
          git commit -m "chore: update bench baselines from glam-rs@${{ github.event.pull_request.merge_commit_sha || github.sha }}"
          git push