Files
Lua-compilateur/build.sh
T
BlackAngelTV 11a2e1ba6a build: add build script and CMake helper for compiled packages
Compiling the compiler, the example and the demo by hand is error prone, so a
single script keeps the whole flow reproducible and ignores build outputs.
2026-11-18 08:48:05 +01:00

62 lines
1.9 KiB
Bash
Executable File

#!/usr/bin/env bash
# Builds the luacpp compiler, compiles the Lua modules of the Demo project with
# it, then builds and runs the resulting C++ program (plus the test suite).
#
# Usage:
# ./build.sh # full build + demo + tests
# ./build.sh path/to/x.lua # just compile one module and show the C++ output
#
# 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)}"
LUACPP="$BUILD_DIR/luacpp"
echo "==> configuring"
cmake -S . -B "$BUILD_DIR" -DCMAKE_BUILD_TYPE=Release
echo "==> building the compiler"
cmake --build "$BUILD_DIR" -j "$JOBS" --target luacpp
"$LUACPP" --version
# Compile a single module on demand.
if [[ $# -gt 0 ]]; then
out_dir="$BUILD_DIR/single"
rm -rf "$out_dir"
"$LUACPP" "$1" --root "$(dirname "$1")" --output "$out_dir"
echo
echo "==> generated header ($out_dir)"
find "$out_dir" -name '*.hpp' -exec sh -c 'echo "--- $1"; cat "$1"' _ {} \;
echo
echo "==> generated source ($out_dir)"
find "$out_dir" -name '*.cpp' -exec sh -c 'echo "--- $1"; cat "$1"' _ {} \;
exit 0
fi
echo "==> compiling Demo/lua/*.lua into C++ packages"
rm -rf "$BUILD_DIR/demo-generated"
"$LUACPP" Demo/lua/todo.lua Demo/lua/report.lua \
--root Demo/lua --namespace demo --output "$BUILD_DIR/demo-generated"
echo "==> building the rest of the repository (example + tests)"
cmake --build "$BUILD_DIR" -j "$JOBS"
echo
echo "==> running the example"
"$BUILD_DIR/examples/luacpp_example"
echo
echo "==> building and running the Demo project"
cmake -S Demo -B "$BUILD_DIR/demo" -DCMAKE_BUILD_TYPE=Release
cmake --build "$BUILD_DIR/demo" -j "$JOBS"
echo
"$BUILD_DIR/demo/luacpp_demo"
echo
echo "==> conformance test (compiled modules vs. plain Lua 5.4)"
( cd "$BUILD_DIR" && ctest --output-on-failure )