Build sherpa-onnx as a single shared library (#1078)

When `-D BUILD_SHARED_LIBS=ON` is passed to `cmake`, it builds a single shared library.

Specifically, 

- For C APIs, it builds `libsherpa-onnx-c-api.so`
- For Python APIs, it builds `_sherpa_onnx.cpython-xx-xx.so`
- For Kotlin and Java APIs, it builds `libsherpa-onnx-jni.so`

There is no `libsherpa-onnx-core.so` any longer.

Note it affects only shared libraries.
This commit is contained in:
Fangjun Kuang
2024-07-06 16:41:54 +08:00
committed by GitHub
parent 55decb7bee
commit a25075101c
69 changed files with 571 additions and 324 deletions

View File

@@ -32,6 +32,7 @@ concurrency:
jobs:
flutter_linux:
if: false
name: linux
runs-on: ${{ matrix.os }}
container: ubuntu:18.04
@@ -49,7 +50,7 @@ jobs:
shell: bash
run: |
apt-get update -y
apt-get install -y build-essential jq git cmake
apt-get install -y build-essential jq git cmake
apt-get install -y curl
- name: Setup Flutter SDK

View File

@@ -37,7 +37,7 @@ jobs:
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, macos-14]
os: [ubuntu-latest, macos-latest, macos-13]
steps:
- uses: actions/checkout@v4

View File

@@ -72,7 +72,12 @@ jobs:
mkdir build
cd build
cmake -D CMAKE_BUILD_TYPE=${{ matrix.build_type }} -DCMAKE_INSTALL_PREFIX=./install -DBUILD_SHARED_LIBS=ON -DSHERPA_ONNX_ENABLE_GPU=ON ..
cmake \
-D CMAKE_BUILD_TYPE=${{ matrix.build_type }} \
-D CMAKE_INSTALL_PREFIX=./install \
-D BUILD_SHARED_LIBS=ON \
-D SHERPA_ONNX_ENABLE_GPU=ON \
..
- name: Build sherpa-onnx for ubuntu
shell: bash
@@ -86,6 +91,12 @@ jobs:
ls -lh lib
ls -lh bin
echo "----"
ls -lh install/lib
echo "----"
ls -lh install/bin
- name: Display dependencies of sherpa-onnx for linux
shell: bash
run: |

View File

@@ -95,7 +95,13 @@ jobs:
mkdir build
cd build
cmake -DSHERPA_ONNX_ENABLE_TTS=ON -D CMAKE_BUILD_TYPE=Release -D BUILD_SHARED_LIBS=ON -DCMAKE_INSTALL_PREFIX=./install -DSHERPA_ONNX_ENABLE_JNI=ON ..
cmake \
-D SHERPA_ONNX_ENABLE_TTS=ON \
-D CMAKE_BUILD_TYPE=Release \
-D BUILD_SHARED_LIBS=ON \
-D CMAKE_INSTALL_PREFIX=./install \
-D SHERPA_ONNX_ENABLE_JNI=ON \
..
make -j2
make install
@@ -105,6 +111,12 @@ jobs:
rm -rf ./install/pkgconfig
rm -rf ./install/share
echo "----"
ls -lh install/lib
echo "----"
ls -lh install/bin
- name: Display dependencies of sherpa-onnx for linux
shell: bash
run: |

View File

@@ -99,7 +99,12 @@ jobs:
mkdir build
cd build
cmake -DSHERPA_ONNX_ENABLE_TTS=${{ matrix.with_tts }} -D CMAKE_BUILD_TYPE=${{ matrix.build_type }} -D BUILD_SHARED_LIBS=${{ matrix.shared_lib }} -DCMAKE_INSTALL_PREFIX=./install ..
cmake \
-D SHERPA_ONNX_ENABLE_TTS=${{ matrix.with_tts }} \
-D CMAKE_BUILD_TYPE=${{ matrix.build_type }} \
-D BUILD_SHARED_LIBS=${{ matrix.shared_lib }} \
-D CMAKE_INSTALL_PREFIX=./install \
..
make -j2
make install
@@ -107,6 +112,12 @@ jobs:
ls -lh lib
ls -lh bin
echo "----"
ls -lh install/lib
echo "----"
ls -lh install/bin
- name: Display dependencies of sherpa-onnx for linux
shell: bash
run: |

