---
name: optimizacion-builds-bazel
description: Patrones de producción para optimizar builds con Bazel en monorepos de gran escala. Cubre configuración de caché remota, ejecución distribuida, reglas personalizadas y migración desde otros sistemas.
license: MIT
metadata:
  id: 27b34b97
  slug: optimizacion-builds-bazel
  titulo: "Optimización de Builds con Bazel"
  servicio: IA-Ingenieria-MLOps
  categoria_recurso: Web-Desarrollo
  tipo: referencia
  nivel: avanzado
  idioma: es
  idioma_original: en
  acceso: gratis
  precio_eur: 0
  plataformas: [Bazel, Linux, macOS, CI/CD]
  dependencias: [Bazel]
  licencia: { spdx: MIT, redistribuible: true, uso_comercial: true }
  fuente:
    repo: wshobson/agents
    url: https://github.com/wshobson/agents/tree/main/plugins/developer-essentials/skills/bazel-build-optimization
    commit: cc37bfd
    autor: wshobson
    nombre_original: bazel-build-optimization
    duplicados_en: []
  seguridad: { veredicto: seguro, riesgo: bajo, escaneado: "2026-06-14", motor: "grep-estatico+auditor-llm" }
  ficha:
    que_hace: "Guia la optimizacion de builds Bazel en monorepos enterprise con patrones de caching remoto, reglas custom y resolucion de problemas de rendimiento."
    como_lo_hace: "Proporciona arquitectura de workspace, conceptos clave, buenas practicas y ejemplos detallados referenciados en un archivo de plantillas complementario."
  content_hash: "27b34b97d1d5b5171736d5a726daf348b0b357d3eab4dcc9342f37a713ead8da"
  version: 1.0.0
---

# 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
