Allow building the wasm libs with native emscripten instead of docker
And build them on the mac CI as well as the linux CI
This commit is contained in:
parent
a1ed12f4f4
commit
ad43b211f4
7 changed files with 200 additions and 83 deletions
|
|
@ -1,12 +1,10 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
set -e
|
||||
|
||||
if [[ "$1" == "--help" || "$1" == "-h" ]]; then
|
||||
usage() {
|
||||
cat <<EOF
|
||||
USAGE
|
||||
|
||||
$0 [--debug]
|
||||
$0 [--help] [--debug] [--docker]
|
||||
|
||||
SUMMARY
|
||||
|
||||
|
|
@ -15,57 +13,97 @@ SUMMARY
|
|||
|
||||
REQUIREMENTS
|
||||
|
||||
You must have the \`docker\` command on your PATH for this to work.
|
||||
You must have either the \`emcc\` command or the \`docker\` command
|
||||
on your PATH for this to work.
|
||||
|
||||
OPTIONS
|
||||
|
||||
--debug: Compile the library more quickly, with fewer optimizations and more runtime assertions.
|
||||
--help: Display this message.
|
||||
--debug: Compile the library more quickly, with fewer optimizations
|
||||
and more runtime assertions.
|
||||
--docker: Run emscripten using docker, even if \`emcc\` is installed.
|
||||
By default, \`emcc\` will be run directly when available.
|
||||
|
||||
EOF
|
||||
exit 0
|
||||
fi
|
||||
}
|
||||
|
||||
set -e
|
||||
|
||||
web_dir=lib/binding_web
|
||||
exports=$(cat ${web_dir}/exports.json)
|
||||
args="-Os"
|
||||
minify=1
|
||||
emscripten_flags="-Os"
|
||||
minify_js=1
|
||||
force_docker=0
|
||||
|
||||
if [[ "$1" == "--debug" ]]; then
|
||||
minify=0
|
||||
args="-s ASSERTIONS=1 -s SAFE_HEAP=1 -Os"
|
||||
while [[ $# > 0 ]]; do
|
||||
case "$1" in
|
||||
--debug)
|
||||
minify_js=0
|
||||
emscripten_flags="-s ASSERTIONS=1 -s SAFE_HEAP=1 -Os"
|
||||
;;
|
||||
|
||||
--help)
|
||||
usage
|
||||
exit 0
|
||||
;;
|
||||
|
||||
--docker)
|
||||
force_docker=1
|
||||
;;
|
||||
|
||||
*)
|
||||
usage
|
||||
echo "Unrecognized argument '$1'"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
shift
|
||||
done
|
||||
|
||||
emcc=
|
||||
if which emcc > /dev/null && [[ "$force_docker" == "0" ]]; then
|
||||
export EMCC_FORCE_STDLIBS=libc++
|
||||
emcc=emcc
|
||||
elif which docker > /dev/null; then
|
||||
emcc="docker run \
|
||||
--rm \
|
||||
-v $(pwd):/src \
|
||||
-u $(id -u) \
|
||||
-e EMCC_FORCE_STDLIBS=libc++ \
|
||||
trzeci/emscripten-slim \
|
||||
emcc"
|
||||
else
|
||||
echo 'You must have either `docker` or `emcc` on your PATH to run this script'
|
||||
exit 1
|
||||
fi
|
||||
|
||||
mkdir -p target/scratch
|
||||
|
||||
docker run \
|
||||
--rm \
|
||||
-v $(pwd):/src \
|
||||
-u $(id -u) \
|
||||
-e EMCC_FORCE_STDLIBS=libc++ \
|
||||
trzeci/emscripten-slim \
|
||||
\
|
||||
emcc \
|
||||
-s WASM=1 \
|
||||
-s TOTAL_MEMORY=33554432 \
|
||||
-s ALLOW_MEMORY_GROWTH \
|
||||
-s MAIN_MODULE=2 \
|
||||
-s NO_FILESYSTEM=1 \
|
||||
# Use emscripten to generate `tree-sitter.js` and `tree-sitter.wasm`
|
||||
# in the `target/scratch` directory
|
||||
$emcc \
|
||||
-s WASM=1 \
|
||||
-s TOTAL_MEMORY=33554432 \
|
||||
-s ALLOW_MEMORY_GROWTH \
|
||||
-s MAIN_MODULE=2 \
|
||||
-s NO_FILESYSTEM=1 \
|
||||
-s "EXPORTED_FUNCTIONS=${exports}" \
|
||||
$args \
|
||||
-std=c99 \
|
||||
-D 'fprintf(...)=' \
|
||||
-I lib/src \
|
||||
-I lib/include \
|
||||
-I lib/utf8proc \
|
||||
--js-library ${web_dir}/imports.js \
|
||||
--pre-js ${web_dir}/prefix.js \
|
||||
--post-js ${web_dir}/binding.js \
|
||||
lib/src/lib.c \
|
||||
${web_dir}/binding.c \
|
||||
$emscripten_flags \
|
||||
-std=c99 \
|
||||
-D 'fprintf(...)=' \
|
||||
-I lib/src \
|
||||
-I lib/include \
|
||||
-I lib/utf8proc \
|
||||
--js-library ${web_dir}/imports.js \
|
||||
--pre-js ${web_dir}/prefix.js \
|
||||
--post-js ${web_dir}/binding.js \
|
||||
lib/src/lib.c \
|
||||
${web_dir}/binding.c \
|
||||
-o target/scratch/tree-sitter.js
|
||||
|
||||
|
||||
if [[ "$minify" == "1" ]]; then
|
||||
# Use terser to write a minified version of `tree-sitter.js` into
|
||||
# the `lib/binding_web` directory.
|
||||
if [[ "$minify_js" == "1" ]]; then
|
||||
if [ ! -d ${web_dir}/node_modules/terser ]; then
|
||||
(
|
||||
cd ${web_dir}
|
||||
|
|
|
|||
30
script/fetch-emscripten
Executable file
30
script/fetch-emscripten
Executable file
|
|
@ -0,0 +1,30 @@
|
|||
#!/bin/bash
|
||||
|
||||
set -e
|
||||
|
||||
mkdir -p target
|
||||
EMSDK_DIR="./target/emsdk"
|
||||
|
||||
(
|
||||
if [ ! -f "$EMSDK_DIR/emsdk" ]; then
|
||||
echo 'Downloading emscripten SDK...'
|
||||
git clone https://github.com/emscripten-core/emsdk.git $EMSDK_DIR
|
||||
fi
|
||||
|
||||
cd $EMSDK_DIR
|
||||
|
||||
echo 'Updating emscripten SDK...'
|
||||
git pull
|
||||
./emsdk list
|
||||
|
||||
echo 'Installing latest emscripten...'
|
||||
./emsdk install latest
|
||||
|
||||
echo 'Activating latest emscripten...'
|
||||
./emsdk activate latest
|
||||
) >&2
|
||||
|
||||
(
|
||||
source "$EMSDK_DIR/emsdk_env.sh" > /dev/null
|
||||
declare -px
|
||||
)
|
||||
Loading…
Add table
Add a link
Reference in a new issue