2018-12-23 18:42:30 +00:00
|
|
|
#!/bin/bash
|
|
|
|
set -eu
|
2021-05-09 11:28:24 +00:00
|
|
|
script_path=$( cd "$(dirname "${BASH_SOURCE[0]}")" ; pwd -P )
|
|
|
|
cd "$script_path/.."
|
2018-12-23 18:42:30 +00:00
|
|
|
|
2020-12-29 16:54:52 +00:00
|
|
|
CRATE_NAME="egui_demo_app"
|
2021-08-21 19:33:51 +00:00
|
|
|
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
|
2018-12-23 18:42:30 +00:00
|
|
|
|
2020-12-29 11:42:15 +00:00
|
|
|
# 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
|
|
|
|
# https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html
|
|
|
|
export RUSTFLAGS=--cfg=web_sys_unstable_apis
|
2020-11-15 19:55:41 +00:00
|
|
|
|
2018-12-23 18:42:30 +00:00
|
|
|
# Clear output from old stuff:
|
2020-12-29 11:42:15 +00:00
|
|
|
rm -f docs/${CRATE_NAME}_bg.wasm
|
2018-12-23 18:42:30 +00:00
|
|
|
|
2020-12-19 20:30:51 +00:00
|
|
|
echo "Building rust…"
|
|
|
|
BUILD=release
|
2021-03-08 19:58:01 +00:00
|
|
|
|
2021-04-24 07:41:57 +00:00
|
|
|
cargo build \
|
|
|
|
-p ${CRATE_NAME} \
|
|
|
|
--release \
|
|
|
|
--lib \
|
|
|
|
--target wasm32-unknown-unknown \
|
2021-10-23 03:58:57 +00:00
|
|
|
--no-default-features \
|
2021-04-24 07:41:57 +00:00
|
|
|
--features ${FEATURES}
|
2018-12-23 23:15:18 +00:00
|
|
|
|
2021-12-29 11:07:05 +00:00
|
|
|
# Get the output directory (in the workspace it is in another location)
|
|
|
|
TARGET=`cargo metadata --format-version=1 | jq --raw-output .target_directory`
|
|
|
|
|
2020-12-19 20:30:51 +00:00
|
|
|
echo "Generating JS bindings for wasm…"
|
2020-12-29 11:42:15 +00:00
|
|
|
TARGET_NAME="${CRATE_NAME}.wasm"
|
2021-12-29 11:07:05 +00:00
|
|
|
wasm-bindgen "${TARGET}/wasm32-unknown-unknown/$BUILD/$TARGET_NAME" \
|
2019-02-10 19:56:59 +00:00
|
|
|
--out-dir docs --no-modules --no-typescript
|
2020-04-23 07:50:03 +00:00
|
|
|
|
2021-04-05 12:23:19 +00:00
|
|
|
# to get wasm-strip: apt/brew/dnf install wabt
|
2021-04-01 21:07:43 +00:00
|
|
|
# wasm-strip docs/${CRATE_NAME}_bg.wasm
|
2021-03-24 20:35:29 +00:00
|
|
|
|
2021-08-21 19:33:51 +00:00
|
|
|
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
|
|
|
|
|
2021-04-01 21:07:43 +00:00
|
|
|
echo "Finished docs/${CRATE_NAME}_bg.wasm"
|
2020-12-19 20:30:51 +00:00
|
|
|
|
2021-08-21 19:33:51 +00:00
|
|
|
if [ "${OPEN}" = true ]; then
|
2021-04-24 07:41:57 +00:00
|
|
|
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
|
|
|
|
# Linux, ex: Fedora
|
|
|
|
xdg-open http://localhost:8888/index.html
|
|
|
|
elif [[ "$OSTYPE" == "msys" ]]; then
|
|
|
|
# Windows
|
|
|
|
start http://localhost:8888/index.html
|
|
|
|
else
|
|
|
|
# Darwin/MacOS, or something else
|
|
|
|
open http://localhost:8888/index.html
|
|
|
|
fi
|
2021-04-05 12:23:19 +00:00
|
|
|
fi
|