aboutsummaryrefslogtreecommitdiff
path: root/src/boot/mkseed.sh
diff options
context:
space:
mode:
authorGravatar zinc <zinc@downsta.ir> 2026-10-15 14:10:03 +0330
committerGravatar zinc <zinc@downsta.ir> 2026-10-15 14:10:03 +0330
commita3b72f0c6d02f96606c200cde04735fd57151805 (patch)
tree7ed42ed6b38588750b31db23c6274cc9fdf8c175 /src/boot/mkseed.sh
parentmerge work/borrow: borrow returns before definition, borrows clause, borrow m... (diff)
boot: build the compiler from a pinned wasm seed (seed/zc.wasm, WASI) under wasmtime or node, proven by the fixpoint; seed/MANIFEST hashes; make seed; legacy c bootstrap kept as make genome-c
Diffstat (limited to 'src/boot/mkseed.sh')
-rwxr-xr-xsrc/boot/mkseed.sh44
1 files changed, 44 insertions, 0 deletions
diff --git a/src/boot/mkseed.sh b/src/boot/mkseed.sh
new file mode 100755
index 0000000..297a853
--- /dev/null
+++ b/src/boot/mkseed.sh
@@ -0,0 +1,44 @@
+#!/bin/sh
+# builds the bootstrap seed: the microcore with a compiler genome inside, as a WASI
+# module, sized down (-Oz, lto, gc-sections, no debug info or names, then wasm-opt -Oz
+# when it is on PATH).
+# src/boot/mkseed.sh GENOME_DIR OUT.wasm build only
+# src/boot/mkseed.sh --manifest GENOME_DIR OUT.wasm build, prove, write MANIFEST beside OUT
+# with --manifest the unoptimized and the optimized module must both compile the
+# compiler sources to the same image, and the optimized one must reach the fixpoint
+# from it; the manifest records both hashes and sizes.
+# needs clang with the wasm32 target and wasm-ld.
+set -e
+cd "$(dirname "$0")/../.."
+MANIFEST=; [ "$1" = --manifest ] && { MANIFEST=1; shift; }
+G=${1:?genome dir}; OUT=${2:?out}
+CC=${WASM_CC:-$(sh src/tools/findcc.sh --wasm)}
+sha() { if command -v sha256sum >/dev/null 2>&1; then sha256sum "$1" | cut -d' ' -f1; else shasum -a 256 "$1" | cut -d' ' -f1; fi; }
+"$CC" --target=wasm32 -Oz -flto -w -fwrapv -nostdlib -fno-builtin -mbulk-memory -DJTYPE=int -DMICRO_PORT_IMAGE \
+ -ffunction-sections -fdata-sections -g0 \
+ -Isrc/core -Ibuild/core/map --embed-dir="$G" -Isrc/micro src/micro/micro.c src/boot/port_wasi.c \
+ -Wl,--gc-sections -Wl,--strip-all -Wl,--initial-memory=134217728 -Wl,-z,stack-size=1048576 -o "$OUT.raw"
+OPT=none
+if command -v wasm-opt >/dev/null 2>&1; then
+ wasm-opt -Oz --strip-debug --strip-producers --enable-bulk-memory "$OUT.raw" -o "$OUT.tmp"; OPT="$(wasm-opt --version)"
+else cp "$OUT.raw" "$OUT.tmp"; echo "mkseed: no wasm-opt on PATH; the seed is not run through it" >&2; fi
+mv "$OUT.tmp" "$OUT"
+if [ -n "$MANIFEST" ]; then
+ M=$(dirname "$OUT")/MANIFEST; T=$(mktemp -d)
+ printf 'seed-sha256 %s\n' "$(sha "$OUT")" > "$M"
+ SEED="$OUT" MAN="$M" sh src/boot/boot.sh "$T"
+ SEED="$OUT.raw" MAN=/dev/null BOOT_NOCHECK=1 BOOT_STAGES=1 sh src/boot/boot.sh "$T/raw"
+ cmp "$T/g1.bin" "$T/raw/g1.bin" || { echo "mkseed: the size-optimized seed compiles differently from the unoptimized one" >&2; exit 1; }
+ {
+ echo "# the pinned bootstrap seed. make checks seed-sha256 before it runs the seed."
+ echo "# regenerate with: make seed"
+ printf 'seed-sha256 %s\n' "$(sha "$OUT")"
+ printf 'seed-size %s\n' "$(wc -c < "$OUT" | tr -d ' ')"
+ printf 'seed-size-unoptimized %s\n' "$(wc -c < "$OUT.raw" | tr -d ' ')"
+ printf 'wasm-opt %s\n' "$OPT"
+ printf 'image-sha256 %s\n' "$(sha "$T/genome.bin")"
+ printf 'image-size %s\n' "$(wc -c < "$T/genome.bin" | tr -d ' ')"
+ } > "$M"
+ rm -rf "$T"; cat "$M"
+fi
+rm -f "$OUT.raw"