diff --git a/CHANGELOG.md b/CHANGELOG.md index b369f33..e854e3a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 --- +## v0.5.2 (2025-12-30) + +### 📚 Documentation +- **Structure**: Major refactor of the `docs/` folder. Content is now split into `en/` and `zh-cn/` subdirectories to support better internationalization. +- **New Guide**: Added **"How to Add Support for a New SoC"** (`ADD_NEW_SOC.md`). This guide details the 5-step process for porting ArcForge to new embedded platforms (e.g., RK3588), covering toolchains, `.env` configuration, and dependency management. +- **Deep Dive**: Added **"ArcForge Build System Explained"** (`BUILD_SYSTEM.md`), featuring Mermaid diagrams to visualize the Modern CMake architecture, dependency topology, and DSL logic. +- **README**: Updated the main README with high-contrast architecture diagrams, improved Quick Start instructions, and correct links to the new documentation paths. + +### 🧹 Refactor +- Removed legacy documentation files in the root `docs/` folder in favor of the new localized structure. + + ## [v0.5.1] - 2025-12-27 ### 🧹 Refactor & Style (重构与规范) diff --git a/README.md b/README.md index 8de0ece..40841ee 100644 --- a/README.md +++ b/README.md @@ -1,128 +1,142 @@
-

ArcForge ASR SDK

-

High-Performance C++ Automatic Speech Recognition Inference Software

+

ArcForge Automatic Speech Recognition (ASR) SDK

+

High-Performance Embedded ASR Inference Framework based on Modern CMake

- Project Banner

C++ Standard Platform - Design Philosophy - Build System + Build System

- English | 简体中文 -

- -

- 🚀 Quick Start • - ⌨️ Command Cheatsheet • - 📂 Output Structure + English | 简体中文

