interplane.Get Omega
Read in your language

cortex

aien-dev/cortex

Brought by drakestapleton

branch main Branches Tags History

cortex / build.sh

46 lines · 2317 bytes Raw Blame History
1#!/bin/sh
2# build.sh : compile the Omega Cortex server and importer with the pinned omc (PIN, tools/omc.sh).
3# build/pincheck tools/pincheck.om, run first on `git ls-files`: a tracked file that restates
4# the pin in PIN fails the build
5# build/cortex server (one OM-2 unit, module order below; see spec/BUILD-CONTRACT.md)
6# build/cortex-import cortex-rs SQLite -> Cortex log importer
7# build/SHA256SUMS sha256 of both binaries, their units and the compiler
8# A compile is accepted only with rc 0 and empty stderr. Exit 0 only when both builds are accepted.
9set -u
10if [ -z "${CXO_NICED:-}" ]; then CXO_NICED=1 exec nice -n 19 ionice -c3 sh "$0" "$@"; fi
11R=$(cd "$(dirname "$0")" && pwd)
12B=$R/build
13OMC=$(sh "$R/tools/omc.sh") || exit 1
14mkdir -p "$B"
15{ echo om2; cat "$R/tools/pincheck.om"; } > "$B/pincheck.unit.om"
16"$OMC" < "$B/pincheck.unit.om" > "$B/pincheck.tmp" 2> "$B/pincheck.err"
17if [ $? -ne 0 ] || [ -s "$B/pincheck.err" ]; then echo "build: pincheck FAILED: $(cat "$B/pincheck.err")" >&2; exit 1; fi
18chmod +x "$B/pincheck.tmp" && mv "$B/pincheck.tmp" "$B/pincheck"
19(cd "$R" && git ls-files | "$B/pincheck") || { echo "build: pincheck refused the tree (above)" >&2; exit 1; }
20SERVER="f64 uni_rust json crc32c uni_fts flog fts like http store log api api2 api3 qs enc de brain srv main"
21IMPORT="crc32c sqlite import_main"
22unit() { # unit OUT MODULES...
23 out=$1; shift
24 { echo om2; for m in "$@"; do cat "$R/om/$m.om"; done; } > "$out.unit.om"
25}
26compile() { # compile NAME
27 rm -f "$B/$1" "$B/$1.tmp"
28 "$OMC" < "$B/$1.unit.om" > "$B/$1.tmp" 2> "$B/$1.err"
29 rc=$?
30 if [ "$rc" -ne 0 ] || [ -s "$B/$1.err" ]; then
31 echo "build: $1 FAILED rc=$rc: $(cat "$B/$1.err")" >&2
32 rm -f "$B/$1.tmp"
33 return 1
34 fi
35 chmod +x "$B/$1.tmp" && mv "$B/$1.tmp" "$B/$1"
36 echo "build: $1 ok fns=$(grep -c '^fn ' "$B/$1.unit.om")"
37}
38# shellcheck disable=SC2086
39unit "$B/cortex" $SERVER
40# shellcheck disable=SC2086
41unit "$B/cortex-import" $IMPORT
42compile cortex || exit 1
43compile cortex-import || exit 1
44(cd "$B" && sha256sum cortex cortex-import cortex.unit.om cortex-import.unit.om) > "$B/SHA256SUMS"
45echo "omc $(sha256sum "$OMC" | cut -d' ' -f1) (omega-mv $(awk '$1 == "omega-mv" { print substr($2, 1, 8) }' "$R/PIN"), PIN)" >> "$B/SHA256SUMS"
46cat "$B/SHA256SUMS"