Bazel Build Optimization

by wshobson46891e7e60daNo licenseListed Oct 8, 2026Updated Oct 8, 2026

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

AI-generated overview

Guides Bazel configuration and build performance optimization for large-scale monorepos.

What it does
This skill provides production patterns for using Bazel in large-scale monorepos. It covers core concepts such as targets, packages, labels, rules, and aspects, along with best practices for fine-grained targets, dependency pinning, remote caching, and visibility. It also points to a references file containing templates and detailed worked examples.
When to use it
Use it when setting up Bazel for a monorepo, configuring remote caching or execution, optimizing build times, writing custom Bazel rules, debugging build issues, or migrating to Bazel.
Requirements
No scripts are included; it is instructions only. It references a model-readable file at references/details.md for templates and worked examples.

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

Source and attribution

Source:wshobson/agentsinplugins/developer-essentials/skills/bazel-build-optimizationat commit46891e7

License: No license

Content belongs to its original authors. SourceWeft indexes it from a public repository.

Report or request removal