build_wasm.sh (1846B)
1 #!/usr/bin/env bash 2 3 set -e # fail if any command has a non-zero exit status 4 set -u # fail if any undefined variable is referenced 5 set -o pipefail # propagate failure exit status through a pipeline 6 shopt -s globstar nullglob # enable recursive and null globbing 7 8 out_dir="./out" 9 wasm_dir="${out_dir}/wasm" 10 11 mkdir -p $wasm_dir 12 cp src/platform_wasm_loader.js $wasm_dir/script.js 13 cp src/platform_wasm_index.html $wasm_dir/index.html 14 cp -r shader/ $wasm_dir 15 cp -r assets/ $wasm_dir 16 17 clang_version=$(clang -v 2>&1 | head -1 | cut -d " " -f 3) 18 clang \ 19 --no-standard-libraries \ 20 --target=wasm32 \ 21 -DPLATFORM_WASM \ 22 -O3 \ 23 -ffreestanding \ 24 -std=c11 \ 25 -Wl,--allow-undefined-file=src/platform_wasm_js_symbols.txt \ 26 -Wl,--export=init \ 27 -Wl,--export=key_callback \ 28 -Wl,--export=render \ 29 -Wl,--export=window_resize \ 30 -Wl,--import-memory \ 31 -Wl,--no-entry \ 32 -o $wasm_dir/binary.wasm \ 33 src/platform_wasm.c 34 35 # TODO: embed the fossil/git commit like we used to back when this was hosted 36 # in git. 37 #current_commit=$(git rev-parse HEAD) 38 #echo "<!-- Source Code: https://git.amin.space/a-game/tree/?id=$current_commit -->" \ 39 # >> $wasm_dir/index.html