build-rust
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseRust Build Operations
Rust构建操作
Efficiently build Rust workspaces with the build-rust CLI.
使用build-rust CLI高效构建Rust工作区。
Usage
使用方法
bash
undefinedbash
undefinedDevelopment (fast, debug symbols)
开发模式(快速,包含调试符号)
./scripts/build-rust.sh dev
./scripts/build-rust.sh dev
Release (optimized, stripped)
发布模式(优化编译,去除符号信息)
./scripts/build-rust.sh release
./scripts/build-rust.sh release
Profile with timing information
带计时信息的性能分析
./scripts/build-rust.sh profile
./scripts/build-rust.sh profile
Fast type-check only
仅快速类型检查
./scripts/build-rust.sh check
./scripts/build-rust.sh check
Clean build artifacts
清理构建产物
./scripts/build-rust.sh clean
./scripts/build-rust.sh clean
Build specific crate
构建指定 crate
./scripts/build-rust.sh release memory-core
undefined./scripts/build-rust.sh release memory-core
undefinedModes
模式说明
| Mode | Purpose | Flags |
|---|---|---|
| Development build | |
| Production optimized | |
| Performance timing | |
| Fast type-check | |
| Clean artifacts | |
| 模式 | 用途 | 标志 |
|---|---|---|
| 开发构建 | |
| 生产环境优化构建 | |
| 性能计时分析 | |
| 快速类型检查 | |
| 清理构建产物 | |
Disk Space Optimization (ADR-032)
磁盘空间优化(ADR-032)
The dev profile is optimized to reduce target/ size (~5.2 GB → ~2 GB):
toml
undefineddev配置文件已优化以减小target/目录大小(约5.2 GB → 约2 GB):
toml
undefined.cargo/config.toml
.cargo/config.toml
[profile.dev]
debug = "line-tables-only" # ~60% smaller debug artifacts
[profile.dev.package."*"]
debug = false # No debug info for dependencies
[profile.dev.build-override]
opt-level = 3 # Faster proc-macro execution
[profile.debugging]
inherits = "dev"
debug = true # Full debug when needed: --profile debugging
`mold` is **not** part of the default project guidance anymore. Current `.cargo/config.toml` keeps CI-compatible linker flags.
**Cleanup (preferred)**:
```bash
./scripts/clean-artifacts.sh quick
./scripts/clean-artifacts.sh standard
./scripts/clean-artifacts.sh full
./scripts/clean-artifacts.sh standard --node-modulesArtifact offloading with :
CARGO_TARGET_DIRbash
CARGO_TARGET_DIR=/mnt/fastssd/rslm-target ./scripts/build-rust.sh dev
CARGO_TARGET_DIR=/mnt/fastssd/rslm-target ./scripts/clean-artifacts.sh standard[profile.dev]
debug = "line-tables-only" # 调试产物大小减少约60%
[profile.dev.package."*"]
debug = false # 依赖库不生成调试信息
[profile.dev.build-override]
opt-level = 3 # 加快过程宏执行速度
[profile.debugging]
inherits = "dev"
debug = true # 需要完整调试信息时使用:--profile debugging
`mold` 不再是默认项目推荐的链接器。当前的 `.cargo/config.toml` 保留了兼容CI的链接器标志。
**推荐的清理方式**:
```bash
./scripts/clean-artifacts.sh quick
./scripts/clean-artifacts.sh standard
./scripts/clean-artifacts.sh full
./scripts/clean-artifacts.sh standard --node-modules使用转移构建产物:
CARGO_TARGET_DIRbash
CARGO_TARGET_DIR=/mnt/fastssd/rslm-target ./scripts/build-rust.sh dev
CARGO_TARGET_DIR=/mnt/fastssd/rslm-target ./scripts/clean-artifacts.sh standardCommon Issues
常见问题
Timeouts
- Use mode for faster iteration
dev - Reduce parallel jobs:
CARGO_BUILD_JOBS=4 ./scripts/build-rust.sh release
Memory errors
- Build with fewer jobs:
cargo build -j 4 - Use instead of full build
check
Dependency conflicts
- Update:
cargo update - Check tree:
cargo tree -e features - Check duplicates:
cargo tree -d | grep -cE "^[a-z]"
Platform-specific
- Install targets:
rustup target add <triple> - Conditional compilation:
#[cfg(target_os = "linux")]
超时问题
- 使用模式加快迭代速度
dev - 减少并行任务数:
CARGO_BUILD_JOBS=4 ./scripts/build-rust.sh release
内存错误
- 减少任务数构建:
cargo build -j 4 - 使用代替完整构建
check
依赖冲突
- 更新依赖:
cargo update - 查看依赖树:
cargo tree -e features - 检查重复依赖:
cargo tree -d | grep -cE "^[a-z]"
平台相关问题
- 安装目标平台:
rustup target add <triple> - 条件编译:
#[cfg(target_os = "linux")]
References
参考资料
- ADR-032: Disk Space Optimization
- ADR-036: Dependency Deduplication
- ADR-032: 磁盘空间优化
- ADR-036: 依赖去重