Skip to content

Commit

Permalink
Add -g option to build_demo_web.sh
Browse files Browse the repository at this point in the history
  • Loading branch information
emilk committed Dec 28, 2023
1 parent d978b37 commit 790b401
Showing 1 changed file with 22 additions and 12 deletions.
34 changes: 22 additions & 12 deletions scripts/build_demo_web.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 " Note that the resulting wasm will ONLY work on browsers with WebGPU."
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 " --open: Open the result in a browser"
echo " --webgpu: Build a binary for WebGPU instead of WebGL."
echo " Note that the resulting wasm will ONLY work on browsers with WebGPU."
exit 0
;;

-g)
shift
WASM_OPT_FLAGS="${WASM_OPT_FLAGS} -g"
echo "'${WASM_OPT_FLAGS}'"
;;

--open)
shift
OPEN=true
;;

--release)
shift
OPTIMIZE=true
Expand All @@ -48,11 +62,6 @@ while test $# -gt 0; do
WEB_GPU=true
;;

--open)
shift
OPEN=true
;;

*)
echo "Unknown option: $1"
exit 1
Expand Down Expand Up @@ -96,14 +105,15 @@ 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}

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}"
Expand Down

0 comments on commit 790b401

Please sign in to comment.