tree-sitter/script/build-wasm

60 lines
1.6 KiB
Text
Raw Normal View History

2019-04-23 14:29:46 -07:00
#!/usr/bin/env bash
2019-04-26 19:13:32 -07:00
set -e
2019-04-23 14:29:46 -07:00
args="-Os"
2019-04-23 14:46:46 -07:00
minify=1
2019-04-23 14:29:46 -07:00
if [[ "$1" == "--debug" ]]; then
2019-04-23 14:46:46 -07:00
minify=0
args="-s ASSERTIONS=1 -s SAFE_HEAP=1 -O0"
2019-04-23 14:29:46 -07:00
fi
2019-04-26 19:13:32 -07:00
mkdir -p target/scratch target/release
2019-04-23 14:29:46 -07:00
2019-04-25 17:27:24 -07:00
docker run \
--rm \
-v $(pwd):/src \
-u $(id -u) \
2019-04-27 18:06:34 -07:00
-e EMCC_FORCE_STDLIBS=libc++ \
2019-04-25 17:27:24 -07:00
trzeci/emscripten-slim \
\
emcc \
2019-04-23 14:29:46 -07:00
-s WASM=1 \
-s TOTAL_MEMORY=33554432 \
2019-04-23 14:29:46 -07:00
-s ALLOW_MEMORY_GROWTH \
-s MAIN_MODULE=1 \
-s EXPORT_ALL=1 \
$args \
-std=c99 \
-D 'fprintf(...)=' \
-I lib/src \
-I lib/include \
-I lib/utf8proc \
--js-library lib/web/imports.js \
--pre-js lib/web/prefix.js \
--post-js lib/web/binding.js \
lib/src/lib.c \
lib/web/binding.c \
2019-04-26 19:13:32 -07:00
-o target/scratch/tree-sitter.js
2019-04-23 14:46:46 -07:00
if [[ "$minify" == "1" ]]; then
if [ ! -d lib/web/node_modules/terser ]; then
(
cd lib/web
npm install
)
fi
lib/web/node_modules/.bin/terser \
--compress \
--mangle \
--keep-fnames \
--keep-classnames \
-- target/scratch/tree-sitter.js \
> target/release/tree-sitter.js
else
cp target/scratch/tree-sitter.js target/release/tree-sitter.js
fi
2019-04-26 19:13:32 -07:00
mv target/scratch/tree-sitter.wasm target/release/tree-sitter.wasm