diff --git a/egui_demo_app/README.md b/egui_demo_app/README.md index 472618ec..e33464f2 100644 --- a/egui_demo_app/README.md +++ b/egui_demo_app/README.md @@ -9,7 +9,7 @@ Run it locally with `cargo run --release -p egui_demo_app`. ```sh ./sh/start_server.sh & -./sh/build_demo_web.sh --fast --open +./sh/build_demo_web.sh --open ``` `egui_demo_app` uses [`egui_demo_lib`](https://github.com/emilk/egui/tree/master/egui_demo_lib). diff --git a/sh/build_demo_web.sh b/sh/build_demo_web.sh index 2a1068ab..f111085d 100755 --- a/sh/build_demo_web.sh +++ b/sh/build_demo_web.sh @@ -3,29 +3,29 @@ set -eu script_path=$( cd "$(dirname "${BASH_SOURCE[0]}")" ; pwd -P ) cd "$script_path/.." -./sh/setup_web.sh - CRATE_NAME="egui_demo_app" # NOTE: persistence use up about 400kB (10%) of the WASM! FEATURES="glow,http,persistence,screen_reader" OPEN=false -FAST=false +OPTIMIZE=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" + echo "build_demo_web.sh [--optimize] [--open]" + echo "" + echo " --optimize: Enable optimization step" + echo " Runs wasm-opt." + echo " NOTE: --optimize also removes debug symbols which are otherwise useful for in-browser profiling." + echo "" + echo " --open: Open the result in a browser" exit 0 ;; - # Skip running `wasm-opt`. - # --fast also preserves debug symbols, which is great for profiling. - --fast) + -O|--optimize) shift - FAST=true + OPTIMIZE=true ;; --open) @@ -39,6 +39,8 @@ while test $# -gt 0; do esac done +./sh/setup_web.sh + # This is required to enable the web_sys clipboard API which eframe web uses # https://rustwasm.github.io/wasm-bindgen/api/web_sys/struct.Clipboard.html # https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html @@ -74,7 +76,7 @@ wasm-bindgen "${WASM_PATH}" --out-dir docs --no-modules --no-typescript # to get wasm-strip: apt/brew/dnf install wabt # wasm-strip docs/${CRATE_NAME}_bg.wasm -if [[ "${FAST}" = false ]]; then +if [[ "${OPTIMIZE}" = true ]]; 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 diff --git a/sh/start_server.sh b/sh/start_server.sh index 958654e1..3382c1b8 100755 --- a/sh/start_server.sh +++ b/sh/start_server.sh @@ -6,11 +6,13 @@ cd "$script_path/.." # Starts a local web-server that serves the contents of the `doc/` folder, # i.e. the web-version of `egui_demo_app`. +PORT=8888 + echo "ensuring basic-http-server is installed…" cargo install basic-http-server echo "starting server…" -echo "serving at http://localhost:8888" +echo "serving at http://localhost:${PORT}" -(cd docs && basic-http-server --addr 127.0.0.1:8888 .) -# (cd docs && python3 -m http.server 8888 --bind 127.0.0.1) +(cd docs && basic-http-server --addr 127.0.0.1:${PORT} .) +# (cd docs && python3 -m http.server ${PORT} --bind 127.0.0.1)