build-rust

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Rust Build Operations

Rust构建操作

Efficiently build Rust workspaces with the build-rust CLI.
使用build-rust CLI高效构建Rust工作区。

Usage

使用方法

bash
undefined
bash
undefined

Development (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
undefined

Modes

模式说明

ModePurposeFlags
dev
Development build
--workspace
release
Production optimized
--release --workspace
profile
Performance timing
--release --timings
check
Fast type-check
--workspace
clean
Clean artifacts
--clean
模式用途标志
dev
开发构建
--workspace
release
生产环境优化构建
--release --workspace
profile
性能计时分析
--release --timings
check
快速类型检查
--workspace
clean
清理构建产物
--clean

Disk Space Optimization (ADR-032)

磁盘空间优化(ADR-032)

The dev profile is optimized to reduce target/ size (~5.2 GB → ~2 GB):
toml
undefined
dev配置文件已优化以减小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-modules
Artifact offloading with
CARGO_TARGET_DIR
:
bash
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_DIR
转移构建产物
bash
CARGO_TARGET_DIR=/mnt/fastssd/rslm-target ./scripts/build-rust.sh dev
CARGO_TARGET_DIR=/mnt/fastssd/rslm-target ./scripts/clean-artifacts.sh standard

Common Issues

常见问题

Timeouts
  • Use
    dev
    mode for faster iteration
  • Reduce parallel jobs:
    CARGO_BUILD_JOBS=4 ./scripts/build-rust.sh release
Memory errors
  • Build with fewer jobs:
    cargo build -j 4
  • Use
    check
    instead of full build
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: 依赖去重