Bazel Build Optimization

作者 wshobson46891e7e60da无许可证收录于 2026年10月8日更新于 2026年10月8日

Optimize Bazel builds for large-scale monorepos. Use when configuring Bazel, implementing remote execution, or optimizing build performance for enterprise codebases.

AI 生成的概览

指导大型单体仓库的 Bazel 配置与构建性能优化。

功能
该技能提供在大型单体仓库中使用 Bazel 的生产实践模式。它涵盖目标、包、标签、规则和切面等核心概念,以及细粒度目标、依赖固定、远程缓存和可见性等最佳实践。它还指向一个包含模板和详细示例的参考文件。
适用场景
适用于为单体仓库设置 Bazel、配置远程缓存或执行、优化构建时间、编写自定义 Bazel 规则、调试构建问题或迁移到 Bazel 的场景。
运行要求
不包含脚本,仅为说明性内容。它引用了一个模型可读文件 references/details.md,其中包含模板和详细示例。

Bazel Build Optimization

Production patterns for Bazel in large-scale monorepos.

When to Use This Skill

  • Setting up Bazel for monorepos
  • Configuring remote caching/execution
  • Optimizing build times
  • Writing custom Bazel rules
  • Debugging build issues
  • Migrating to Bazel

Core Concepts

1. Bazel Architecture

workspace/├── WORKSPACE.bazel       # External dependencies├── .bazelrc              # Build configurations├── .bazelversion         # Bazel version├── BUILD.bazel           # Root build file├── apps/│   └── web/│       └── BUILD.bazel├── libs/│   └── utils/│       └── BUILD.bazel└── tools/    └── bazel/        └── rules/

2. Key Concepts

ConceptDescription
TargetBuildable unit (library, binary, test)
PackageDirectory with BUILD file
LabelTarget identifier //path/to:target
RuleDefines how to build a target
AspectCross-cutting build behavior

Templates and detailed worked examples

Full template library and detailed worked examples live in references/details.md. Read that file when you need the concrete templates.

Best Practices

Do's

  • Use fine-grained targets - Better caching
  • Pin dependencies - Reproducible builds
  • Enable remote caching - Share build artifacts
  • Use visibility wisely - Enforce architecture
  • Write BUILD files per directory - Standard convention

Don'ts

  • Don't use glob for deps - Explicit is better
  • Don't commit bazel-* dirs - Add to .gitignore
  • Don't skip WORKSPACE setup - Foundation of build
  • Don't ignore build warnings - Technical debt

来源与署名

来源:wshobson/agents位于plugins/developer-essentials/skills/bazel-build-optimization提交46891e7

许可证: 无许可证

内容归原作者所有。SourceWeft 从公开仓库中收录这些内容。

举报或申请下架