2025-11-02 18:07:33 +09:00
|
|
|
|
Hybrid Selfhost Build (80/20)
|
|
|
|
|
|
|
|
|
|
|
|
Purpose
|
|
|
|
|
|
- Provide a minimal, fast path to compile Hako source via Hakorune Stage‑B to Program(JSON v0), and optionally run it via Core‑Direct (in‑proc).
|
|
|
|
|
|
- Future: add MIR emit and ny-llvmc EXE build in small increments.
|
|
|
|
|
|
|
|
|
|
|
|
Script
|
|
|
|
|
|
- tools/selfhost/selfhost_build.sh
|
|
|
|
|
|
- --in <file.hako>: input Hako source
|
|
|
|
|
|
- --json <out.json>: write Program(JSON v0); default: /tmp/hako_stageb_$$.json
|
2025-11-02 18:48:34 +09:00
|
|
|
|
- --mir <out.json>: emit MIR(JSON) from source (runner path)
|
|
|
|
|
|
- --exe <out>: build native executable via ny-llvmc (llvmlite harness)
|
2025-11-02 18:07:33 +09:00
|
|
|
|
- --run: run via Gate‑C/Core Direct (in‑proc). Exit code mirrors program return.
|
|
|
|
|
|
- Env:
|
|
|
|
|
|
- NYASH_BIN: path to hakorune/nyash binary (auto-detected)
|
|
|
|
|
|
- NYASH_ROOT: repo root (auto-detected)
|
2025-11-02 18:48:34 +09:00
|
|
|
|
- HAKO_USE_BUILDBOX=1: use BuildBox for emit-only (no run/exe)
|
2025-11-02 18:07:33 +09:00
|
|
|
|
|
|
|
|
|
|
Examples
|
|
|
|
|
|
```bash
|
2025-11-02 18:48:34 +09:00
|
|
|
|
# Emit JSON only (Stage‑B)
|
2025-11-02 18:07:33 +09:00
|
|
|
|
tools/selfhost/selfhost_build.sh --in apps/demo/main.hako --json /tmp/demo.json
|
|
|
|
|
|
|
|
|
|
|
|
# Run and use exit code
|
|
|
|
|
|
tools/selfhost/selfhost_build.sh --in apps/demo/return7.hako --run; echo $?
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
Notes
|
2025-11-02 18:48:34 +09:00
|
|
|
|
- Stage‑B emit uses either the Stage‑B entry or BuildBox(HAKO_USE_BUILDBOX=1 for emit-only)
|
2025-11-02 18:07:33 +09:00
|
|
|
|
- Runner executes Core‑Direct in-proc under HAKO_CORE_DIRECT_INPROC=1.
|
|
|
|
|
|
- For heavier cases (bundles/alias/require), keep Stage‑B canaries opt‑in in quick profile.
|
2025-11-15 05:42:32 +09:00
|
|
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
|
|
|
|
|
|
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) Stage‑B + 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.
|