-
Notifications
You must be signed in to change notification settings - Fork 40
/
build.sh
executable file
·86 lines (73 loc) · 2.33 KB
/
build.sh
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#!/bin/bash
set -e
export OPTIMIZE="-Os"
export LDFLAGS=${OPTIMIZE}
export CFLAGS=${OPTIMIZE}
export CXXFLAGS=${OPTIMIZE}
ENTRY_POINT="rnnoise.js"
ENTRY_POINT_SYNC="rnnoise-sync.js"
MODULE_CREATE_NAME="createRNNWasmModule"
MODULE_CREATE_NAME_SYNC="createRNNWasmModuleSync"
RNN_EXPORTED_FUNCTIONS="['_rnnoise_process_frame', '_rnnoise_init', '_rnnoise_destroy', '_rnnoise_create', '_malloc', '_free']"
if [[ `uname` == "Darwin" ]]; then
SO_SUFFIX="dylib"
else
SO_SUFFIX="so"
fi
echo "============================================="
echo "Compiling wasm bindings"
echo "============================================="
(
cd rnnoise
# Clean possible autotools clutter that might affect the configurations step
git clean -f -d
./autogen.sh
# For some reason setting the CFLAGS export doesn't apply optimization to all compilation steps
# so we need to explicitly pass it to configure.
emconfigure ./configure CFLAGS=${OPTIMIZE} --enable-static=no --disable-examples --disable-doc
emmake make clean
emmake make V=1
# Compile librnnoise generated LLVM bytecode to wasm with an async loading module.
emcc \
${OPTIMIZE} \
-g2 \
-s STRICT=1 \
-s ALLOW_MEMORY_GROWTH=1 \
-s MALLOC=emmalloc \
-s MODULARIZE=1 \
-s ENVIRONMENT="web,worker" \
-s EXPORT_ES6=1 \
-s USE_ES6_IMPORT_META=0 \
-s EXPORT_NAME=${MODULE_CREATE_NAME} \
-s EXPORTED_FUNCTIONS="${RNN_EXPORTED_FUNCTIONS}" \
.libs/librnnoise.${SO_SUFFIX} \
-o ./$ENTRY_POINT
# Compile librnnoise generated LLVM bytecode to wasm with a sync loading module and inline wasm bytecode.
emcc \
${OPTIMIZE} \
-g2 \
-s ALLOW_MEMORY_GROWTH=1 \
-s MALLOC=emmalloc \
-s MODULARIZE=1 \
-s ENVIRONMENT="web,worker" \
-s EXPORT_ES6=1 \
-s USE_ES6_IMPORT_META=1 \
-s WASM_ASYNC_COMPILATION=0 \
-s SINGLE_FILE=1 \
-s EXPORT_NAME=${MODULE_CREATE_NAME_SYNC} \
-s EXPORTED_FUNCTIONS="${RNN_EXPORTED_FUNCTIONS}" \
.libs/librnnoise.${SO_SUFFIX} \
-o ./$ENTRY_POINT_SYNC
# Create output folder
rm -rf ../dist
mkdir -p ../dist
# Move artifacts
mv $ENTRY_POINT ../dist/
mv $ENTRY_POINT_SYNC ../dist/
mv rnnoise.wasm ../dist/
# Clean cluttter
git clean -f -d
)
echo "============================================="
echo "Compiling wasm bindings done"
echo "============================================="