build_demo_web.sh: add --fast flag to skip optimization step

This commit is contained in:
Emil Ernerfeldt 2021-08-21 21:33:51 +02:00
parent 91bdf9ba6e
commit 0e457c4b06

View file

@ -3,9 +3,33 @@ set -eu
script_path=$( cd "$(dirname "${BASH_SOURCE[0]}")" ; pwd -P )
cd "$script_path/.."
# Usage: build_demo_web.sh [--open]
CRATE_NAME="egui_demo_app"
FEATURES="http,persistence,screen_reader"
OPEN=false
FAST=false
while test $# -gt 0; do
case "$1" in
-h|--help)
echo "build_demo_web.sh [--fast] [--open]"
echo " --fast: skip optimization step"
echo " --open: open the result in a browser"
exit 0
;;
--fast)
shift
FAST=true
;;
--open)
shift
OPEN=true
;;
*)
break
;;
esac
done
# This is required to enable the web_sys clipboard API which egui_web uses
# https://rustwasm.github.io/wasm-bindgen/api/web_sys/struct.Clipboard.html
@ -17,7 +41,6 @@ rm -f docs/${CRATE_NAME}_bg.wasm
echo "Building rust…"
BUILD=release
FEATURES="http,persistence,screen_reader"
cargo build \
-p ${CRATE_NAME} \
@ -34,12 +57,15 @@ wasm-bindgen "target/wasm32-unknown-unknown/$BUILD/$TARGET_NAME" \
# to get wasm-strip: apt/brew/dnf install wabt
# wasm-strip docs/${CRATE_NAME}_bg.wasm
echo "Optimizing wasm…"
# to get wasm-opt: apt/brew/dnf install binaryen
wasm-opt docs/${CRATE_NAME}_bg.wasm -O2 --fast-math -o docs/${CRATE_NAME}_bg.wasm # add -g to get debug symbols
if [ "${FAST}" = false ]; then
echo "Optimizing wasm…"
# to get wasm-opt: apt/brew/dnf install binaryen
wasm-opt docs/${CRATE_NAME}_bg.wasm -O2 --fast-math -o docs/${CRATE_NAME}_bg.wasm # add -g to get debug symbols
fi
echo "Finished docs/${CRATE_NAME}_bg.wasm"
if [[ "${1:-}" == "--open" ]]; then
if [ "${OPEN}" = true ]; then
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
# Linux, ex: Fedora
xdg-open http://localhost:8888/index.html