build-compile
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseBuild 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
构建模式
| Mode | Use Case | Performance | Size | Flags |
|---|---|---|---|---|
| Development iteration | Fast | Large | |
| Production deployment | Optimized | Medium | |
| Performance analysis | Medium | Medium | |
| Fast validation | Fastest | N/A | |
| Artifact cleanup | N/A | N/A | |
| 模式 | 使用场景 | 性能 | 大小 | 标志 |
|---|---|---|---|---|
| 开发迭代 | 快速 | 大 | |
| 生产部署 | 已优化 | 中等 | |
| 性能分析 | 中等 | 中等 | |
| 快速验证 | 最快 | 不适用 | |
| 清理构建产物 | 不适用 | 不适用 | |
CLI Integration
CLI集成
For human operators, see the build-rust CLI documentation:
bash
undefined面向人工操作者,请查看build-rust CLI文档:
bash
undefinedQuick 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
undefinedError Handling Patterns
错误处理模式
Timeout Errors
- Symptom: Build exceeds time limits
- Diagnosis: Check parallelism
CARGO_BUILD_JOBS - Solution: Reduce concurrency:
CARGO_BUILD_JOBS=4 cargo build - Alternative: Use mode for faster feedback
check
Memory Errors
- Symptom: OOM during link phase
- Diagnosis: Monitor with
/usr/bin/time -v cargo build - Solution: (sequential)
cargo build -j 1 - Fallback: Use mode (no codegen)
check
Dependency Conflicts
- Symptom: Feature flag conflicts
- Diagnosis:
cargo tree -e features - Solution: for compatible versions
cargo update - Manual: Edit feature resolution
Cargo.toml
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
undefinedDefault: 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**
```bashhyperfine -N 'cargo build -j 1' 'cargo build -j 2' 'cargo build -j 4'
**构建产物管理**
```bashSave 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
undefinedldd target/release/memory-mcp
./target/release/memory-mcp --version
undefinedVerification 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-depsQuick Development Cycle
bash
#!/usr/bin/env bash
cargo check -p memory-core
cargo test -p memory-core --lib
cargo build -p memory-coreProduction 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-* > SHA256SUMSTroubleshooting
故障排查
Issue: Incremental compilation cache corruption
Fix:
cargo clean && cargo buildIssue: Stale lock file
Fix:
rm Cargo.lock && cargo generate-lockfileIssue: 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-muslRelated 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流水线集成