--- -> ### ⚠️ Cross-Compilation Notice -> **Env Configuration is Critical.** This project relies heavily on the `.env` file to locate the cross-compilation toolchain. If you encounter `gcc not found` or similar errors, please check if your `.env` configuration is loaded correctly. +### 📖 Introduction + +ArcForge is a C++ ASR inference framework designed specifically for **edge computing**. +It integrates the `sherpa-zipformer` model, implementing a complete pipeline from low-level NPU binding to high-level Client/Server calls. The standout feature of this project is **"Architectural Transparency"** — we fully disclose and deconstruct the complete industrial-grade Modern CMake build logic. + +### 🏗️ Architecture + +We provide not just the source code, but also a **fully visualized** build system. -### ✨ Core Features +> **🔍 Deep Dive**: [**ArcForge Build System Explained (BUILD_SYSTEM.md)**](docs/en/BUILD_SYSTEM.md) +> *(Click the link above to view the Build Lifecycle, Core DSL Logic, and Detailed Dependency Topology)* -- **⚡ High-Performance Inference**: Currently uses the `sherpa-zipformer` model for ASR inference (tested and verified); designed as an integrated ASR inference engine for edge computing. -- **🛠️ Modern CMake Architecture**: Adopts namespace isolation (`Namespace::Lib`, e.g., `Arcforge::Utils`). Automatically renames artifacts during the build process (e.g., `libarcforge_utils.so`) to ensure symbol safety. -- **📦 Dependency Isolation**: Decouples the local environment from the source code via `.env`. Supports offline caching and automatic downloading of third-party dependencies (e.g., sherpa-onnx). -- **🔌 Client/Server Ready**: Built-in complete C/S architecture examples. The Server includes NPU binding logic, while the Client provides standard calling interfaces. +**Core Module Overview:** + +```mermaid +graph LR + %% ========================================== + %% High Contrast Styles + %% Strategy: Dark background + White text + Bright borders + %% ========================================== + classDef appNode fill:#0d47a1,stroke:#90caf9,stroke-width:2px,color:#fff; + classDef libNode fill:#e65100,stroke:#ffcc80,stroke-width:2px,color:#fff; + classDef thirdNode fill:#333333,stroke:#ffffff,stroke-width:2px,color:#fff,stroke-dasharray: 5 5; + + subgraph Apps [Application Layer] + direction TB + Client(ASR Client):::appNode + Server(ASR Server):::appNode + end + + subgraph Libs [Core Library Layer] + direction LR + Engine[ASREngine]:::libNode --> Net[Network]:::libNode + Net --> Utils[Utils]:::libNode + end + + subgraph 3rd [Dependency Layer] + direction LR + Engine -.-> Sherpa[SherpaOnnx]:::thirdNode + Sherpa -.-> RKNN[RKNNRT]:::thirdNode + end + + Client --> Engine + Server --> Engine +``` --- ### 🚀 Quick Start -This project uses Modern CMake for build management and isolates local environment differences via the `.env` file. - -#### Step 1: Configuration +This project relies heavily on `.env` for environment isolation. Please strictly follow the steps below: -Before compiling, you must create a local configuration file. This file is git-ignored and used to adapt to different developers' local paths. +#### 1. Environment Configuration (Required) ```bash -# 1. Copy config file from template +# 1. Copy the configuration template cp .env.example .env -# 2. Edit .env file, fill in local SDK and cache paths +# 2. Edit the configuration file +# ARC_RV1126BP_SDK_ROOT: Path to your cross-compilation toolchain root (Required) +# ARC_DEP_CACHE_DIR: Path to third-party library cache (Recommended for faster builds) vim .env ``` -**Key Configuration Items:** +#### 2. Build -* `ARC_RV1126BP_SDK_ROOT`: **(Required)** The absolute path to the cross-compilation toolchain (Buildroot SDK) on the host machine. -* `ARC_DEP_CACHE_DIR`: **(Optional)** Local cache directory for third-party dependencies (e.g., `sherpa-onnx`). - * If this path is configured and the corresponding tarball exists, the build system will prefer the local file (offline mode). - * If not configured or the file is missing, it will automatically download from GitHub Releases. +Use the `build.sh` script to drive CMake Presets: -#### Step 2: Build +```bash +# [Recommended] Clean Build (RV1126 Release) +./build.sh cb rv1126bp -The project provides a unified build script `build.sh`, which encapsulates the CMake Presets logic. +# [Dev] Incremental Build (Compile only modified parts) +./build.sh build rv1126bp -**Basic Syntax:** -```bash -./build.sh [Platform] [BuildType] +# [Debug] Native Verification (x86 Debug) +./build.sh cb native debug ``` -**Common Workflow Examples:** - -1. **Clean Build**: Suitable for first-time builds or after environment changes. - ```bash - ./build.sh cb rv1126bp - ``` -2. **Incremental Build**: For debugging after code modifications. - ```bash - ./build.sh build rv1126bp - ``` -3. **Native Test**: Verify business logic on an x86 host. - ```bash - ./build.sh cb native - ``` - --- ### ⌨️ Command Cheatsheet -| Action | Command | Description | +| Scenario | Command | Description | | :--- | :--- | :--- | -| **Release Build** | | | -| Clean Build (RV1126) | `./build.sh cb rv1126bp` | Clean and compile Release version, includes SDK linking | -| Incremental Build | `./build.sh build rv1126bp` | Compile only modified files; fastest speed | -| **Debug Build** | | | -| Debug Mode (RV1126) | `./build.sh cb rv1126bp debug` | Enable debug symbols, unoptimized version | -| Native Debug (x86) | `./build.sh cb native debug` | Compile using host GCC/Clang, used for logic verification | -| **Maintenance** | | | -| Clean All | `./build.sh cleanall` | Delete all build directories and install artifacts | +| **Production** | `./build.sh cb rv1126bp` | Clean & Build Release version (-O3) | +| **Debugging** | `./build.sh cb rv1126bp debug` | Build Debug version (with symbols, -Og) | +| **Cleanup** | `./build.sh cleanall` | Remove `build/` and `install/` directories | +| **Git Clean** | `git clean -fdx -e .env` | **Caution**: Remove all untracked files (keeps config) | --- -### 📂 Output Structure +### 📂 Output Directory -Upon build completion, all artifacts will be installed to the `install/` directory, following the renaming rules (`libarcforge_*.so`): +After building, artifacts are located in the `install/` directory. We automatically handle renaming and RPATH settings, so they are ready for deployment: ```text -install/ -└── rv1126bp/ - └── debug/ - ├── bin/ - │ ├── ArcForge_ASR_Client # Client Application - │ └── ArcForge_ASR_Server # Server Application (with NPU binding) - ├── lib/ - │ ├── libarcforge_core.so # Core Business Lib (was Arcforge::Core) - │ ├── libarcforge_utils.so # Utils Lib (was Arcforge::Utils) - │ └── libsherpa-onnx*.so # 3rd-party Dependency Lib - └── include/ # SDK Headers +install/rv1126bp/release/ +├── bin/ +│ ├── ArcForge_ASR_Client # Client test application +│ └── ArcForge_ASR_Server # Server main application +└── lib/ + ├── libarcforge_asrengine.so # Core engine library + ├── libarcforge_network.so # Network library + ├── libarcforge_utils.so # Basic utilities library + └── libsherpa-onnx*.so # Dependency library ``` -### ⚠️ Limitations & Roadmap -- **Network & Caching**: - - The build system defaults to attempting to pull third-party dependencies (e.g., `sherpa-onnx`) from GitHub. - - Given potential network instability, it is **recommended** to configure `ARC_DEP_CACHE_DIR` in `.env` and pre-populate it with dependency packages to ensure build stability ("Offline-First" mode). Please refer to `CMakePresets.json` for exact package URLs. +### 🧩 Supporting New Platforms + +Currently, only RV1126BP and RK3588S platforms are supported. To support a new platform, there are two suggested methods: + +#### 1. Add it yourself + +Please read this tutorial carefully: + +> **🔍 Deep Dive**: [**How to Add Support for a New SoC in ArcForge**](./ADD_NEW_SOC_ZH_CN.md) +> *(Click the link above to view detailed steps guiding you through supporting a new SoC)* + +#### 2. Submit an issue to me \ No newline at end of file diff --git a/docs/ADD_NEW_SOC.md b/docs/ADD_NEW_SOC.md deleted file mode 100644 index 7005951..0000000 --- a/docs/ADD_NEW_SOC.md +++ /dev/null @@ -1,139 +0,0 @@ -Here is the updated documentation. I have added **Step 3** specifically for managing the `sherpa-onnx` prebuilt binaries and hashes, while keeping the rest of the structure intact. - ---- - -# How to Add Support for a New SoC - -This guide outlines the steps to add support for a new System-on-Chip (SoC) or Cross-Compilation target in the ArcForge build system. - -**Old Way:** Create a toolchain file and hardcode absolute paths. -**New Way:** Create a toolchain file (using Env Vars), update `CMakePresets.json`, and configure your environment. - ---- - -## Step 1: Create the Toolchain File - -We strictly follow the "99/100 Best Practice" template. Do not start from scratch; copy an existing configuration. - -1. **Copy** the template: - ```bash - cp cmake/toolchains/rv1126bp.cmake cmake/toolchains/.cmake - # Example: cp cmake/toolchains/rv1126bp.cmake cmake/toolchains/rk3588.cmake - ``` - -2. **Edit** the new file (`cmake/toolchains/rk3588.cmake`): - * **Modify Processor**: Update `CMAKE_SYSTEM_PROCESSOR` (e.g., `aarch64`, `arm`, `riscv64`). - * **Define Env Var**: Change the environment variable name used to find the SDK. - * *Change*: `if(DEFINED ENV{RV1126BP_SDK_ROOT})` - * *To*: `if(DEFINED ENV{RK3588_SDK_ROOT})` - * **Update Paths**: Adjust the internal layout variables (like `TOOLCHAIN_BIN_DIR`) to match your specific SDK structure. - * **Update Compilers**: Update the filenames for `gcc`, `g++`, `strip`, etc. - -**Key Rule**: Never hardcode absolute paths (like `/home/user/sdk`). Always rely on the `$ENV{...}` variable or a fallback default. - ---- - -## Step 2: Configure Your Environment - -Since the toolchain file now relies on environment variables, you must define where the SDK lives on your specific machine. - -1. **Temporary (Current Shell)**: - ```bash - export RK3588_SDK_ROOT=/opt/rk3588_sdk/host - ``` - -2. **Permanent (Recommended)**: - Add the line above to your `~/.bashrc` or `~/.zshrc`. - ---- - -## Step 3: Configure External Dependencies (Sherpa-Onnx) - -You must provide the download URL and SHA256 Hash for the prebuilt `sherpa-onnx` binaries specific to your new SoC. - -1. **Prepare the Tarball**: Upload your prebuilt `sherpa-onnx` tarball (containing `lib/` and `include/`) to a hosted location (e.g., GitHub Releases). -2. **Get the Hash**: Calculate the SHA256 hash of the file: `sha256sum filename.tar.xz`. -3. **Create a Dependency Mixin**: In `CMakePresets.json`, add a new entry under `configurePresets` to define these variables. - -```json - { - "name": "mixin-deps-rk3588", - "hidden": true, - "description": "External dependencies URLs and Hashes for RK3588", - "cacheVariables": { - "SHERPA_ONNX_URL": "https://github.com/.../sherpa-onnx-v1.12.20-rk3588.tar.xz", - "SHERPA_ONNX_HASH": "SHA256=a1b2c3d4e5..." - } - }, -``` - ---- - -## Step 4: Register in CMakePresets.json - -Now define the platform configuration and the final build targets, inheriting the dependency mixin you created above. - -Open `CMakePresets.json` and add entries to the `configurePresets` array. - -### 4.1. Add the "Platform" Preset (Hidden) -This links the logical name to the toolchain file. - -```json - { - "name": "plat-rk3588", - "hidden": true, - "description": "Rockchip RK3588 Target", - "cacheVariables": { - "CMAKE_TOOLCHAIN_FILE": "${sourceDir}/cmake/toolchains/rk3588.cmake" - } - }, -``` - -### 4.2. Add Concrete Build Presets -Define the actual build targets. -**Important**: You must inherit the dependency mixin (`mixin-deps-rk3588`) here. - -```json - { - "name": "rk3588-release", - "inherits": ["base", "plat-rk3588", "mixin-deps-rk3588", "cfg-release", "cfg-shared"], - "installDir": "${sourceDir}/install/rk3588/release", - "cacheVariables": { - "CMAKE_PREFIX_PATH": "${sourceDir}/install/rk3588/release" - } - }, - { - "name": "rk3588-debug", - "inherits": ["base", "plat-rk3588", "mixin-deps-rk3588", "cfg-debug", "cfg-shared"], - "installDir": "${sourceDir}/install/rk3588/debug", - "cacheVariables": { - "CMAKE_PREFIX_PATH": "${sourceDir}/install/rk3588/debug" - } - } -``` - ---- - -## Step 5: Verify and Build - -1. **Check Visibility**: - Run the interactive build script or list presets to see if your new SoC appears. - ```bash - ./build.sh list - ``` - *You should see `rk3588-release` and `rk3588-debug` in the list.* - -2. **Run Build**: - ```bash - ./build.sh cb rk3588-release - ``` - ---- - -## Summary Checklist - -- [ ] **Toolchain**: Created `cmake/toolchains/xxx.cmake` (Copied from template). -- [ ] **Env Var**: Updated the specific `ENV{XXX_SDK_ROOT}` in the toolchain file & exported it in shell. -- [ ] **Deps**: Added `mixin-deps-xxx` in `CMakePresets.json` with valid `SHERPA_ONNX_URL` and `HASH`. -- [ ] **Presets**: Added `plat-xxx` and `xxx-release` (inheriting `mixin-deps-xxx`). -- [ ] **Sync**: Ensured `installDir` matches `CMAKE_PREFIX_PATH` in the preset. \ No newline at end of file diff --git a/docs/BUILD_SYSTEM.md b/docs/BUILD_SYSTEM.md deleted file mode 100644 index b7c8fbc..0000000 --- a/docs/BUILD_SYSTEM.md +++ /dev/null @@ -1,124 +0,0 @@ - -# ArcForge 构建系统架构与集成指南 - -本文档记录了 ArcForge 项目的构建系统设计原则、模块化规范以及集成开发指南。 - -## 1. 设计哲学 - -本项目采用 **Mono-repo** 结构,但构建逻辑高度解耦。核心设计原则如下: - -* **单一事实来源 (Single Source of Truth)**:`build.sh` 仅作为环境配置与启动器,所有构建依赖、顺序、产物规则完全由 CMake 内部逻辑(DAG)控制。 -* **源码外构建 (Out-of-Source Build)**:构建目录结构严格镜像源码目录,互不干扰。临时文件隔离在 `build/` 目录下,禁止污染源码树。 -* **统一交付区 (Staging Area)**:所有模块(Lib/Bin/Headers)编译后统一安装至 `build/install`,模拟最终文件系统布局。 -* **标准导出 (Standard Export)**:库文件通过 CMake `EXPORT` 机制生成标准配置文件,支持 `find_package` 索引与带命名空间的引用。 - -## 2. 构建流程详解 - -### 2.1 启动器 (`build.sh`) -脚本职责被严格限制为“点火”: -1. 解析参数(Platform, Debug/Release)。 -2. 设置工具链路径 (`CMAKE_TOOLCHAIN_FILE`)。 -3. 定义构建根目录 (`-B build`) 与源码入口 (`-S .`)。 -4. 触发 `cmake` 配置与 `make` 构建。 - -### 2.2 依赖管理与头文件路径 -为解决开发阶段与安装阶段路径不一致的问题,所有模块的 `CMakeLists.txt` 均采用生成器表达式定义头文件路径: - -```cmake -target_include_directories(TargetName PUBLIC - # 编译阶段:直接读取源码目录下的 include - $ - # 安装阶段/外部引用:读取安装目录下的 include - $ -) -``` -此机制确保了模块间(如 Network 依赖 Utils)在构建时无需先执行 `make install` 即可正确找到头文件。 - -## 3. 模块开发规范 - -新增模块需遵循以下 CMake 编写规范,以保证自动化集成。 - -### 3.1 库命名与输出 -* **逻辑目标 (Logical Target)**:CMake 内部使用的名称,如 `Utils`。保持简洁,便于内部 `target_link_libraries`。 -* **物理文件名 (Physical Output)**:通过 `OUTPUT_NAME` 属性增加前缀,避免系统级命名冲突。 - -**示例 (`libs/utils/CMakeLists.txt`):** -```cmake -add_library(Utils SHARED ...) - -# 生成 libArcForge_Utils.so,但内部引用依然叫 Utils -set_target_properties(Utils - PROPERTIES - OUTPUT_NAME - "ArcForge_Utils" -) -``` - -### 3.2 安装与导出 (Export) -必须显式定义安装规则,并关联到 `EXPORT` 集合。禁止在 `src/` 子目录下编写 `install` 规则,所有安装逻辑收敛至模块顶层。 - -```cmake -install(TARGETS Utils - EXPORT UtilsTargets # 注册到导出集 - LIBRARY DESTINATION lib # .so 路径 - ARCHIVE DESTINATION lib # .a 路径 - RUNTIME DESTINATION bin # 可执行文件路径 -) - -# 头文件统一安装 -install(DIRECTORY include/ DESTINATION include) -``` - -### 3.3 命名空间 (Namespace) -为防止符号冲突,所有导出的库在安装阶段自动附加命名空间 `ArcForge::`。 - -```cmake -install(EXPORT UtilsTargets - FILE "ArcForge_UtilsTargets.cmake" - NAMESPACE "ArcForge::" # 关键设计 - DESTINATION "lib/cmake/Utils" -) -``` - -## 4. 集成指南 (如何使用库) - -### 4.1 内部模块依赖 -在同一 Mono-repo 下开发其他模块(如 `libs/network`)时,直接链接逻辑目标名称: - -```cmake -# Network 依赖 Utils -target_link_libraries(Socket PUBLIC Utils) -``` - -### 4.2 外部项目集成 (或 SDK 使用) -当 `build/install` 目录被打包作为 SDK 发布给客户或第三方应用使用时,需使用标准的 CMake 导入方式: - -1. **查找包**: - ```cmake - # CMake 会在 lib/cmake/Utils 下查找 ArcForge_UtilsTargets.cmake - find_package(Utils REQUIRED) - ``` - -2. **链接** (必须带命名空间): - ```cmake - # 使用 ArcForge:: 前缀,明确这是来自 ArcForge 的库 - target_link_libraries(MyApp PRIVATE ArcForge::Utils) - ``` - -## 5. 常用维护命令 - -### 清理构建环境 -若需彻底清理构建产物(推荐 git 提交前执行): -```bash -# 方式一:Git 清理 (推荐,需小心未跟踪文件) -git clean -fdx -e .vscode - -# 方式二:Find 清理 (仅删除 CMake 临时文件,保留 build 目录结构) -find . -name "CMakeCache.txt" -o -name "CMakeFiles" -exec rm -rf {} + -``` - -### 切换构建类型 -```bash -./build.sh cb rv1126bp debug # 交叉编译 Debug 版 (带符号表,无优化) -./build.sh cb rv1126bp release # 交叉编译 Release 版 (O3 优化) -``` \ No newline at end of file diff --git a/docs/README_ZH_CN.md b/docs/README_ZH_CN.md deleted file mode 100644 index 12d56e8..0000000 --- a/docs/README_ZH_CN.md +++ /dev/null @@ -1,131 +0,0 @@ - - -
-

