Selfhost build: add EXE path via ny-llvmc (tools) + smoke

- tools/selfhost/selfhost_build.sh: support --exe <out>, using LLVM harness (ny-llvmc)
- Add selfhost EXE canary (opt-in): selfhost_build_exe_return.sh
- Keep Stage‑B JSON emit for verification; EXE path currently parses original Hako source (80/20)
This commit is contained in:
nyash-codex
2025-11-02 18:16:11 +09:00
parent 075257a948
commit 2dcf5006c6
2 changed files with 64 additions and 1 deletions

View File

@ -24,6 +24,7 @@ fi
IN=""
JSON_OUT=""
EXE_OUT=""
DO_RUN=0
while [ $# -gt 0 ]; do
@ -31,6 +32,7 @@ while [ $# -gt 0 ]; do
--in) IN="$2"; shift 2;;
--json) JSON_OUT="$2"; shift 2;;
--run) DO_RUN=1; shift;;
--exe) EXE_OUT="$2"; shift 2;;
*) echo "[selfhost] unknown arg: $1" >&2; exit 2;;
esac
done
@ -71,6 +73,26 @@ if [ -n "$JSON_OUT" ]; then
echo "[selfhost] JSON v0 written: $tmp_json" >&2
fi
# Optional: build native EXE via ny-llvmc harness (fallback path; parses original source)
if [ -n "$EXE_OUT" ]; then
# Requirements: ny-llvmc present and harness envs
NYLL="${NYASH_NY_LLVM_COMPILER:-$ROOT/target/release/ny-llvmc}"
if [ ! -x "$NYLL" ] && [ ! -f "$NYLL" ]; then
echo "[selfhost] ny-llvmc not found: $NYLL (skip EXE). Set NYASH_NY_LLVM_COMPILER or build ny-llvmc" >&2
exit 2
fi
NYRT_DIR="${NYASH_EMIT_EXE_NYRT:-$ROOT/target/release}"
export NYASH_LLVM_USE_HARNESS=1
export NYASH_NY_LLVM_COMPILER="$NYLL"
export NYASH_EMIT_EXE_NYRT="$NYRT_DIR"
echo "[selfhost] emitting EXE via ny-llvmc → $EXE_OUT" >&2
# Note: This path compiles the original Hako source via LLVM backend. StageB JSON is emitted above for reference.
"$BIN" --backend llvm --emit-exe "$EXE_OUT" "$IN"
# Done
if [ -z "$JSON_OUT" ]; then rm -f "$tmp_json" 2>/dev/null || true; fi
exit 0
fi
if [ "$DO_RUN" = "1" ]; then
# Run via CoreDirect (inproc), quiet
set +e
@ -85,4 +107,3 @@ else
# Emit-only
echo "$tmp_json"
fi