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

@@ -2,5 +2,5 @@
package sherpa_onnx
// #cgo LDFLAGS: -L ${SRCDIR}/lib/x86_64-apple-darwin -lsherpa-onnx-c-api -lsherpa-onnx-core -lkaldi-native-fbank-core -lkaldi-decoder-core -lsherpa-onnx-kaldifst-core -lsherpa-onnx-fstfar -lsherpa-onnx-fst -lpiper_phonemize -lespeak-ng -lucd -lonnxruntime -lssentencepiece_core -Wl,-rpath,${SRCDIR}/lib/x86_64-apple-darwin
// #cgo LDFLAGS: -L ${SRCDIR}/lib/x86_64-apple-darwin -lsherpa-onnx-c-api -lonnxruntime -Wl,-rpath,${SRCDIR}/lib/x86_64-apple-darwin
import "C"

View File

@@ -2,5 +2,5 @@
package sherpa_onnx
// #cgo LDFLAGS: -L ${SRCDIR}/lib/aarch64-apple-darwin -lsherpa-onnx-c-api -lsherpa-onnx-core -lkaldi-native-fbank-core -lkaldi-decoder-core -lsherpa-onnx-kaldifst-core -lsherpa-onnx-fstfar -lsherpa-onnx-fst -lpiper_phonemize -lespeak-ng -lucd -lonnxruntime -lssentencepiece_core -Wl,-rpath,${SRCDIR}/lib/aarch64-apple-darwin
// #cgo LDFLAGS: -L ${SRCDIR}/lib/aarch64-apple-darwin -lsherpa-onnx-c-api -lonnxruntime -Wl,-rpath,${SRCDIR}/lib/aarch64-apple-darwin
import "C"

View File

@@ -0,0 +1,6 @@
//go:build !android && linux && amd64 && !musl
package sherpa_onnx
// #cgo LDFLAGS: -L ${SRCDIR}/lib/x86_64-unknown-linux-gnu -lsherpa-onnx-c-api -lonnxruntime -Wl,-rpath,${SRCDIR}/lib/x86_64-unknown-linux-gnu
import "C"

View File

@@ -0,0 +1,6 @@
//go:build linux && arm && !arm7
package sherpa_onnx
// #cgo LDFLAGS: -L ${SRCDIR}/lib/arm-unknown-linux-gnueabihf -lsherpa-onnx-c-api -lonnxruntime -Wl,-rpath,${SRCDIR}/lib/arm-unknown-linux-gnueabihf
import "C"

View File

@@ -0,0 +1,6 @@
//go:build linux && arm64
package sherpa_onnx
// #cgo LDFLAGS: -L ${SRCDIR}/lib/aarch64-unknown-linux-gnu -lsherpa-onnx-c-api -lsherpa-onnx-core -lkaldi-native-fbank-core -lkaldi-decoder-core -lsherpa-onnx-kaldifst-core -lsherpa-onnx-fstfar -lsherpa-onnx-fst -lpiper_phonemize -lespeak-ng -lucd -lonnxruntime -lssentencepiece_core -Wl,-rpath,${SRCDIR}/lib/aarch64-unknown-linux-gnu
import "C"

View File

@@ -0,0 +1,6 @@
//go:build windows && 386
package sherpa_onnx
// #cgo LDFLAGS: -L ${SRCDIR}/lib/i686-pc-windows-gnu -lsherpa-onnx-c-api -lonnxruntime
import "C"

View File

@@ -0,0 +1,6 @@
//go:build windows && amd64
package sherpa_onnx
// #cgo LDFLAGS: -L ${SRCDIR}/lib/x86_64-pc-windows-gnu -lsherpa-onnx-c-api -lonnxruntime
import "C"

View File

@@ -0,0 +1 @@
../../../../build/lib

View File

@@ -17,8 +17,11 @@ echo "SHERPA_ONNX_VERSION $SHERPA_ONNX_VERSION"
function linux() {
echo "Process linux"
git clone git@github.com:k2-fsa/sherpa-onnx-go-linux.git
rm -v ./sherpa-onnx-go-linux/*.go
cp -v ./sherpa_onnx.go ./sherpa-onnx-go-linux/
cp -v ./_internal/c-api.h ./sherpa-onnx-go-linux/
cp -v ./_internal/build_linux_*.go ./sherpa-onnx-go-linux/
rm -rf sherpa-onnx-go-linux/lib/x86_64-unknown-linux-gnu/lib*
dst=$(realpath sherpa-onnx-go-linux/lib/x86_64-unknown-linux-gnu)
@@ -29,6 +32,10 @@ function linux() {
cp -v sherpa_onnx/lib/*.so* $dst
pushd $dst
cp -v libonnxruntime.so.1.17.1 libonnxruntime.so
popd
cd ..
rm -rf t
@@ -41,6 +48,10 @@ function linux() {
cp -v sherpa_onnx/lib/*.so* $dst
pushd $dst
cp -v libonnxruntime.so.1.17.1 libonnxruntime.so
popd
cd ..
rm -rf t
@@ -53,6 +64,10 @@ function linux() {
cp -v sherpa_onnx/lib/*.so* $dst
pushd $dst
cp -v libonnxruntime.so.1.17.1 libonnxruntime.so
popd
cd ..
rm -rf t
@@ -71,8 +86,10 @@ function linux() {
function osx() {
echo "Process osx-x64"
git clone git@github.com:k2-fsa/sherpa-onnx-go-macos.git
rm -v ./sherpa-onnx-go-macos/*.go
cp -v ./sherpa_onnx.go ./sherpa-onnx-go-macos/
cp -v ./_internal/c-api.h ./sherpa-onnx-go-macos/
cp -v ./_internal/build_darwin_*.go ./sherpa-onnx-go-macos/
rm -rf sherpa-onnx-go-macos/lib/x86_64-apple-darwin/lib*
dst=$(realpath sherpa-onnx-go-macos/lib/x86_64-apple-darwin/)
@@ -84,6 +101,10 @@ function osx() {
cp -v sherpa_onnx/lib/*.dylib $dst/
pushd $dst
cp -v libonnxruntime.1.17.1.dylib libonnxruntime.dylib
popd
cd ..
rm -rf t
@@ -98,6 +119,10 @@ function osx() {
cp -v sherpa_onnx/lib/*.dylib $dst/
pushd $dst
cp -v libonnxruntime.1.17.1.dylib libonnxruntime.dylib
popd
cd ..
rm -rf t
echo "------------------------------"
@@ -115,8 +140,10 @@ function osx() {
function windows() {
echo "Process windows"
git clone git@github.com:k2-fsa/sherpa-onnx-go-windows.git
rm -v ./sherpa-onnx-go-windows/*.go
cp -v ./sherpa_onnx.go ./sherpa-onnx-go-windows/
cp -v ./_internal/c-api.h ./sherpa-onnx-go-windows/
cp -v ./_internal/build_windows_*.go ./sherpa-onnx-go-windows/
rm -fv sherpa-onnx-go-windows/lib/x86_64-pc-windows-gnu/*
dst=$(realpath sherpa-onnx-go-windows/lib/x86_64-pc-windows-gnu)