build-compile

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Build Compile Agent

构建编译Agent

Orchestrate Rust build operations with proper error handling, optimization, and workspace management. Use this agent when compiling the self-learning memory project or troubleshooting build errors in CI/CD pipelines.
对Rust构建操作进行编排,具备完善的错误处理、优化和工作区管理能力。在编译自学习内存项目或排查CI/CD流水线中的构建错误时可使用该Agent。

Core Capabilities

核心能力

Build Operations
  • Compile Rust workspaces with appropriate optimization levels
  • Handle build errors with systematic debugging
  • Manage cross-compilation and platform-specific targets
  • Parallel build optimization for CI/CD
Error Diagnosis
  • Parse compiler error messages
  • Identify dependency conflicts
  • Resolve feature flag issues
  • Detect memory/timeout constraints
Quality Assurance
  • Run clippy for lint checks
  • Execute test suite compilation
  • Verify release build integrity
  • Validate stripped binary sizes
构建操作
  • 以合适的优化级别编译Rust工作区
  • 通过系统化调试处理构建错误
  • 管理交叉编译和特定平台目标
  • 针对CI/CD的并行构建优化
错误诊断
  • 解析编译器错误信息
  • 识别依赖冲突
  • 解决特性标志问题
  • 检测内存/超时限制
质量保证
  • 运行clippy进行代码检查
  • 执行测试套件编译
  • 验证发布构建的完整性
  • 验证剥离调试符号后的二进制文件大小

Build Modes

构建模式

ModeUse CasePerformanceSizeFlags
dev
Development iterationFastLarge
--workspace
release
Production deploymentOptimizedMedium
--release --workspace
profile
Performance analysisMediumMedium
--release --timings
check
Fast validationFastestN/A
--workspace
(type-check only)
clean
Artifact cleanupN/AN/A
--clean
模式使用场景性能大小标志
dev
开发迭代快速
--workspace
release
生产部署已优化中等
--release --workspace
profile
性能分析中等中等
--release --timings
check
快速验证最快不适用
--workspace
(仅类型检查)
clean
清理构建产物不适用不适用
--clean

CLI Integration

CLI集成

For human operators, see the build-rust CLI documentation:
bash
undefined
面向人工操作者,请查看build-rust CLI文档:
bash
undefined

Quick development iteration

快速开发迭代

./scripts/build-rust.sh dev
./scripts/build-rust.sh dev

Production build

生产环境构建

./scripts/build-rust.sh release
./scripts/build-rust.sh release

Performance profiling

性能分析

./scripts/build-rust.sh profile
./scripts/build-rust.sh profile

Fast type-check

快速类型检查

./scripts/build-rust.sh check
./scripts/build-rust.sh check

Clean artifacts

清理构建产物

./scripts/build-rust.sh clean
undefined
./scripts/build-rust.sh clean
undefined

Error Handling Patterns

错误处理模式

Timeout Errors
  • Symptom: Build exceeds time limits
  • Diagnosis: Check
    CARGO_BUILD_JOBS
    parallelism
  • Solution: Reduce concurrency:
    CARGO_BUILD_JOBS=4 cargo build
  • Alternative: Use
    check
    mode for faster feedback
Memory Errors
  • Symptom: OOM during link phase
  • Diagnosis: Monitor with
    /usr/bin/time -v cargo build
  • Solution:
    cargo build -j 1
    (sequential)
  • Fallback: Use
    check
    mode (no codegen)
Dependency Conflicts
  • Symptom: Feature flag conflicts
  • Diagnosis:
    cargo tree -e features
  • Solution:
    cargo update
    for compatible versions
  • Manual: Edit
    Cargo.toml
    feature resolution
Platform-Specific
  • Symptom: Missing target triple
  • Diagnosis: Check
    rustc --print target-list
  • Solution:
    rustup target add <triple>
  • Conditional:
    #[cfg(target_os = "linux")]
超时错误
  • 症状:构建超出时间限制
  • 诊断:检查
    CARGO_BUILD_JOBS
    并行度
  • 解决方案:降低并发度:
    CARGO_BUILD_JOBS=4 cargo build
  • 替代方案:使用
    check
    模式获取更快反馈
内存错误
  • 症状:链接阶段出现内存不足(OOM)
  • 诊断:使用
    /usr/bin/time -v cargo build
    进行监控
  • 解决方案:
    cargo build -j 1
    (串行构建)
  • 备选方案:使用
    check
    模式(无代码生成)
依赖冲突
  • 症状:特性标志冲突
  • 诊断:执行
    cargo tree -e features
  • 解决方案:
    cargo update
    更新至兼容版本
  • 手动处理:编辑
    Cargo.toml
    调整特性解析
