bazel-build-optimization
wshobson/agents
Optimize Bazel builds for large-scale monorepos with remote caching and custom rules.
What is bazel-build-optimization?
Bazel build optimization provides production patterns for configuring Bazel in large-scale monorepos, including remote caching/execution setup, custom rule writing, and build performance tuning. Use this when setting up Bazel, migrating to it, or debugging build issues in enterprise codebases.
- Configure Bazel workspace structure with WORKSPACE.bazel, BUILD.bazel, and .bazelrc files
- Set up remote caching and remote execution for distributed builds
- Write custom Bazel rules and aspects for project-specific build logic
- Optimize build times through fine-grained targets and dependency management
- Debug build issues and enforce architecture constraints with visibility rules
- Migrate existing projects to Bazel with reproducible build setup
How to install bazel-build-optimization
npx skills add https://github.com/wshobson/agents --skill bazel-build-optimizationHow to use bazel-build-optimization
- 1.Create WORKSPACE.bazel file to declare external dependencies
- 2.Set up .bazelrc with build configurations and remote caching settings
- 3.Write BUILD.bazel files per directory with fine-grained targets
- 4.Configure remote execution backend if using distributed builds
- 5.Pin dependency versions for reproducible builds
- 6.Enable visibility rules to enforce architectural boundaries
- 7.Test builds locally before deploying to remote execution
Use cases
- Setting up Bazel for a new monorepo with multiple apps and shared libraries
- Implementing remote caching to share build artifacts across team members
- Optimizing CI/CD pipeline by enabling remote execution for faster builds
- Writing custom rules for domain-specific build requirements
- Migrating a legacy build system to Bazel while maintaining reproducibility
- Build engineers managing large-scale monorepos
- DevOps engineers optimizing CI/CD pipelines
- Platform teams standardizing build infrastructure
- Software architects designing modular codebases
bazel-build-optimization FAQ
A package is a directory containing a BUILD file. A target is a buildable unit (library, binary, test) defined in that BUILD file. A label is the unique identifier for a target, formatted as //path/to:target.
Fine-grained targets enable better caching and incremental builds. Explicit dependencies are more maintainable and prevent unnecessary rebuilds when unrelated files change.
Configure remote caching in .bazelrc by specifying a remote cache backend URL and enabling the --remote_cache flag. This allows build artifacts to be shared across team members and CI/CD runs.
Add bazel-* directories (bazel-bin, bazel-genfiles, bazel-out, bazel-testlogs) to .gitignore to avoid committing generated build artifacts.
Start by setting up WORKSPACE.bazel with external dependencies, create BUILD files incrementally per directory, pin all dependency versions, and test builds locally before enabling remote execution.
Full instructions (SKILL.md)
Source of truth, from wshobson/agents.
name: bazel-build-optimization description: Optimize Bazel builds for large-scale monorepos. Use when configuring Bazel, implementing remote execution, or optimizing build performance for enterprise codebases.
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
| Concept | Description |
|---|---|
| Target | Buildable unit (library, binary, test) |
| Package | Directory with BUILD file |
| Label | Target identifier //path/to:target |
| Rule | Defines how to build a target |
| Aspect | Cross-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
Related skills
More from wshobson/agents and the wider catalog.

before-you-build
Pre-build risk review for products, features, and launches—identify assumptions and validation steps before implementation.

billing-automation
Build automated billing systems for recurring payments, invoicing, subscriptions, and dunning management.

binary-analysis-patterns
Master disassembly, decompilation, control flow analysis, and code pattern recognition for binary analysis.

block-no-verify-hook
Prevent AI agents from bypassing git pre-commit hooks with --no-verify flags.

brand-landingpage
Brand-first landing page designer with guided interviews and Stitch-powered iteration.

changelog-automation
Automate changelog generation from commits and releases using Keep a Changelog and Conventional Commits.