Rust FFI 与编译
Rust 动态库的编译流程、产物复制与新增 crate 的完整检查清单。
IriX 通过 FFI 调用 Rust 编译出的动态库。理解编译与复制流程是日常开发的基础。
| 动态库 | 对应 crate | Dart 侧使用 |
|---|---|---|
xmc_backup.dll | backup | backup_ffi.dart |
xmc_downloader.dll | downloader | downloader.dart(Downloader.downloadFile) |
xmc_http_client.dll | http_client | http_ffi.dart(HttpFfiService) |
xmc_file_ops.dll | file_ops | file_ops_ffi.dart |
xmc_logger.dll | logger | logger_ffi.dart |
xmc_db_client.dll | db_client | db_client_ffi.dart(DbClientFfi) |
xmc_vector_store.dll | vector_store | knowledge 相关服务 |
完整的调用关系见 FFI 服务清单。
# 编译(Windows 也可直接双击 build_rust.bat)cargo build --release --manifest-path rust/Cargo.toml
# Linux / macOS./build_rust.sh产物复制目标(脚本已处理):
- Windows →
windows/runner/(同时复制一份到项目根目录) - Linux →
linux/ - macOS →
macos/
新增 crate 检查清单
Section titled “新增 crate 检查清单”新增一个 Rust crate 时,需要同步更新以下 7 处:
rust/Cargo.toml的members列表build_rust.bat(Windows 构建脚本)build_rust.sh(Linux/macOS 构建脚本)linux/CMakeLists.txt(Linux .so 安装)windows/runner/CMakeLists.txt(Windows 复制)macos/Runner.xcodeproj/project.pbxproj(dylib 复制 + 签名脚本)- 两个 CI workflow:
.github/workflows/build-and-test.yml.github/workflows/package.yml
Dart 侧封装模式
Section titled “Dart 侧封装模式”Rust 导出函数通过 FFI 调用,Dart 侧统一封装在 lib/services/*_ffi.dart:
Rust 导出函数 ←─ package:ffi 绑定 ←─ lib/services/*_ffi.dart ←─ 业务服务调用典型封装示例:backup_ffi.dart、file_ops_ffi.dart、logger_ffi.dart、http_ffi.dart、db_client_ffi.dart。新增 API 服务遵循现有 *_api_service.dart / *_provider.dart 命名模式。
