From ea3e583ac94b17e3dc9d994347d313f6e343305d Mon Sep 17 00:00:00 2001 From: Fangjun Kuang Date: Mon, 30 Jun 2025 14:21:01 +0800 Subject: [PATCH] Fix static link without tts (#2328) --- .github/workflows/pkg-config.yaml | 31 ++++++++++++++++++++++----- cmake/sherpa-onnx-static-no-tts.pc.in | 2 +- 2 files changed, 27 insertions(+), 6 deletions(-) diff --git a/.github/workflows/pkg-config.yaml b/.github/workflows/pkg-config.yaml index 2e40d776..271a8c61 100644 --- a/.github/workflows/pkg-config.yaml +++ b/.github/workflows/pkg-config.yaml @@ -33,13 +33,14 @@ concurrency: jobs: pkg_config: runs-on: ${{ matrix.os }} - name: ${{ matrix.os }} ${{ matrix.build_type }} ${{ matrix.lib_type }} + name: ${{ matrix.os }} ${{ matrix.build_type }} ${{ matrix.lib_type }} tts-${{ matrix.tts }} strategy: fail-fast: false matrix: os: [ubuntu-latest, macos-latest] build_type: [Release, Debug] lib_type: [shared, static] + tts: [ON, OFF] steps: - uses: actions/checkout@v4 @@ -67,12 +68,12 @@ jobs: mkdir build cd build if [[ ${{ matrix.lib_type }} == "shared" ]]; then - cmake -DSHERPA_ONNX_ENABLE_C_API=ON -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} -DCMAKE_INSTALL_PREFIX=./install -DBUILD_SHARED_LIBS=ON .. + cmake -DSHERPA_ONNX_ENABLE_TTS=${{ matrix.tts }} -DSHERPA_ONNX_ENABLE_C_API=ON -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} -DCMAKE_INSTALL_PREFIX=./install -DBUILD_SHARED_LIBS=ON .. else - cmake -DSHERPA_ONNX_ENABLE_C_API=ON -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} -DCMAKE_INSTALL_PREFIX=./install -DBUILD_SHARED_LIBS=OFF .. + cmake -DSHERPA_ONNX_ENABLE_TTS=${{ matrix.tts }} -DSHERPA_ONNX_ENABLE_C_API=ON -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} -DCMAKE_INSTALL_PREFIX=./install -DBUILD_SHARED_LIBS=OFF .. fi - - name: Build sherpa-onnx for ${{ matrix.os }} ${{ matrix.build_type }} ${{ matrix.lib_type }} + - name: Build sherpa-onnx for ${{ matrix.os }} ${{ matrix.build_type }} ${{ matrix.lib_type }} tts-${{ matrix.tts }} shell: bash run: | export PATH="/usr/lib/ccache:/usr/local/opt/ccache/libexec:$PATH" @@ -104,16 +105,36 @@ jobs: cat build/install/sherpa-onnx.pc + - name: Show pkg-config + shell: bash + run: | + export PKG_CONFIG_PATH=$PWD/build/install:$PKG_CONFIG_PATH + pkg-config --cflags sherpa-onnx + pkg-config --libs sherpa-onnx + - name: Build C API example shell: bash run: | export PKG_CONFIG_PATH=$PWD/build/install:$PKG_CONFIG_PATH cd c-api-examples + pkg-config --cflags sherpa-onnx + gcc -o decode-file-c-api $(pkg-config --cflags sherpa-onnx) ./decode-file-c-api.c $(pkg-config --libs sherpa-onnx) + ./decode-file-c-api --help + - name: Build C API example (tts) + if: matrix.tts == 'ON' + shell: bash + run: | + export PKG_CONFIG_PATH=$PWD/build/install:$PKG_CONFIG_PATH + cd c-api-examples + + pkg-config --cflags sherpa-onnx + gcc -o offline-tts-c-api $(pkg-config --cflags sherpa-onnx) ./offline-tts-c-api.c $(pkg-config --libs sherpa-onnx) + ./offline-tts-c-api --help - name: Test online transducer (C API) @@ -126,5 +147,5 @@ jobs: - uses: actions/upload-artifact@v4 with: - name: tts-generated-test-files-${{ matrix.os }}-${{ matrix.build_type }}-${{ matrix.lib_type }} + name: tts-generated-test-files-${{ matrix.os }}-${{ matrix.build_type }}-${{ matrix.lib_type }}-tts-${{ matrix.tts }} path: tts diff --git a/cmake/sherpa-onnx-static-no-tts.pc.in b/cmake/sherpa-onnx-static-no-tts.pc.in index 069d620d..4fab62cd 100644 --- a/cmake/sherpa-onnx-static-no-tts.pc.in +++ b/cmake/sherpa-onnx-static-no-tts.pc.in @@ -22,4 +22,4 @@ Cflags: -I"${includedir}" # Note: -lcargs is required only for the following file # https://github.com/k2-fsa/sherpa-onnx/blob/master/c-api-examples/decode-file-c-api.c # We add it here so that users don't need to specify -lcargs when compiling decode-file-c-api.c -Libs: -L"${libdir}" -lsherpa-onnx-c-api -lsherpa-onnx-core -lkaldi-decoder-core -lsherpa-onnx-kaldifst-core -lsherpa-onnx-fst -lkaldi-native-fbank-core -lkissfft-float -lonnxruntime -lssentencepiece_core -Wl,-rpath,${libdir} @SHERPA_ONNX_PKG_WITH_CARGS@ @SHERPA_ONNX_PKG_CONFIG_EXTRA_LIBS@ +Libs: -L"${libdir}" -lsherpa-onnx-c-api -lsherpa-onnx-core -lkaldi-decoder-core -lsherpa-onnx-kaldifst-core -lsherpa-onnx-fstfar -lsherpa-onnx-fst -lkaldi-native-fbank-core -lkissfft-float -lonnxruntime -lssentencepiece_core -Wl,-rpath,${libdir} @SHERPA_ONNX_PKG_WITH_CARGS@ @SHERPA_ONNX_PKG_CONFIG_EXTRA_LIBS@