| 1 |
#!/bin/bash |
| 2 |
# Copyright 2021 Google LLC |
| 3 |
# |
| 4 |
# Use of this source code is governed by a BSD-style license that can be |
| 5 |
# found in the LICENSE file. |
| 6 |
|
| 7 |
set -ex |
| 8 |
|
| 9 |
BASE_DIR=`cd $(dirname ${BASH_SOURCE[0]}) && pwd` |
| 10 |
# This expects the environment variable EMSDK to be set |
| 11 |
if [[ ! -d $EMSDK ]]; then |
| 12 |
cat >&2 << "EOF" |
| 13 |
Be sure to set the EMSDK environment variable to the location of Emscripten SDK: |
| 14 |
|
| 15 |
https://emscripten.org/docs/getting_started/downloads.html |
| 16 |
EOF |
| 17 |
exit 1 |
| 18 |
fi |
| 19 |
|
| 20 |
# Navigate to SKIA_HOME from where this file is located. |
| 21 |
pushd $BASE_DIR/../.. |
| 22 |
|
| 23 |
if [[ $@ == *debug* ]]; then |
| 24 |
echo "Building a Debug build" |
| 25 |
DEBUG=true |
| 26 |
EXTRA_CFLAGS="\"-DSK_DEBUG\", \"-DGPU_TEST_UTILS\", " |
| 27 |
RELEASE_CONF="-O1 --js-opts 0 -s DEMANGLE_SUPPORT=1 -frtti -s ASSERTIONS=1 -s GL_ASSERTIONS=1 -g \ |
| 28 |
-DSK_DEBUG" |
| 29 |
BUILD_DIR=${BUILD_DIR:="out/tskit_debug"} |
| 30 |
else |
| 31 |
echo "Building a release build" |
| 32 |
DEBUG=false |
| 33 |
BUILD_DIR=${BUILD_DIR:="out/tskit"} |
| 34 |
RELEASE_CONF="-O3 --closure 1 -DSK_RELEASE" |
| 35 |
EXTRA_CFLAGS="\"-DSK_RELEASE\", \"-DGPU_TEST_UTILS\", " |
| 36 |
fi |
| 37 |
|
| 38 |
EXTENSION_OPT="--pre-js $BASE_DIR/build/extension.js \ |
| 39 |
$BASE_DIR/bindings/extension.cpp |
| 40 |
" |
| 41 |
if [[ $@ = *no_ext* ]] ; then |
| 42 |
echo "disabling extension" |
| 43 |
EXTENSION_OPT="" |
| 44 |
fi |
| 45 |
|
| 46 |
mkdir -p $BUILD_DIR |
| 47 |
# sometimes the .a files keep old symbols around - cleaning them out makes sure |
| 48 |
# we get a fresh build. |
| 49 |
rm -f $BUILD_DIR/*.a |
| 50 |
|
| 51 |
source $EMSDK/emsdk_env.sh |
| 52 |
EMCC=`which emcc` |
| 53 |
EMCXX=`which em++` |
| 54 |
EMAR=`which emar` |
| 55 |
|
| 56 |
export EMCC_CLOSURE_ARGS="--externs $BASE_DIR/build/externs.js " |
| 57 |
|
| 58 |
EMCC_DEBUG=1 ${EMCXX} \ |
| 59 |
$RELEASE_CONF \ |
| 60 |
-I. \ |
| 61 |
-std=c++20 \ |
| 62 |
--bind \ |
| 63 |
--no-entry \ |
| 64 |
--pre-js $BASE_DIR/build/load.js \ |
| 65 |
--pre-js $BASE_DIR/build/memory.js \ |
| 66 |
--pre-js $BASE_DIR/build/core.js \ |
| 67 |
$BASE_DIR/bindings/core.cpp \ |
| 68 |
$EXTENSION_OPT \ |
| 69 |
-s ALLOW_MEMORY_GROWTH=1 \ |
| 70 |
-s EXPORT_NAME="InitTSKit" \ |
| 71 |
-s EXPORTED_FUNCTIONS=['_malloc','_free'] \ |
| 72 |
-s FORCE_FILESYSTEM=0 \ |
| 73 |
-s FILESYSTEM=0 \ |
| 74 |
-s MODULARIZE=1 \ |
| 75 |
-s NO_EXIT_RUNTIME=1 \ |
| 76 |
-s INITIAL_MEMORY=256MB \ |
| 77 |
-s WASM=1 \ |
| 78 |
-o $BUILD_DIR/tskit.js |