ArcForge 自动语音识别(ASR)软件开发包

-

高性能C++ 自动语音识别模型推理

-
- -

- - Project Banner -

- -

- C++ Standard - Platform - Design Philosophy - Build System -

- -

- English | 简体中文 -

- -

- 🚀 快速上手 • - ⌨️ 构建命令速查 • - 📂 产物说明 -

- ---- - -> ### ⚠️ 交叉编译注意事项(Cross-Compilation Notice) -> **Env Configuration is Critical.** 本项目强依赖 `.env` 文件来定位交叉编译工具链。如果遇到 `gcc not found` 或类似错误,请直接检查你的 `.env` 配置是否正确加载。 - -### ✨ 核心功能(Core Features) - -- **⚡ 高性能推理(High-Performance Inference)**: 目前代码使用 `sherpa-zipformer` 模型进行ASR推理,并测试通过,是专为边缘计算进行整合的 ASR 推理引擎。 -- **🛠️ 现代CMake架构(Modern CMake Architecture)**: 采用命名空间隔离(`Namespace::Lib` 如 `Arcforge::Utils`),构建时自动重命名产物(如 `libarcforge_utils.so`),确保符号安全。 -- **📦 依赖隔离(Dependency Isolation)**: 通过 `.env` 实现本地环境与源码解耦,支持第三方依赖(如 sherpa-onnx)的离线缓存与自动下载。 -- **🔌 CS应用程序范例(Client/Server Ready)**: 内置完整的 C/S 架构示例,服务端包含 NPU 绑定逻辑,客户端提供标准调用接口。 - ---- - -### 🚀 快速上手 (Quick Start) - -本项目采用 Modern CMake 管理构建,并通过 `.env` 文件隔离本地环境差异。 - -#### Step 1: 环境配置 (Configuration) - -在开始编译前,必须建立本地配置文件。该文件已被 git 忽略,用于适配不同开发者的本地路径。 - -```bash -# 1. 从模板复制配置文件 -cp .env.example .env - -# 2. 编辑 .env 文件,填入本地 SDK 和缓存路径 -vim .env -``` - -**关键配置项说明:** - -* `ARC_RV1126BP_SDK_ROOT`: **(必填)** 交叉编译工具链(Buildroot SDK)在宿主机上的绝对路径。 -* `ARC_DEP_CACHE_DIR`: **(可选)** 第三方依赖包(如 `sherpa-onnx`)的本地缓存目录。 - * 若配置该路径且目录下存在对应 tarball,构建系统将优先使用本地文件(离线模式)。 - * 若未配置或文件不存在,将自动从 GitHub Release 下载。 - -#### Step 2: 编译构建 (Build) - -项目提供统一构建脚本 `build.sh`,封装了 CMake Presets 逻辑。 - -**基础语法:** -```bash -./build.sh [Platform] [BuildType] -``` - -**常用场景流程:** - -1. **全量构建 (Clean Build)**: 适用于首次构建或环境变更后。 - ```bash - ./build.sh cb rv1126bp - ``` -2. **开发调试 (Incremental)**: 修改代码后的增量编译。 - ```bash - ./build.sh build rv1126bp - ``` -3. **本机测试 (Native)**: 在 x86 主机上验证业务逻辑。 - ```bash - ./build.sh cb native - ``` - ---- - -### ⌨️ 构建命令速查 (Command Cheatsheet) - -| Action | Command | Description | -| :--- | :--- | :--- | -| **Release Build** | | | -| Clean Build (RV1126) | `./build.sh cb rv1126bp` | 清理并编译 Release 版本,包含 SDK 链接 | -| Incremental Build | `./build.sh build rv1126bp` | 仅编译修改过的文件,速度最快 | -| **Debug Build** | | | -| Debug Mode (RV1126) | `./build.sh cb rv1126bp debug` | 开启调试符号,未优化版本 | -| Native Debug (x86) | `./build.sh cb native debug` | 使用本机 GCC/Clang 编译,用于逻辑验证 | -| **Maintenance** | | | -| Clean All | `./build.sh cleanall` | 删除所有 build 目录和 install 产物 | - ---- - -### 📂 产物说明 (Output) - -构建完成后,所有产物将遵循重命名规则(`libarcforge_*.so`)安装至 `install/` 目录下: - -```text -install/ -└── rv1126bp/ - └── debug/ - ├── bin/ - │ ├── ArcForge_ASR_Client # 客户端应用 - │ └── ArcForge_ASR_Server # 服务端应用 (含 NPU 绑定) - ├── lib/ - │ ├── libarcforge_core.so # 核心业务库 (原 Arcforge::Core) - │ ├── libarcforge_utils.so # 工具库 (原 Arcforge::Utils) - │ └── libsherpa-onnx*.so # 第三方依赖库 - └── include/ # SDK 头文件 -``` - -### ⚠️ 限制与规划(Limitations & Roadmap) - -- **Network & Caching (网络环境)**: - - 构建系统默认尝试从 GitHub 拉取第三方依赖(如 `sherpa-onnx`)。 - - 鉴于网络环境的不稳定性,**建议** 配置 `.env` 中的 `ARC_DEP_CACHE_DIR` 并预先放入依赖包,以确保构建的稳定性(即“离线优先”模式)。确切的包地址请查看CMakePreset.json。 - diff --git a/docs/en/ADD_NEW_SOC.md b/docs/en/ADD_NEW_SOC.md new file mode 100644 index 0000000..03701ef --- /dev/null +++ b/docs/en/ADD_NEW_SOC.md @@ -0,0 +1,162 @@ +# ArcForge How to Add Support for a New SoC + +This guide outlines the steps to add support for a new SoC (System on Chip) or cross-compilation target in the ArcForge build system. + +**Method:** Create a toolchain file (using environment variables), update `CMakePresets.json`, and configure your environment. + +--- + +## Step 1: Create a Toolchain File + +Do not start from scratch; please copy an existing configuration. + +1. **Copy** the template: + ```bash + cp cmake/toolchains/rv1126bp.cmake cmake/toolchains/.cmake + # Example: cp cmake/toolchains/rv1126bp.cmake cmake/toolchains/rk3588.cmake + ``` + +2. **Edit** the new file (`cmake/toolchains/rk3588.cmake`): + * **Modify Processor**: Update `CMAKE_SYSTEM_PROCESSOR` (e.g., `aarch64`, `arm`, `riscv64`). + * **Define SDK Environment Variable**: For example, if using Buildroot for RK SoC board SDK development, there will be a complete development environment (e.g., sysroot/toolchain, etc.) under `buildroot/output/rockchip_${new_soc_name}/host`. + * *Change from*: `if(DEFINED ENV{RV1126BP_SDK_ROOT})` + * *To*: `if(DEFINED ENV{RK3588_SDK_ROOT})` + * **Update Paths**: Adjust internal layout variables (such as `TOOLCHAIN_BIN_DIR`) to match your specific SDK structure. + * **Update Compilers**: Update the filenames for `gcc`, `g++`, `strip`, etc. + +**Key Rule**: Never hardcode absolute paths (e.g., `/home/user/sdk`). Always rely on `$ENV{...}` variables or fallback default values. + +--- + +## Step 2: Configure Your Environment + +Since the toolchain file now relies on environment variables, you must define the location of the SDK on your specific machine. + +1. **Definition Method (Recommended)**: + Modify the `.env` file in the project root directory (if this file does not exist, you need to go back to the first step of the entire project to create it. See [[README_ZH_CN.md# #### 1. 环境配置 (必做)]] for details). + + ```bash + vim .env + ``` + Add a new environment variable: + ```bash + ARC_${new_soc_name}_SDK_ROOT=".../xxxx" + # Example: + # ARC_RK3588S_SDK_ROOT="/development/docker_volumes/src/sdk/rk3588s-linux/buildroot/output/rockchip_rk3588/host" + ``` + +--- + +## Step 3: Configure External Dependencies + +### Dependency 1: Sherpa-Onnx +You must provide the download URL and SHA256 hash for the pre-compiled `sherpa-onnx` binaries specific to the new SoC. + +1. **Prepare Tarball**: (Assuming you have already compiled sherpa-onnx) Upload your pre-compiled `sherpa-onnx` tarball (containing `lib/` and `include/`) to a hosting location (e.g., GitHub Releases). +2. **Get Hash**: Calculate the SHA256 hash of the file: `sha256sum filename.tar.xz`. +3. **Create Dependency Mixin**: In `CMakePresets.json`, add a new entry under `configurePresets` to define these variables. + +```json + { + "name": "mixin-deps-rk3588", + "hidden": true, + "description": "External dependencies URLs and Hashes for RK3588", + "cacheVariables": { + "SHERPA_ONNX_URL": "https://github.com/.../sherpa-onnx-v1.12.20-rk3588.tar.xz", + "SHERPA_ONNX_HASH": "SHA256=a1b2c3d4e5..." + } + }, +``` + +### Dependency 2: Librknnrt.so +1. **Download Library File**: Download the file used by your new SoC from [RK's official repository](https://github.com/airockchip/rknn-toolkit2/tree/master/rknpu2/runtime/Linux/librknn_api) (If the repository link is invalid, the old repository usually explicitly states the location of the new repository). +- **Note:** + - Which version to download? + - It depends on the version of the `librknnrt` library used when converting your sherpa-zipformer model. If the model uses a specific version of the rknn runtime library, you must remain consistent with it here. + +2. **Prepare Tarball**: Compress the `librknnrt.so` you just downloaded into a tarball and upload it to your own hosting location (e.g., GitHub Releases). +3. **Get Hash**: Obtain or manually calculate the SHA256 hash of the file: `sha256sum filename.tar.xz`. +4. **Create Dependency Mixin**: In `CMakePresets.json`, add a new entry under `configurePresets` to define these variables. + +```json + { + "name": "mixin-deps-librknnrt-linux-aarch64", + "hidden": true, + "description": "External dependencies URLs and Hashes for librknnrt", + "cacheVariables": { + "LIBRKNNRT_URL": "https://github.com/../librknnrt-v2.2.0-linux-aarch64-shared-official.tar.xz", + "LIBRKNNRT_HASH": "SHA256=d933df1daeb112d6c..." + } + }, +``` + +--- + +## Step 4: Register in CMakePresets.json + +Now define the platform configuration and the final build target, inheriting the dependency Mixin you created above. + +Open `CMakePresets.json` and add entries to the `configurePresets` array. + +### 4.1. Add "Platform" Preset (Hidden) +This links the logical name to the toolchain file. + +```json + { + "name": "plat-rk3588", + "hidden": true, + "description": "Rockchip RK3588 Target", + "cacheVariables": { + "CMAKE_TOOLCHAIN_FILE": "${sourceDir}/cmake/toolchains/rk3588.cmake" + } + }, +``` + +### 4.2. Add Concrete Build Presets +Define the actual build targets. +**Important**: You must inherit the dependency Mixin (`mixin-deps-rk3588`) here. + +```json + { + "name": "rk3588-release", + "inherits": ["base", "plat-rk3588", "mixin-deps-rk3588", "cfg-release", "cfg-shared", "mixin-deps-librknnrt-linux-aarch64"], + "installDir": "${sourceDir}/install/rk3588/release", + "cacheVariables": { + "CMAKE_PREFIX_PATH": "${sourceDir}/install/rk3588/release" + } + }, + { + "name": "rk3588-debug", + "inherits": ["base", "plat-rk3588", "mixin-deps-rk3588", "cfg-debug", "cfg-shared", "mixin-deps-librknnrt-linux-aarch64"], + "installDir": "${sourceDir}/install/rk3588/debug", + "cacheVariables": { + "CMAKE_PREFIX_PATH": "${sourceDir}/install/rk3588/debug" + } + } +``` + +--- + +## Step 5: Verify and Build + +1. **Check Visibility**: + Run the interactive build script or list presets to see if your new SoC appears. + ```bash + ./build.sh list + ``` + *You should see `rk3588-release` and `rk3588-debug` in the list.* + +2. **Run Build**: + ```bash + ./build.sh cb rk3588-release + ``` + +--- + +## Summary Checklist + +- [ ] **Toolchain**: Created `cmake/toolchains/xxx.cmake` (copied from template). +- [ ] **Env Vars**: Updated the specific `ENV{XXX_SDK_ROOT}` in the toolchain file and exported it in the Shell. +- [ ] **Dependencies**: Added `mixin-deps-xxx` in `CMakePresets.json` with valid `SHERPA_ONNX_URL` and `HASH`. +- [ ] **Presets**: Added `plat-xxx` and `xxx-release` (inheriting `mixin-deps-xxx`). +- [ ] **Sync**: Ensured `installDir` in presets matches `CMAKE_PREFIX_PATH`. \ No newline at end of file diff --git a/docs/en/BUILD_SYSTEM.md b/docs/en/BUILD_SYSTEM.md new file mode 100644 index 0000000..b9045d3 --- /dev/null +++ b/docs/en/BUILD_SYSTEM.md @@ -0,0 +1,381 @@ +# ArcForge Build System Explained + +This document aims to reveal the build system architecture of the ArcForge project. The project adopts the **"Modern CMake"** philosophy, achieving automation and standardization of build logic through a highly encapsulated DSL (Domain-Specific Language). + +--- + +## 1. Core Architecture View + +### 1.1 Module Dependency Topology (Module Topology) +ArcForge employs a strict layered architecture. Lower-level modules are invisible to upper layers, while upper layers inherit lower-level functionalities through interfaces. + + + +```mermaid +graph BT + %% ========================================== + %% Styles Definition (Figure 3 Specific) + %% ========================================== + classDef app fill:#0d47a1,stroke:#90caf9,stroke-width:2px,color:#fff; + classDef lib fill:#e65100,stroke:#ffcc80,stroke-width:2px,color:#fff; + classDef third fill:#333333,stroke:#ffffff,stroke-width:2px,color:#fff,stroke-dasharray: 5 5; + classDef test fill:#880e4f,stroke:#f48fb1,stroke-width:2px,color:#fff; + classDef base fill:#006064,stroke:#80deea,stroke-width:1px,color:#fff; + + subgraph Application Layer + App_Client[exe: ASR_Client]:::app + App_Server[exe: ASR_Server]:::app + end + + subgraph Core Library Layer + Lib_Utils[lib: Utils]:::lib + Lib_Network[lib: Network]:::lib + Lib_ASR[lib: ASREngine]:::lib + + %% Inherit base settings + Lib_Utils -. private link .- Settings[interface: arc_base_settings]:::base + Lib_Network -. private link .- Settings + Lib_ASR -. private link .- Settings + + %% Inter-library dependencies + Lib_Network -- public link --> Lib_Utils + Lib_ASR -- public link --> Lib_Utils + + %% Business library depends on third-party + Lib_ASR -- public link --> Sherpa[shared: SherpaOnnx]:::third + Lib_ASR -- public link --> RKNN[shared: LibRKNNRT]:::third + end + + subgraph Dependency Layer + RKNN + Sherpa + + %% Corresponds to INTERFACE_LINK_LIBRARIES in sherpa-onnx/CMakeLists.txt + Sherpa -- link --> RKNN + end + + subgraph Test Layer + Test_Net[exe: test_Network]:::test + GTest[lib: GTest_Main]:::third + + Test_Net -- private link --> Lib_Network + Test_Net -- private link --> GTest + end + + App_Client -- link --> Lib_Network + App_Client -- link --> Lib_ASR + App_Client -- link --> Lib_Utils + App_Client -- link --> Sherpa + + App_Server -- link --> Lib_Network + App_Server -- link --> Lib_ASR + App_Server -- link --> Lib_Utils + App_Server -- link --> Sherpa +``` + +### 1.2 Design Principles +* **Single Source of Truth**: `build.sh` acts solely as an entry point; build dependencies are entirely controlled by the CMake DAG. +* **Out-of-Source Build**: Build artifacts are strictly isolated in the `build/` directory, preventing contamination of the source tree. +* **DSL Driven**: Implementation modules contain minimal logic, relying solely on standard interfaces provided by `ArcFunctions`. + +--- + +## 2. Build Lifecycle (Build Lifecycle) + +This section details the entire process from executing `build.sh` to generating artifacts, illustrating the flow of control between scripts, configuration files, and CMake. + + + +```mermaid +graph TB + %% ========================================== + %% Styles Definition (Figure 1 Specific) + %% ========================================== + classDef entry fill:#37474f,stroke:#cfd8dc,stroke-width:2px,color:#fff; + classDef config fill:#f57f17,stroke:#ffe082,stroke-width:2px,color:#fff; + classDef toolchain fill:#e65100,stroke:#ffcc80,stroke-width:2px,color:#fff; + classDef root fill:#0277bd,stroke:#81d4fa,stroke-width:2px,color:#fff; + classDef dsl fill:#7b1fa2,stroke:#ce93d8,stroke-width:2px,color:#fff; + classDef submodule fill:#2e7d32,stroke:#a5d6a7,stroke-width:2px,color:#fff; + + %% Avoid title overlap, adjust subgraph padding + %% (Mermaid doesn't directly support padding, but node arrangement can mitigate this) + + %% ========================================== + %% 1. Entry and Configuration Phase (Setup Phase) + %% ========================================== + subgraph Phase_Entry [Entry Phase] + direction TB + Entry_Script([Start: build.sh]):::entry + end + + subgraph Phase_Config [CMakePresets.json] + direction TB + %% Linear logic: Define variables first, then toolchain + Preset_Vars[1. Inject Cache Variables
URLs & Hash]:::config + Preset_Tool[2. Specify Toolchain File Path]:::config + + Preset_Vars ==> Preset_Tool + end + + subgraph Phase_Toolchain [cmake/toolchains/xxx] + direction TB + %% Simplified into a single block + TC_Env[3. Load Cross-Compilation Environment
RK3588S Sysroot & Compilers]:::toolchain + end + + %% ========================================== + %% 2. Core Orchestration Phase (Orchestration Phase) + %% ========================================== + subgraph Phase_Orchestrator [Root CMakeLists.txt] + direction TB + + %% Use Roman numerals for movements + Orch_I[I. Load Build Functions Library
include ArcFunctions]:::root + Orch_II[II. Process Third-Party Dependencies
add_subdirectory third_party]:::root + Orch_III[III. Process Core Libraries
add_subdirectory libs]:::root + Orch_IV[IV. Process Applications
add_subdirectory apps]:::root + + Orch_I ==> Orch_II ==> Orch_III ==> Orch_IV + end + + subgraph Phase_DSL [Build Toolbox: ArcFunctions.cmake] + direction TB + DSL_Defs[Defines arc_* Macros & Functions]:::dsl + end + + %% ========================================== + %% 3. Execution Phase (Execution Phase) + %% ========================================== + subgraph Phase_Exec_3rd [third_party/CMakeLists.txt] + direction TB + Exec_3A[A. FetchContent Download/Extract]:::submodule + Exec_3B[B. Create Imported Targets]:::submodule + Exec_3A ==> Exec_3B + end + + subgraph Phase_Exec_Libs [libs/CMakeLists.txt] + direction TB + Exec_Libs_Dist[Distribute: utils -> network -> asr]:::submodule + + subgraph Inner_Lib_Build [libs/*/CMakeLists.txt] + Lib_Step1[A. add_library]:::submodule + Lib_Step2[B. arc_setup_system_info]:::submodule + Lib_Step3[C. arc_install_library]:::submodule + Lib_Step1 ==> Lib_Step2 ==> Lib_Step3 + end + + Exec_Libs_Dist ==> Inner_Lib_Build + end + + subgraph Phase_Exec_Apps [apps/CMakeLists.txt] + direction TB + Exec_Apps_Dist[Distribute: client -> server]:::submodule + + subgraph Inner_App_Build [apps/*/CMakeLists.txt] + App_Step1[A. add_executable]:::submodule + App_Step2[B. arc_setup_system_info]:::submodule + App_Step3[C. arc_install_executable]:::submodule + App_Step1 ==> App_Step2 ==> App_Step3 + end + + Exec_Apps_Dist ==> Inner_App_Build + end + + %% ========================================== + %% Wiring (Wiring) + %% ========================================== + + %% 1. Entry -> Configuration + Entry_Script ==> Preset_Vars + + %% 2. Configuration -> Toolchain Loading + Preset_Tool -. Specifies Path .-> TC_Env + + %% 3. Environment Aggregation -> Orchestrator (Root) + %% Toolchain Environment and Preset Variables are injected into Root + TC_Env ==> Orch_I + Preset_Vars -. Variable Injection .-> Orch_I + + %% 4. Orchestrator Calls DSL + Orch_I -. include .-> DSL_Defs + + %% 5. Orchestrator Distributes Tasks (Main Flow) + Orch_II ==> Exec_3A + Orch_III ==> Exec_Libs_Dist + Orch_IV ==> Exec_Apps_Dist + + %% 6. DSL Callbacks (Functions Called by Submodules) + DSL_Defs -. function call .-> Lib_Step2 + DSL_Defs -. function call .-> Lib_Step3 + DSL_Defs -. function call .-> App_Step2 + DSL_Defs -. function call .-> App_Step3 +``` + +**Key Phase Explanations:** +1. **Pre-Configure (Preset)**: `CMakePresets.json` injects Toolchain and dependency version information. +2. **Orchestration (Root)**: The root `CMakeLists.txt` acts as the conductor, loading the DSL and dispatching tasks. +3. **Execution (Subdirs)**: Subdirectories invoke the DSL to perform specific compilation and linking. + +--- + +## 3. Build Black Magic: ArcFunctions DSL + +To simplify `CMakeLists.txt` writing, the project encapsulates `cmake/ArcFunctions.cmake`. The following diagrams illustrate the automatic operations performed when you call `arc_install_library` or `arc_setup_system_info`. + + + +```mermaid +graph TB + %% ========================================== + %% 样式定义 (图2专用) + %% ========================================== + classDef fileContainer fill:#263238,stroke:#90a4ae,stroke-width:2px,stroke-dasharray: 5 5,color:#fff; + classDef initGroup fill:#1565c0,stroke:#90caf9,stroke-width:2px,color:#fff; + classDef setupGroup fill:#ef6c00,stroke:#ffcc80,stroke-width:2px,color:#fff; + classDef installGroup fill:#2e7d32,stroke:#a5d6a7,stroke-width:2px,color:#fff; + classDef testGroup fill:#c2185b,stroke:#f48fb1,stroke-width:2px,color:#fff; + classDef nodeStep fill:#455a64,stroke:#cfd8dc,stroke-width:1px,color:#fff; + + subgraph ArcFunctions_File [ArcFunctions.cmake 工具箱] + direction TB + + %% ========================================== + %% 1. 全局初始化簇 + %% ========================================== + subgraph Cluster_Init [1.全局初始化类] + direction TB + + subgraph Func_Ver [arc_extract_version_from_changelog] + direction TB + V1[读取 CHANGELOG.md]:::nodeStep --> V2[正则匹配 ## vX.Y.Z]:::nodeStep + V2 --> V3[导出 ARC_PROJECT_VERSION]:::nodeStep + end + + subgraph Func_Meta [arc_init_project_metadata] + direction TB + M1[获取 Version 变量]:::nodeStep --> M2[设置作者 PotterWhite]:::nodeStep + M2 --> M3[生成 UTC 时间戳]:::nodeStep + M3 --> M4[导出 GLOBAL__变量]:::nodeStep + end + + subgraph Func_Global [arc_init_global_settings] + direction TB + G1[创建接口库 arc_base_settings]:::nodeStep + G2[强制 C++17 & PIC]:::nodeStep --> G1 + G3[设置 -Wall -Werror]:::nodeStep --> G1 + G4[根据 Debug/Release 设优化级]:::nodeStep --> G1 + G5[导出 BUILD_TYPE]:::nodeStep --> G1 + end + end + class Cluster_Init initGroup + + %% ========================================== + %% 2. 目标配置簇 + %% ========================================== + subgraph Cluster_Setup [2.目标配置类] + direction TB + + subgraph Func_SetupInfo [arc_setup_system_info] + direction TB + S1[校验命名空间]:::nodeStep --> S2[生成 system-info.h]:::nodeStep + S2 --> S3[设置 Include 路径 src/gen]:::nodeStep + S3 --> S4[挂载 PCH 预编译头]:::nodeStep + S4 --> S5[设置 SOVERSION]:::nodeStep + S5 --> S6[链接 arc_base_settings]:::nodeStep + end + + subgraph Func_GenHeader [arc_generate_system_info_header] + direction TB + H1[生成通用 system-info-gen.h]:::nodeStep --> H2[创建接口库 project_version_info]:::nodeStep + end + end + class Cluster_Setup setupGroup + + %% ========================================== + %% 3. 安装部署簇 + %% ========================================== + subgraph Cluster_Install [3.安装部署类] + direction TB + + subgraph Func_InstLib [arc_install_library] + direction TB + L1[安装头文件 include/]:::nodeStep --> L2[安装二进制 lib/ bin/]:::nodeStep + L2 --> L3[生成 ConfigVersion.cmake]:::nodeStep + L3 --> L4[生成 Config.cmake]:::nodeStep + L4 --> L5[导出 Targets.cmake]:::nodeStep + end + + subgraph Func_InstExe [arc_install_executable] + direction TB + E1[安装 Target 到 bin/]:::nodeStep + end + end + class Cluster_Install installGroup + + %% ========================================== + %% 4. 质量保证簇 + %% ========================================== + subgraph Cluster_Test [4.测试集成类] + direction TB + + subgraph Func_AddTest [arc_add_test] + direction TB + T1[定义 exe 名称 test_Target]:::nodeStep + T1 --> T2[链接 GTest::gtest_main]:::nodeStep + T2 --> T3[链接 被测库 ArcForge::Target]:::nodeStep + T3 --> T4[注入私有头文件路径 /src]:::nodeStep + T4 --> T5[注册 gtest_discover_tests]:::nodeStep + end + end + class Cluster_Test testGroup + + end + class ArcFunctions_File fileContainer +``` + +**DSL's Automated Features:** +* **Version Injection**: Automatically generates `system-info.h` with Git version and build timestamp. +* **Standardized Installation**: Automatically handles RPATH, generates `Config.cmake` and `Targets.cmake` for standard `find_package`. +* **Environment Isolation**: Automatically configures PCH (Precompiled Headers) and different Include paths for Build/Install phases. + +--- + +## 4. Integration Guide (Integration Guide) + +### 4.1 Internal Module Development +When developing new modules, simply call the DSL; no need to manage installation rules directly: + +```cmake +# libs/new_module/CMakeLists.txt + +add_library(MyModule) +# 1. Automatically configure headers, version, and alias +arc_setup_system_info(MyModule) +# 2. Link dependencies (using namespaced aliases) +target_link_libraries(MyModule PUBLIC ArcForge::Utils) +# 3. Automatically generate installation rules +arc_install_library(MyModule ${INCLUDE_DIR}) +``` + +### 4.2 External SDK Usage +When `build/install` is packaged for distribution, third-party applications can integrate using standard CMake: + +```cmake +# 1. Find the package (CMake will automatically read lib/cmake/Utils/ArcForge_UtilsConfig.cmake) +find_package(ArcForge_Utils REQUIRED) + +# 2. Link (Must use the ArcForge:: prefix) +target_link_libraries(UserApp PRIVATE ArcForge::Utils) +``` + +--- + +## 5. Maintenance Command Cheatsheet + +| Operation | Command | Description | +| :--- | :--- | :--- | +| **Full Build** | `./build.sh cb ` | Cleans and rebuilds (Clean Build) | +| **Incremental Build** | `./build.sh build ` | Compiles only modified parts, recommended for development | +| **Debug Build** | `./build.sh cb debug` | Builds with debug symbols, no optimization (-Og) | +| **Full Cleanup** | `git clean -fdx -e .env` | **Use with Caution**: Removes all untracked files (preserves .env) | \ No newline at end of file diff --git a/docs/zh-cn/ADD_NEW_SOC_ZH_CN.md b/docs/zh-cn/ADD_NEW_SOC_ZH_CN.md new file mode 100644 index 0000000..8cda939 --- /dev/null +++ b/docs/zh-cn/ADD_NEW_SOC_ZH_CN.md @@ -0,0 +1,162 @@ +# ArcForge 如何添加对新 SoC 的支持 + +本指南概述了在 ArcForge 构建系统中添加对新 SoC(片上系统)或交叉编译目标支持的步骤。 + +**方法:** 创建工具链文件(使用环境变量),更新 `CMakePresets.json`,并配置你的环境。 + +--- + +## 步骤 1:创建工具链文件 + +不要从零开始;请复制现有的配置。 + +1. **复制**模板: + ```bash + cp cmake/toolchains/rv1126bp.cmake cmake/toolchains/.cmake + # 示例: cp cmake/toolchains/rv1126bp.cmake cmake/toolchains/rk3588.cmake + ``` + +2. **编辑**新文件 (`cmake/toolchains/rk3588.cmake`): + * **修改处理器 (Processor)**:更新 `CMAKE_SYSTEM_PROCESSOR`(例如:`aarch64`, `arm`, `riscv64`)。 + * **定义SDK环境变量**:例如RK的SOC用Buildroot进行板子SDK开发的话,那么在buildroot/output/rockchip_${new_soc_name}/host下会有完整的开发环境(如sysroot/toolchain等) + * *将*:`if(DEFINED ENV{RV1126BP_SDK_ROOT})` + * *改为*:`if(DEFINED ENV{RK3588_SDK_ROOT})` + * **更新路径**:调整内部布局变量(如 `TOOLCHAIN_BIN_DIR`)以匹配你特定的 SDK 结构。 + * **更新编译器**:更新 `gcc`, `g++`, `strip` 等的文件名。 + +**关键规则**:永远不要硬编码绝对路径(如 `/home/user/sdk`)。始终依赖 `$ENV{...}` 变量或回退默认值。 + +--- + +## 步骤 2:配置你的环境 + +由于工具链文件现在依赖于环境变量,你必须定义 SDK 在你特定机器上的位置。 + +1. **定义方式(推荐)**: + 修改项目根目录的.env(若无此文件,需要回到整个项目的第一步进行创建。详细查看[[README_ZH_CN.md# #### 1. 环境配置 (必做)]] + + ```bash + vim .env + ``` + 新增一个环境变量: + ```bash + ARC_${new_soc_name}_SDK_ROOT=".../xxxx" + # 例如: + # ARC_RK3588S_SDK_ROOT="/development/docker_volumes/src/sdk/rk3588s-linux/buildroot/output/rockchip_rk3588/host" + ``` + +--- + +## 步骤 3:配置外部依赖 + +### 依赖1:Sherpa-Onnx +你必须为特定于新 SoC 的预编译 `sherpa-onnx` 二进制文件提供下载 URL 和 SHA256 哈希值。 + +1. **准备 Tar 包**:(此处假设你已经编译完sherpa-onnx)将你的预编译 `sherpa-onnx` tar 包(包含 `lib/` 和 `include/`)上传到托管位置(例如 GitHub Releases)。 +2. **获取哈希值**:计算文件的 SHA256 哈希值:`sha256sum filename.tar.xz`。 +3. **创建依赖 Mixin**:在 `CMakePresets.json` 中,在 `configurePresets` 下添加一个新条目来定义这些变量。 + +```json + { + "name": "mixin-deps-rk3588", + "hidden": true, + "description": "RK3588 的外部依赖 URL 和哈希值", + "cacheVariables": { + "SHERPA_ONNX_URL": "https://github.com/.../sherpa-onnx-v1.12.20-rk3588.tar.xz", + "SHERPA_ONNX_HASH": "SHA256=a1b2c3d4e5..." + } + }, +``` + +### 依赖2:Librknnrt.so +1. **下载库文件**:[从RK的官方仓库](https://github.com/airockchip/rknn-toolkit2/tree/master/rknpu2/runtime/Linux/librknn_api)(仓库链接若失效,一般在旧仓库会明确告知新仓库的位置)下载到你新的SOC所使用的文件。 +- **注意点:** + - 下载哪一个版本? + - 要看你使用的sherpa-zipformer模型转换时所使用的librknnrt库的版本。模型rknn使用了哪一个版本的runtime库,你此处就得跟它保持一致。 + +2. **准备 Tar 包**:将你刚才下载的 `librknnrt.so` 压缩成 tar 包上传到你自己的托管位置(例如 GitHub Releases)。 +2. **获取哈希值**:获取或自行计算文件的 SHA256 哈希值:`sha256sum filename.tar.xz`。 +3. **创建依赖 Mixin**:在 `CMakePresets.json` 中,在 `configurePresets` 下添加一个新条目来定义这些变量。 + +```json + { + "name": "mixin-deps-librknnrt-linux-aarch64", + "hidden": true, + "description": "External dependencies URLs and Hashes for librknnrt ", + "cacheVariables": { + "LIBRKNNRT_URL": "https://github.com/../librknnrt-v2.2.0-linux-aarch64-shared-official.tar.xz", + "LIBRKNNRT_HASH": "SHA256=d933df1daeb112d6c..." + } + }, +``` + +--- + +## 步骤 4:在 CMakePresets.json 中注册 + +现在定义平台配置和最终构建目标,并继承你上面创建的依赖 Mixin。 + +打开 `CMakePresets.json` 并向 `configurePresets` 数组添加条目。 + +### 4.1. 添加 “平台 (Platform)” 预设(隐藏) +这将逻辑名称链接到工具链文件。 + +```json + { + "name": "plat-rk3588", + "hidden": true, + "description": "Rockchip RK3588 目标", + "cacheVariables": { + "CMAKE_TOOLCHAIN_FILE": "${sourceDir}/cmake/toolchains/rk3588.cmake" + } + }, +``` + +### 4.2. 添加具体构建预设 +定义实际的构建目标。 +**重要**:你必须在此处继承依赖 Mixin (`mixin-deps-rk3588`)。 + +```json + { + "name": "rk3588-release", + "inherits": ["base", "plat-rk3588", "mixin-deps-rk3588", "cfg-release", "cfg-shared", "mixin-deps-librknnrt-linux-aarch64"], + "installDir": "${sourceDir}/install/rk3588/release", + "cacheVariables": { + "CMAKE_PREFIX_PATH": "${sourceDir}/install/rk3588/release" + } + }, + { + "name": "rk3588-debug", + "inherits": ["base", "plat-rk3588", "mixin-deps-rk3588", "cfg-debug", "cfg-shared", "mixin-deps-librknnrt-linux-aarch64"], + "installDir": "${sourceDir}/install/rk3588/debug", + "cacheVariables": { + "CMAKE_PREFIX_PATH": "${sourceDir}/install/rk3588/debug" + } + } +``` + +--- + +## 步骤 5:验证并构建 + +1. **检查可见性**: + 运行交互式构建脚本或列出预设,查看你的新 SoC 是否出现。 + ```bash + ./build.sh list + ``` + *你应该会在列表中看到 `rk3588-release` 和 `rk3588-debug`。* + +2. **运行构建**: + ```bash + ./build.sh cb rk3588-release + ``` + +--- + +## 总结清单 + +- [ ] **工具链**:已创建 `cmake/toolchains/xxx.cmake`(从模板复制)。 +- [ ] **环境变量**:已更新工具链文件中的特定 `ENV{XXX_SDK_ROOT}` 并在 Shell 中导出。 +- [ ] **依赖**:已在 `CMakePresets.json` 中添加 `mixin-deps-xxx`,并包含有效的 `SHERPA_ONNX_URL` 和 `HASH`。 +- [ ] **预设**:已添加 `plat-xxx` 和 `xxx-release`(继承 `mixin-deps-xxx`)。 +- [ ] **同步**:已确保预设中的 `installDir` 与 `CMAKE_PREFIX_PATH` 匹配。 diff --git a/docs/zh-cn/BUILD_SYSTEM_ZH_CN.md b/docs/zh-cn/BUILD_SYSTEM_ZH_CN.md new file mode 100644 index 0000000..febd040 --- /dev/null +++ b/docs/zh-cn/BUILD_SYSTEM_ZH_CN.md @@ -0,0 +1,386 @@ +# ArcForge 构建系统详解 + +本文档旨在揭示 ArcForge 项目的构建系统架构。项目采用 **"Modern CMake"** 理念,通过高度封装的 DSL(领域特定语言)实现了构建逻辑的自动化与标准化。 + +--- + +## 1. 核心架构视图 + +### 1.1 模块依赖拓扑 (Module Topology) +ArcForge 采用严格的分层架构。底层模块对上层不可见,上层通过接口继承底层功能。 + + + +```mermaid +graph BT + %% ========================================== + %% 样式定义 (图3专用) + %% ========================================== + classDef app fill:#0d47a1,stroke:#90caf9,stroke-width:2px,color:#fff; + classDef lib fill:#e65100,stroke:#ffcc80,stroke-width:2px,color:#fff; + classDef third fill:#333333,stroke:#ffffff,stroke-width:2px,color:#fff,stroke-dasharray: 5 5; + classDef test fill:#880e4f,stroke:#f48fb1,stroke-width:2px,color:#fff; + classDef base fill:#006064,stroke:#80deea,stroke-width:1px,color:#fff; + + subgraph 基础配置层 + Settings[interface: arc_base_settings]:::base + end + + subgraph 第三方依赖层 + RKNN[shared: LibRKNNRT]:::third + Sherpa[shared: SherpaOnnx]:::third + + %% 对应 sherpa-onnx/CMakeLists.txt 中的 INTERFACE_LINK_LIBRARIES + Sherpa -- link --> RKNN + end + + subgraph 核心库层 + Lib_Utils[lib: Utils]:::lib + Lib_Network[lib: Network]:::lib + Lib_ASR[lib: ASREngine]:::lib + + %% 继承基础配置 + Lib_Utils -. private link .- Settings + Lib_Network -. private link .- Settings + Lib_ASR -. private link .- Settings + + %% 库间依赖 + Lib_Network -- public link --> Lib_Utils + Lib_ASR -- public link --> Lib_Utils + + %% 业务库依赖第三方 + Lib_ASR -- public link --> Sherpa + Lib_ASR -- public link --> RKNN + end + + subgraph 应用层 + App_Client[exe: ASR_Client]:::app + App_Server[exe: ASR_Server]:::app + + App_Client -- link --> Lib_Network + App_Client -- link --> Lib_ASR + App_Client -- link --> Lib_Utils + App_Client -- link --> Sherpa + + App_Server -- link --> Lib_Network + App_Server -- link --> Lib_ASR + App_Server -- link --> Lib_Utils + App_Server -- link --> Sherpa + end + + subgraph 测试层 + Test_Net[exe: test_Network]:::test + GTest[lib: GTest_Main]:::third + + Test_Net -- private link --> Lib_Network + Test_Net -- private link --> GTest + end +``` + +### 1.2 设计原则 +* **单一事实来源**:`build.sh` 仅作入口,构建依赖关系完全由 CMake DAG 控制。 +* **源码外构建**:构建产物严格隔离在 `build/` 目录,禁止污染源码树。 +* **DSL 驱动**:业务模块(Implementation)不包含复杂逻辑,仅调用 `ArcFunctions` 提供的标准接口。 + +--- + +## 2. 构建生命周期 (Build Lifecycle) + +从执行 `build.sh` 到产物生成,控制权在脚本、配置文件与 CMake 之间流转的全过程。 + + + +```mermaid +graph TB + %% ========================================== + %% 样式定义 (图1专用) + %% ========================================== + classDef entry fill:#37474f,stroke:#cfd8dc,stroke-width:2px,color:#fff; + classDef config fill:#f57f17,stroke:#ffe082,stroke-width:2px,color:#fff; + classDef toolchain fill:#e65100,stroke:#ffcc80,stroke-width:2px,color:#fff; + classDef root fill:#0277bd,stroke:#81d4fa,stroke-width:2px,color:#fff; + classDef dsl fill:#7b1fa2,stroke:#ce93d8,stroke-width:2px,color:#fff; + classDef submodule fill:#2e7d32,stroke:#a5d6a7,stroke-width:2px,color:#fff; + + %% 避免标题遮挡,调整子图内部边距 + %% (Mermaid不直接支持padding,但通过节点排布可以缓解) + + %% ========================================== + %% 1. 入口与配置阶段 (Setup Phase) + %% ========================================== + subgraph Phase_Entry [入口阶段] + direction TB + Entry_Script([Start: build.sh]):::entry + end + + subgraph Phase_Config [CMakePresets.json] + direction TB + %% 线性逻辑:先定变量,再定工具链 + Preset_Vars[1.注入 Cache 变量
URLs & Hash]:::config + Preset_Tool[2.指定 Toolchain 文件路径]:::config + + Preset_Vars ==> Preset_Tool + end + + subgraph Phase_Toolchain [cmake/toolchains/xxx] + direction TB + %% 简化为一个块 + TC_Env[3.加载交叉编译环境
RK3588S Sysroot & Compilers]:::toolchain + end + + %% ========================================== + %% 2. 核心编排阶段 (Orchestration Phase) + %% ========================================== + subgraph Phase_Orchestrator [Root CMakeLists.txt] + direction TB + + %% 使用罗马数字标记乐章 + Orch_I[I. 加载构建函数库
include ArcFunctions]:::root + Orch_II[II. 处理第三方依赖
add_subdirectory third_party]:::root + Orch_III[III. 处理核心库
add_subdirectory libs]:::root + Orch_IV[IV. 处理应用程序
add_subdirectory apps]:::root + + Orch_I ==> Orch_II ==> Orch_III ==> Orch_IV + end + + subgraph Phase_DSL [构建工具箱: ArcFunctions.cmake] + direction TB + DSL_Defs[定义 arc_* 宏与函数]:::dsl + end + + %% ========================================== + %% 3. 执行落地阶段 (Execution Phase) + %% ========================================== + subgraph Phase_Exec_3rd [third_party/CMakeLists.txt] + direction TB + Exec_3A[A. FetchContent 下载/解压]:::submodule + Exec_3B[B. 创建 Imported Targets]:::submodule + Exec_3A ==> Exec_3B + end + + subgraph Phase_Exec_Libs [libs/CMakeLists.txt] + direction TB + Exec_Libs_Dist[分发: utils -> network -> asr]:::submodule + + subgraph Inner_Lib_Build [libs/*/CMakeLists.txt] + Lib_Step1[A. add_library]:::submodule + Lib_Step2[B. arc_setup_system_info]:::submodule + Lib_Step3[C. arc_install_library]:::submodule + Lib_Step1 ==> Lib_Step2 ==> Lib_Step3 + end + + Exec_Libs_Dist ==> Inner_Lib_Build + end + + subgraph Phase_Exec_Apps [apps/CMakeLists.txt] + direction TB + Exec_Apps_Dist[分发: client -> server]:::submodule + + subgraph Inner_App_Build [apps/*/CMakeLists.txt] + App_Step1[A. add_executable]:::submodule + App_Step2[B. arc_setup_system_info]:::submodule + App_Step3[C. arc_install_executable]:::submodule + App_Step1 ==> App_Step2 ==> App_Step3 + end + + Exec_Apps_Dist ==> Inner_App_Build + end + + %% ========================================== + %% 连线关系 (Wiring) + %% ========================================== + + %% 1. 入口 -> 配置 + Entry_Script ==> Preset_Vars + + %% 2. 配置 -> 工具链加载 + Preset_Tool -. 指定路径 .-> TC_Env + + %% 3. 环境汇聚 -> 指挥中心 (Root) + %% 工具链环境 和 预设变量 都注入到 Root + TC_Env ==> Orch_I + Preset_Vars -. 变量注入 .-> Orch_I + + %% 4. 指挥中心调用 DSL + Orch_I -. include .-> DSL_Defs + + %% 5. 指挥中心分发任务 (主流程) + Orch_II ==> Exec_3A + Orch_III ==> Exec_Libs_Dist + Orch_IV ==> Exec_Apps_Dist + + %% 6. DSL 回调 (函数被子模块调用) + DSL_Defs -. function call .-> Lib_Step2 + DSL_Defs -. function call .-> Lib_Step3 + DSL_Defs -. function call .-> App_Step2 + DSL_Defs -. function call .-> App_Step3 +``` + +**关键阶段说明:** +1. **Pre-Configure (Preset)**:`CMakePresets.json` 注入工具链(Toolchain)与依赖版本信息。 +2. **Orchestration (Root)**:根目录 `CMakeLists.txt` 作为指挥中心,加载 DSL 并分发任务。 +3. **Execution (Subdirs)**:子目录调用 DSL 完成具体的编译与链接。 + +--- + +## 3. 构建黑科技:ArcFunctions DSL + +为了简化 `CMakeLists.txt` 的编写,项目封装了 `cmake/ArcFunctions.cmake`。以下图表展示了当你调用 `arc_install_library` 或 `arc_setup_system_info` 时,系统内部自动执行的操作。 + + + +```mermaid +graph TB + %% ========================================== + %% 样式定义 (图2专用) + %% ========================================== + classDef fileContainer fill:#263238,stroke:#90a4ae,stroke-width:2px,stroke-dasharray: 5 5,color:#fff; + classDef initGroup fill:#1565c0,stroke:#90caf9,stroke-width:2px,color:#fff; + classDef setupGroup fill:#ef6c00,stroke:#ffcc80,stroke-width:2px,color:#fff; + classDef installGroup fill:#2e7d32,stroke:#a5d6a7,stroke-width:2px,color:#fff; + classDef testGroup fill:#c2185b,stroke:#f48fb1,stroke-width:2px,color:#fff; + classDef nodeStep fill:#455a64,stroke:#cfd8dc,stroke-width:1px,color:#fff; + + subgraph ArcFunctions_File [ArcFunctions.cmake 工具箱] + direction TB + + %% ========================================== + %% 1. 全局初始化簇 + %% ========================================== + subgraph Cluster_Init [1.全局初始化类] + direction TB + + subgraph Func_Ver [arc_extract_version_from_changelog] + direction TB + V1[读取 CHANGELOG.md]:::nodeStep --> V2[正则匹配 ## vX.Y.Z]:::nodeStep + V2 --> V3[导出 ARC_PROJECT_VERSION]:::nodeStep + end + + subgraph Func_Meta [arc_init_project_metadata] + direction TB + M1[获取 Version 变量]:::nodeStep --> M2[设置作者 PotterWhite]:::nodeStep + M2 --> M3[生成 UTC 时间戳]:::nodeStep + M3 --> M4[导出 GLOBAL__变量]:::nodeStep + end + + subgraph Func_Global [arc_init_global_settings] + direction TB + G1[创建接口库 arc_base_settings]:::nodeStep + G2[强制 C++17 & PIC]:::nodeStep --> G1 + G3[设置 -Wall -Werror]:::nodeStep --> G1 + G4[根据 Debug/Release 设优化级]:::nodeStep --> G1 + G5[导出 BUILD_TYPE]:::nodeStep --> G1 + end + end + class Cluster_Init initGroup + + %% ========================================== + %% 2. 目标配置簇 + %% ========================================== + subgraph Cluster_Setup [2.目标配置类] + direction TB + + subgraph Func_SetupInfo [arc_setup_system_info] + direction TB + S1[校验命名空间]:::nodeStep --> S2[生成 system-info.h]:::nodeStep + S2 --> S3[设置 Include 路径 src/gen]:::nodeStep + S3 --> S4[挂载 PCH 预编译头]:::nodeStep + S4 --> S5[设置 SOVERSION]:::nodeStep + S5 --> S6[链接 arc_base_settings]:::nodeStep + end + + subgraph Func_GenHeader [arc_generate_system_info_header] + direction TB + H1[生成通用 system-info-gen.h]:::nodeStep --> H2[创建接口库 project_version_info]:::nodeStep + end + end + class Cluster_Setup setupGroup + + %% ========================================== + %% 3. 安装部署簇 + %% ========================================== + subgraph Cluster_Install [3.安装部署类] + direction TB + + subgraph Func_InstLib [arc_install_library] + direction TB + L1[安装头文件 include/]:::nodeStep --> L2[安装二进制 lib/ bin/]:::nodeStep + L2 --> L3[生成 ConfigVersion.cmake]:::nodeStep + L3 --> L4[生成 Config.cmake]:::nodeStep + L4 --> L5[导出 Targets.cmake]:::nodeStep + end + + subgraph Func_InstExe [arc_install_executable] + direction TB + E1[安装 Target 到 bin/]:::nodeStep + end + end + class Cluster_Install installGroup + + %% ========================================== + %% 4. 质量保证簇 + %% ========================================== + subgraph Cluster_Test [4.测试集成类] + direction TB + + subgraph Func_AddTest [arc_add_test] + direction TB + T1[定义 exe 名称 test_Target]:::nodeStep + T1 --> T2[链接 GTest::gtest_main]:::nodeStep + T2 --> T3[链接 被测库 ArcForge::Target]:::nodeStep + T3 --> T4[注入私有头文件路径 /src]:::nodeStep + T4 --> T5[注册 gtest_discover_tests]:::nodeStep + end + end + class Cluster_Test testGroup + + end + class ArcFunctions_File fileContainer +``` + +**DSL 带来的自动化特性:** +* **版本注入**:自动生成 `system-info.h`,包含 Git 版本与构建时间戳。 +* **安装标准化**:自动处理 RPATH,生成 `Config.cmake` 和 `Targets.cmake`,支持标准 `find_package`。 +* **环境隔离**:自动配置 PCH(预编译头)和 Build/Install 阶段不同的 Include 路径。 + +--- + +## 4. 集成指南 (Integration Guide) + +### 4.1 内部模块开发 +新增模块时,无需关心安装规则,只需调用 DSL: + +```cmake +# libs/new_module/CMakeLists.txt + +add_library(MyModule) +# 1. 自动配置头文件、版本、别名 +arc_setup_system_info(MyModule) +# 2. 链接依赖 (使用带命名空间的别名) +target_link_libraries(MyModule PUBLIC ArcForge::Utils) +# 3. 自动生成安装规则 +arc_install_library(MyModule ${INCLUDE_DIR}) +``` + +### 4.2 外部 SDK 使用 +当 `build/install` 被打包发布后,第三方应用可通过标准 CMake 方式集成: + +```cmake +# 1. 查找包 (CMake 会自动读取 lib/cmake/Utils/ArcForge_UtilsConfig.cmake) +find_package(ArcForge_Utils REQUIRED) + +# 2. 链接 (必须使用 ArcForge:: 前缀) +target_link_libraries(UserApp PRIVATE ArcForge::Utils) +``` + +--- + +## 5. 维护命令速查 + +| 操作 | 命令 | 说明 | +| :--- | :--- | :--- | +| **全量构建** | `./build.sh cb ` | 清理并重新构建 (Clean Build) | +| **增量构建** | `./build.sh build ` | 仅编译修改部分,开发推荐 | +| **调试版本** | `./build.sh cb debug` | 带符号表,无优化 (-Og) | +| **彻底清理** | `git clean -fdx -e .env` | **危险**:删除所有未跟踪文件 (保留 .env) | + diff --git a/docs/zh-cn/README_ZH_CN.md b/docs/zh-cn/README_ZH_CN.md new file mode 100644 index 0000000..b4df857 --- /dev/null +++ b/docs/zh-cn/README_ZH_CN.md @@ -0,0 +1,145 @@ +
+

