-
Notifications
You must be signed in to change notification settings - Fork 0
/
build_wasm.sh
executable file
·42 lines (35 loc) · 1.18 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
#!/usr/bin/env bash
set -e # fail if any command has a non-zero exit status
set -u # fail if any undefined variable is referenced
set -o pipefail # propagate failure exit status through a pipeline
shopt -s globstar nullglob # enable recursive and null globbing
out_dir="./out"
wasm_dir="${out_dir}/wasm"
mkdir -p $wasm_dir
cp src/platform_wasm_loader.js $wasm_dir/script.js
cp src/platform_wasm_index.html $wasm_dir/index.html
cp -r shader/ $wasm_dir
clang \
-cc1 \
-Ofast \
-emit-llvm-bc \
-triple=wasm32-unknown-unknown-unknown-wasm \
-ffreestanding \
-fno-builtin \
-std=c11 \
-DGAME_WEBGL \
-o $wasm_dir/wasm.bc \
src/platform_wasm.c
llvm-link -o $wasm_dir/wasm.bc $wasm_dir/wasm.bc
opt -O3 -disable-simplify-libcalls $wasm_dir/wasm.bc -o $wasm_dir/wasm.bc
llc -O3 -disable-simplify-libcalls -filetype=obj $wasm_dir/wasm.bc -o $wasm_dir/wasm.o
wasm-ld \
--no-entry $wasm_dir/wasm.o \
-o $wasm_dir/binary.wasm \
-allow-undefined-file src/platform_wasm_js_symbols.txt \
--export=init \
--export=render \
--export=window_resize \
--import-memory
rm $wasm_dir/*.o
rm $wasm_dir/*.bc