Updated build file.

This commit is contained in:
2026-09-29 07:54:23 +02:00
parent 29c88a67ad
commit 5f38503b49
Regular → Executable
+56 -58
View File
@@ -4,6 +4,7 @@ set -e
# Find the odin binary # Find the odin binary
export PATH="$HOME/.odin:$PATH" export PATH="$HOME/.odin:$PATH"
SRC_DIR="src" SRC_DIR="src"
OUT_DIR="out" OUT_DIR="out"
OUT_NAME="pong" OUT_NAME="pong"
@@ -16,91 +17,88 @@ DEBUGGER=0
VALGRIND=0 VALGRIND=0
usage() { usage() {
echo "Usage: $0 [-b] [-o] [-w] [-d] [-v] [-c] [-h]" echo "Usage: $0 [-b] [-o] [-w] [-d] [-v] [-c] [-h]"
echo " -b build only, don't run" echo " -b build only, don't run"
echo " -o optimized release build (-o:speed, no debug info)" echo " -o optimized release build (-o:speed, no debug info)"
echo " -w web/WASM build (js_wasm32 target)" echo " -w web/WASM build (js_wasm32 target)"
echo " -d build then launch in debugger instead of running" echo " -d build then launch in debugger instead of running"
echo " -v build then run under Valgrind" echo " -v build then run under Valgrind"
echo " -c clean build artifacts" echo " -c clean build artifacts"
echo " -h show this help" echo " -h show this help"
exit 1 exit 1
} }
while getopts "bowdvch" opt; do while getopts "bowdvch" opt; do
case $opt in case $opt in
b) BUILD_ONLY=1 ;; b) BUILD_ONLY=1 ;;
o) OPTIMIZED=1 ;; o) OPTIMIZED=1 ;;
w) WEB=1 ;; w) WEB=1 ;;
d) DEBUGGER=1 ;; d) DEBUGGER=1 ;;
v) VALGRIND=1 ;; v) VALGRIND=1 ;;
c) CLEAN=1 ;; c) CLEAN=1 ;;
h) usage ;; h) usage ;;
*) usage ;; *) usage ;;
esac esac
done done
mkdir -p "$OUT_DIR" mkdir -p "$OUT_DIR"
if [ "$CLEAN" -eq 1 ]; then if [ "$CLEAN" -eq 1 ]; then
echo "Cleaning..." echo "Cleaning..."
rm -rf "${OUT_DIR:?}"/* rm -rf "${OUT_DIR:?}"/*
exit 0 exit 0
fi fi
if [ "$WEB" -eq 1 ]; then if [ "$WEB" -eq 1 ]; then
echo "Building web (WASM)..." echo "Building web (WASM)..."
odin build "$SRC_DIR" \ odin build "$SRC_DIR" \
-target:js_wasm32 \ -target:js_wasm32 \
-out:"$OUT_DIR/$OUT_NAME.wasm" \ -out:"$OUT_DIR/$OUT_NAME.wasm" \
$( [ "$OPTIMIZED" -eq 1 ] && echo "-o:speed" || echo "-debug" ) $( [ "$OPTIMIZED" -eq 1 ] && echo "-o:speed" || echo "-debug" )
# Copy the HTML shell if one exists # Copy the HTML shell if one exists
if [ -f "web/index_template.html" ]; then if [ -f "web/index_template.html" ]; then
cp web/index_template.html "$OUT_DIR/index.html" cp web/index_template.html "$OUT_DIR/index.html"
fi fi
echo "Web build complete -> $OUT_DIR/$OUT_NAME.wasm" echo "Web build complete -> $OUT_DIR/$OUT_NAME.wasm"
exit 0 exit 0
fi fi
if [ "$OPTIMIZED" -eq 1 ]; then if [ "$OPTIMIZED" -eq 1 ]; then
echo "Building optimized ($SRC_DIR -> $OUT_DIR/$OUT_NAME)..." echo "Building optimized ($SRC_DIR -> $OUT_DIR/$OUT_NAME)..."
odin build "$SRC_DIR" \ odin build "$SRC_DIR" \
-out:"$OUT_DIR/$OUT_NAME" \ -out:"$OUT_DIR/$OUT_NAME" \
-o:speed \ -o:speed u
-no-bounds-check -no-bounds-check
else else
echo "Building debug ($SRC_DIR -> $OUT_DIR/$OUT_NAME)..." echo "Building debug ($SRC_DIR -> $OUT_DIR/$OUT_NAME)..."
odin build "$SRC_DIR" \ odin build "$SRC_DIR" \
-out:"$OUT_DIR/$OUT_NAME" \ -out:"$OUT_DIR/$OUT_NAME" \
-define:DEBUG_MODE=true -define:DEBUG_MODE=true
fi fi
echo "Build complete." echo "Build complete."
if [ "$BUILD_ONLY" -eq 0 ]; then if [ "$BUILD_ONLY" -eq 0 ]; then
echo "----------------------------------------" echo "----------------------------------------"
if [ "$DEBUGGER" -eq 1 ]; then if [ "$DEBUGGER" -eq 1 ]; then
lldb "$OUT_DIR/$OUT_NAME" lldb "$OUT_DIR/$OUT_NAME"
elif [ "$VALGRIND" -eq 1 ]; then elif [ "$VALGRIND" -eq 1 ]; then
# --show-leak-kinds=definite,possible reduces tons of noise valgrind \
# still shows the leaks you actually need to fix.
# to audit whole process, temporarily switch back to --show-leak-kinds=all
valgrind \
--leak-check=full \ --leak-check=full \
--show-leak-kinds=definite,possible \ --show-leak-kinds=definite,possible \
--track-origins=yes \ --track-origins=yes \
--errors-for-leak-kinds=definite,possible \ --errors-for-leak-kinds=definite,possible \
--error-exitcode=1 \ --error-exitcode=1 \
--log-file="$OUT_DIR/valgrind.log" \ --log-file="$OUT_DIR/valgrind.log" \
"./$OUT_DIR/$OUT_NAME" "./$OUT_DIR/$OUT_NAME"
echo echo
echo "Valgrind report written to $OUT_DIR/valgrind.log" echo "Valgrind report written to $OUT_DIR/valgrind.log"
else else
"./$OUT_DIR/$OUT_NAME" "./$OUT_DIR/$OUT_NAME"
fi fi
fi fi