forked from nic-hartley/git-gud
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.sh
executable file
·108 lines (95 loc) · 2.72 KB
/
build.sh
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#!/bin/bash
# We need Bash specifically so that emsdk_env.sh works, but once
# https://github.com/emscripten-core/emsdk/issues/219 is closed that won't be
# true anymore!
if [ "$(head -n 1 README.md)" != "# git-gud" ]; then
echo "ERROR! Run build script from the git-gud project root!"
fi
refresh_emcc() {
echo "Adding emcc to PATH"
if [ -f ./emsdk/emsdk_env.sh ]; then
. ./emsdk/emsdk_env.sh >/dev/null 2>&1
else
return 1
fi
}
install_emcc() {
refresh_emcc && return 0
echo "Failed to reload emsdk, so we need to reinstall"
echo "Downloading..."
git clone https://github.com/emscripten-core/emsdk.git >/dev/null 2>&1
cd emsdk
echo "Installing [1/3]..."
git pull >/dev/null 2>&1
echo "Installing [2/3]... (may take a while)"
./emsdk install latest >/dev/null 2>&1
echo "Installing [3/3]..."
./emsdk activate latest >/dev/null 2>&1
cd ..
refresh_emcc
}
refresh_wabt() {
echo "Adding wasm2wat to PATH"
if [ -d ./wabt ]; then
export PATH="$(pwd)/wabt/build:$PATH"
return 0
else
return 1
fi
}
install_wabt() {
refresh_wabt && return 0
cmake --version || (echo "You need CMake to install wabt! Talk to Nic." && exit 1)
echo "Failed to reload wabt, so we need to reinstall"
echo "Downloading..."
git clone --recursive https://github.com/WebAssembly/wabt >/dev/null 2>&1
cd wabt
mkdir build
cd build
echo "Building [1/2]..."
cmake .. >/dev/null 2>&1
echo "Building [2/2]... (may take a while)"
make wasm2wat >/dev/null 2>&1
cd ..
refresh_wabt
}
clean() {
echo "Cleaning out to just sources"
echo "Deleting compiled things..."
rm -r docs/
echo "Deleting emcc..."
rm -rf emsdk/
rm -rf ~/.emscripten*
echo "Deleting wabt..."
rm -rf wabt/
}
build() {
echo Copying non-compiled resources to docs/
mkdir -p docs
cp src/* docs/
# but not you, lib.js. You're just to get Emscripten not to warn.
rm docs/lib.js
# and not the C++ sources, since they're just compiled into the .wasm file
rm docs/*.[ch]pp
# Install EMSDK if necessary
emcc --version >/dev/null 2>&1 || install_emcc
echo Compiling src/*.cpp to docs/git-gud.wasm
emcc src/*.cpp -O3 -o docs/git-gud.js -std=c++11 -s DISABLE_EXCEPTION_CATCHING=0 -s WASM=1 --js-library src/lib.js --pre-js src/lib-pre.js >/dev/null
# Install WABT if necessary
wasm2wat --help >/dev/null 2>&1 || install_wabt
echo Generating WASM text representation
wasm2wat docs/git-gud.wasm >docs/git-gud.wat
echo "Compilation done!"
}
if [ -z "$1" ]; then
echo "Normal rebuild"
build
elif [ "$1" = "reset" ]; then
echo "Resetting to just sources without rebuild"
clean
echo "Reset complete. Rebuild with $0"
elif [ "$1" = "full" ]; then
echo "Resetting to just sources and rebuilding"
clean
build
fi