forked from k2-fsa/sherpa-onnx
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add WebAssembly for NodeJS. (k2-fsa#628)
- Loading branch information
1 parent
ac6825f
commit ed06ced
Showing
39 changed files
with
1,484 additions
and
1,921 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ concurrency: | |
|
||
permissions: | ||
contents: read | ||
id-token: write | ||
|
||
jobs: | ||
nodejs: | ||
|
@@ -20,39 +21,59 @@ jobs: | |
python-version: ["3.8"] | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 | ||
|
||
- name: Install emsdk | ||
uses: mymindstorm/setup-emsdk@v14 | ||
|
||
- name: View emsdk version | ||
shell: bash | ||
run: | | ||
emcc -v | ||
echo "--------------------" | ||
emcc --check | ||
- name: Setup Python ${{ matrix.python-version }} | ||
uses: actions/setup-python@v5 | ||
with: | ||
python-version: ${{ matrix.python-version }} | ||
|
||
- uses: actions/setup-node@v4 | ||
with: | ||
node-version: 13 | ||
registry-url: 'https://registry.npmjs.org' | ||
|
||
- name: Display node version | ||
shell: bash | ||
run: | | ||
node --version | ||
npm --version | ||
cd nodejs-examples | ||
npm install [email protected] -g | ||
npm install [email protected] | ||
npm --version | ||
- name: Build nodejs package | ||
shell: bash | ||
env: | ||
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} | ||
run: | | ||
./build-wasm-simd-nodejs.sh | ||
cp -v build-wasm-simd-nodejs/install/bin/wasm/nodejs/*.js ./scripts/nodejs/ | ||
cp -v build-wasm-simd-nodejs/install/bin/wasm/nodejs/*.wasm ./scripts/nodejs/ | ||
SHERPA_ONNX_VERSION=$(grep "SHERPA_ONNX_VERSION" ./CMakeLists.txt | cut -d " " -f 2 | cut -d '"' -f 2) | ||
echo "SHERPA_ONNX_VERSION $SHERPA_ONNX_VERSION" | ||
cd scripts/nodejs | ||
./run.sh | ||
owner=${{ github.repository_owner }} | ||
echo "owner: $owner" | ||
sed -i.bak s/SHERPA_ONNX_VERSION/$SHERPA_ONNX_VERSION/g ./package.json | ||
sed -i.bak s/k2-fsa/$owner/g ./package.json | ||
rm package.json.bak | ||
git diff | ||
npm install | ||
rm run.sh | ||
npm ci | ||
# see https://docs.npmjs.com/generating-provenance-statements | ||
npm publish --provenance --access public |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,57 +24,46 @@ jobs: | |
strategy: | ||
fail-fast: false | ||
matrix: | ||
os: [ubuntu-latest, macos-latest] #, windows-2019] | ||
os: [ubuntu-latest] #, macos-latest] #, windows-2019] | ||
python-version: ["3.8"] | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 | ||
|
||
- name: ccache | ||
uses: hendrikmuhs/[email protected] | ||
with: | ||
key: ${{ matrix.os }}-Release-ON | ||
- name: Install emsdk | ||
uses: mymindstorm/setup-emsdk@v14 | ||
|
||
- name: Configure CMake | ||
- name: View emsdk version | ||
shell: bash | ||
run: | | ||
export CMAKE_CXX_COMPILER_LAUNCHER=ccache | ||
export PATH="/usr/lib/ccache:/usr/local/opt/ccache/libexec:$PATH" | ||
cmake --version | ||
mkdir build | ||
cd build | ||
cmake -D CMAKE_BUILD_TYPE=Release -D BUILD_SHARED_LIBS=ON -DCMAKE_INSTALL_PREFIX=./install .. | ||
cmake --build . --target install --config Release | ||
ls -lh install/lib | ||
emcc -v | ||
echo "--------------------" | ||
emcc --check | ||
- name: Setup Python ${{ matrix.python-version }} | ||
uses: actions/setup-python@v5 | ||
with: | ||
python-version: ${{ matrix.python-version }} | ||
|
||
- name: Copy files | ||
- uses: actions/setup-node@v4 | ||
with: | ||
registry-url: 'https://registry.npmjs.org' | ||
|
||
- name: Display node version | ||
shell: bash | ||
run: | | ||
node --version | ||
- name: Build nodejs package | ||
shell: bash | ||
env: | ||
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} | ||
run: | | ||
os=${{ matrix.os }} | ||
if [[ $os == 'ubuntu-latest' ]]; then | ||
mkdir -p scripts/nodejs/lib/linux-x64 | ||
dst=scripts/nodejs/lib/linux-x64 | ||
elif [[ $os == 'macos-latest' ]]; then | ||
mkdir -p scripts/nodejs/lib/osx-x64 | ||
dst=scripts/nodejs/lib/osx-x64 | ||
elif [[ $os == 'windows-2019' ]]; then | ||
mkdir -p scripts/nodejs/lib/win-x64 | ||
dst=scripts/nodejs/lib/win-x64 | ||
fi | ||
ls -lh build/install/lib/ | ||
rm -rf build/install/lib/pkgconfig | ||
cp -v build/install/lib/* $dst/ | ||
./build-wasm-simd-nodejs.sh | ||
cp -v build-wasm-simd-nodejs/install/bin/wasm/nodejs/*.js ./scripts/nodejs/ | ||
cp -v build-wasm-simd-nodejs/install/bin/wasm/nodejs/*.wasm ./scripts/nodejs/ | ||
- name: replace files | ||
shell: bash | ||
|
@@ -89,17 +78,6 @@ jobs: | |
git diff | ||
cp *.js ../scripts/nodejs | ||
- uses: actions/setup-node@v4 | ||
with: | ||
node-version: 13 | ||
registry-url: 'https://registry.npmjs.org' | ||
|
||
- name: Display node version | ||
shell: bash | ||
run: | | ||
node --version | ||
npm --version | ||
- name: Run tests | ||
shell: bash | ||
run: | | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
#!/usr/bin/env bash | ||
# Copyright (c) 2024 Xiaomi Corporation | ||
# | ||
# This script is to build sherpa-onnx for WebAssembly (NodeJS) | ||
# | ||
# Please use NodeJS >= 18 | ||
|
||
set -ex | ||
|
||
if [ x"$EMSCRIPTEN" == x"" ]; then | ||
if ! command -v emcc &> /dev/null; then | ||
echo "Please install emscripten first" | ||
echo "" | ||
echo "You can use the following commands to install it:" | ||
echo "" | ||
echo "git clone https://github.com/emscripten-core/emsdk.git" | ||
echo "cd emsdk" | ||
echo "git pull" | ||
echo "./emsdk install latest" | ||
echo "./emsdk activate latest" | ||
echo "source ./emsdk_env.sh" | ||
exit 1 | ||
else | ||
EMSCRIPTEN=$(dirname $(realpath $(which emcc))) | ||
fi | ||
fi | ||
|
||
export EMSCRIPTEN=$EMSCRIPTEN | ||
echo "EMSCRIPTEN: $EMSCRIPTEN" | ||
if [ ! -f $EMSCRIPTEN/cmake/Modules/Platform/Emscripten.cmake ]; then | ||
echo "Cannot find $EMSCRIPTEN/cmake/Modules/Platform/Emscripten.cmake" | ||
echo "Please make sure you have installed emsdk correctly" | ||
exit 1 | ||
fi | ||
|
||
mkdir -p build-wasm-simd-nodejs | ||
pushd build-wasm-simd-nodejs | ||
|
||
export SHERPA_ONNX_IS_USING_BUILD_WASM_SH=ON | ||
|
||
cmake \ | ||
-DCMAKE_INSTALL_PREFIX=./install \ | ||
-DCMAKE_BUILD_TYPE=Release \ | ||
-DCMAKE_TOOLCHAIN_FILE=$EMSCRIPTEN/cmake/Modules/Platform/Emscripten.cmake \ | ||
\ | ||
-DSHERPA_ONNX_ENABLE_PYTHON=OFF \ | ||
-DSHERPA_ONNX_ENABLE_TESTS=OFF \ | ||
-DSHERPA_ONNX_ENABLE_CHECK=OFF \ | ||
-DBUILD_SHARED_LIBS=OFF \ | ||
-DSHERPA_ONNX_ENABLE_PORTAUDIO=OFF \ | ||
-DSHERPA_ONNX_ENABLE_JNI=OFF \ | ||
-DSHERPA_ONNX_ENABLE_C_API=ON \ | ||
-DSHERPA_ONNX_ENABLE_WEBSOCKET=OFF \ | ||
-DSHERPA_ONNX_ENABLE_GPU=OFF \ | ||
-DSHERPA_ONNX_ENABLE_WASM=ON \ | ||
-DSHERPA_ONNX_ENABLE_WASM_NODEJS=ON \ | ||
-DSHERPA_ONNX_ENABLE_BINARY=OFF \ | ||
-DSHERPA_ONNX_LINK_LIBSTDCPP_STATICALLY=OFF \ | ||
.. | ||
make -j10 | ||
make install | ||
|
||
ls -lh install/bin/wasm/nodejs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
node_modules | ||
lib | ||
package-lock.json | ||
*.tar.bz2 |
Oops, something went wrong.