|
| 1 | +#!/usr/bin/env bash |
| 2 | +# |
| 3 | +# Installs komet-node (the local Stellar testnet on K semantics) into a |
| 4 | +# dedicated uv-managed virtualenv and builds its kompiled semantics. |
| 5 | +# |
| 6 | +# Prerequisites (provided by the Dockerfile): uv on PATH, and the `komet` / |
| 7 | +# K toolchain installed via kup (so `kdist`/`kompile` are available). |
| 8 | +# |
| 9 | +# Result: `source $KOMET_NODE_VENV/bin/activate` then |
| 10 | +# `python -m komet_node --trace` runs the node. |
| 11 | +set -euo pipefail |
| 12 | + |
| 13 | +export PATH="/home/node/.nix-profile/bin:/home/node/.local/bin:${PATH}" |
| 14 | + |
| 15 | +VENV="${KOMET_NODE_VENV:-/home/node/.komet-node}" |
| 16 | +KOMET_NODE_REF="${KOMET_NODE_REF:-main}" |
| 17 | + |
| 18 | +echo ">>> Creating komet-node venv at ${VENV}" |
| 19 | +uv venv --python 3.10 "${VENV}" |
| 20 | +# shellcheck disable=SC1091 |
| 21 | +source "${VENV}/bin/activate" |
| 22 | + |
| 23 | +echo ">>> Installing komet-node from git (@${KOMET_NODE_REF})" |
| 24 | +uv pip install "git+https://github.com/runtimeverification/komet-node.git@${KOMET_NODE_REF}" |
| 25 | + |
| 26 | +echo ">>> Building komet-node kdist semantics" |
| 27 | +# Builds the node semantics on top of the komet/KWasm semantics. This is the |
| 28 | +# slow step; it reuses prebuilt komet artifacts from the kup install. |
| 29 | +# |
| 30 | +# kup installs `komet` as a makeWrapper script that injects the K binaries |
| 31 | +# (kompile, krun, ...) onto komet's *own* PATH only — they aren't exposed |
| 32 | +# globally. kdist invokes `kompile` directly, so locate K's bin dir from the |
| 33 | +# komet wrapper and put it on PATH (grep -a so it works whether the wrapper is |
| 34 | +# a shell script or a compiled binary wrapper; the store paths are embedded in |
| 35 | +# both). |
| 36 | +# |
| 37 | +# NOTE: reference the kup wrapper by its explicit nix-profile path, NOT via |
| 38 | +# `command -v komet`. The activated venv installs its own `komet` console |
| 39 | +# script that shadows the wrapper but contains no /nix/store paths. |
| 40 | +KUP_KOMET="${HOME}/.nix-profile/bin/komet" |
| 41 | +if ! command -v kompile >/dev/null 2>&1; then |
| 42 | + komet_wrapper="$(readlink -f "${KUP_KOMET}")" |
| 43 | + for d in $(grep -aoE "/nix/store/[^\"' :]+/bin" "${komet_wrapper}" | sort -u); do |
| 44 | + if [ -x "${d}/kompile" ]; then |
| 45 | + export PATH="${d}:${PATH}" |
| 46 | + break |
| 47 | + fi |
| 48 | + done |
| 49 | +fi |
| 50 | +command -v kompile >/dev/null 2>&1 || { |
| 51 | + echo "ERROR: could not locate kompile (K framework) via the komet wrapper" >&2 |
| 52 | + exit 1 |
| 53 | +} |
| 54 | + |
| 55 | +# Align the venv's pyk to the kompile that will build the kdist targets. The |
| 56 | +# komet-node wheel pins `kframework<7.1.321` (kast JSON format v3), but the |
| 57 | +# kup-installed K binaries are newer and emit a later format. pyk validates the |
| 58 | +# kast version when it reads `compiled.json`, so a pyk older than the kompile |
| 59 | +# that produced the artifact aborts with `Invalid version: N` and the node dies |
| 60 | +# on its first request. The invariant is "pyk must match kompile", so we install |
| 61 | +# the matching kframework version, overriding the wheel's upper-bound pin. |
| 62 | +K_VERSION="$(kompile --version | sed -n 's/^K version:[[:space:]]*v//p')" |
| 63 | +echo ">>> Aligning pyk to K ${K_VERSION}" |
| 64 | +uv pip install "kframework==${K_VERSION}" |
| 65 | + |
| 66 | +echo ">>> Building kdist semantics" |
| 67 | +# The node imports the four soroban-semantics definitions (llvm, llvm-tracing, |
| 68 | +# llvm-library, haskell) at module load time, plus komet-node's own simbolik |
| 69 | +# target. Building only 'komet-node.*' leaves the soroban-semantics targets |
| 70 | +# unbuilt, so the server crashes on import with |
| 71 | +# `Target undefined or not built: soroban-semantics.llvm`. |
| 72 | +kdist build 'soroban-semantics.*' 'komet-node.*' |
| 73 | + |
| 74 | +echo ">>> komet-node install complete" |
| 75 | +python -m komet_node --help >/dev/null 2>&1 || true |
0 commit comments