67 lines
1.7 KiB
Bash
67 lines
1.7 KiB
Bash
|
|
#!/usr/bin/env bash
|
||
|
|
set -euo pipefail
|
||
|
|
|
||
|
|
usage() {
|
||
|
|
cat << USAGE
|
||
|
|
Usage: tools/build_aot.sh <input.nyash> [-o <output>]
|
||
|
|
|
||
|
|
Builds Nyash with Cranelift, emits an AOT object (.o) for the given program,
|
||
|
|
links it with libnyrt.a into a native executable, and prints the result path.
|
||
|
|
|
||
|
|
Options:
|
||
|
|
-o <output> Output executable name (default: app)
|
||
|
|
|
||
|
|
Notes:
|
||
|
|
- Requires a Cranelift-enabled build.
|
||
|
|
- Runtime requires nyash.toml and plugin .so files resolvable by nyash.toml paths.
|
||
|
|
USAGE
|
||
|
|
}
|
||
|
|
|
||
|
|
if [[ $# -lt 1 ]]; then usage; exit 1; fi
|
||
|
|
|
||
|
|
INPUT=""
|
||
|
|
OUT="app"
|
||
|
|
while [[ $# -gt 0 ]]; do
|
||
|
|
case "$1" in
|
||
|
|
-h|--help) usage; exit 0 ;;
|
||
|
|
-o) OUT="$2"; shift 2 ;;
|
||
|
|
*) INPUT="$1"; shift ;;
|
||
|
|
esac
|
||
|
|
done
|
||
|
|
|
||
|
|
if [[ ! -f "$INPUT" ]]; then
|
||
|
|
echo "error: input file not found: $INPUT" >&2
|
||
|
|
exit 1
|
||
|
|
fi
|
||
|
|
|
||
|
|
echo "[1/4] Building nyash (Cranelift) ..."
|
||
|
|
cargo build --release --features cranelift-jit >/dev/null
|
||
|
|
|
||
|
|
echo "[2/4] Emitting object (.o) via JIT ..."
|
||
|
|
rm -rf target/aot_objects && mkdir -p target/aot_objects
|
||
|
|
NYASH_AOT_OBJECT_OUT=target/aot_objects \
|
||
|
|
NYASH_USE_PLUGIN_BUILTINS=1 \
|
||
|
|
NYASH_JIT_EXEC=1 \
|
||
|
|
NYASH_JIT_THRESHOLD=1 \
|
||
|
|
./target/release/nyash --backend vm "$INPUT" >/dev/null || true
|
||
|
|
|
||
|
|
OBJ="target/aot_objects/main.o"
|
||
|
|
if [[ ! -f "$OBJ" ]]; then
|
||
|
|
echo "error: object not generated: $OBJ" >&2
|
||
|
|
echo "hint: ensure the program's entry function is JIT-compilable (e.g., main)" >&2
|
||
|
|
exit 2
|
||
|
|
fi
|
||
|
|
|
||
|
|
echo "[3/4] Building libnyrt.a ..."
|
||
|
|
( cd crates/nyrt && cargo build --release >/dev/null )
|
||
|
|
|
||
|
|
echo "[4/4] Linking $OUT ..."
|
||
|
|
cc "$OBJ" \
|
||
|
|
-L crates/nyrt/target/release \
|
||
|
|
-Wl,--whole-archive -lnyrt -Wl,--no-whole-archive \
|
||
|
|
-lpthread -ldl -lm -o "$OUT"
|
||
|
|
|
||
|
|
echo "✅ Done: $OUT"
|
||
|
|
echo " (runtime requires nyash.toml and plugin .so per config)"
|
||
|
|
|