Added valgrind option to build commands.

This commit is contained in:
2026-07-24 08:20:55 +02:00
parent b7b701b34a
commit 101ef99218
+33 -5
View File
@@ -13,24 +13,27 @@ OPTIMIZED=0
WEB=0
CLEAN=0
DEBUGGER=0
VALGRIND=0
usage() {
echo "Usage: $0 [-b] [-o] [-w] [-d] [-c] [-h]"
echo "Usage: $0 [-b] [-o] [-w] [-d] [-v] [-c] [-h]"
echo " -b build only, don't run"
echo " -o optimized release build (-o:speed, no debug info)"
echo " -w web/WASM build (js_wasm32 target)"
echo " -d build then launch in debugger instead of running"
echo " -v build then run under Valgrind"
echo " -c clean build artifacts"
echo " -h show this help"
exit 1
}
while getopts "bowdch" opt; do
while getopts "bowdvch" opt; do
case $opt in
b) BUILD_ONLY=1 ;;
o) OPTIMIZED=1 ;;
w) WEB=1 ;;
d) DEBUGGER=1 ;;
v) VALGRIND=1 ;;
c) CLEAN=1 ;;
h) usage ;;
*) usage ;;
@@ -52,7 +55,7 @@ if [ "$WEB" -eq 1 ]; then
-out:"$OUT_DIR/$OUT_NAME.wasm" \
$( [ "$OPTIMIZED" -eq 1 ] && echo "-o:speed" || echo "-debug" )
# copy the JS glue/html shell if you keep one alongside the script
# Copy the HTML shell if one exists
if [ -f "web/index_template.html" ]; then
cp web/index_template.html "$OUT_DIR/index.html"
fi
@@ -63,18 +66,43 @@ fi
if [ "$OPTIMIZED" -eq 1 ]; then
echo "Building optimized ($SRC_DIR -> $OUT_DIR/$OUT_NAME)..."
odin build "$SRC_DIR" -out:"$OUT_DIR/$OUT_NAME" -o:speed -no-bounds-check
odin build "$SRC_DIR" \
-out:"$OUT_DIR/$OUT_NAME" \
-o:speed \
-no-bounds-check
else
echo "Building debug ($SRC_DIR -> $OUT_DIR/$OUT_NAME)..."
odin build "$SRC_DIR" -out:"$OUT_DIR/$OUT_NAME" -debug
odin build "$SRC_DIR" \
-out:"$OUT_DIR/$OUT_NAME" \
-debug
fi
echo "Build complete."
if [ "$BUILD_ONLY" -eq 0 ]; then
echo "----------------------------------------"
if [ "$DEBUGGER" -eq 1 ]; then
lldb "$OUT_DIR/$OUT_NAME"
elif [ "$VALGRIND" -eq 1 ]; then
# --show-leak-kinds=definite,possible reduces tons of noise
# 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 \
--show-leak-kinds=definite,possible \
--track-origins=yes \
--errors-for-leak-kinds=definite,possible \
--error-exitcode=1 \
--log-file="$OUT_DIR/valgrind.log" \
"./$OUT_DIR/$OUT_NAME"
echo
echo "Valgrind report written to $OUT_DIR/valgrind.log"
else
"./$OUT_DIR/$OUT_NAME"
fi