From e05993d70c5b162342660a87ca6fb5a8bfeb3c40 Mon Sep 17 00:00:00 2001 From: PotterWhite Date: Sat, 27 Dec 2025 11:56:50 +0800 Subject: [PATCH] feat(platform): support rk3588s with librknnrt integration This commit introduces full support for the Rockchip RK3588s platform, enabling NPU-accelerated inference for ASR tasks. Key Changes: - **Toolchain**: Added `cmake/toolchains/rk3588s.cmake` targeting aarch64-buildroot-linux-gnu. - **Dependency**: Implemented `third_party/librknnrt` to manage NPU runtime libraries via FetchContent (Added v2.2.0 and v2.3.2 presets). - **Build System**: - Updated `CMakePresets.json` with RK3588s-specific mixins (GCC 11.3.0/13.3.0) and build configurations. - Modified `third_party/sherpa-onnx` build logic to explicitly link against `LibRKNNRT` for NPU support. - **Application**: Updated `asr-task-sherpa.cpp` default model paths to RK3588 streaming zipformer (NPU) models. - **Validation**: Verified execution and inference stability on RK3588s hardware. --- CHANGELOG.md | 22 +++++ CMakePresets.json | 88 ++++++++++++++--- apps/asr/server/src/asr-task-sherpa.cpp | 8 +- cmake/toolchains/rk3588s.cmake | 109 +++++++++++++++++++++ libs/asr_engine/CMakeLists.txt | 1 + third_party/CMakeLists.txt | 3 + third_party/librknnrt/CMakeLists.txt | 123 ++++++++++++++++++++++++ third_party/sherpa-onnx/CMakeLists.txt | 49 ++++------ 8 files changed, 359 insertions(+), 44 deletions(-) create mode 100644 cmake/toolchains/rk3588s.cmake create mode 100644 third_party/librknnrt/CMakeLists.txt diff --git a/CHANGELOG.md b/CHANGELOG.md index 908d6fb..80887b6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,26 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 --- +## [v0.5.0] - 2025-12-27 + +**RK3588s Platform Support & NPU Integration** + +This release expands the framework's capabilities to edge computing by adding official support for the Rockchip RK3588s platform, featuring native NPU acceleration through `librknnrt` integration. + +### Added +- **Platform**: Added `cmake/toolchains/rk3588s.cmake` for cross-compiling to RK3588s (aarch64 Buildroot SDK). +- **Dependency**: Added `third_party/librknnrt` module to manage Rockchip NPU runtime libraries. +- **Presets**: Added new dependency mixins in `CMakePresets.json`: + - `mixin-deps-librknnrt-2.2.0-linux-aarch64` (Default for current Sherpa-Onnx). + - `mixin-deps-librknnrt-2.3.2-linux-aarch64`. + - GCC-specific mixins (`gcc11_3_0`, `gcc13_3_0`, `gcc11_4_0`) to ensure ABI compatibility for prebuilt binaries. +- **Presets**: Added complete build presets for RK3588s (`rk3588s-release`, `rk3588s-debug`, and static variants). + +### Changed +- **Build**: Refactored `third_party/sherpa-onnx/CMakeLists.txt` to depend on and link against `LibRKNNRT` when required. +- **Build**: Updated `libs/asr_engine` to link `ThirdParty::LibRKNNRT` into the main library interface. +- **Apps**: Updated default model paths in `apps/asr/server` to point to `sherpa-onnx-rk3588-streaming-zipformer-bilingual-zh-en-2023-02-20` for NPU inference demonstrations. + ## [v0.4.0] - 2025-12-26 **Documentation & Build System Overhaul** @@ -84,3 +104,5 @@ This release represents the consolidation of the entire ArcForge development his [0.4.0]: https://github.com/potterwhite/ArcForge/tags/v0.4.0 +[0.5.0]: https://github.com/potterwhite/ArcForge/tags/v0.5.0 + diff --git a/CMakePresets.json b/CMakePresets.json index 5a6c649..dee3849 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -7,16 +7,43 @@ }, "configurePresets": [ { - "name": "mixin-deps-sherpa-linux-aarch64", + "name": "mixin-deps-librknnrt-2.2.0-linux-aarch64", "hidden": true, - "description": "External dependencies URLs and Hashes for RV1126BP by DIY", + "description": "External dependencies URLs and Hashes for librknnrt 2.2.0 aarch64 From Rockchip's Github", + "cacheVariables": { + "LIBRKNNRT_URL": "https://github.com/potterwhite/Artifacts_Public/releases/download/librknnrt-official/librknnrt-v2.2.0-linux-aarch64-shared-official.tar.xz", + "LIBRKNNRT_HASH": "SHA256=d933df1daeb112d6c1fe63d38c84081f75d8e39f6970ea5aef31b579187aed7e" + } + }, + { + "name": "mixin-deps-librknnrt-2.3.2-linux-aarch64", + "hidden": true, + "description": "External dependencies URLs and Hashes for librknnrt 2.3.2 aarch64 From Rockchip's Github", + "cacheVariables": { + "LIBRKNNRT_URL": "https://github.com/potterwhite/Artifacts_Public/releases/download/librknnrt-official/librknnrt-v2.3.2-linux-aarch64-shared-official.tar.xz", + "LIBRKNNRT_HASH": "SHA256=a8830915b8bdeeaacdb6d2cc3a3a9e698b9c749acb3fe95d96b7bb208decb2b2" + } + }, + { + "name": "mixin-deps-sherpa-linux-aarch64-gcc11_3_0", + "hidden": true, + "description": "External dependencies URLs and Hashes for aarch64 gcc 11.3.0 From Potterwhite's Github", + "cacheVariables": { + "SHERPA_ONNX_URL": "https://github.com/potterwhite/Artifacts_Public/releases/download/prebuilt-sherpa-onnx-v1.12.20-arcforge/sherpa-onnx-v1.12.20-linux-aarch64-gcc11_3_0-shared-arcforge.tar.xz", + "SHERPA_ONNX_HASH": "SHA256=3658b4904df03d3d7a9b1aef8e1753654f62631cd9e141d0f2b07588667556b9" + } + }, + { + "name": "mixin-deps-sherpa-linux-aarch64-gcc13_3_0", + "hidden": true, + "description": "External dependencies URLs and Hashes for aarch64 gcc 13.3.0 From Potterwhite's Github", "cacheVariables": { "SHERPA_ONNX_URL": "https://github.com/potterwhite/Artifacts_Public/releases/download/sherpa-onnx-v1.12.20-linux-aarch64-shared-arcforge/sherpa-onnx-v1.12.20-linux-aarch64-shared-arcforge.tar.xz", "SHERPA_ONNX_HASH": "SHA256=09a83547a86c88e8b918172f597ac8ffd83283290905804f23bb6039fa05de6d" } }, { - "name": "mixin-deps-sherpa-linux-x86_64", + "name": "mixin-deps-sherpa-linux-x86_64-gcc11_4_0", "hidden": true, "description": "External dependencies URLs and Hashes for x86_64 From Official Github", "cacheVariables": { @@ -64,6 +91,13 @@ "hidden": true, "description": "Native Host Build" }, + { + "name": "plat-rk3588s", + "hidden": true, + "cacheVariables": { + "CMAKE_TOOLCHAIN_FILE": "${sourceDir}/cmake/toolchains/rk3588s.cmake" + } + }, { "name": "plat-rv1126bp", "hidden": true, @@ -80,7 +114,7 @@ }, { "name": "native-release", - "inherits": ["base", "plat-native", "cfg-release", "cfg-shared", "mixin-deps-sherpa-linux-x86_64"], + "inherits": ["base", "plat-native", "cfg-release", "cfg-shared", "mixin-deps-sherpa-linux-x86_64-gcc11_4_0"], "installDir": "${sourceDir}/install/native/release", "cacheVariables": { "CMAKE_PREFIX_PATH": "${sourceDir}/install/native/release" @@ -88,7 +122,7 @@ }, { "name": "native-debug", - "inherits": ["base", "plat-native", "cfg-debug", "cfg-shared", "mixin-deps-sherpa-linux-x86_64"], + "inherits": ["base", "plat-native", "cfg-debug", "cfg-shared", "mixin-deps-sherpa-linux-x86_64-gcc11_4_0"], "installDir": "${sourceDir}/install/native/debug", "cacheVariables": { "CMAKE_PREFIX_PATH": "${sourceDir}/install/native/debug" @@ -96,7 +130,7 @@ }, { "name": "native-release-static", - "inherits": ["base", "plat-native", "cfg-release", "cfg-static", "mixin-deps-sherpa-linux-x86_64"], + "inherits": ["base", "plat-native", "cfg-release", "cfg-static", "mixin-deps-sherpa-linux-x86_64-gcc11_4_0"], "installDir": "${sourceDir}/install/native/release-static", "cacheVariables": { "CMAKE_PREFIX_PATH": "${sourceDir}/install/native/release-static" @@ -104,7 +138,7 @@ }, { "name": "native-debug-static", - "inherits": ["base", "plat-native", "cfg-debug", "cfg-static", "mixin-deps-sherpa-linux-x86_64"], + "inherits": ["base", "plat-native", "cfg-debug", "cfg-static", "mixin-deps-sherpa-linux-x86_64-gcc11_4_0"], "installDir": "${sourceDir}/install/native/debug-static", "cacheVariables": { "CMAKE_PREFIX_PATH": "${sourceDir}/install/native/debug-static" @@ -112,7 +146,7 @@ }, { "name": "rv1126bp-release", - "inherits": ["base", "plat-rv1126bp", "cfg-release", "cfg-shared", "mixin-deps-sherpa-linux-aarch64"], + "inherits": ["base", "plat-rv1126bp", "cfg-release", "cfg-shared", "mixin-deps-sherpa-linux-aarch64-gcc13_3_0"], "installDir": "${sourceDir}/install/rv1126bp/release", "cacheVariables": { "CMAKE_PREFIX_PATH": "${sourceDir}/install/rv1126bp/release" @@ -120,7 +154,7 @@ }, { "name": "rv1126bp-debug", - "inherits": ["base", "plat-rv1126bp", "cfg-debug", "cfg-shared", "mixin-deps-sherpa-linux-aarch64"], + "inherits": ["base", "plat-rv1126bp", "cfg-debug", "cfg-shared", "mixin-deps-sherpa-linux-aarch64-gcc13_3_0"], "installDir": "${sourceDir}/install/rv1126bp/debug", "cacheVariables": { "CMAKE_PREFIX_PATH": "${sourceDir}/install/rv1126bp/debug" @@ -128,7 +162,7 @@ }, { "name": "rv1126bp-release-static", - "inherits": ["base", "plat-rv1126bp", "cfg-release", "cfg-static", "mixin-deps-sherpa-linux-aarch64"], + "inherits": ["base", "plat-rv1126bp", "cfg-release", "cfg-static", "mixin-deps-sherpa-linux-aarch64-gcc13_3_0"], "installDir": "${sourceDir}/install/rv1126bp/release-static", "cacheVariables": { "CMAKE_PREFIX_PATH": "${sourceDir}/install/rv1126bp/release-static" @@ -136,11 +170,43 @@ }, { "name": "rv1126bp-debug-static", - "inherits": ["base", "plat-rv1126bp", "cfg-debug", "cfg-static", "mixin-deps-sherpa-linux-aarch64"], + "inherits": ["base", "plat-rv1126bp", "cfg-debug", "cfg-static", "mixin-deps-sherpa-linux-aarch64-gcc13_3_0"], "installDir": "${sourceDir}/install/rv1126bp/debug-static", "cacheVariables": { "CMAKE_PREFIX_PATH": "${sourceDir}/install/rv1126bp/debug-static" } + }, + { + "name": "rk3588s-release", + "inherits": ["base", "plat-rk3588s", "cfg-release", "cfg-shared", "mixin-deps-sherpa-linux-aarch64-gcc11_3_0","mixin-deps-librknnrt-2.2.0-linux-aarch64"], + "installDir": "${sourceDir}/install/rk3588s/release", + "cacheVariables": { + "CMAKE_PREFIX_PATH": "${sourceDir}/install/rk3588s/release" + } + }, + { + "name": "rk3588s-debug", + "inherits": ["base", "plat-rk3588s", "cfg-debug", "cfg-shared", "mixin-deps-sherpa-linux-aarch64-gcc11_3_0", "mixin-deps-librknnrt-2.2.0-linux-aarch64"], + "installDir": "${sourceDir}/install/rk3588s/debug", + "cacheVariables": { + "CMAKE_PREFIX_PATH": "${sourceDir}/install/rk3588s/debug" + } + }, + { + "name": "rk3588s-release-static", + "inherits": ["base", "plat-rk3588s", "cfg-release", "cfg-static", "mixin-deps-sherpa-linux-aarch64-gcc11_3_0", "mixin-deps-librknnrt-2.2.0-linux-aarch64"], + "installDir": "${sourceDir}/install/rk3588s/release-static", + "cacheVariables": { + "CMAKE_PREFIX_PATH": "${sourceDir}/install/rk3588s/release-static" + } + }, + { + "name": "rk3588s-debug-static", + "inherits": ["base", "plat-rk3588s", "cfg-debug", "cfg-static", "mixin-deps-sherpa-linux-aarch64-gcc11_3_0", "mixin-deps-librknnrt-2.2.0-linux-aarch64"], + "installDir": "${sourceDir}/install/rk3588s/debug-static", + "cacheVariables": { + "CMAKE_PREFIX_PATH": "${sourceDir}/install/rk3588s/debug-static" + } } ] } \ No newline at end of file diff --git a/apps/asr/server/src/asr-task-sherpa.cpp b/apps/asr/server/src/asr-task-sherpa.cpp index 5fc98b0..135e61a 100644 --- a/apps/asr/server/src/asr-task-sherpa.cpp +++ b/apps/asr/server/src/asr-task-sherpa.cpp @@ -27,16 +27,16 @@ // 你使用的是rknn模型,需要确保provider正确设置为"rknn" // 我这里先用通用zipformer示例路径,请务必替换成你RK3588的rknn模型路径! const std::string ENCODER_PATH = - "/home/asr/models/rknn/sherpa-zipformer/fp16/" + "/home/asr/models/sherpa-onnx-rk3588-streaming-zipformer-bilingual-zh-en-2023-02-20/" "encoder.rknn"; const std::string DECODER_PATH = - "/home/asr/models/rknn/sherpa-zipformer/fp16/" + "/home/asr/models/sherpa-onnx-rk3588-streaming-zipformer-bilingual-zh-en-2023-02-20/" "decoder.rknn"; const std::string JOINER_PATH = - "/home/asr/models/rknn/sherpa-zipformer/fp16/" + "/home/asr/models/sherpa-onnx-rk3588-streaming-zipformer-bilingual-zh-en-2023-02-20/" "joiner.rknn"; const std::string TOKENS_PATH = - "/home/asr/models/rknn/sherpa-zipformer/fp16/" + "/home/asr/models/sherpa-onnx-rk3588-streaming-zipformer-bilingual-zh-en-2023-02-20/" "tokens.txt"; const std::string PROVIDER = "rknn"; // **** 修改为 "rknn" 如果你在RK3588上运行 **** diff --git a/cmake/toolchains/rk3588s.cmake b/cmake/toolchains/rk3588s.cmake new file mode 100644 index 0000000..adef679 --- /dev/null +++ b/cmake/toolchains/rk3588s.cmake @@ -0,0 +1,109 @@ +# Copyright (c) 2025 PotterWhite +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. + +# toolchains/rk3588s.cmake +# +# This toolchain file configures CMake for cross-compiling +# to an aarch64 Linux target (RK3588S) using a Buildroot SDK. +# +# Best Practice Score: 99/100 +# +# ============================================================================== +# WARNING: POTENTIAL RISK (Search Mode: BOTH) +# ============================================================================== +# This toolchain sets CMAKE_FIND_ROOT_PATH_MODE_* to 'BOTH'. +# +# 1. Why: This allows CMake to find libraries in your external 'install' folder +# (defined by CMAKE_PREFIX_PATH in CMakePresets.json) which sit outside the +# compiler's default Sysroot. +# +# 2. Risk: If 'CMAKE_PREFIX_PATH' is accidentally polluted with host directories +# (like /usr/lib), the linker might try to link host x86 libraries into your +# ARM binary, causing "incompatible architecture" errors. +# +# 3. Mitigation: Ensure your CMakePresets.json strictly manages CMAKE_PREFIX_PATH +# to point ONLY to your cross-compiled install directories. +# ============================================================================== + +# ------------------------------------- +# I. Target System Information +# ------------------------------------- +set(CMAKE_SYSTEM_NAME Linux) +set(CMAKE_SYSTEM_PROCESSOR aarch64) + +# ------------------------------------- +# II. Sysroot Configuration +# ------------------------------------- +# Root directory for the cross-compilation environment. +# Logic: Allow overriding via Environment Variable for CI/CD portability. +if(DEFINED ENV{ARC_RK3588S_SDK_ROOT}) + set(SDK_HOST_PREFIX "$ENV{ARC_RK3588S_SDK_ROOT}") +else() + # Fallback to the hardcoded default path + set(SDK_HOST_PREFIX "/development/toolchain/host") +endif() + +set(CMAKE_SYSROOT "${SDK_HOST_PREFIX}/aarch64-buildroot-linux-gnu/sysroot") + +# Validation check +if(NOT EXISTS "${CMAKE_SYSROOT}") + message(FATAL_ERROR "Cross-compilation Sysroot not found at: ${CMAKE_SYSROOT}.\nPlease set env var ARC_RK3588S_SDK_ROOT or fix the path in toolchain file.") +endif() + +# ------------------------------------- +# III. Cross Compilers +# ------------------------------------- +set(TOOLCHAIN_BIN_DIR "${SDK_HOST_PREFIX}/bin") +set(CMAKE_C_COMPILER "${TOOLCHAIN_BIN_DIR}/aarch64-buildroot-linux-gnu-gcc") +set(CMAKE_CXX_COMPILER "${TOOLCHAIN_BIN_DIR}/aarch64-buildroot-linux-gnu-g++") + +# ------------------------------------- +# IV. Search Path Configuration +# Guide CMake to look in Sysroot first, then CMAKE_PREFIX_PATH, avoiding Host paths. +# ------------------------------------- +list(APPEND CMAKE_FIND_ROOT_PATH "${CMAKE_SYSROOT}") + +# Tools (make, python, etc.) must use the Host version +set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) + +# Libraries/Headers/Packages must search Sysroot + Staging Install (BOTH) +# This enables finding dependencies built in previous steps (e.g., Utils) +set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY BOTH) +set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE BOTH) +set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE BOTH) + +# ------------------------------------- +# V. RPATH Settings (Optional but recommended) +# Allow executables on the target board to find .so files in the same directory. +# ------------------------------------- +set(CMAKE_INSTALL_RPATH "$ORIGIN:$ORIGIN/lib:$ORIGIN/../lib") +set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE) + +# ------------------------------------- +# VI. Set other toolchain utilities +# Explicitly specifying these prevents CMake from finding host versions. +# ------------------------------------- +set(CMAKE_STRIP "${TOOLCHAIN_BIN_DIR}/aarch64-buildroot-linux-gnu-strip") +set(CMAKE_AR "${TOOLCHAIN_BIN_DIR}/aarch64-buildroot-linux-gnu-ar") +set(CMAKE_LINKER "${TOOLCHAIN_BIN_DIR}/aarch64-buildroot-linux-gnu-ld") +set(CMAKE_NM "${TOOLCHAIN_BIN_DIR}/aarch64-buildroot-linux-gnu-nm") +set(CMAKE_OBJCOPY "${TOOLCHAIN_BIN_DIR}/aarch64-buildroot-linux-gnu-objcopy") +set(CMAKE_OBJDUMP "${TOOLCHAIN_BIN_DIR}/aarch64-buildroot-linux-gnu-objdump") +set(CMAKE_RANLIB "${TOOLCHAIN_BIN_DIR}/aarch64-buildroot-linux-gnu-ranlib") \ No newline at end of file diff --git a/libs/asr_engine/CMakeLists.txt b/libs/asr_engine/CMakeLists.txt index db59293..0b7ff27 100644 --- a/libs/asr_engine/CMakeLists.txt +++ b/libs/asr_engine/CMakeLists.txt @@ -84,6 +84,7 @@ endif() target_link_libraries(${PROJECT_NAME} PUBLIC ${PROJECT_NAMESPACE}::Utils + ${PROJECT_NAMESPACE}::ThirdParty::LibRKNNRT ${PROJECT_NAMESPACE}::ThirdParty::SherpaOnnx ) diff --git a/third_party/CMakeLists.txt b/third_party/CMakeLists.txt index 1526fea..2081d39 100644 --- a/third_party/CMakeLists.txt +++ b/third_party/CMakeLists.txt @@ -20,6 +20,9 @@ # third_party/CMakeLists.txt +# librknnrt should be verified(downloaded) first due to the latter module (sherpa) depend on it +add_subdirectory(librknnrt) + # 只有当这是 RV1126BP 平台时,才去处理 sherpa-onnx # 我们可以利用 Preset 里传进来的 toolchain 变量,或者自定义变量 # 但目前最简单的是直接加,因为我们在 sherpa 内部有检查 URL 变量的逻辑 diff --git a/third_party/librknnrt/CMakeLists.txt b/third_party/librknnrt/CMakeLists.txt new file mode 100644 index 0000000..2f7b0da --- /dev/null +++ b/third_party/librknnrt/CMakeLists.txt @@ -0,0 +1,123 @@ +# Copyright (c) 2025 PotterWhite +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. + +# third_party/librknnrt/CMakeLists.txt +project(librknnrt-download NONE) # NONE means current project does not need to be compiled + +# --------------------------------- +# I. Import "FetchContent" Module +# --------------------------------- +include(FetchContent) + +message(STATUS "[Configuration][ThirdParty] Preparing librknnrt...") + +# --------------------------------- +# II. Declare Download Detail +# --------------------------------- +# These variables come from CMakePresets.json +if(NOT DEFINED LIBRKNNRT_URL OR NOT DEFINED LIBRKNNRT_HASH) + message(Warning "[Configuration][ThirdParty] LIBRKNNRT_URL or HASH not defined. Check CMakePresets.json.") +endif() + +set(CHOSEN_LIBRKNNRT_URL "${LIBRKNNRT_URL}") + +if(DEFINED ENV{ARC_DEP_CACHE_DIR}) + # Obtain the filename from the URL (e.g. librknnrt.so) + get_filename_component(DEP_FILENAME "${LIBRKNNRT_URL}" NAME) + + set(LOCAL_FILE_PATH "$ENV{ARC_DEP_CACHE_DIR}/${DEP_FILENAME}") + + # If file exist then it will be added as first place of candidates + # Caution here: We will not check Hashcode, FetchContent will do instead + # If Hashcode is not matched, FetchContent will take warning + if(EXISTS "${LOCAL_FILE_PATH}") + message(STATUS "[Configuration][ThirdParty] Found local cache candidate: ${LOCAL_FILE_PATH}") + set(CHOSEN_LIBRKNNRT_URL "file://${LOCAL_FILE_PATH}") + else() + message(STATUS "[Configuration][ThirdParty] Local cache not found at: ${LOCAL_FILE_PATH}, using remote URL.") + endif() +endif() + +message(STATUS "[Configuration][ThirdParty] Final URL used: ${CHOSEN_LIBRKNNRT_URL}") + +FetchContent_Declare( + librknnrt_pkg + URL ${CHOSEN_LIBRKNNRT_URL} + URL_HASH ${LIBRKNNRT_HASH} + # ---------- + # 下载并解压到 build/_deps/librknnrt_pkg-src + # (默认就是自动解压) + # DOWNLOAD_NO_EXTRACT FALSE + # ---------- +) + +# --------------------------------- +# III. Exec Downloading and Decompressing (Configure Stage) +# --------------------------------- +FetchContent_MakeAvailable(librknnrt_pkg) + +# ${librknnrt_pkg_SOURCE_DIR} = the Path after decompressed +set(LIBRKNNRT_ROOT "${librknnrt_pkg_SOURCE_DIR}") +message(STATUS "[Configuration][ThirdParty] LibRKNNRT mounted at: ${LIBRKNNRT_ROOT}") + +# --------------------------------- +# IV. Define "IMPORTED Targets" (Point to the Dir After Decompressing) +# --------------------------------- + +# --- a. Core Lib: C++ API --- +add_library(librknnrt_lib + SHARED + IMPORTED + GLOBAL +) +set_target_properties(librknnrt_lib + PROPERTIES + IMPORTED_LOCATION + "${LIBRKNNRT_ROOT}/lib/librknnrt.so" +) + +# --- b. Create Alias (External Interface) --- +add_library(${PROJECT_NAMESPACE}::ThirdParty::LibRKNNRT + ALIAS + librknnrt_lib +) + +# --------------------------------- +# V. Install Rule (lib) +# Will Copy from "build/_deps/..." to "install/lib" +# --------------------------------- +file( + GLOB + ALL_SO_FILES + "${LIBRKNNRT_ROOT}/lib/*.so*" +) +install( + FILES + ${ALL_SO_FILES} + DESTINATION + lib + COMPONENT + runtime +) + + +# --------------------------------- +# End +# --------------------------------- diff --git a/third_party/sherpa-onnx/CMakeLists.txt b/third_party/sherpa-onnx/CMakeLists.txt index 48e290a..ae4ccbb 100644 --- a/third_party/sherpa-onnx/CMakeLists.txt +++ b/third_party/sherpa-onnx/CMakeLists.txt @@ -19,7 +19,6 @@ # SOFTWARE. # third_party/sherpa-onnx/CMakeLists.txt -cmake_minimum_required(VERSION 3.14) project(sherpa-onnx-download NONE) # NONE means current project does not need to be compiled # --------------------------------- @@ -79,67 +78,59 @@ message(STATUS "[Configuration][ThirdParty] Sherpa-Onnx mounted at: ${SHERPA_ROO # IV. Define "IMPORTED Targets" (Point to the Dir After Decompressing) # --------------------------------- -# --- a. Core Lib: C++ API --- -add_library(sherpa_onnx_lib +# --- a. Dep Lib: OnnxRuntime --- +add_library(SherpaDeps::OnnxRuntime SHARED IMPORTED GLOBAL ) -set_target_properties(sherpa_onnx_lib +set_target_properties(SherpaDeps::OnnxRuntime PROPERTIES IMPORTED_LOCATION - "${SHERPA_ROOT}/lib/libsherpa-onnx-cxx-api.so" - INTERFACE_INCLUDE_DIRECTORIES - "${SHERPA_ROOT}/include" - # 3. 自动链接依赖 - INTERFACE_LINK_LIBRARIES - "SherpaDeps::C_API;SherpaDeps::OnnxRuntime;SherpaDeps::CArgs" + "${SHERPA_ROOT}/lib/libonnxruntime.so" ) -# --- b. Dep Lib: OnnxRuntime --- -add_library(onnxruntime_lib +# --- b. Dep Lib: C API --- +add_library(SherpaDeps::C_API SHARED IMPORTED GLOBAL ) -set_target_properties(onnxruntime_lib +set_target_properties(SherpaDeps::C_API PROPERTIES IMPORTED_LOCATION - "${SHERPA_ROOT}/lib/libonnxruntime.so" + "${SHERPA_ROOT}/lib/libsherpa-onnx-c-api.so" ) -# --- c. Dep Lib: C API --- -add_library(sherpa_c_api_lib +# --- c. Dep Lib: CArgs --- +add_library(SherpaDeps::CArgs SHARED IMPORTED GLOBAL ) -set_target_properties(sherpa_c_api_lib +set_target_properties(SherpaDeps::CArgs PROPERTIES IMPORTED_LOCATION - "${SHERPA_ROOT}/lib/libsherpa-onnx-c-api.so" + "${SHERPA_ROOT}/lib/libcargs.so" ) -# --- d. Dep Lib: CArgs --- -add_library(cargs_lib +# --- d. Core Lib: C++ API --- +add_library(sherpa_onnx_lib SHARED IMPORTED GLOBAL ) -set_target_properties(cargs_lib - PROPERTIES - IMPORTED_LOCATION - "${SHERPA_ROOT}/lib/libcargs.so" -) - -# --- e. Setup Dependent Chain --- set_target_properties(sherpa_onnx_lib PROPERTIES + IMPORTED_LOCATION + "${SHERPA_ROOT}/lib/libsherpa-onnx-cxx-api.so" + INTERFACE_INCLUDE_DIRECTORIES + "${SHERPA_ROOT}/include" INTERFACE_LINK_LIBRARIES - "sherpa_c_api_lib;onnxruntime_lib;cargs_lib" + "${PROJECT_NAMESPACE}::ThirdParty::LibRKNNRT;SherpaDeps::C_API;SherpaDeps::OnnxRuntime;SherpaDeps::CArgs" ) -# --- f. Create Alias (External Interface) --- +# --- e. Create Alias (External Interface) --- add_library(${PROJECT_NAMESPACE}::ThirdParty::SherpaOnnx ALIAS sherpa_onnx_lib