$npx -y skills add wshobson/agents --skill bazel-build-optimizationOptimize Bazel builds for large-scale monorepos. Use when configuring Bazel, implementing remote execution, or optimizing build performance for enterprise codebases.
| 1 | # Bazel Build Optimization |
| 2 | |
| 3 | Production patterns for Bazel in large-scale monorepos. |
| 4 | |
| 5 | ## When to Use This Skill |
| 6 | |
| 7 | - Setting up Bazel for monorepos |
| 8 | - Configuring remote caching/execution |
| 9 | - Optimizing build times |
| 10 | - Writing custom Bazel rules |
| 11 | - Debugging build issues |
| 12 | - Migrating to Bazel |
| 13 | |
| 14 | ## Core Concepts |
| 15 | |
| 16 | ### 1. Bazel Architecture |
| 17 | |
| 18 | ``` |
| 19 | workspace/ |
| 20 | ├── WORKSPACE.bazel # External dependencies |
| 21 | ├── .bazelrc # Build configurations |
| 22 | ├── .bazelversion # Bazel version |
| 23 | ├── BUILD.bazel # Root build file |
| 24 | ├── apps/ |
| 25 | │ └── web/ |
| 26 | │ └── BUILD.bazel |
| 27 | ├── libs/ |
| 28 | │ └── utils/ |
| 29 | │ └── BUILD.bazel |
| 30 | └── tools/ |
| 31 | └── bazel/ |
| 32 | └── rules/ |
| 33 | ``` |
| 34 | |
| 35 | ### 2. Key Concepts |
| 36 | |
| 37 | | Concept | Description | |
| 38 | | ----------- | -------------------------------------- | |
| 39 | | **Target** | Buildable unit (library, binary, test) | |
| 40 | | **Package** | Directory with BUILD file | |
| 41 | | **Label** | Target identifier `//path/to:target` | |
| 42 | | **Rule** | Defines how to build a target | |
| 43 | | **Aspect** | Cross-cutting build behavior | |
| 44 | |
| 45 | ## Templates and detailed worked examples |
| 46 | |
| 47 | Full template library and detailed worked examples live in `references/details.md`. Read that file when you need the concrete templates. |
| 48 | |
| 49 | ## Best Practices |
| 50 | |
| 51 | ### Do's |
| 52 | |
| 53 | - **Use fine-grained targets** - Better caching |
| 54 | - **Pin dependencies** - Reproducible builds |
| 55 | - **Enable remote caching** - Share build artifacts |
| 56 | - **Use visibility wisely** - Enforce architecture |
| 57 | - **Write BUILD files per directory** - Standard convention |
| 58 | |
| 59 | ### Don'ts |
| 60 | |
| 61 | - **Don't use glob for deps** - Explicit is better |
| 62 | - **Don't commit bazel-\* dirs** - Add to .gitignore |
| 63 | - **Don't skip WORKSPACE setup** - Foundation of build |
| 64 | - **Don't ignore build warnings** - Technical debt |