build-wasm-simd-for-nodejs.sh 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. #!/usr/bin/env bash
  2. # Copyright (c) 2024 Xiaomi Corporation
  3. #
  4. # This script is to build sherpa-ncnn for WebAssembly (NodeJS)
  5. #
  6. # See also
  7. # https://github.com/Tencent/ncnn/wiki/how-to-build#build-for-webassembly
  8. #
  9. # Please refer to
  10. # https://k2-fsa.github.io/sherpa/ncnn/wasm/index.html
  11. # for more details.
  12. set -ex
  13. if [ x"$EMSCRIPTEN" == x"" ]; then
  14. if ! command -v emcc &> /dev/null; then
  15. echo "Please install emscripten first"
  16. echo ""
  17. echo "You can use the following commands to install it:"
  18. echo ""
  19. echo "git clone https://github.com/emscripten-core/emsdk.git"
  20. echo "cd emsdk"
  21. echo "git pull"
  22. echo "./emsdk install latest"
  23. echo "./emsdk activate latest"
  24. echo "source ./emsdk_env.sh"
  25. exit 1
  26. else
  27. EMSCRIPTEN=$(dirname $(realpath $(which emcc)))
  28. fi
  29. fi
  30. export EMSCRIPTEN=$EMSCRIPTEN
  31. echo "EMSCRIPTEN: $EMSCRIPTEN"
  32. if [ ! -f $EMSCRIPTEN/cmake/Modules/Platform/Emscripten.cmake ]; then
  33. echo "Cannot find $EMSCRIPTEN/cmake/Modules/Platform/Emscripten.cmake"
  34. echo "Please make sure you have installed emsdk correctly"
  35. exit 1
  36. fi
  37. mkdir -p build-wasm-simd-for-nodejs
  38. pushd build-wasm-simd-for-nodejs
  39. export SHERPA_NCNN_IS_USING_BUILD_WASM_SH=ON
  40. cmake \
  41. -DCMAKE_INSTALL_PREFIX=./install \
  42. -DCMAKE_BUILD_TYPE=Release \
  43. -DCMAKE_TOOLCHAIN_FILE=$EMSCRIPTEN/cmake/Modules/Platform/Emscripten.cmake \
  44. -DNCNN_THREADS=OFF \
  45. -DNCNN_OPENMP=OFF \
  46. -DNCNN_SIMPLEOMP=OFF \
  47. -DNCNN_RUNTIME_CPU=OFF \
  48. -DNCNN_SSE2=ON \
  49. -DNCNN_AVX2=OFF \
  50. -DNCNN_AVX=OFF \
  51. -DNCNN_BUILD_TOOLS=OFF \
  52. -DNCNN_BUILD_EXAMPLES=OFF \
  53. -DNCNN_BUILD_BENCHMARK=OFF \
  54. \
  55. -DSHERPA_NCNN_ENABLE_WASM=ON \
  56. -DSHERPA_NCNN_ENABLE_WASM_FOR_NODEJS=ON \
  57. -DBUILD_SHARED_LIBS=OFF \
  58. -DSHERPA_NCNN_ENABLE_PYTHON=OFF \
  59. -DSHERPA_NCNN_ENABLE_PORTAUDIO=OFF \
  60. -DSHERPA_NCNN_ENABLE_JNI=OFF \
  61. -DSHERPA_NCNN_ENABLE_BINARY=OFF \
  62. -DSHERPA_NCNN_ENABLE_TEST=OFF \
  63. -DSHERPA_NCNN_ENABLE_C_API=ON \
  64. -DSHERPA_NCNN_ENABLE_GENERATE_INT8_SCALE_TABLE=OFF \
  65. -DSHERPA_NCNN_ENABLE_FFMPEG_EXAMPLES=OFF \
  66. ..
  67. make -j2
  68. make install
  69. ls -lh install/bin/wasm