Add -g option to build_demo_web.sh

This commit is contained in:
Emil Ernerfeldt 2023-12-28 10:36:07 +01:00
parent d978b37732
commit 790b401adf
1 changed files with 22 additions and 12 deletions

View File

@ -19,23 +19,37 @@ OPTIMIZE=false
BUILD=debug
BUILD_FLAGS=""
WEB_GPU=false
WASM_OPT_FLAGS="-O2 --fast-math"
while test $# -gt 0; do
case "$1" in
-h|--help)
echo "build_demo_web.sh [--release] [--webgpu] [--open]"
echo ""
echo " --release: Build with --release, and enable extra optimization step"
echo " Runs wasm-opt."
echo " NOTE: --release also removes debug symbols which are otherwise useful for in-browser profiling."
echo " -g: Keep debug symbols even with --release."
echo " These are useful profiling and size trimming."
echo ""
echo " --webgpu: Build a binary for WebGPU instead of WebGL"
echo " --open: Open the result in a browser."
echo ""
echo " --release: Build with --release, and then run wasm-opt."
echo " NOTE: --release also removes debug symbols, unless you also use -g."
echo ""
echo " --webgpu: Build a binary for WebGPU instead of WebGL."
echo " Note that the resulting wasm will ONLY work on browsers with WebGPU."
echo ""
echo " --open: Open the result in a browser"
exit 0
;;
-g)
shift
WASM_OPT_FLAGS="${WASM_OPT_FLAGS} -g"
echo "'${WASM_OPT_FLAGS}'"
;;
--open)
shift
OPEN=true
;;
--release)
shift
OPTIMIZE=true
@ -48,11 +62,6 @@ while test $# -gt 0; do
WEB_GPU=true
;;
--open)
shift
OPEN=true
;;
*)
echo "Unknown option: $1"
exit 1
@ -96,6 +105,7 @@ wasm-bindgen "${WASM_PATH}" --out-dir web_demo --out-name ${OUT_FILE_NAME} --no-
# if this fails with "error: cannot import from modules (`env`) with `--no-modules`", you can use:
# wasm2wat target/wasm32-unknown-unknown/release/egui_demo_app.wasm | rg env
# wasm2wat target/wasm32-unknown-unknown/release/egui_demo_app.wasm | rg "call .now\b" -B 20 # What calls `$now` (often a culprit)
# Or use https://rustwasm.github.io/twiggy/usage/command-line-interface/paths.html#twiggy-paths
# to get wasm-strip: apt/brew/dnf install wabt
# wasm-strip ${FINAL_WASM_PATH}
@ -103,7 +113,7 @@ wasm-bindgen "${WASM_PATH}" --out-dir web_demo --out-name ${OUT_FILE_NAME} --no-
if [[ "${OPTIMIZE}" = true ]]; then
echo "Optimizing wasm…"
# to get wasm-opt: apt/brew/dnf install binaryen
wasm-opt "${FINAL_WASM_PATH}" -O2 --fast-math -o "${FINAL_WASM_PATH}" # add -g to get debug symbols
wasm-opt "${FINAL_WASM_PATH}" $WASM_OPT_FLAGS -o "${FINAL_WASM_PATH}"
fi
echo "Finished ${FINAL_WASM_PATH}"