正在显示
7 个修改的文件
包含
167 行增加
和
5 行删除
.github/workflows/pkg-config.yaml
0 → 100644
| 1 | +name: pkg-config | ||
| 2 | + | ||
| 3 | +on: | ||
| 4 | + push: | ||
| 5 | + branches: | ||
| 6 | + - master | ||
| 7 | + - pkg-config | ||
| 8 | + tags: | ||
| 9 | + - '*' | ||
| 10 | + paths: | ||
| 11 | + - '.github/workflows/pkg-config.yaml' | ||
| 12 | + - 'CMakeLists.txt' | ||
| 13 | + - 'cmake/**' | ||
| 14 | + - 'sherpa-onnx/csrc/*' | ||
| 15 | + - 'sherpa-onnx/c-api/*' | ||
| 16 | + - 'c-api-examples/**' | ||
| 17 | + pull_request: | ||
| 18 | + branches: | ||
| 19 | + - master | ||
| 20 | + paths: | ||
| 21 | + - '.github/workflows/pkg-config.yaml' | ||
| 22 | + - 'CMakeLists.txt' | ||
| 23 | + - 'cmake/**' | ||
| 24 | + - 'sherpa-onnx/csrc/*' | ||
| 25 | + - 'sherpa-onnx/c-api/*' | ||
| 26 | + | ||
| 27 | + workflow_dispatch: | ||
| 28 | + | ||
| 29 | +concurrency: | ||
| 30 | + group: pkg-config-${{ github.ref }} | ||
| 31 | + cancel-in-progress: true | ||
| 32 | + | ||
| 33 | +jobs: | ||
| 34 | + linux: | ||
| 35 | + runs-on: ${{ matrix.os }} | ||
| 36 | + name: ${{ matrix.os }} ${{ matrix.build_type }} ${{ matrix.lib_type }} | ||
| 37 | + strategy: | ||
| 38 | + fail-fast: false | ||
| 39 | + matrix: | ||
| 40 | + os: [ubuntu-latest, macos-latest] | ||
| 41 | + build_type: [Release, Debug] | ||
| 42 | + lib_type: [shared, static] | ||
| 43 | + | ||
| 44 | + steps: | ||
| 45 | + - uses: actions/checkout@v2 | ||
| 46 | + with: | ||
| 47 | + fetch-depth: 0 | ||
| 48 | + | ||
| 49 | + - name: Configure CMake | ||
| 50 | + shell: bash | ||
| 51 | + run: | | ||
| 52 | + mkdir build | ||
| 53 | + cd build | ||
| 54 | + if [[ ${{ matrix.lib_type }} == "shared" ]]; then | ||
| 55 | + cmake -DSHERPA_ONNX_ENABLE_C_API=ON -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} -DCMAKE_INSTALL_PREFIX=./install -DBUILD_SHARED_LIBS=ON .. | ||
| 56 | + else | ||
| 57 | + cmake -DSHERPA_ONNX_ENABLE_C_API=ON -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} -DCMAKE_INSTALL_PREFIX=./install -DBUILD_SHARED_LIBS=OFF .. | ||
| 58 | + fi | ||
| 59 | + | ||
| 60 | + - name: Build sherpa-onnx for ${{ matrix.os }} ${{ matrix.build_type }} ${{ matrix.lib_type }} | ||
| 61 | + shell: bash | ||
| 62 | + run: | | ||
| 63 | + cd build | ||
| 64 | + make -j2 | ||
| 65 | + make install | ||
| 66 | + | ||
| 67 | + ls -lh lib | ||
| 68 | + ls -lh bin | ||
| 69 | + | ||
| 70 | + - name: Install tree | ||
| 71 | + if: matrix.os == 'ubuntu-latest' | ||
| 72 | + shell: bash | ||
| 73 | + run: | | ||
| 74 | + sudo apt-get install tree | ||
| 75 | + | ||
| 76 | + - name: Install tree | ||
| 77 | + if: matrix.os == 'macos-latest' | ||
| 78 | + shell: bash | ||
| 79 | + run: | | ||
| 80 | + brew install tree | ||
| 81 | + | ||
| 82 | + - name: Display generated files of sherpa-onnx for ${{ matrix.os }} ${{ matrix.build_type }} ${{ matrix.lib_type }} | ||
| 83 | + shell: bash | ||
| 84 | + run: | | ||
| 85 | + tree build/install | ||
| 86 | + ls -lh build/install | ||
| 87 | + | ||
| 88 | + cat build/install/sherpa-onnx.pc | ||
| 89 | + | ||
| 90 | + - name: Build C API example | ||
| 91 | + shell: bash | ||
| 92 | + run: | | ||
| 93 | + export PKG_CONFIG_PATH=$PWD/build/install:$PKG_CONFIG_PATH | ||
| 94 | + cd c-api-examples | ||
| 95 | + gcc -o decode-file-c-api $(pkg-config --cflags sherpa-onnx) ./decode-file-c-api.c $(pkg-config --libs sherpa-onnx) | ||
| 96 | + ./decode-file-c-api --help | ||
| 97 | + | ||
| 98 | + - name: Test online transducer (C API) | ||
| 99 | + shell: bash | ||
| 100 | + run: | | ||
| 101 | + export PATH=$PWD/c-api-examples:$PATH | ||
| 102 | + export EXE=decode-file-c-api | ||
| 103 | + | ||
| 104 | + .github/scripts/test-online-transducer.sh |
| 1 | cmake_minimum_required(VERSION 3.13 FATAL_ERROR) | 1 | cmake_minimum_required(VERSION 3.13 FATAL_ERROR) |
| 2 | project(sherpa-onnx) | 2 | project(sherpa-onnx) |
| 3 | 3 | ||
| 4 | -set(SHERPA_ONNX_VERSION "1.7.0") | 4 | +set(SHERPA_ONNX_VERSION "1.7.1") |
| 5 | 5 | ||
| 6 | # Disable warning about | 6 | # Disable warning about |
| 7 | # | 7 | # |
| @@ -167,3 +167,22 @@ if(SHERPA_ONNX_ENABLE_C_API) | @@ -167,3 +167,22 @@ if(SHERPA_ONNX_ENABLE_C_API) | ||
| 167 | add_subdirectory(c-api-examples) | 167 | add_subdirectory(c-api-examples) |
| 168 | endif() | 168 | endif() |
| 169 | message(STATUS "CMAKE_CXX_FLAGS: ${CMAKE_CXX_FLAGS}") | 169 | message(STATUS "CMAKE_CXX_FLAGS: ${CMAKE_CXX_FLAGS}") |
| 170 | + | ||
| 171 | +if(NOT BUILD_SHARED_LIBS) | ||
| 172 | + if(APPLE) | ||
| 173 | + set(SHERPA_ONNX_PKG_CONFIG_EXTRA_LIBS "-lc++") | ||
| 174 | + endif() | ||
| 175 | + | ||
| 176 | + if(UNIX AND NOT APPLE) | ||
| 177 | + set(SHERPA_ONNX_PKG_CONFIG_EXTRA_LIBS "-lstdc++ -lm") | ||
| 178 | + endif() | ||
| 179 | +endif() | ||
| 180 | + | ||
| 181 | +# See https://people.freedesktop.org/~dbn/pkg-config-guide.html | ||
| 182 | +configure_file(cmake/sherpa-onnx.pc.in ${PROJECT_BINARY_DIR}/sherpa-onnx.pc @ONLY) | ||
| 183 | +install( | ||
| 184 | + FILES | ||
| 185 | + ${PROJECT_BINARY_DIR}/sherpa-onnx.pc | ||
| 186 | + DESTINATION | ||
| 187 | + . | ||
| 188 | +) |
| @@ -2,10 +2,11 @@ function(download_cargs) | @@ -2,10 +2,11 @@ function(download_cargs) | ||
| 2 | include(FetchContent) | 2 | include(FetchContent) |
| 3 | 3 | ||
| 4 | set(cargs_URL "https://github.com/likle/cargs/archive/refs/tags/v1.0.3.tar.gz") | 4 | set(cargs_URL "https://github.com/likle/cargs/archive/refs/tags/v1.0.3.tar.gz") |
| 5 | + set(cargs_URL2 "https://huggingface.co/csukuangfj/sherpa-onnx-cmake-deps/resolve/main/cargs-1.0.3.tar.gz") | ||
| 5 | set(cargs_HASH "SHA256=ddba25bd35e9c6c75bc706c126001b8ce8e084d40ef37050e6aa6963e836eb8b") | 6 | set(cargs_HASH "SHA256=ddba25bd35e9c6c75bc706c126001b8ce8e084d40ef37050e6aa6963e836eb8b") |
| 6 | 7 | ||
| 7 | # If you don't have access to the Internet, | 8 | # If you don't have access to the Internet, |
| 8 | - # please pre-download asio | 9 | + # please pre-download cargs |
| 9 | set(possible_file_locations | 10 | set(possible_file_locations |
| 10 | $ENV{HOME}/Downloads/cargs-1.0.3.tar.gz | 11 | $ENV{HOME}/Downloads/cargs-1.0.3.tar.gz |
| 11 | ${PROJECT_SOURCE_DIR}/cargs-1.0.3.tar.gz | 12 | ${PROJECT_SOURCE_DIR}/cargs-1.0.3.tar.gz |
| @@ -19,11 +20,18 @@ function(download_cargs) | @@ -19,11 +20,18 @@ function(download_cargs) | ||
| 19 | set(cargs_URL "${f}") | 20 | set(cargs_URL "${f}") |
| 20 | file(TO_CMAKE_PATH "${cargs_URL}" cargs_URL) | 21 | file(TO_CMAKE_PATH "${cargs_URL}" cargs_URL) |
| 21 | message(STATUS "Found local downloaded cargs: ${cargs_URL}") | 22 | message(STATUS "Found local downloaded cargs: ${cargs_URL}") |
| 23 | + set(cargs_URL2) | ||
| 22 | break() | 24 | break() |
| 23 | endif() | 25 | endif() |
| 24 | endforeach() | 26 | endforeach() |
| 25 | 27 | ||
| 26 | - FetchContent_Declare(cargs URL ${cargs_URL} URL_HASH ${cargs_HASH}) | 28 | + FetchContent_Declare(cargs |
| 29 | + URL | ||
| 30 | + ${cargs_URL} | ||
| 31 | + ${cargs_URL2} | ||
| 32 | + URL_HASH | ||
| 33 | + ${cargs_HASH} | ||
| 34 | + ) | ||
| 27 | 35 | ||
| 28 | FetchContent_GetProperties(cargs) | 36 | FetchContent_GetProperties(cargs) |
| 29 | if(NOT cargs_POPULATED) | 37 | if(NOT cargs_POPULATED) |
| @@ -32,6 +40,11 @@ function(download_cargs) | @@ -32,6 +40,11 @@ function(download_cargs) | ||
| 32 | endif() | 40 | endif() |
| 33 | message(STATUS "cargs is downloaded to ${cargs_SOURCE_DIR}") | 41 | message(STATUS "cargs is downloaded to ${cargs_SOURCE_DIR}") |
| 34 | add_subdirectory(${cargs_SOURCE_DIR} ${cargs_BINARY_DIR} EXCLUDE_FROM_ALL) | 42 | add_subdirectory(${cargs_SOURCE_DIR} ${cargs_BINARY_DIR} EXCLUDE_FROM_ALL) |
| 43 | + | ||
| 44 | + install(TARGETS cargs DESTINATION lib) | ||
| 45 | + install(FILES ${cargs_SOURCE_DIR}/include/cargs.h | ||
| 46 | + DESTINATION include | ||
| 47 | + ) | ||
| 35 | endfunction() | 48 | endfunction() |
| 36 | 49 | ||
| 37 | download_cargs() | 50 | download_cargs() |
| @@ -57,6 +57,9 @@ function(download_portaudio) | @@ -57,6 +57,9 @@ function(download_portaudio) | ||
| 57 | 57 | ||
| 58 | if(BUILD_SHARED_LIBS) | 58 | if(BUILD_SHARED_LIBS) |
| 59 | set_target_properties(portaudio PROPERTIES OUTPUT_NAME "sherpa-onnx-portaudio") | 59 | set_target_properties(portaudio PROPERTIES OUTPUT_NAME "sherpa-onnx-portaudio") |
| 60 | + if(NOT WIN32) | ||
| 61 | + target_compile_options(portaudio PRIVATE "-Wno-deprecated-declarations") | ||
| 62 | + endif() | ||
| 60 | 63 | ||
| 61 | if(SHERPA_ONNX_ENABLE_PYTHON AND WIN32) | 64 | if(SHERPA_ONNX_ENABLE_PYTHON AND WIN32) |
| 62 | install(TARGETS portaudio DESTINATION ..) | 65 | install(TARGETS portaudio DESTINATION ..) |
| @@ -65,6 +68,9 @@ function(download_portaudio) | @@ -65,6 +68,9 @@ function(download_portaudio) | ||
| 65 | endif() | 68 | endif() |
| 66 | else() | 69 | else() |
| 67 | set_target_properties(portaudio_static PROPERTIES OUTPUT_NAME "sherpa-onnx-portaudio_static") | 70 | set_target_properties(portaudio_static PROPERTIES OUTPUT_NAME "sherpa-onnx-portaudio_static") |
| 71 | + if(NOT WIN32) | ||
| 72 | + target_compile_options(portaudio_static PRIVATE "-Wno-deprecated-declarations") | ||
| 73 | + endif() | ||
| 68 | if(SHERPA_ONNX_ENABLE_PYTHON AND WIN32) | 74 | if(SHERPA_ONNX_ENABLE_PYTHON AND WIN32) |
| 69 | install(TARGETS portaudio_static DESTINATION ..) | 75 | install(TARGETS portaudio_static DESTINATION ..) |
| 70 | else() | 76 | else() |
cmake/sherpa-onnx.pc.in
0 → 100644
| 1 | +prefix="@CMAKE_INSTALL_PREFIX@" | ||
| 2 | +exec_prefix="${prefix}" | ||
| 3 | +includedir="${prefix}/include" | ||
| 4 | +libdir="${exec_prefix}/lib" | ||
| 5 | + | ||
| 6 | +Name: sherpa-onnx | ||
| 7 | +Description: pkg-config for sherpa-onnx | ||
| 8 | +URL: https://github.com/k2-fsa/sherpa-onnx | ||
| 9 | + | ||
| 10 | +Version: @SHERPA_ONNX_VERSION@ | ||
| 11 | +Cflags: -I"${includedir}" | ||
| 12 | + | ||
| 13 | +# Note: -lcargs is required only for the following file | ||
| 14 | +# https://github.com/k2-fsa/sherpa-onnx/blob/master/c-api-examples/decode-file-c-api.c | ||
| 15 | +# We add it here so that users don't need to specify -lcargs when compiling decode-file-c-api.c | ||
| 16 | +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@ |
| @@ -82,13 +82,17 @@ def process_windows(s): | @@ -82,13 +82,17 @@ def process_windows(s): | ||
| 82 | "sherpa-onnx-c-api.dll", | 82 | "sherpa-onnx-c-api.dll", |
| 83 | "sherpa-onnx-core.dll", | 83 | "sherpa-onnx-core.dll", |
| 84 | ] | 84 | ] |
| 85 | + | ||
| 86 | + version = get_version() | ||
| 87 | + | ||
| 85 | prefix1 = f"{SHERPA_ONNX_DIR}/windows/sherpa_onnx/lib/" | 88 | prefix1 = f"{SHERPA_ONNX_DIR}/windows/sherpa_onnx/lib/" |
| 86 | prefix2 = f"{SHERPA_ONNX_DIR}/windows/sherpa_onnx/" | 89 | prefix2 = f"{SHERPA_ONNX_DIR}/windows/sherpa_onnx/" |
| 87 | prefix3 = f"{SHERPA_ONNX_DIR}/windows/" | 90 | prefix3 = f"{SHERPA_ONNX_DIR}/windows/" |
| 91 | + prefix4 = f"{SHERPA_ONNX_DIR}/windows/sherpa_onnx-${version}.data/data/bin/" | ||
| 88 | 92 | ||
| 89 | lib_list = [] | 93 | lib_list = [] |
| 90 | for lib in libs: | 94 | for lib in libs: |
| 91 | - for prefix in [prefix1, prefix2, prefix3]: | 95 | + for prefix in [prefix1, prefix2, prefix3, prefix4]: |
| 92 | f = Path(prefix) / lib | 96 | f = Path(prefix) / lib |
| 93 | if f.is_file(): | 97 | if f.is_file(): |
| 94 | lib_list.append(str(f)) | 98 | lib_list.append(str(f)) |
| @@ -4,7 +4,7 @@ | @@ -4,7 +4,7 @@ | ||
| 4 | // Copyright 2023 Xiaomi Corporation | 4 | // Copyright 2023 Xiaomi Corporation |
| 5 | #ifndef SHERPA_ONNX_CSRC_TEXT_UTILS_H_ | 5 | #ifndef SHERPA_ONNX_CSRC_TEXT_UTILS_H_ |
| 6 | #define SHERPA_ONNX_CSRC_TEXT_UTILS_H_ | 6 | #define SHERPA_ONNX_CSRC_TEXT_UTILS_H_ |
| 7 | -#include <errno.h>. | 7 | +#include <errno.h> |
| 8 | #include <stdlib.h> | 8 | #include <stdlib.h> |
| 9 | 9 | ||
| 10 | #include <limits> | 10 | #include <limits> |
-
请 注册 或 登录 后发表评论