View File

@@ -52,8 +52,8 @@ jobs:
cmake \
-D BUILD_SHARED_LIBS=ON \
-D CMAKE_BUILD_TYPE=Release \
-DCMAKE_OSX_ARCHITECTURES=$arch \
-DSHERPA_ONNX_ENABLE_JNI=ON \
-D CMAKE_OSX_ARCHITECTURES=$arch \
-D SHERPA_ONNX_ENABLE_JNI=ON \
-DCMAKE_INSTALL_PREFIX=./install \
..

View File

@@ -84,7 +84,13 @@ jobs:
BUILD_SHARED_LIBS=ON
fi
cmake -DSHERPA_ONNX_ENABLE_TTS=${{ matrix.with_tts }} -D BUILD_SHARED_LIBS=$BUILD_SHARED_LIBS -D CMAKE_BUILD_TYPE=${{ matrix.build_type }} -DCMAKE_OSX_ARCHITECTURES='arm64;x86_64' -DCMAKE_INSTALL_PREFIX=./install ..
cmake \
-DSHERPA_ONNX_ENABLE_TTS=${{ matrix.with_tts }} \
-D BUILD_SHARED_LIBS=$BUILD_SHARED_LIBS \
-D CMAKE_BUILD_TYPE=${{ matrix.build_type }} \
-D CMAKE_OSX_ARCHITECTURES='arm64;x86_64' \
-D CMAKE_INSTALL_PREFIX=./install \
..
- name: Build sherpa-onnx for macos
shell: bash

View File

