Browse Source

Change `build_demo_web.sh` option from `--fast` to `--optimize`

pull/1878/head
Emil Ernerfeldt 2 years ago
parent
commit
5d8ef5326b
  1. 2
      egui_demo_app/README.md
  2. 24
      sh/build_demo_web.sh
  3. 8
      sh/start_server.sh

2
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).

24
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

8
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)

Loading…
Cancel
Save