#!/usr/bin/bash set -e for arg in "$@"; do declare "$arg"='1'; done if [ ! -v release ]; then debug=1; fi if [ -v debug ]; then echo "[web debug build]"; fi if [ -v release ]; then echo "[web release build]"; fi # If emsdk is installed but not sourced in this shell, try the common location. if ! command -v emcc >/dev/null 2>&1; then if [ -f "$HOME/emsdk/emsdk_env.sh" ]; then # shellcheck disable=SC1091 source "$HOME/emsdk/emsdk_env.sh" >/dev/null fi fi if ! command -v emcc >/dev/null 2>&1; then echo "error: emcc not found. Source emsdk_env.sh or add emcc to PATH." >&2 exit 1 fi mkdir -p build_web incs="-Isrc -Isrc/external/glad" flags="-Wall -Wextra -Werror -Wno-error=experimental -Wno-error=unused-parameter -Wformat=2 -Wundef -Wshadow -Wno-missing-field-initializers -Wno-missing-braces -Wno-writable-strings \ -fdiagnostics-absolute-paths \ -nostdlib++ -fno-exceptions" wasmflags="-sALLOW_MEMORY_GROWTH=0 -sTOTAL_STACK=5MB -sINITIAL_MEMORY=256MB \ -sUSE_SDL=3 -sUSE_WEBGL2=1 -sMIN_WEBGL_VERSION=2 -sMAX_WEBGL_VERSION=2 -sFULL_ES3=1 \ -sASYNCIFY=1 -sASSERTIONS=2 \ -sEXIT_RUNTIME=0 \ -msimd128" if [ -v debug ]; then flags="$flags -g -gsource-map -DDEBUG_BUILD=1" else flags="$flags -O3 -DDEBUG_BUILD=0" fi emcc -o build_web/text_editor.html \ --shell-file data/shell.html \ $flags $incs $wasmflags \ src/text_editor.cpp \ -lm echo "Wrote build_web/text_editor.html"