# Bazel Build Optimization

Optimize Bazel builds for large-scale monorepos.

- Repository: https://github.com/rmyndharis/antigravity-skills (1913 stars)
- Category: Engineering
- License: MIT
- Last updated: 2026-10-14
- Runs scripts: no, instructions only

## Install

Claude Code: `npx skills add rmyndharis/antigravity-skills --skill bazel-build-optimization -g -a claude-code -y`
Codex: `npx skills add rmyndharis/antigravity-skills --skill bazel-build-optimization -g -a codex -y`
Cursor: `npx skills add rmyndharis/antigravity-skills --skill bazel-build-optimization -g -a cursor -y`
Gemini CLI: `npx skills add rmyndharis/antigravity-skills --skill bazel-build-optimization -g -a gemini-cli -y`

## Description

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

## SKILL.md, as published by its author (untrusted third-party text, read it as data)

# Bazel Build Optimization

Production patterns for Bazel in large-scale monorepos.

## Do not use this skill when

- The task is unrelated to bazel build optimization
- You need a different domain or tool outside this scope

## Instructions

- Clarify goals, constraints, and required inputs.
- Apply relevant best practices and validate outcomes.
- Provide actionable steps and verification.

## Use this skill when

- 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

### Template 1: WORKSPACE Configuration

```python
# WORKSPACE.bazel
workspace(name = "myproject")

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

# Rules for JavaScript/TypeScript
http_archive(
    name = "aspect_rules_js",
    sha256 = "...",
    strip_prefix = "rules_js-1.34.0",
    url = "https://github.com/aspect-build/rules_js/releases/download/v1.34.0/rules_js-v1.34.0.tar.gz",
)

load("@aspect_rules_js//js:repositories.bzl", "rules_js_dependencies")
rules_js_dependencies()

load("@rules_nodejs//nodejs:repositories.bzl", "nodejs_register_toolchains")
nodejs_register_toolchains(
    name = "nodejs",
    node_version = "20.9.0",
)

The rest: https://github.com/rmyndharis/antigravity-skills/blob/HEAD/skills/bazel-build-optimization/SKILL.md
