#!/usr/bin/env bash # build-soul.sh — compile a soul binary from a plain source tree (no git needed). # # Reuses the amalgam recipe worked out in gen-soul-amalgam.sh (round 9.1) and the # compile flags from .gitea/workflows/ci.yaml, so the binary under test is the # same translation unit CI ships — not a re-implementation. # # elc --target=c emits only an extern prototype for any module that has a .elh # header beside it, and inlines the module's bodies when it does not. So the # amalgam is produced in a scratch copy with every .elh on the import chain # deleted. # # usage: build-soul.sh set -euo pipefail SRC="${1:?usage: build-soul.sh }" OUT="${2:?out-binary}" ELC="${ELC:-$HOME/neuron-dev-stack/src/el/lang/dist/platform/elc}" EL_REPO="${EL_REPO:-$HOME/Development/neuron-technologies/el}" RTDIR="${RTDIR:-$SRC/vendor/el-runtime/v1.0.0-20260501}" SSL="${SSL_PREFIX:-/opt/homebrew/opt/openssl@3}" [ -x "$ELC" ] || { echo "no elc at $ELC" >&2; exit 2; } [ -f "$RTDIR/el_runtime.c" ] || { echo "no el_runtime.c at $RTDIR" >&2; exit 2; } GEN="$(mktemp -d "${TMPDIR:-/tmp}/soul-build.XXXXXX")" trap 'rm -rf "$GEN"' EXIT mkdir -p "$GEN/neuron" "$GEN/foundation/el/elp/src" cp "$SRC"/*.el "$GEN/neuron/" cp "$EL_REPO"/elp/src/*.el "$GEN/foundation/el/elp/src/" find "$GEN" -name '*.elh' -delete ( cd "$GEN/neuron" && "$ELC" --target=c soul.el ) > "$GEN/soul.c" BODIES=$(grep -c '^el_val_t .*) {$' "$GEN/soul.c" || true) echo "[build-soul] amalgam $(wc -c < "$GEN/soul.c" | tr -d ' ') bytes, ${BODIES} inlined bodies" [ "$BODIES" -ge 1200 ] || { echo "[build-soul] FAIL: only $BODIES bodies — an import was not inlined"; exit 1; } cc -O2 -DHAVE_CURL -rdynamic \ -I"$RTDIR" -I"$SSL/include" -L"$SSL/lib" \ "$GEN/soul.c" "$RTDIR/el_runtime.c" \ -lssl -lcrypto -lcurl -lpthread -lm \ -o "$OUT" 2> "$GEN/cc.log" || { echo "[build-soul] FAIL compile"; tail -40 "$GEN/cc.log"; exit 1; } if grep -qE 'implicit.*(engram_|el_)' "$GEN/cc.log"; then echo "[build-soul] FAIL: implicit declarations of runtime symbols"; grep -E 'implicit' "$GEN/cc.log" | head; exit 1; fi echo "[build-soul] OK -> $OUT ($(wc -c < "$OUT" | tr -d ' ') bytes)"