-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild-wasm.sh
executable file
·85 lines (60 loc) · 4.21 KB
/
build-wasm.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
#!/bin/bash
echo "Building csound-extended for WebAssembly..."
export EMSCRIPTEN_ALLOW_NEWER_PYTHON=1
source ~/emsdk/emsdk_env.sh
echo "OSTYPE: $OSTYPE."
echo "EMSCRIPTEN_ROOT: $EMSCRIPTEN_ROOT."
echo "Python version (must be 3 or higher):"
python3 --version
if [[ "$OSTYPE" == "linux"* ]]; then
echo "Building on Linux..."
export EIGEN_INCLUDE_ROOT="/usr/include/eigen3"
export BOOST_ROOT="/usr/include/boost"
export BOOST_INCLUDE_ROOT="/usr/include/boost"
elif [[ "$OSTYPE" == "darwin"* ]]; then
echo "Building on macOS..."
export EIGEN_INCLUDE_ROOT="/opt/homebrew/opt/eigen/include/eigen3"
export BOOST_ROOT="/opt/homebrew/opt/boost"
export BOOST_INCLUDE_ROOT="/opt/homebrew/opt/boost/include"
else
echo "Unsupported platform!"
exit
fi
bash update-dependency-submodules.sh
# Total memory for a WebAssembly module must be a multiple of 64 KB so...
# 1024 * 64 = 65536 is 64 KB
# 65536 * 1024 * 4 is 268435456
CXX_FLAGS="-v -std=c++17 -O2 -Wno-implicit-int-float-conversion -DINIT_STATIC_MODULES=1 -g "
export CXX_FLAGS
# Most emcc flags should be the same for both the 'compile' and the 'compile and link' passes.
EMCC_FLAGS='-s ENVIRONMENT="web,webview,worker,node,shell" -s WASMFS -s ERROR_ON_UNDEFINED_SYMBOLS=0 -s ALLOW_MEMORY_GROWTH=1 -s ASSERTIONS=1 -s DEMANGLE_SUPPORT=1 -s FORCE_FILESYSTEM=1 -s INITIAL_MEMORY=268435456 -s LINKABLE=1 -s NO_EXIT_RUNTIME=0 -s SAFE_HEAP=0 -s WASM=1 -g '
export EMCC_FLAGS
rm -rf build-wasm
mkdir -p build-wasm
cp -f dependencies/csound-ac/CsoundAC/version.h dependencies/csound/include/version.h
cd build-wasm
rm -f CMakeCache.txt
# Haven't figured out how to get this work yet, may never.
# echo "Packaging resources..."
#
# cp -r ../csound-assets/ .
# python $EMSCRIPTEN_ROOT/tools/file_packager.py csound_assets.data --preload csound-assets --js-output=csound_assets.js
echo "Configuring to build static libraries..."
emcmake cmake -G "Unix Makefiles" -DBUILD_STATIC_LIBRARY=1 -DUSE_COMPILER_OPTIMIZATIONS=0 -DBIG_ENDIAN=0 -DISBIGENDIAN=0 -DIS_BIG_ENDIAN=0 -DEIGEN_ROOT="/opt/homebrew/opt/eigen" -DBOOST_ROOT="${BOOST_ROOT}" -DCSOUND_INCLUDE_DIR="../dependencies/csound" -DSNDFILE_H_PATH="../deps/include" -DSNDFILE_LIBRARY="../deps/lib/libsndfile.a" -Wno-dev -S .. -B .
echo "Building Csound library..."
emmake make csound-static -j6 VERBOSE=1
## cmake --build csound-static -j6 VERBOSE=1
echo "Building CsoundAC static library..."
emmake make csoundac-static -j6 VERBOSE=1
## cmake --build csoundac-static -j6 VERBOSE=1
echo "Compiling csound_embind..."
em++ ${CXX_FLAGS} ${EMCC_FLAGS} -iquote ../src -I../dependencies -I../dependencies/csound/include -I../dependencies/csound/H -I../dependencies/csound/interfaces -I../deps/libsndfile-1.0.25/src -Iinclude -I${EIGEN_INCLUDE_ROOT} -c ../src/csound_embind.cpp --bind
echo "Compiling CsoundAudioProcessor..."
em++ ${CXX_FLAGS} -O1 ${EMCC_FLAGS} --bind -s EXPORTED_RUNTIME_METHODS='["ccall", "cwrap", "FS"]' -s RESERVED_FUNCTION_POINTERS=2 -s SINGLE_FILE=1 -s WASM_ASYNC_COMPILATION=0 -s EXTRA_EXPORTED_RUNTIME_METHODS=FS --source-map-base . --pre-js ../src/CsoundAudioProcessor_prejs.js --post-js ../src/CsoundAudioProcessor_postjs.js csound_embind.o dependencies/csound/libcsound.a ../deps/lib/libsndfile.a ../deps/lib/libogg.a ../deps/lib/libvorbis.a ../deps/lib/libvorbisenc.a ../deps/lib/libvorbisfile.a ../deps/lib/libFLAC.a -o CsoundAudioProcessor.js
echo "Compiling CsoundAC..."
em++ ${CXX_FLAGS} ${EMCC_FLAGS} -I../dependencies -I../dependencies/csound-extended --bind -s EXPORT_ES6=0 -s EXPORT_NAME="createCsoundAC" -s EXPORTED_RUNTIME_METHODS='["ccall", "cwrap", "FS"]' -s MODULARIZE=1 -s RESERVED_FUNCTION_POINTERS=1 -s SINGLE_FILE=1 -s WASM_ASYNC_COMPILATION=1 --source-map-base . ../CsoundAC/csoundac_embind.cpp -I../dependencies/csound-ac -I${EIGEN_INCLUDE_ROOT} -I${BOOST_INCLUDE_ROOT} -I../deps/libsndfile-1.0.25/src -I.. CsoundAC/libcsoundac-static.a dependencies/csound/libcsound.a ../deps/lib/libsndfile.a ../deps/lib/libogg.a ../deps/lib/libvorbis.a ../deps/lib/libvorbisenc.a ../deps/lib/libvorbisfile.a ../deps/lib/libFLAC.a -o CsoundAC.js
cd ..
find deps -name "*.a" -ls
find build-wasm -name "*.a" -ls
bash release-wasm.sh
echo "Finished building csound-extended for WebAssembly."