构建 Rust 核心
本页是贡献者面向的参考,用于在全新机器上编译 Rust 核心。
它只涵盖仓库根 crate:
- Cargo 包:
openhuman - 二进制文件:
openhuman-core - 库:
openhuman_core
如果您想要完整的桌面应用(pnpm dev、Tauri、CEF、前端工具),请使用环境搭建。那条路径有额外的 JavaScript、子模块和桌面运行时要求,不需要纯核心的 cargo 工作流程。
1. 安装固定的 Rust 工具链
仓库在 rust-toolchain.toml 中固定 Rust:
- 频道:
1.93.0 - 组件:
rustfmt、clippy
推荐安装:
rustup toolchain install 1.93.0 --component rustfmt --component clippy
rustup default 1.93.0
2. 克隆仓库
仅核心工作:
git clone https://github.com/tinyhumansai/openhuman.git
cd openhuman
仅核心工作只需仓库根 crate。桌面/Tauri 工作需要 app/src-tauri/vendor/ 子模块。
3. 构建命令
从仓库根目录:
# 快速依赖 + 类型检查
cargo check --manifest-path Cargo.toml
# 调试构建
cargo build --manifest-path Cargo.toml --bin openhuman-core
# 发布构建
cargo build --manifest-path Cargo.toml --release --bin openhuman-core
# Rust 测试
cargo test --manifest-path Cargo.toml
注意:
- 包名是
openhuman,但可运行二进制文件是openhuman-core - 构建的二进制文件位于
target/debug/openhuman-core或target/release/openhuman-core
4. macOS 前置要求
安装:
- Xcode Command Line Tools:
xcode-select --install
原因:
whisper-rs在构建期间编译原生代码- 在 macOS 上,这个 crate 使用
Cargo.toml中的metalfeature 构建,所以需要 Apple 工具链和 SDK 头文件
5. Linux 前置要求
核心仅包集
Ubuntu / Debian:
sudo apt-get update
sudo apt-get install -y \
build-essential cmake pkg-config clang libssl-dev libclang-dev \
libasound2-dev libxi-dev libxtst-dev libxdo-dev libudev-dev \
libstdc++-14-dev
Arch Linux:
sudo pacman -S --needed base-devel cmake pkgconf clang openssl \
alsa-lib libxi libxtst xdotool libevdev
whisper-rs + clang 注意
whisper-rs-sys 在 clang 下可能失败:
fatal error: 'array' file not found
这就是为什么文档中指出了 libstdc++-14-dev:在 Ubuntu 运行器上,clang 可能拾取 GCC 14 C++ 头文件。
6. Windows 前置要求
安装:
- 通过
rustup安装 Rust - Visual Studio Build Tools 2022 或带有 Desktop development with C++ 工作负载的 Visual Studio
- CI 和发布构建使用的 MSVC 目标:
x86_64-pc-windows-msvc