bazel-build-optimization

Configure and optimize Bazel builds for large-scale monorepos with remote caching and execution.

Updated Apr 23, 2026
One-click install
npx skills add https://github.com/SanketAdlak/PDMProjectDesign --skill bazel-build-optimization-sanketadlak
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: bazel-build-optimization
Source: https://github.com/SanketAdlak/PDMProjectDesign/tree/main/.agents/skills/bazel-build-optimization
Command: npx skills add https://github.com/SanketAdlak/PDMProjectDesign --skill bazel-build-optimization-sanketadlak

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Setting up and tuning Bazel for large monorepos involves complex WORKSPACE configuration, BUILD file authoring, remote caching, and performance profiling that is difficult to get right without proven patterns. ## Core Features & Use Cases - Workspace and .bazelrc Templates: Ready-to-use configurations for JavaScript/TypeScript (rules_js, rules_ts), Python (rules_python), remote caching, and remote execution. - Custom Rule Authoring: Patterns for writing custom Bazel rules in Starlark, such as Docker image builds. - Dependency Analysis & Profiling: Query recipes for dependency graphs, reverse dependencies, changed targets, and build performance profiling. - Use Case: A platform team migrating a polyglot monorepo to Bazel can use these templates to configure toolchains, enable remote execution on CI, and profile slow build actions. ## Quick Start Ask the AI to generate a Bazel WORKSPACE and .bazelrc configuration for a TypeScript and Python monorepo with remote caching enabled.

Frequently Asked Questions about bazel-build-optimization

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I set up Bazel for a monorepo with TypeScript and Python?

Define external dependencies in WORKSPACE.bazel using http_archive for aspect_rules_js and rules_python, then register toolchains and npm packages via npm_translate_lock. Create per-directory BUILD.bazel files with ts_project and py_library targets for fine-grained caching.

How to enable remote caching and remote execution in Bazel?

Add --remote_cache=grpcs://your-cache-endpoint to .bazelrc for caching, and --remote_executor with platform definitions for remote execution. Use named configs like build:remote-cache and build:ci so teams can opt in per environment.

How do I find what depends on a Bazel target?

Use bazel query "rdeps(//..., //libs/utils:utils)" to find reverse dependencies of a target. You can also run bazel query "deps(//target)" --output=graph piped to Graphviz dot to visualize the dependency graph.

Why is my Bazel build slow and how do I profile it?

Slow builds usually come from coarse-grained targets, missing cache hits, or oversized actions. Run bazel build with --profile=profile.json and analyze it with bazel analyze-profile, or use --execution_log_json_file to identify slow actions.

Can I write custom Bazel rules for Docker images?

Yes, define a rule in a .bzl file using the rule() function with an implementation that calls ctx.actions.run to invoke a builder tool. Declare inputs, outputs, and attributes like dockerfile and base_image, then load the rule in BUILD files.

When should I not use glob in Bazel BUILD files?

Avoid glob for deps since explicit dependency lists improve cache correctness and prevent accidental coupling. Glob is acceptable for srcs within a package, but cross-package dependencies should always be declared explicitly.