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 從公開儲存庫中收錄這些內容。

檢舉或申請下架