22#
33# Opt-in installer for Verrou (the Valgrind FP-perturbation tool used by
44# `./mfc.sh fp-stability`). Verrou is NOT a Python/pip package — it is a fork of
5- # Valgrind that must be compiled from source (~20 min), so this is a deliberate,
6- # explicit step rather than something `fp-stability` does silently.
5+ # Valgrind. By default this downloads a prebuilt, hash-verified artifact (seconds);
6+ # if none is available for this tag/arch it falls back to a source build (~20 min).
7+ # Either way it's a deliberate, explicit step, not something fp-stability does silently.
78#
8- # bash toolchain/bootstrap/verrou.sh # build into $HOME/.local/verrou
9+ # bash toolchain/bootstrap/verrou.sh # install into $HOME/.local/verrou
910# VERROU_HOME=/path bash toolchain/bootstrap/verrou.sh
10- # bash toolchain/bootstrap/verrou.sh --force # rebuild even if present
11+ # bash toolchain/bootstrap/verrou.sh --force # reinstall even if present
12+ # VERROU_BUILD_FROM_SOURCE=1 bash toolchain/bootstrap/verrou.sh # skip the prebuilt
1113#
1214# Versions are pinned to match the fp-stability CI workflow.
1315
1416set -euo pipefail
1517
1618VALGRIND_VERSION=" 3.26.0"
1719VERROU_COMMIT=" a58d434"
20+ # Prebuilt artifacts (built once per arch) live in a small companion repo. The tag
21+ # pins to the (valgrind, verrou) pair above — bump all three together.
22+ VERROU_DIST_REPO=" ${VERROU_DIST_REPO:- sbryngelson/ verrou-dist} "
23+ VERROU_DIST_TAG=" ${VERROU_DIST_TAG:- v1} "
1824PREFIX=" ${VERROU_HOME:- $HOME / .local/ verrou} "
1925FORCE=" ${1:- } "
2026
2127echo " ==> Verrou bootstrap (Valgrind ${VALGRIND_VERSION} + edf-hpc/verrou@${VERROU_COMMIT} ) -> ${PREFIX} "
2228
23- # Idempotent: skip if already installed and working.
24- if [ " $FORCE " != " --force" ] && [ -x " ${PREFIX} /bin/valgrind" ] && " ${PREFIX} /bin/valgrind" --tool=verrou --version > /dev/null 2>&1 ; then
29+ # Idempotent: skip if already installed and working. Source env.sh first if present
30+ # (a prebuilt tree needs VALGRIND_LIB to run; a source build works either way).
31+ if [ " $FORCE " != " --force" ] && [ -x " ${PREFIX} /bin/valgrind" ] \
32+ && ( [ -f " ${PREFIX} /env.sh" ] && . " ${PREFIX} /env.sh" ; " ${PREFIX} /bin/valgrind" --tool=verrou --version > /dev/null 2>&1 ); then
2533 echo " ==> Verrou already installed at ${PREFIX} (use --force to rebuild). Nothing to do."
2634 exit 0
2735fi
@@ -31,9 +39,11 @@ if [ "$(uname -s)" != "Linux" ]; then
3139 echo " ERROR: Verrou requires Linux (Valgrind does not support modern macOS, incl. Apple Silicon)." >&2
3240 exit 1
3341fi
42+ arch_tag=" "
3443case " $( uname -m) " in
35- x86_64) ;;
44+ x86_64) arch_tag= " x86_64 " ;;
3645 aarch64|arm64)
46+ arch_tag=" aarch64"
3747 echo " WARNING: $( uname -m) detected. Valgrind builds here, but Verrou's FP backends are" >&2
3848 echo " best-validated on x86_64 — treat results as experimental on this arch." >&2
3949 ;;
@@ -42,6 +52,59 @@ case "$(uname -m)" in
4252 ;;
4353esac
4454
55+ # Fast path: download a prebuilt, hash-verified artifact and source its relocatable
56+ # env.sh, instead of building from source. Any failure (no asset for this arch/tag,
57+ # missing zstd/sha256sum, checksum mismatch, won't run) falls through to the build.
58+ try_prebuilt () {
59+ [ -n " $arch_tag " ] || return 1
60+ [ " ${VERROU_BUILD_FROM_SOURCE:- } " = " 1" ] && return 1
61+ command -v sha256sum > /dev/null 2>&1 || return 1
62+ tar --zstd --help > /dev/null 2>&1 || command -v zstd > /dev/null 2>&1 || return 1
63+ command -v curl > /dev/null 2>&1 || command -v wget > /dev/null 2>&1 || return 1
64+
65+ local asset base dl
66+ asset=" verrou-${VERROU_COMMIT} -valgrind-${VALGRIND_VERSION} -linux-${arch_tag} .tar.zst"
67+ base=" https://github.com/${VERROU_DIST_REPO} /releases/download/${VERROU_DIST_TAG} /${asset} "
68+ dl=" $( mktemp -d) "
69+
70+ echo " ==> Trying prebuilt ${VERROU_DIST_REPO} @${VERROU_DIST_TAG} (${asset} )"
71+ _fetch () { # url dest
72+ if command -v curl > /dev/null 2>&1 ; then curl -fsSL -o " $2 " " $1 " ; else wget -q -O " $2 " " $1 " ; fi
73+ }
74+ if ! _fetch " $base " " $dl /$asset " || ! _fetch " $base .sha256" " $dl /$asset .sha256" ; then
75+ echo " ==> No prebuilt for this tag/arch — building from source instead."
76+ rm -rf " $dl " ; return 1
77+ fi
78+ if ! ( cd " $dl " && sha256sum -c " $asset .sha256" > /dev/null 2>&1 ); then
79+ echo " WARNING: prebuilt checksum mismatch — building from source instead." >&2
80+ rm -rf " $dl " ; return 1
81+ fi
82+
83+ mkdir -p " $PREFIX "
84+ if tar --zstd --help > /dev/null 2>&1 ; then
85+ tar -C " $PREFIX " --zstd -xf " $dl /$asset "
86+ else
87+ zstd -dc " $dl /$asset " | tar -C " $PREFIX " -xf -
88+ fi
89+ rm -rf " $dl "
90+
91+ # Valgrind bakes its build prefix into the binary; the artifact's env.sh sets
92+ # VALGRIND_LIB relative to the extracted tree so the relocated install works.
93+ if ! ( . " ${PREFIX} /env.sh" && " ${PREFIX} /bin/valgrind" --tool=verrou --version > /dev/null 2>&1 ); then
94+ echo " WARNING: prebuilt did not run — building from source instead." >&2
95+ return 1
96+ fi
97+ return 0
98+ }
99+
100+ if try_prebuilt; then
101+ echo " ==> Verifying"
102+ ( . " ${PREFIX} /env.sh" && " ${PREFIX} /bin/valgrind" --tool=verrou --version )
103+ echo " ==> Done (prebuilt). Verrou installed at ${PREFIX} "
104+ echo " Run: ./mfc.sh fp-stability (or set VERROU_HOME=${PREFIX} if you used a custom prefix)"
105+ exit 0
106+ fi
107+
45108# Build dependencies.
46109missing=" "
47110for tool in tar git make patch autoconf automake; do
0 commit comments