Phase 25.1a: selfhost builder hotfix (fn rename, docs)

This commit is contained in:
nyash-codex
2025-11-15 05:42:32 +09:00
parent 8d9bbc40bd
commit 6856922374
40 changed files with 2013 additions and 72 deletions

View File

@ -29,3 +29,45 @@ Notes
- StageB emit uses either the StageB entry or BuildBoxHAKO_USE_BUILDBOX=1 for emit-only
- Runner executes CoreDirect in-proc under HAKO_CORE_DIRECT_INPROC=1.
- For heavier cases (bundles/alias/require), keep StageB canaries optin in quick profile.
---
Stage1 Selfhost Binary (Phase 25.1 — initial wiring)
Purpose
- Provide a concrete Stage1 binary (`hakorune`) built from Hako sources.
- Separate the Rust bootstrap binary (Stage0, `nyash`) from the Hakorune selfhost binary at the build-script level.
Script
- tools/selfhost/build_stage1.sh
- Builds a Stage1 selfhost executable from a Nyash/Hako entry point.
- Current entry (default):
- `lang/src/runner/launcher.hako` — Stage1 CLI launcher (commands: emit program-json/mir-json, etc.).
- Output:
- `target/selfhost/hakorune` by default.
Usage
```bash
# Build Stage1 selfhost binary with defaults
tools/selfhost/build_stage1.sh
# Custom output path
tools/selfhost/build_stage1.sh --out /tmp/hakorune-dev
# Custom entry (experimental)
tools/selfhost/build_stage1.sh --entry apps/selfhost-minimal/main.hako --out /tmp/hako_min
```
How it works
- Pipeline:
1) StageB + MirBuilder:
- `tools/hakorune_emit_mir.sh <entry.hako> <mir.json>`
2) LLVM EXE build:
- `tools/ny_mir_builder.sh --in <mir.json> --emit exe -o <exe>`
- The Rust binary (Stage0) is resolved via the existing helpers inside `hakorune_emit_mir.sh` / `ny_mir_builder.sh`:
- Prefers `target/release/hakorune` when present.
- Falls back to `target/release/nyash` otherwise.
Notes
- This Stage1 binary is a minimal Ny Executor and not yet a full CLI replacement.
- Full CLI / mode selection for Stage1 will be implemented in later phases; this script focuses on establishing the binary layout and build wiring.

View File

@ -0,0 +1,89 @@
#!/usr/bin/env bash
# build_stage1.sh — Build Hakorune Stage1 selfhost binary
#
# Purpose
# - Produce a minimal Stage1 (Hakorune selfhost) executable from Nyash/Hako sources.
# - Current target is the Stage1 CLI launcher in lang/src/runner/launcher.hako.
# - This is an initial implementation for Phase 25.1: binary layoutと Stage1 dev bin 用導線のみ。
#
# Output
# - target/selfhost/hakorune (by default)
#
# Env / args
# - HAKORUNE_STAGE1_ENTRY: override Stage1 entry .hako (optional).
# - HAKORUNE_STAGE1_OUT: override output path (optional).
# - NYASH_LLVM_SKIP_BUILD: set to 1 to skip cargo build in ny_mir_builder.sh when artifacts already exist.
# - Args:
# --out <path> : override output path (same as HAKORUNE_STAGE1_OUT).
# --entry <file> : override entry .hako (same as HAKORUNE_STAGE1_ENTRY).
# -h|--help : show usage and exit.
#
set -euo pipefail
usage() {
cat <<'USAGE'
build_stage1.sh — Build Hakorune Stage1 selfhost binary
Usage:
tools/selfhost/build_stage1.sh [--out <exe_path>] [--entry <entry.hako>]
Defaults:
entry .hako : lang/src/runner/launcher.hako
output exe : target/selfhost/hakorune
Notes:
- This script uses the Stage-B + MirBuilder pipeline:
lang/src/runner/launcher.hako
→ tools/hakorune_emit_mir.sh (Program(JSON v0 → MIR JSON)
→ tools/ny_mir_builder.sh --emit exe
- The Rust binary (Stage0) is treated as bootstrap and is resolved via
the existing helpers inside hakorune_emit_mir.sh / ny_mir_builder.sh.
USAGE
}
ROOT="${NYASH_ROOT:-$(cd "$(dirname "$0")/../.." && pwd)}"
ENTRY_DEFAULT="$ROOT/lang/src/runner/launcher.hako"
OUT_DEFAULT="$ROOT/target/selfhost/hakorune"
ENTRY="${HAKORUNE_STAGE1_ENTRY:-$ENTRY_DEFAULT}"
OUT="${HAKORUNE_STAGE1_OUT:-$OUT_DEFAULT}"
while [ $# -gt 0 ]; do
case "$1" in
--out)
OUT="$2"
shift 2
;;
--entry)
ENTRY="$2"
shift 2
;;
-h|--help)
usage
exit 0
;;
*)
echo "[stage1] unknown arg: $1" >&2
usage
exit 2
;;
esac
done
if [ ! -f "$ENTRY" ]; then
echo "[stage1] entry .hako not found: $ENTRY" >&2
exit 2
fi
OUT_DIR="$(dirname "$OUT")"
mkdir -p "$OUT_DIR"
echo "[stage1] building Stage1 selfhost binary" >&2
echo " entry : $ENTRY" >&2
echo " output: $OUT" >&2
# Use the StageB → MirBuilder → ny-llvmc path
NYASH_ROOT="$ROOT" bash "$ROOT/tools/selfhost_exe_stageb.sh" "$ENTRY" -o "$OUT"
echo "[stage1] done: $OUT" >&2