特定平台问题
  • 症状:缺少目标三元组
  • 诊断:检查
    rustc --print target-list
  • 解决方案:
    rustup target add <triple>
  • 条件编译:使用
    #[cfg(target_os = "linux")]

CI/CD Optimization

CI/CD优化

Caching Strategy
yaml
- name: Cache cargo registry
  uses: actions/cache@v3
  with:
    path: ~/.cargo/registry
    key: ${{ runner.os }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }}
Parallel Jobs
bash
undefined
缓存策略
yaml
- name: Cache cargo registry
  uses: actions/cache@v3
  with:
    path: ~/.cargo/registry
    key: ${{ runner.os }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }}
并行任务
bash
undefined

Default: Number of CPU cores

默认:CPU核心数

export CARGO_BUILD_JOBS=4
export CARGO_BUILD_JOBS=4

Measure optimal concurrency

测量最优并发度

hyperfine -N 'cargo build -j 1' 'cargo build -j 2' 'cargo build -j 4'

**Artifact Management**
```bash
hyperfine -N 'cargo build -j 1' 'cargo build -j 2' 'cargo build -j 4'

**构建产物管理**
```bash

Save compiled dependencies

保存编译后的依赖

cargo build --release
cargo build --release

Strip debug symbols (80% size reduction)

剥离调试符号(大小减少80%)

strip target/release/memory-mcp
strip target/release/memory-mcp

Verify binary

验证二进制文件

ldd target/release/memory-mcp ./target/release/memory-mcp --version
undefined
ldd target/release/memory-mcp ./target/release/memory-mcp --version
undefined

Verification Checklist

验证清单

  • Build completes without errors
  • No clippy warnings (
    cargo clippy -- -D warnings
    )
  • Tests compile (
    cargo test --no-run
    )
  • Binary size acceptable (< 10MB stripped)
  • Startup time < 100ms
  • No memory leaks (valgrind/check)
  • Cross-platform targets build successfully
  • 构建无错误完成
  • 无clippy警告 (
    cargo clippy -- -D warnings
    )
  • 测试套件编译通过 (
    cargo test --no-run
    )
  • 二进制文件大小符合要求(剥离后<10MB)
  • 启动时间<100ms
  • 无内存泄漏(valgrind/check检测)
  • 跨平台目标构建成功

Common Workflows

常见工作流

Full CI Pipeline
bash
#!/usr/bin/env bash
set -euxo pipefail
./scripts/code-quality.sh fmt
./scripts/code-quality.sh clippy --workspace
cargo build --release --workspace
cargo test --all
cargo doc --no-deps
Quick Development Cycle
bash
#!/usr/bin/env bash
cargo check -p memory-core
cargo test -p memory-core --lib
cargo build -p memory-core
Production Release
bash
#!/usr/bin/env bash
cargo build --release --workspace
strip target/release/memory-*
upx --best --lzma target/release/memory-*
sha256sum target/release/memory-* > SHA256SUMS
完整CI流水线
bash
#!/usr/bin/env bash
set -euxo pipefail
./scripts/code-quality.sh fmt
./scripts/code-quality.sh clippy --workspace
cargo build --release --workspace
cargo test --all
cargo doc --no-deps
快速开发周期
bash
#!/usr/bin/env bash
cargo check -p memory-core
cargo test -p memory-core --lib
cargo build -p memory-core
生产环境发布
bash
#!/usr/bin/env bash
cargo build --release --workspace
strip target/release/memory-*
upx --best --lzma target/release/memory-*
sha256sum target/release/memory-* > SHA256SUMS

Troubleshooting

故障排查

Issue: Incremental compilation cache corruption Fix:
cargo clean && cargo build
Issue: Stale lock file Fix:
rm Cargo.lock && cargo generate-lockfile
Issue: Rust version mismatch Fix:
rustup update stable && rustup default stable
**Issue: Cross-compilation failures Fix: Install toolchain:
rustup target add x86_64-unknown-linux-musl
问题:增量编译缓存损坏 修复方案
cargo clean && cargo build
问题:过时的锁文件 修复方案
rm Cargo.lock && cargo generate-lockfile
问题:Rust版本不匹配 修复方案
rustup update stable && rustup default stable
问题:交叉编译失败 修复方案:安装工具链:
rustup target add x86_64-unknown-linux-musl

Related Skills

相关技能

  • code-quality: Lint and format checks before builds
  • test-runner: Execute tests after successful compilation
  • debug-troubleshoot: Diagnose runtime issues post-build
  • github-workflows: CI/CD pipeline integration
  • code-quality:构建前的代码检查与格式化
  • test-runner:编译成功后执行测试
  • debug-troubleshoot:构建后诊断运行时问题
  • github-workflows:CI/CD流水线集成