Linked repository source
examples/rewind_lab/vendor_box2d.sh
This read-only view comes from the file in the Gododin repository. It retains its design, example or evidence context.
Download the original file · Return to the guide
#!/bin/bash
# RL-0 archive decision, revised as observed facts changed (recorded in
# README.md). The pinned Odin commit ships vendor/box2d with native archives
# committed, so the example does not build an archive. The vendored bindings
# cannot resolve as a vendor: collection inside the pipeline (the staged
# managed compiler publication is a manifest-sealed tree), so the dependency
# lives INSIDE the project as a plain relative package, installed by this
# script:
#
# examples/rewind_lab/box2d/ the vendored Odin bindings, verbatim
# from the pinned checkout, plus
# lib/box2d_darwin_arm64.a only
#
# and the project's gododin.toml admits it as a second subsystem root and
# declares the archive under [project].foreign_libraries (ADR 0064), so the
# pipeline stages the archive into every snapshot, links it into the project
# image, and records its digest in the artifact manifest. Upstream's
# compile-time #exists guard therefore observes a truthful tree everywhere
# and the bindings are installed verbatim; the one remaining recorded
# deviation is the archive trim to this example's platform.
#
# Identity is verified at each step:
# 1. the checkout's HEAD equals the pinned Odin commit,
# 2. the checkout working tree is clean,
# 3. lib/box2d_darwin_arm64.a matches the digest recorded below,
# 4. the installed archive matches the same digest after the copy.
#
# Box2D remains an example dependency, never a Gododin product dependency.
# The installed tree is machine-local and git-ignored; run this script once
# per checkout (test.sh gates on it).
#
# usage: vendor_box2d.sh --odin-checkout <path-to-odin-git-checkout>
# Idempotent: an installed collection whose archive and bindings match the
# pinned checkout is left untouched; anything else is reinstalled.
set -euo pipefail
export LC_ALL=C
script_dir="$(cd -P -- "$(dirname -- "$0")" && pwd -P)"
ODIN_COMMIT="8412dc37aa91def0c2fa90f89eade29056b4e608"
ARCHIVE_SHA256="b4c373851bb8975641339f99d047a9c5705e19c0156a3ea087fb218b2827fe8f"
ARCHIVE_REL="lib/box2d_darwin_arm64.a"
usage() {
echo "usage: $0 --odin-checkout <path-to-odin-git-checkout>" >&2
exit 64
}
checkout=""
while [[ $# -gt 0 ]]; do
case "$1" in
--odin-checkout)
[[ $# -ge 2 ]] || usage
checkout="$2"; shift 2 ;;
-h|--help) usage ;;
*) usage ;;
esac
done
[[ -n "$checkout" ]] || usage
checkout="$(cd -P -- "$checkout" && pwd -P)"
[[ -d "$checkout/.git" ]] || { echo "error: not a git checkout: $checkout" >&2; exit 65; }
head_commit="$(git -C "$checkout" rev-parse HEAD)"
if [[ "$head_commit" != "$ODIN_COMMIT" ]]; then
echo "error: Odin checkout HEAD $head_commit is not the pinned $ODIN_COMMIT" >&2
exit 65
fi
if [[ -n "$(git -C "$checkout" status --porcelain)" ]]; then
echo "error: Odin checkout working tree is not clean; refusing to vendor from it" >&2
exit 65
fi
source_archive="$checkout/vendor/box2d/$ARCHIVE_REL"
[[ -f "$source_archive" ]] || { echo "error: checkout is missing vendor/box2d/$ARCHIVE_REL" >&2; exit 65; }
source_sha="$(shasum -a 256 "$source_archive" | awk '{print $1}')"
if [[ "$source_sha" != "$ARCHIVE_SHA256" ]]; then
echo "error: source archive digest $source_sha does not match the recorded $ARCHIVE_SHA256" >&2
exit 65
fi
target="$script_dir/box2d"
installed_archive="$target/$ARCHIVE_REL"
installed_ok() {
[[ -f "$installed_archive" ]] || return 1
local archive_sha binding_sha
archive_sha="$(shasum -a 256 "$installed_archive" | awk '{print $1}')"
[[ "$archive_sha" == "$ARCHIVE_SHA256" ]] || return 1
binding_sha="$(shasum -a 256 "$target/box2d.odin" | awk '{print $1}')"
[[ "$binding_sha" == "$(shasum -a 256 "$checkout/vendor/box2d/box2d.odin" | awk '{print $1}')" ]] || return 1
return 0
}
if installed_ok; then
echo "GODODIN_REWIND_LAB_VENDOR_PASS state=already_installed odin_commit=$ODIN_COMMIT archive_sha256=$ARCHIVE_SHA256"
exit 0
fi
chmod -R u+w "$target" 2>/dev/null || true
rm -rf "$target"
mkdir -p "$target/lib"
# The bindings, verbatim; the archives, only the platform this example runs
# on (the one recorded deviation). Everything copied comes from the verified
# clean checkout at the pinned commit.
for item in LICENSE README.md box2d.odin box2d_wasm.odin collision.odin id.odin math_functions.odin types.odin build_box2d.sh wasm.Makefile; do
cp "$checkout/vendor/box2d/$item" "$target/$item"
done
cp "$source_archive" "$installed_archive"
installed_sha="$(shasum -a 256 "$installed_archive" | awk '{print $1}')"
if [[ "$installed_sha" != "$ARCHIVE_SHA256" ]]; then
echo "error: installed archive digest $installed_sha does not match; removing the copy" >&2
chmod -R u+w "$target"
rm -rf "$target"
exit 65
fi
echo "GODODIN_REWIND_LAB_VENDOR_PASS state=installed odin_commit=$ODIN_COMMIT archive_sha256=$ARCHIVE_SHA256"