-
Notifications
You must be signed in to change notification settings - Fork 1
/
test
executable file
·57 lines (53 loc) · 2.88 KB
/
test
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/bin/bash
INITIAL_MEMORY=${INITIAL_MEMORY:-315mb}
MAX_THREADS=${MAX_THREADS:-1}
EMSDK=${EMSDK:-emsdk}
JOBS=${JOBS:-$(nproc)}
if [ "$EMSDK" != emsdk ] && [ ! -d "$EMSDK" ]; then
echo "Invalid emsdk path"
exit 1
fi
if [ "$MAX_THREADS" -lt 1 ]; then
echo "MAX_THREADS must be greater than or equal to 1"
exit 1
fi
if [ "$JOBS" -lt 1 ]; then
echo "JOBS must be greater than or equal to 1"
exit 1
fi
if ! [[ $INITIAL_MEMORY =~ ^[0-9]+([kmgt]b)?$ ]]; then
echo "INITIAL_MEMORY valid suffixes are kb, mb, gb, tb, none (bytes)"
exit 1
fi
if [ "$EMSDK" = emsdk ] && [ ! -d "$EMSDK" ]; then
echo "Installing emsdk + Emscripten..."
git clone --depth=1 https://github.com/emscripten-core/emsdk.git ../emsdk &&
cd ../emsdk &&
./emsdk install 3.1.69 &&
./emsdk activate 3.1.69
fi
. $(realpath "$EMSDK")/emsdk_env.sh &&
export PATH=:$PATH:$(realpath "$EMSDK")/upstream/bin
KALDI=$(realpath kaldi)
VOSK=$(realpath vosk)
OPENFST=$(realpath openfst)
OPENBLAS=$(realpath openblas)
SRC=$(realpath src)
cd "$SRC" &&
files="Util.o CommonModel.o Recognizer.o Bindings.o"
sharedFlags="-Wall -Wextra -Wpedantic -fno-rtti -msimd128 -matomics -mbulk-memory -mreference-types -mnontrapping-fptoint -mextended-const -msign-ext -mmutable-globals -sSTRICT -sWASM_WORKERS=2"
sharedCXXFlags="-std=c++23 -I$VOSK/src -I. -DEMSCRIPTEN_HAS_UNBOUND_TYPE_NAMES=0 -DMAX_WORKERS=$MAX_THREADS"
sharedLDFlags="-sWASMFS -sWASM_BIGINT -sMODULARIZE -sWASM_EXNREF -sTEXTDECODER=2 -sEVAL_CTORS=2 -sINITIAL_MEMORY=$INITIAL_MEMORY -sALLOW_MEMORY_GROWTH -sPOLYFILL=0 -sEXIT_RUNTIME=0 -sINVOKE_RUN=0 -sSUPPORT_LONGJMP=0 -sINCOMING_MODULE_JS_API=wasmMemory,instantiateWasm,wasm -sEXPORT_NAME=loadVosklet -sMALLOC=emmalloc -sENVIRONMENT=web,worker -L$KALDI/src -l:online2/kaldi-online2.a -l:decoder/kaldi-decoder.a -l:ivector/kaldi-ivector.a -l:gmm/kaldi-gmm.a -l:tree/kaldi-tree.a -l:feat/kaldi-feat.a -l:cudamatrix/kaldi-cudamatrix.a -l:lat/kaldi-lat.a -l:lm/kaldi-lm.a -l:rnnlm/kaldi-rnnlm.a -l:hmm/kaldi-hmm.a -l:nnet3/kaldi-nnet3.a -l:transform/kaldi-transform.a -l:matrix/kaldi-matrix.a -l:fstext/kaldi-fstext.a -l:util/kaldi-util.a -l:base/kaldi-base.a -L$OPENFST/lib -l:libfst.a -l:libfstngram.a -L$OPENBLAS -l:lib/libopenblas.a -L$VOSK/src -l:vosk.a -lembind --no-entry --pre-js ../Examples/Wrapper.js -o ../test.js"
MODE=1 && # 0: Debug, 1: Optimized release
echo "Mode = $MODE" &&
if [ "$MODE" = 0 ]; then
# shellcheck disable=SC2086
em++ ${files//.o/.cc} $sharedFlags $sharedCXXFlags -O0 -c &&
em++ $files $sharedFlags $sharedLDFlags -O0 -g3 -sASSERTIONS=2 -sRUNTIME_DEBUG -sALLOW_UNIMPLEMENTED_SYSCALLS -sSTACK_OVERFLOW_CHECK=2 -sCHECK_NULL_WRITES
elif [ "$MODE" = 1 ]; then
# shellcheck disable=SC2086
em++ ${files//.o/.cc} $sharedFlags $sharedCXXFlags -O3 -fno-exceptions -flto -c &&
em++ $files $sharedFlags $sharedLDFlags -O3 -flto --closure 1&&
tr -d '\n' < ../test.js | tr -s ' ' > /tmp/hehe && mv /tmp/hehe ../test.js
fi
rm -f $files