-
Notifications
You must be signed in to change notification settings - Fork 1
/
build-wasm.sh
executable file
·72 lines (57 loc) · 1.55 KB
/
build-wasm.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
#!/usr/bin/env bash
set -euo pipefail
cd "$(dirname "$0")"
source _scripto.sh
OPTIMIZE=
BROWSER=
PYTHON=
JAVASCRIPT=
for arg in "$@"; do
case "$arg" in
--optimize) OPTIMIZE=1 ;;
--all|--browser) BROWSER=1 ;;&
--all|--langs|--python) PYTHON=1 ;;&
--all|--langs|--javascript) JAVASCRIPT=1 ;;&
esac
done
ensure_some_target BROWSER PYTHON JAVASCRIPT
OUTDIR="$PWD"/wasm-dist
mkdir -p "$OUTDIR"
ansi_color JSYELLOWBG 48 2 240 219 79
ansi_color JSGRAY 38 2 50 51 48
ansi_color PYBLUEBG 48 2 48 105 152
ansi_color PYYELLOW 38 2 255 212 59
pids=()
copy_lang() {
fname=$(basename "$1")
if [[ $OPTIMIZE ]]; then
# Do this in order to work around some weird parsing bug in wasm-opt
wasm-dis "$1" -o "$fname.wat"
wasm-opt "$fname.wat" -Os -o "$1"
rm "$fname.wat"
fi
mkdir -p "$OUTDIR/lang-runners"
cp "$1" "$OUTDIR/lang-runners/$fname"
}
if [[ $BROWSER ]]; then
{
wasm-pack build env-runners/browser
cp -rT env-runners/browser/pkg "$OUTDIR/browser-runner"
} 2>&1 | prepend browser-runner: &
pids+=($!)
fi
if [[ $PYTHON ]]; then
{
cargo build -p pyrunner --target wasm32-wasi --release
copy_lang target/wasm32-wasi/release/pyrunner.wasm
} 2>&1 | prepend "$PYBLUEBG$PYYELLOW"pyrunner: &
pids+=($!)
fi
if [[ $JAVASCRIPT ]]; then
{
make -C lang-runners/javascript
copy_lang lang-runners/javascript/jsrunner.wasm
} 2>&1 | prepend "$JSYELLOWBG$JSGRAY"jsrunner: &
pids+=($!)
fi
wait_pids "${pids[@]}"