#!/bin/bash
# Strata bench: build the Strata engine from pinned source (never setup.py, never a release binary), at the recon's pin
# 8fc40dde (v0.1.25) and at HEAD 36fa455e (v0.1.36, STRATA-DELTA's conditions), CUDA sm_120, ggml from the local
# llama.cpp 3cf03257 checkout so CMake's FetchContent never fetches. Flags as setup.py:1018-1020 writes them.
set -euo pipefail
GG=/data/strata-bench/src/llama.cpp-3cf03257
LOG=$HOME/bench-archive/plans-2026-10-02/strata-bench/receipts/build-strata.log
exec >>"$LOG" 2>&1
export PATH=/usr/local/cuda-13.4/bin:$PATH
for pair in 8fc40dde:8fc40dde5e8897a097ec0ea6ea27f9313d171268 36fa455e:36fa455e579b23a9c909c2c6fe1bddd9e51cb8ca; do
  short=${pair%%:*}; full=${pair##*:}
  SRC=/data/strata-bench/src/strata-$short; OUT=/data/strata-bench/build/strata-$short
  got=$(git -C "$SRC" rev-parse HEAD); [ "$got" = "$full" ] || { echo "STOP: $SRC is at $got, want $full"; exit 3; }
  echo "$(date -u +%FT%TZ) BUILD START strata $full"
  cmake -G Ninja -S "$SRC" -B "$OUT" -DCMAKE_BUILD_TYPE=Release -DSTRATA_ENABLE_CUDA=ON -DSTRATA_BUILD_TESTS=OFF \
    -DCMAKE_CUDA_ARCHITECTURES=120 -DCMAKE_CUDA_COMPILER=/usr/local/cuda-13.4/bin/nvcc -DSTRATA_GGML_DIR="$GG"
  cmake --build "$OUT" --target strata -j 8
  echo "$(date -u +%FT%TZ) BUILD DONE strata $short bin_sha=$(sha256sum "$OUT/strata" | cut -c1-16)"
done
