|
| 1 | +#!/usr/bin/env bash |
| 2 | +# SPDX-License-Identifier: MPL-2.0 |
| 3 | +# On-demand provisioning of the Agda proof-checker toolchain for this repo. |
| 4 | +# |
| 5 | +# Automates the steps documented in the "# Build" section of CLAUDE.md so that |
| 6 | +# `agda proofs/agda/All.agda` and `agda proofs/agda/Smoke.agda` typecheck. |
| 7 | +# Idempotent: safe to re-run; skips anything already in place. |
| 8 | +# |
| 9 | +# Usage: bash scripts/provision-agda.sh |
| 10 | +set -euo pipefail |
| 11 | + |
| 12 | +log() { echo "[provision-agda] $*"; } |
| 13 | + |
| 14 | +STDLIB_DIR=/opt/agda-stdlib |
| 15 | +STDLIB_BRANCH=v2.3 |
| 16 | +AGDA_HOME="${HOME}/.agda" |
| 17 | +REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" |
| 18 | + |
| 19 | +# 1. Agda compiler (Ubuntu universe ships 2.6.3; repo needs >= 2.6.3). |
| 20 | +if command -v agda >/dev/null 2>&1; then |
| 21 | + log "Agda already present: $(agda --version)" |
| 22 | +else |
| 23 | + log "installing Agda compiler (agda-bin)…" |
| 24 | + export DEBIAN_FRONTEND=noninteractive |
| 25 | + apt-get update -qq || true # tolerate unrelated third-party PPA failures |
| 26 | + apt-get install -y agda-bin >/dev/null |
| 27 | + log "Agda installed: $(agda --version)" |
| 28 | +fi |
| 29 | + |
| 30 | +# 2. agda-stdlib 2.3 from source (Ubuntu's agda-stdlib is 1.7.x — too old: it |
| 31 | +# lacks Data.Product.Base and other modules this repo imports). |
| 32 | +if [ -f "${STDLIB_DIR}/standard-library.agda-lib" ]; then |
| 33 | + log "agda-stdlib already at ${STDLIB_DIR}" |
| 34 | +else |
| 35 | + log "cloning agda-stdlib ${STDLIB_BRANCH}…" |
| 36 | + rm -rf "${STDLIB_DIR}" |
| 37 | + git clone --depth 1 --branch "${STDLIB_BRANCH}" \ |
| 38 | + https://github.com/agda/agda-stdlib.git "${STDLIB_DIR}" >/dev/null 2>&1 |
| 39 | + # ships as `name: standard-library-2.3`; echo-types depends on `standard-library`. |
| 40 | + sed -i 's/^name: standard-library-2.3$/name: standard-library/' \ |
| 41 | + "${STDLIB_DIR}/standard-library.agda-lib" |
| 42 | + log "agda-stdlib ${STDLIB_BRANCH} ready" |
| 43 | +fi |
| 44 | + |
| 45 | +# 3. Locate absolute-zero (echo-types.agda-lib: `depend: standard-library absolute-zero`). |
| 46 | +# Expected as a sibling checkout in the multi-repo workspace. |
| 47 | +AZ_LIB="" |
| 48 | +for cand in \ |
| 49 | + "${REPO_ROOT}/../absolute-zero/absolute-zero.agda-lib" \ |
| 50 | + "/home/user/absolute-zero/absolute-zero.agda-lib" \ |
| 51 | + "${HOME}/absolute-zero/absolute-zero.agda-lib"; do |
| 52 | + if [ -f "$cand" ]; then |
| 53 | + AZ_LIB="$(cd "$(dirname "$cand")" && pwd)/absolute-zero.agda-lib" |
| 54 | + break |
| 55 | + fi |
| 56 | +done |
| 57 | + |
| 58 | +# 4. Register libraries + default (idempotent rewrite). |
| 59 | +mkdir -p "${AGDA_HOME}" |
| 60 | +{ |
| 61 | + echo "${STDLIB_DIR}/standard-library.agda-lib" |
| 62 | + if [ -n "${AZ_LIB}" ]; then echo "${AZ_LIB}"; fi |
| 63 | +} > "${AGDA_HOME}/libraries" |
| 64 | +echo "standard-library" > "${AGDA_HOME}/defaults" |
| 65 | + |
| 66 | +if [ -n "${AZ_LIB}" ]; then |
| 67 | + log "registered libraries: standard-library + absolute-zero" |
| 68 | +else |
| 69 | + log "WARNING: absolute-zero library not found — echo-types depends on it and" |
| 70 | + log " will not typecheck. Check out the absolute-zero repo as a sibling" |
| 71 | + log " of echo-types (or add it to this session's scope), then re-run." |
| 72 | +fi |
| 73 | + |
| 74 | +log "done. Verify with: LC_ALL=C.UTF-8 agda proofs/agda/All.agda" |
0 commit comments