@@ -93,17 +93,12 @@ jobs:
make install
ls -lh ./install/lib
rm -v ./install/lib/libonnxruntime.so
- name: Copy pre-built libs
shell: bash
run: |
cp -v build/install/lib/lib*.so* flutter/sherpa_onnx_linux/linux/
pushd flutter/sherpa_onnx_linux/linux/
rm libonnxruntime.so
ln -s libonnxruntime.so.* ./libonnxruntime.so
popd
mv -v flutter/sherpa_onnx_linux /tmp/to_be_published
@@ -197,27 +192,19 @@ jobs:
cd build
make -j2 install
ls -lh install/lib/libsherpa-onnx-core.dylib
file install/lib/libsherpa-onnx-core.dylib
ls -lh install/lib/libsherpa-onnx-c-api.dylib
file install/lib/libsherpa-onnx-c-api.dylib
rm -v install/lib/libonnxruntime.dylib
- name: Copy pre-built libs
shell: bash
run: |
cp -v build/install/lib/lib*.dylib* flutter/sherpa_onnx_macos/macos/
mv -v flutter/sherpa_onnx_macos /tmp/to_be_published
ls -lh /tmp/to_be_published/macos
pushd /tmp/to_be_published/macos
rm libonnxruntime.dylib
ls -lh
popd
- name: Release
shell: bash
run: |
@@ -283,7 +270,7 @@ jobs:
shell: bash
run: |
cd build
cmake --build . --target install --config Release
cmake --build . --target install --config Release -- -m:2
ls -lh install/lib/*.dll

View File

@@ -123,8 +123,16 @@ jobs:
ls -lh build-riscv64-linux-gnu/bin
ls -lh build-riscv64-linux-gnu/lib
echo "---install/lib---"
ls -lh build-riscv64-linux-gnu/install/lib
echo "---install/bin---"
ls -lh build-riscv64-linux-gnu/install/bin
file build-riscv64-linux-gnu/bin/sherpa-onnx
readelf -d build-riscv64-linux-gnu/bin/sherpa-onnx
- name: Test sherpa-onnx
shell: bash
run: |

View File

@@ -78,7 +78,7 @@ jobs:
- name: Install Python dependencies
shell: bash
run: |
python3 -m pip install --upgrade pip numpy pypinyin sentencepiece>=0.1.96 soundfile
python3 -m pip install --upgrade pip numpy pypinyin sentencepiece>=0.1.96 soundfile setuptools wheel
- name: Install sherpa-onnx
shell: bash
@@ -87,7 +87,7 @@ jobs:
export PATH="/usr/lib/ccache:/usr/local/opt/ccache/libexec:$PATH"
cmake --version
python3 setup.py install
python3 -m pip install .
- name: Test sherpa-onnx
shell: bash

View File

@@ -39,7 +39,7 @@ jobs:
strategy:
fail-fast: false
matrix:
os: [macos-latest, macos-14]
os: [macos-latest, macos-13]
steps:
- uses: actions/checkout@v4

View File

@@ -110,10 +110,20 @@ jobs:
python3 setup.py bdist_wheel
ls -lh dist
- uses: actions/upload-artifact@v4
with:
name: wheel-${{ matrix.os }}-${{ matrix.python-version }}
path: ./dist/*.whl
- name: Display wheel
shell: bash
run: |
ls -lh dist
cd dist
mkdir t
cd t
unzip ../*.whl
- name: Install wheel
shell: bash

View File

@@ -70,7 +70,7 @@ jobs:
cd build
cmake \
-D BUILD_SHARED_LIBS=ON \
-DBUILD_SHARED_LIBS=ON \
-DSHERPA_ONNX_ENABLE_PORTAUDIO=OFF \
-DSHERPA_ONNX_ENABLE_WEBSOCKET=OFF \
-DBUILD_ESPEAK_NG_EXE=OFF \

View File

@@ -26,8 +26,10 @@ jobs:
include:
- os: ubuntu-latest
arch: amd64
- os: macos-latest
- os: macos-13
arch: amd64
- os: macos-14
arch: arm64
- os: windows-latest
arch: x64
- os: windows-latest

View File

@@ -35,7 +35,7 @@ jobs:
strategy:
fail-fast: false
matrix:
os: [macos-latest, macos-14]
os: [macos-latest, macos-13, ubuntu-latest, windows-latest]
steps:
- uses: actions/checkout@v4
@@ -67,12 +67,63 @@ jobs:
- name: Build sherpa-onnx
shell: bash
run: |
upload_dir=$PWD/to-upload
mkdir -p $upload_dir
echo "upload_dir"
export PATH="/usr/lib/ccache:/usr/local/opt/ccache/libexec:$PATH"
mkdir build
cd build
cmake -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache -DBUILD_SHARED_LIBS=ON -DSHERPA_ONNX_ENABLE_PORTAUDIO=OFF -DSHERPA_ONNX_ENABLE_WEBSOCKET=OFF ..
make -j1
cp -v _deps/onnxruntime-src/lib/libonnxruntime*dylib ./lib/
cmake \
-DCMAKE_C_COMPILER_LAUNCHER=ccache \
-DCMAKE_CXX_COMPILER_LAUNCHER=ccache \
-DBUILD_SHARED_LIBS=ON \
-DSHERPA_ONNX_ENABLE_PORTAUDIO=OFF \
-DSHERPA_ONNX_ENABLE_WEBSOCKET=OFF \
-DCMAKE_INSTALL_PREFIX=./install \
..
if [[ ${{ matrix.os }} == windows-latest ]]; then
cmake --build . --target install --config Release -- -m:2
else
make -j2 install
fi
if [[ ${{ matrix.os }} == ubuntu-latest ]]; then
cp -v ./lib/*.so $upload_dir
cp -v _deps/onnxruntime-src/lib/libonnxruntime*so* $upload_dir
cp -v _deps/onnxruntime-src/lib/libonnxruntime*so* ./lib/
rm -v ./lib/libonnxruntime.so
cd lib
ln -s libonnxruntime.so.1.17.1 libonnxruntime.so
cd ..
rm -v ./lib/*.a
ls -h ./lib
elif [[ ${{ matrix.os }} == windows-latest ]]; then
cp -v ./install/lib/sherpa-onnx-c-api.dll ../scripts/go/_internal/lib/x86_64-pc-windows-gnu/
cp -v ./install/lib/onnxruntime.dll ../scripts/go/_internal/lib/x86_64-pc-windows-gnu/
ls -lh ../scripts/go/_internal/lib/x86_64-pc-windows-gnu/
cp -v ../scripts/go/_internal/lib/x86_64-pc-windows-gnu/*.dll ../scripts/go/_internal/speaker-identification/
cp -v ../scripts/go/_internal/lib/x86_64-pc-windows-gnu/*.dll ../scripts/go/_internal/streaming-hlg-decoding/
cp -v ../scripts/go/_internal/lib/x86_64-pc-windows-gnu/*.dll ../scripts/go/_internal/non-streaming-tts/
cp -v ../scripts/go/_internal/lib/x86_64-pc-windows-gnu/*.dll ../scripts/go/_internal/non-streaming-decode-files/
cp -v ../scripts/go/_internal/lib/x86_64-pc-windows-gnu/*.dll ../scripts/go/_internal/streaming-decode-files/
cp -v ../scripts/go/_internal/lib/x86_64-pc-windows-gnu/*.dll $upload_dir
else
cp -v _deps/onnxruntime-src/lib/libonnxruntime*dylib $upload_dir/
cp -v lib/*.dylib $upload_dir
cp -v _deps/onnxruntime-src/lib/libonnxruntime*dylib ./lib/
rm ./lib/*.a
rm ./lib/libonnxruntime.dylib
cd lib
ln -s libonnxruntime.1.17.1.dylib libonnxruntime.dylib
cd ..
fi
cd ../scripts/go/_internal/
ls -lh lib
@@ -83,6 +134,11 @@ jobs:
go mod tidy
go build
- uses: actions/upload-artifact@v4
with:
name: ${{ matrix.os }}-libs
path: to-upload/
- name: Test speaker identification
shell: bash
run: |
@@ -95,7 +151,7 @@ jobs:
cd scripts/go/_internal/streaming-hlg-decoding/
./run.sh
- name: Test non-streaming TTS (macOS)
- name: Test non-streaming TTS
shell: bash
run: |
mkdir tts-waves
@@ -130,7 +186,7 @@ jobs:
name: tts-waves-${{ matrix.os }}
path: tts-waves
- name: Test non-streaming decoding files (macOS)
- name: Test non-streaming decoding files
shell: bash
run: |
cd scripts/go/_internal/non-streaming-decode-files/

View File

@@ -57,7 +57,7 @@ jobs:
- name: Install Python dependencies
shell: bash
run: |
python3 -m pip install --upgrade pip numpy pypinyin sentencepiece
python3 -m pip install --upgrade pip numpy pypinyin sentencepiece setuptools wheel
- name: Install sherpa-onnx
shell: bash
@@ -66,7 +66,7 @@ jobs:
export PATH="/usr/lib/ccache:/usr/local/opt/ccache/libexec:$PATH"
cmake --version
python3 setup.py install
python3 -m pip install .
python3 -m pip install websockets
- name: Start server for transducer models

View File

@@ -57,7 +57,7 @@ jobs:
- name: Install Python dependencies
shell: bash
run: |
python3 -m pip install --upgrade pip numpy pypinyin sentencepiece
python3 -m pip install --upgrade pip numpy pypinyin sentencepiece setuptools wheel
- name: Install sherpa-onnx
shell: bash
@@ -66,7 +66,7 @@ jobs:
export PATH="/usr/lib/ccache:/usr/local/opt/ccache/libexec:$PATH"
cmake --version
python3 setup.py install
python3 -m pip install .
python3 -m pip install websockets
- name: Start server for zipformer2 CTC models

View File

@@ -47,7 +47,14 @@ jobs:
run: |
mkdir build
cd build
cmake -A ARM64 -DSHERPA_ONNX_ENABLE_TTS=${{ matrix.with_tts }} -D CMAKE_BUILD_TYPE=Release -D BUILD_SHARED_LIBS=${{ matrix.shared_lib }} -DCMAKE_INSTALL_PREFIX=./install -DBUILD_ESPEAK_NG_EXE=OFF ..
cmake \
-A ARM64 \
-DSHERPA_ONNX_ENABLE_TTS=${{ matrix.with_tts }} \
-D CMAKE_BUILD_TYPE=Release \
-D BUILD_SHARED_LIBS=${{ matrix.shared_lib }} \
-D CMAKE_INSTALL_PREFIX=./install \
-D BUILD_ESPEAK_NG_EXE=OFF \
..
- name: Build sherpa-onnx for windows
shell: bash

View File

@@ -57,7 +57,13 @@ jobs:
run: |
mkdir build
cd build
cmake -A x64 -D CMAKE_BUILD_TYPE=Release -D BUILD_SHARED_LIBS=ON -DCMAKE_INSTALL_PREFIX=./install -DSHERPA_ONNX_ENABLE_GPU=ON ..
cmake \
-A x64 \
-D CMAKE_BUILD_TYPE=Release \
-D BUILD_SHARED_LIBS=ON \
-D CMAKE_INSTALL_PREFIX=./install \
-D SHERPA_ONNX_ENABLE_GPU=ON \
..
- name: Build sherpa-onnx for windows
shell: bash

View File

@@ -59,7 +59,12 @@ jobs:
run: |
mkdir build
cd build
cmake -A x64 -D CMAKE_BUILD_TYPE=${{ matrix.build_type }} -D BUILD_SHARED_LIBS=${{ matrix.shared_lib }} -DCMAKE_INSTALL_PREFIX=./install ..
cmake \
-A x64 \
-D CMAKE_BUILD_TYPE=${{ matrix.build_type }} \
-D BUILD_SHARED_LIBS=${{ matrix.shared_lib }} \
-D CMAKE_INSTALL_PREFIX=./install \
..
- name: Build sherpa-onnx for windows
shell: bash

View File

@@ -37,7 +37,13 @@ jobs:
run: |
mkdir build
cd build
cmake -A x64 -D CMAKE_BUILD_TYPE=Release -D BUILD_SHARED_LIBS=ON -DSHERPA_ONNX_ENABLE_JNI=ON -DCMAKE_INSTALL_PREFIX=./install ..
cmake \
-A x64 \
-D CMAKE_BUILD_TYPE=Release \
-D BUILD_SHARED_LIBS=ON \
-D SHERPA_ONNX_ENABLE_JNI=ON \
-D CMAKE_INSTALL_PREFIX=./install \
..
- name: Build sherpa-onnx for windows
shell: bash

View File

@@ -63,7 +63,13 @@ jobs:
run: |
mkdir build
cd build
cmake -A x64 -DSHERPA_ONNX_ENABLE_TTS=${{ matrix.with_tts }} -D CMAKE_BUILD_TYPE=Release -D BUILD_SHARED_LIBS=${{ matrix.shared_lib }} -DCMAKE_INSTALL_PREFIX=./install ..
cmake \
-A x64 \
-DSHERPA_ONNX_ENABLE_TTS=${{ matrix.with_tts }} \
-D CMAKE_BUILD_TYPE=Release \
-D BUILD_SHARED_LIBS=${{ matrix.shared_lib }} \
-DCMAKE_INSTALL_PREFIX=./install \
..
- name: Build sherpa-onnx for windows
shell: bash

View File

@@ -59,7 +59,11 @@ jobs:
run: |
mkdir build
cd build
cmake -A Win32 -D CMAKE_BUILD_TYPE=${{ matrix.build_type }} -D BUILD_SHARED_LIBS=${{ matrix.shared_lib }} -D CMAKE_INSTALL_PREFIX=./install ..
cmake \
-A Win32 \
-D CMAKE_BUILD_TYPE=${{ matrix.build_type }} \
-D BUILD_SHARED_LIBS=${{ matrix.shared_lib }} \
-D CMAKE_INSTALL_PREFIX=./install ..
- name: Build sherpa-onnx for windows
shell: bash

View File

@@ -63,14 +63,20 @@ jobs:
run: |
mkdir build
cd build
cmake -A Win32 -DSHERPA_ONNX_ENABLE_TTS=${{ matrix.with_tts }} -D CMAKE_BUILD_TYPE=Release -D BUILD_SHARED_LIBS=${{ matrix.shared_lib }} -D CMAKE_INSTALL_PREFIX=./install ..
cmake \
-A Win32 \
-DSHERPA_ONNX_ENABLE_TTS=${{ matrix.with_tts }} \
-D CMAKE_BUILD_TYPE=Release \
-D BUILD_SHARED_LIBS=${{ matrix.shared_lib }} \
-D CMAKE_INSTALL_PREFIX=./install \
..
- name: Build sherpa-onnx for windows
shell: bash
run: |
cd build
cmake --build . --config Release -- -m:2
cmake --build . --config Release --target install -- -m:2
cmake --build . --config Release
cmake --build . --config Release --target install
ls -lh ./bin/Release/sherpa-onnx.exe