2021-03-10 20:30:39 +03:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
set -e
|
|
|
|
set -x
|
|
|
|
|
2021-08-31 16:45:14 +03:00
|
|
|
# Usage
|
|
|
|
Usage="Build translator to wasm (with/without wormhole).
|
|
|
|
|
|
|
|
Usage: $(basename "$0") [WORMHOLE]
|
|
|
|
|
|
|
|
where:
|
|
|
|
WORMHOLE An optional string argument
|
|
|
|
- when specified on command line, builds wasm artifacts with wormhole
|
|
|
|
- when not specified (the default behaviour), builds wasm artifacts without wormhole."
|
|
|
|
|
|
|
|
if [ "$#" -gt 1 ]; then
|
|
|
|
echo "Illegal number of parameters passed"
|
|
|
|
echo "$Usage"
|
|
|
|
exit
|
|
|
|
fi
|
|
|
|
|
|
|
|
WORMHOLE=false
|
|
|
|
|
|
|
|
if [ "$#" -eq 1 ]; then
|
|
|
|
if [ "$1" = "WORMHOLE" ]; then
|
|
|
|
WORMHOLE=true
|
|
|
|
else
|
|
|
|
echo "Illegal parameter passed"
|
|
|
|
echo "$Usage"
|
|
|
|
exit
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2021-03-10 20:30:39 +03:00
|
|
|
# Run script from the context of the script-containing directory
|
|
|
|
cd "$(dirname $0)"
|
|
|
|
|
2021-06-08 16:36:22 +03:00
|
|
|
# Prerequisite: Download and Install Emscripten using following instructions (unless the EMSDK env var is already set)
|
2021-03-10 20:30:39 +03:00
|
|
|
if [ "$EMSDK" == "" ]; then
|
|
|
|
EMSDK_UPDATE_REQUIRED=0
|
|
|
|
if [ ! -d "emsdk" ]; then
|
|
|
|
git clone https://github.com/emscripten-core/emsdk.git
|
|
|
|
EMSDK_UPDATE_REQUIRED=1
|
|
|
|
else
|
|
|
|
cd emsdk
|
|
|
|
git fetch
|
|
|
|
# Only pull if necessary
|
|
|
|
if [ $(git rev-parse HEAD) != $(git rev-parse @{u}) ]; then
|
|
|
|
git pull --ff-only
|
|
|
|
EMSDK_UPDATE_REQUIRED=1
|
|
|
|
fi
|
|
|
|
cd -
|
|
|
|
fi
|
|
|
|
if [ "$EMSDK_UPDATE_REQUIRED" == "1" ]; then
|
|
|
|
cd emsdk
|
2021-05-20 08:59:30 +03:00
|
|
|
./emsdk install 2.0.9
|
|
|
|
./emsdk activate 2.0.9
|
2021-03-10 20:30:39 +03:00
|
|
|
cd -
|
|
|
|
fi
|
|
|
|
source ./emsdk/emsdk_env.sh
|
|
|
|
fi
|
|
|
|
|
2021-06-08 16:36:22 +03:00
|
|
|
# Compile
|
2021-08-31 16:45:14 +03:00
|
|
|
# 1. Create a folder where you want to build all the artifacts and compile
|
|
|
|
BUILD_DIRECTORY="build-wasm"
|
|
|
|
if [ ! -d ${BUILD_DIRECTORY} ]; then
|
|
|
|
mkdir ${BUILD_DIRECTORY}
|
|
|
|
fi
|
|
|
|
cd ${BUILD_DIRECTORY}
|
|
|
|
|
|
|
|
if [ "$WORMHOLE" = true ]; then
|
|
|
|
emcmake cmake -DCOMPILE_WASM=on ../
|
|
|
|
else
|
|
|
|
emcmake cmake -DCOMPILE_WASM=on -DWORMHOLE=off ../
|
2021-03-10 20:30:39 +03:00
|
|
|
fi
|
2021-06-08 16:36:22 +03:00
|
|
|
emmake make -j2
|
2021-03-10 20:30:39 +03:00
|
|
|
|
2021-06-08 16:36:22 +03:00
|
|
|
# 2. Enable SIMD Wormhole via Wasm instantiation API in generated artifacts
|
2021-08-31 16:45:14 +03:00
|
|
|
if [ "$WORMHOLE" = true ]; then
|
|
|
|
bash ../wasm/patch-artifacts-enable-wormhole.sh
|
|
|
|
fi
|
2021-03-10 20:30:39 +03:00
|
|
|
|
2021-08-31 16:45:14 +03:00
|
|
|
# The artifacts (.js and .wasm files) will be available in the build directory
|
2021-03-10 20:30:39 +03:00
|
|
|
exit 0
|