ArcForge 自动语音识别(ASR)软件开发包

+

基于 Modern CMake 的高性能嵌入式 ASR 推理框架

+
+ +

+ Project Banner +

+ +

+ C++ Standard + Platform + Build System +

+ +

+ English | 简体中文 +

+ +--- + +### 📖 项目简介 + +ArcForge 是一个专为**边缘计算**设计的 C++ ASR 推理框架。 +它集成了 `sherpa-zipformer` 模型,实现了从底层 NPU 绑定到上层 Client/Server 调用的完整链路。本项目最大的特点是**“架构透明”**——我们公开并解构了完整的工业级 CMake 构建逻辑。 + +### 🏗️ 系统架构 + +不仅提供源码,还提供了一套**完全可视化**的构建系统。 + +> **🔍 深度阅读**:[**ArcForge 构建系统详解 (BUILD_SYSTEM_ZH_CN.md)**](./BUILD_SYSTEM.md) +> *(点击上方链接,查看构建生命周期、核心函数 DSL 逻辑图及详细依赖拓扑)* + +**核心模块概览:** + +```mermaid +graph LR + %% ========================================== + %% 高对比度样式定义 (High Contrast Styles) + %% 策略:深色背景 + 纯白文字 + 亮色边框 + %% ========================================== + classDef appNode fill:#0d47a1,stroke:#90caf9,stroke-width:2px,color:#fff; + classDef libNode fill:#e65100,stroke:#ffcc80,stroke-width:2px,color:#fff; + classDef thirdNode fill:#333333,stroke:#ffffff,stroke-width:2px,color:#fff,stroke-dasharray: 5 5; + + subgraph Apps [应用层] + direction TB + Client(ASR Client):::appNode + Server(ASR Server):::appNode + end + + subgraph Libs [核心库层] + direction LR + Engine[ASREngine]:::libNode --> Net[Network]:::libNode + Net --> Utils[Utils]:::libNode + end + + subgraph 3rd [依赖层] + direction LR + Engine -.-> Sherpa[SherpaOnnx]:::thirdNode + Sherpa -.-> RKNN[RKNNRT]:::thirdNode + end + + Client --> Engine + Server --> Engine +``` + +--- + +### 🚀 快速上手 + +本项目强依赖 `.env` 进行环境隔离。请严格按照以下步骤操作: + +#### 1. 环境配置 (必做) + +```bash +# 1. 复制环境配置模板 +cp .env.example .env + +# 2. 编辑配置文件 +# ARC_RV1126BP_SDK_ROOT: 指向你的交叉编译工具链根目录 (必填) +# ARC_DEP_CACHE_DIR: 指向第三方库缓存目录 (推荐配置,加速构建) +vim .env +``` + +#### 2. 编译构建 + +使用 `build.sh` 脚本驱动 CMake Presets: + +```bash +# [推荐] 全量构建 (RV1126 Release版) +./build.sh cb rv1126bp + +# [开发] 增量构建 (仅编译修改部分) +./build.sh build rv1126bp + +# [调试] 本机验证 (x86 Debug版) +./build.sh cb native debug +``` + +--- + +### ⌨️ 命令速查 + +| 场景 | 命令 | 作用 | +| :--- | :--- | :--- | +| **生产发布** | `./build.sh cb rv1126bp` | 清理并构建 Release 版本 (-O3) | +| **代码调试** | `./build.sh cb rv1126bp debug` | 构建 Debug 版本 (带符号表, -Og) | +| **环境清理** | `./build.sh cleanall` | 删除 build/ 和 install/ 目录 | +| **Git清理** | `git clean -fdx -e .env` | **慎用**:删除所有未跟踪文件 (保留配置) | + +--- + +### 📂 产物目录 + +构建完成后,产物位于 `install/` 目录。我们自动处理了重命名与 RPATH,可直接部署: + +```text +install/rv1126bp/release/ +├── bin/ +│ ├── ArcForge_ASR_Client # 客户端测试程序 +│ └── ArcForge_ASR_Server # 服务端主程序 +└── lib/ + ├── libarcforge_asrengine.so # 核心引擎库 + ├── libarcforge_network.so # 网络库 + ├── libarcforge_utils.so # 基础工具库 + └── libsherpa-onnx*.so # 依赖库 +``` + +### 🧩 支持新平台 + +目前所支持的平台只有RV1126BP和RK3588S,要支持新平台,有两种建议方法: + +#### 1. 自行添加 + +请仔细阅读该教程: + +> **🔍 深度阅读**:[**ArcForge 如何添加对新 SoC 的支持**](./ADD_NEW_SOC_ZH_CN.md) +> *(点击上方链接,查看仔细步骤,引导你对新SOC进行支持)* + +#### 2. 提交issues给我 + + + +