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

View File

@ -0,0 +1,42 @@
#!/bin/bash
# selfhost_build_exe_return.sh — Build EXE via tools/selfhost_build.sh (optin)
set -euo pipefail
if [ "${SMOKES_ENABLE_SELFHOST:-0}" != "1" ]; then
echo "[SKIP] selfhost_build_exe_return (SMOKES_ENABLE_SELFHOST=1 to enable)"
exit 0
fi
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
ROOT="$(git -C "$SCRIPT_DIR" rev-parse --show-toplevel 2>/dev/null || cd "$SCRIPT_DIR/../../../../../../.." && pwd)"
source "$ROOT/tools/smokes/v2/lib/test_runner.sh"
require_env || exit 2
# Check ny-llvmc
NYLL="${NYASH_NY_LLVM_COMPILER:-$ROOT/target/release/ny-llvmc}"
if [ ! -f "$NYLL" ]; then
echo "[SKIP] selfhost_build_exe_return (ny-llvmc not found)"
exit 0
fi
tmp_hako="/tmp/selfhost_exe_return7_$$.hako"
tmp_exe="/tmp/selfhost_exe_return7_$$.out"
cat > "$tmp_hako" <<'HAKO'
static box Main { method main(args) { return 7 } }
HAKO
"$ROOT/tools/selfhost/selfhost_build.sh" --in "$tmp_hako" --exe "$tmp_exe" >/dev/null 2>&1 || { echo "[FAIL] selfhost_build_exe_return (build failed)" >&2; exit 1; }
set +e
"$tmp_exe" >/dev/null 2>&1
rc=$?
set -e
rm -f "$tmp_hako" "$tmp_exe" 2>/dev/null || true
if [ "$rc" = "7" ]; then
echo "[PASS] selfhost_build_exe_return"
else
echo "[FAIL] selfhost_build_exe_return (rc=$rc)" >&2
exit 1
fi