Files
Lua-compilateur/build.sh
T
BlackAngelTV cd8b8ce8eb refactor(demo): keep the demo Lua-only
Calling the compiled modules required a CMake project and a C++ main, which
contradicted the point of the compiler. A Lua entry script now prints the same
report, and the modules sit next to it so require resolves without any flag.
2026-11-18 08:48:05 +01:00

51 lines
1.4 KiB
Bash
Executable File

#!/usr/bin/env bash
# Builds the luacpp compiler (the C++ program), nothing else.
# Then use the compiler from anywhere, for example:
#
# ./build/luacpp run mon_script.lua # compile le Lua en C++ puis l'exécute
# cd build && ./luacpp run ../script.lua # même chose depuis le dossier build
#
# Options:
# ./build.sh --full # + tests de conformité et démo Lua
#
# Environment:
# BUILD_DIR build directory (default: build)
# JOBS parallel jobs (default: nproc)
set -euo pipefail
cd "$(dirname "$0")"
BUILD_DIR="${BUILD_DIR:-build}"
JOBS="${JOBS:-$(nproc 2>/dev/null || echo 2)}"
echo "==> configuring"
cmake -S . -B "$BUILD_DIR" -DCMAKE_BUILD_TYPE=Release
echo "==> building the compiler"
cmake --build "$BUILD_DIR" -j "$JOBS" --target luacpp
LUACPP="$BUILD_DIR/luacpp"
"$LUACPP" --version
echo
echo "compilateur prêt : $LUACPP"
echo
echo "Utilisation :"
echo " $LUACPP run <script.lua> [args...] # compile le Lua en C++ puis l'exécute"
echo " cd $BUILD_DIR && ./luacpp run ../Demo/hello.lua"
echo " $LUACPP <module.lua> -n demo -o gen # génère seulement .hpp/.cpp"
echo
if [[ "${1:-}" != "--full" ]]; then
exit 0
fi
echo "==> building the tests"
cmake --build "$BUILD_DIR" -j "$JOBS"
echo
echo "==> Demo (Lua only, compiled and run by luacpp)"
( cd "$BUILD_DIR" && ./luacpp run ../Demo/main.lua )
echo
echo "==> conformance test (compiled modules vs. plain Lua 5.4)"
( cd "$BUILD_DIR" && ctest --output-on-failure )