diff --git a/.github/workflows/pkg-config.yaml b/.github/workflows/pkg-config.yaml new file mode 100644 index 00000000..6445ae5d --- /dev/null +++ b/.github/workflows/pkg-config.yaml @@ -0,0 +1,104 @@ +name: pkg-config + +on: + push: + branches: + - master + - pkg-config + tags: + - '*' + paths: + - '.github/workflows/pkg-config.yaml' + - 'CMakeLists.txt' + - 'cmake/**' + - 'sherpa-onnx/csrc/*' + - 'sherpa-onnx/c-api/*' + - 'c-api-examples/**' + pull_request: + branches: + - master + paths: + - '.github/workflows/pkg-config.yaml' + - 'CMakeLists.txt' + - 'cmake/**' + - 'sherpa-onnx/csrc/*' + - 'sherpa-onnx/c-api/*' + + workflow_dispatch: + +concurrency: + group: pkg-config-${{ github.ref }} + cancel-in-progress: true + +jobs: + linux: + runs-on: ${{ matrix.os }} + name: ${{ matrix.os }} ${{ matrix.build_type }} ${{ matrix.lib_type }} + strategy: + fail-fast: false + matrix: + os: [ubuntu-latest, macos-latest] + build_type: [Release, Debug] + lib_type: [shared, static] + + steps: + - uses: actions/checkout@v2 + with: + fetch-depth: 0 + + - name: Configure CMake + shell: bash + run: | + 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 .. + else + cmake -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 }} + shell: bash + run: | + cd build + make -j2 + make install + + ls -lh lib + ls -lh bin + + - name: Install tree + if: matrix.os == 'ubuntu-latest' + shell: bash + run: | + sudo apt-get install tree + + - name: Install tree + if: matrix.os == 'macos-latest' + shell: bash + run: | + brew install tree + + - name: Display generated files of sherpa-onnx for ${{ matrix.os }} ${{ matrix.build_type }} ${{ matrix.lib_type }} + shell: bash + run: | + tree build/install + ls -lh build/install + + cat build/install/sherpa-onnx.pc + + - name: Build C API example + shell: bash + run: | + export PKG_CONFIG_PATH=$PWD/build/install:$PKG_CONFIG_PATH + cd c-api-examples + 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: Test online transducer (C API) + shell: bash + run: | + export PATH=$PWD/c-api-examples:$PATH + export EXE=decode-file-c-api + + .github/scripts/test-online-transducer.sh diff --git a/CMakeLists.txt b/CMakeLists.txt index 35146194..89ee2c87 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,7 @@ cmake_minimum_required(VERSION 3.13 FATAL_ERROR) project(sherpa-onnx) -set(SHERPA_ONNX_VERSION "1.7.0") +set(SHERPA_ONNX_VERSION "1.7.1") # Disable warning about # @@ -167,3 +167,22 @@ if(SHERPA_ONNX_ENABLE_C_API) add_subdirectory(c-api-examples) endif() message(STATUS "CMAKE_CXX_FLAGS: ${CMAKE_CXX_FLAGS}") + +if(NOT BUILD_SHARED_LIBS) + if(APPLE) + set(SHERPA_ONNX_PKG_CONFIG_EXTRA_LIBS "-lc++") + endif() + + if(UNIX AND NOT APPLE) + set(SHERPA_ONNX_PKG_CONFIG_EXTRA_LIBS "-lstdc++ -lm") + endif() +endif() + +# See https://people.freedesktop.org/~dbn/pkg-config-guide.html +configure_file(cmake/sherpa-onnx.pc.in ${PROJECT_BINARY_DIR}/sherpa-onnx.pc @ONLY) +install( + FILES + ${PROJECT_BINARY_DIR}/sherpa-onnx.pc + DESTINATION + . +) diff --git a/cmake/cargs.cmake b/cmake/cargs.cmake index 8aa5d466..a9b620c3 100644 --- a/cmake/cargs.cmake +++ b/cmake/cargs.cmake @@ -2,10 +2,11 @@ function(download_cargs) include(FetchContent) set(cargs_URL "https://github.com/likle/cargs/archive/refs/tags/v1.0.3.tar.gz") + set(cargs_URL2 "https://huggingface.co/csukuangfj/sherpa-onnx-cmake-deps/resolve/main/cargs-1.0.3.tar.gz") set(cargs_HASH "SHA256=ddba25bd35e9c6c75bc706c126001b8ce8e084d40ef37050e6aa6963e836eb8b") # If you don't have access to the Internet, - # please pre-download asio + # please pre-download cargs set(possible_file_locations $ENV{HOME}/Downloads/cargs-1.0.3.tar.gz ${PROJECT_SOURCE_DIR}/cargs-1.0.3.tar.gz @@ -19,11 +20,18 @@ function(download_cargs) set(cargs_URL "${f}") file(TO_CMAKE_PATH "${cargs_URL}" cargs_URL) message(STATUS "Found local downloaded cargs: ${cargs_URL}") + set(cargs_URL2) break() endif() endforeach() - FetchContent_Declare(cargs URL ${cargs_URL} URL_HASH ${cargs_HASH}) + FetchContent_Declare(cargs + URL + ${cargs_URL} + ${cargs_URL2} + URL_HASH + ${cargs_HASH} + ) FetchContent_GetProperties(cargs) if(NOT cargs_POPULATED) @@ -32,6 +40,11 @@ function(download_cargs) endif() message(STATUS "cargs is downloaded to ${cargs_SOURCE_DIR}") add_subdirectory(${cargs_SOURCE_DIR} ${cargs_BINARY_DIR} EXCLUDE_FROM_ALL) + + install(TARGETS cargs DESTINATION lib) + install(FILES ${cargs_SOURCE_DIR}/include/cargs.h + DESTINATION include + ) endfunction() download_cargs() diff --git a/cmake/portaudio.cmake b/cmake/portaudio.cmake index dbf9917d..ba2534b5 100644 --- a/cmake/portaudio.cmake +++ b/cmake/portaudio.cmake @@ -57,6 +57,9 @@ function(download_portaudio) if(BUILD_SHARED_LIBS) set_target_properties(portaudio PROPERTIES OUTPUT_NAME "sherpa-onnx-portaudio") + if(NOT WIN32) + target_compile_options(portaudio PRIVATE "-Wno-deprecated-declarations") + endif() if(SHERPA_ONNX_ENABLE_PYTHON AND WIN32) install(TARGETS portaudio DESTINATION ..) @@ -65,6 +68,9 @@ function(download_portaudio) endif() else() set_target_properties(portaudio_static PROPERTIES OUTPUT_NAME "sherpa-onnx-portaudio_static") + if(NOT WIN32) + target_compile_options(portaudio_static PRIVATE "-Wno-deprecated-declarations") + endif() if(SHERPA_ONNX_ENABLE_PYTHON AND WIN32) install(TARGETS portaudio_static DESTINATION ..) else() diff --git a/cmake/sherpa-onnx.pc.in b/cmake/sherpa-onnx.pc.in new file mode 100644 index 00000000..2e640ed0 --- /dev/null +++ b/cmake/sherpa-onnx.pc.in @@ -0,0 +1,16 @@ +prefix="@CMAKE_INSTALL_PREFIX@" +exec_prefix="${prefix}" +includedir="${prefix}/include" +libdir="${exec_prefix}/lib" + +Name: sherpa-onnx +Description: pkg-config for sherpa-onnx +URL: https://github.com/k2-fsa/sherpa-onnx + +Version: @SHERPA_ONNX_VERSION@ +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 -lonnxruntime -lkaldi-native-fbank-core -lcargs -Wl,-rpath,${libdir} @SHERPA_ONNX_PKG_CONFIG_EXTRA_LIBS@ diff --git a/scripts/dotnet/generate.py b/scripts/dotnet/generate.py index 52e0a762..6da03800 100755 --- a/scripts/dotnet/generate.py +++ b/scripts/dotnet/generate.py @@ -82,13 +82,17 @@ def process_windows(s): "sherpa-onnx-c-api.dll", "sherpa-onnx-core.dll", ] + + version = get_version() + prefix1 = f"{SHERPA_ONNX_DIR}/windows/sherpa_onnx/lib/" prefix2 = f"{SHERPA_ONNX_DIR}/windows/sherpa_onnx/" prefix3 = f"{SHERPA_ONNX_DIR}/windows/" + prefix4 = f"{SHERPA_ONNX_DIR}/windows/sherpa_onnx-${version}.data/data/bin/" lib_list = [] for lib in libs: - for prefix in [prefix1, prefix2, prefix3]: + for prefix in [prefix1, prefix2, prefix3, prefix4]: f = Path(prefix) / lib if f.is_file(): lib_list.append(str(f)) diff --git a/sherpa-onnx/csrc/text-utils.h b/sherpa-onnx/csrc/text-utils.h index 87010152..55d3a281 100644 --- a/sherpa-onnx/csrc/text-utils.h +++ b/sherpa-onnx/csrc/text-utils.h @@ -4,7 +4,7 @@ // Copyright 2023 Xiaomi Corporation #ifndef SHERPA_ONNX_CSRC_TEXT_UTILS_H_ #define SHERPA_ONNX_CSRC_TEXT_UTILS_H_ -#include . +#include #include #include