bazel-build-optimization
Optimize Bazel builds for large-scale monorepos. Use when configuring Bazel, implementing remote execution, or optimizing build performance for enterprise codebases.
Author
Category
Development ToolsInstall
Hot:27
Download and extract to your skills directory
Copy command and send to OpenClaw for auto-install:
Download and install this skill https://openskills.cc/api/download?slug=sickn33-skills-bazel-build-optimization&locale=en&source=copy
Bazel Build Optimization
Skill Overview
Provide Bazel build optimization solutions for large monorepos, covering build configuration, remote caching, custom rule authoring, and performance tuning, helping enterprise-scale codebases achieve fast and reliable builds.
Applicable Scenarios
When your repository contains multiple projects and multiple languages and build time becomes a development bottleneck, use this skill to optimize Bazel build performance, configure remote caching and execution, and reduce build times from hours to minutes.
When you need to introduce Bazel to a new or existing project, use this skill to complete WORKSPACE configuration, write BUILD files, set up toolchains and platform configuration, and establish a scalable build infrastructure.
When your Bazel builds suffer from performance regressions, excessive memory usage, or build failures, use this skill for dependency analysis, build profiling, root cause identification, and fixes to restore build efficiency.
Core Features
Provide full configuration templates for WORKSPACE, .bazelrc, and BUILD files, supporting multi-language projects such as TypeScript, Python, and Java, and including best practices for dependency management, toolchain registration, and platform configuration.
Configure a Bazel remote cache server to share build artifacts and enable distributed remote execution to increase build parallelism. Support CI/CD integration and team collaboration scenarios to greatly reduce redundant build time.
Write Starlark custom rules to extend build capabilities, use bazel query for dependency analysis and impact assessment, and identify performance bottlenecks through build profiling.
Frequently Asked Questions
What scale of projects is Bazel suitable for?
Bazel is best suited for medium-to-large monorepos and enterprise projects that span multiple technology stacks. If your project build time exceeds 10 minutes, contains multiple subprojects, and requires incremental builds and remote caching, Bazel is an ideal choice. For small single-language projects, Bazel's learning cost may outweigh the benefits.
How to optimize Bazel builds that are too slow?
Common ways to optimize Bazel build speed include: enabling local disk cache (--disk_cache) and repository cache (--repository_cache), configuring a remote cache to share build artifacts, adjusting concurrency resource settings (--jobs, --local_cpu_resources), using bazel query to analyze dependencies and find unnecessary dependency chains, and using build profiling to locate slow actions. For very large projects, it is recommended to configure remote execution (--remote_executor) to enable distributed builds.
How to configure Bazel remote cache?
Add remote cache configuration in .bazelrc:
build --remote_cache=grpcs://cache.example.com and set --remote_upload_local_results=true. You can use a self-hosted cache service (such as bazel-remote) or cloud services (such as Google Remote Build Execution). After configuration, the team shares build artifacts and avoids rebuilding the same dependencies. In CI environments, it is recommended to also configure BES (Build Event Service) for visualizing build results.How to write custom Bazel rules?
Use the Starlark language to define rules in .bzl files. A rule includes an implementation function (describing build logic), attrs (defining attributes), and return values (typically DefaultInfo). For example, creating a docker_image rule requires defining attributes like dockerfile and base_image; in the implementation you use ctx.actions.run to execute build commands and finally return the output files. See Template 5 for a complete example.