-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild_web.sh
More file actions
90 lines (80 loc) · 2.5 KB
/
Copy pathbuild_web.sh
File metadata and controls
90 lines (80 loc) · 2.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#!/bin/bash
set -euo pipefail
echo "======================================"
echo " Building Community WebAssembly Bundle "
echo "======================================"
try_source_emsdk() {
local emsdk_env
for emsdk_env in \
"${EMSDK:-}/emsdk_env.sh" \
"./.emsdk/emsdk_env.sh" \
"./emsdk/emsdk_env.sh" \
"../.emsdk/emsdk_env.sh" \
"../emsdk/emsdk_env.sh" \
"$HOME/.emsdk/emsdk_env.sh" \
"$HOME/emsdk/emsdk_env.sh" \
"/opt/emsdk/emsdk_env.sh"
do
if [ -f "$emsdk_env" ]; then
# shellcheck disable=SC1090
source "$emsdk_env" >/dev/null 2>&1 || true
return 0
fi
done
return 1
}
if ! command -v em++ >/dev/null 2>&1; then
try_source_emsdk || true
fi
if ! command -v em++ >/dev/null 2>&1; then
# Try to bootstrap a local emsdk checkout in this repository.
if [ -x "./.emsdk/emsdk" ] || [ -f "./.emsdk/emsdk.py" ]; then
echo "em++ missing. Bootstrapping local .emsdk toolchain (one-time setup)..."
(
cd ./.emsdk
./emsdk install latest
./emsdk activate latest
)
try_source_emsdk || true
fi
fi
if ! command -v em++ >/dev/null 2>&1; then
echo "ERROR: em++ not found. Install and activate Emscripten (emsdk) first."
echo " https://emscripten.org/docs/getting_started/downloads.html"
echo
echo "Quick start:"
echo " git clone https://github.com/emscripten-core/emsdk.git"
echo " cd emsdk && ./emsdk install latest && ./emsdk activate latest"
echo " source ./emsdk_env.sh"
echo
echo "If this repository already has .emsdk, run:"
echo " cd .emsdk && ./emsdk install latest && ./emsdk activate latest"
echo " source ./emsdk_env.sh"
exit 1
fi
DIST_DIR="dist_web"
OUT_HTML="$DIST_DIR/index.html"
rm -rf "$DIST_DIR"
mkdir -p "$DIST_DIR"
SRC=$(find . -name "*.cpp" \
-not -path "./.emsdk/*" \
-not -path "./glfw/*" \
-not -path "./dist/*" \
-not -path "./dist_web/*" \
-not -path "./core/net/http.cpp" | tr '\n' ' ')
em++ $SRC \
-std=c++17 \
-I. \
-O2 \
-sUSE_GLFW=3 \
-sLEGACY_GL_EMULATION=1 \
-sFORCE_FILESYSTEM=1 \
-sALLOW_MEMORY_GROWTH=1 \
-sMIN_WEBGL_VERSION=1 \
-sMAX_WEBGL_VERSION=2 \
--preload-file assets@/assets \
--preload-file game/data@/game/data \
--shell-file web/shell.html \
-o "$OUT_HTML"
echo "Build complete: $OUT_HTML"
echo "Serve it locally: python3 -m http.server 8080 --directory $DIST_DIR"