Install any skill in seconds. Free to start, no credit card required.
Get Started Free →Optimize Bazel builds for large-scale monorepos. Use when configuring Bazel, implementing remote execution, or optimizing build performance for enterprise codebases.
.claude/skills/dicklesworthstone-bazel-build-optimization/SKILL.md| Test case | Without → With | Effect | Δ tokens | Δ turns |
|---|---|---|---|---|
| case-02 | ✗→✓ | ▲ Improved | 124% | 0% |
| case-04 | ✗→✓ | ▲ Improved | 84% | 0% |
| case-06 | ✗→✓ | ▲ Improved | 169% | 0% |
| case-07 | ✗→✓ | ▲ Improved | 55% | 0% |
| case-18 | ✗→✓ | ▲ Improved | 227% | 0% |
Production patterns for Bazel in large-scale monorepos.
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/| 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 |
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", ) load("@aspect_rules_js//npm:repositories.bzl", "npm_translate_lock") npm_translate_lock( name = "npm", pnpm_lock = "//:pnpm-lock.yaml", verify_node_modules_ignored = "//:.bazelignore", ) load("@npm//:repositories.bzl", "npm_repositories") npm_repositories() # Rules for Python http_archive( name = "rules_python", sha256 = "...", strip_prefix = "rules_python-0.27.0", url = "https://github.com/bazelbuild/rules_python/releases/download/0.27.0/rules_python-0.27.0.tar.gz", ) load("@rules_python//python:repositories.bzl", "py_repositories") py_repositories()
bash# .bazelrc # Build settings build --enable_platform_specific_config build --incompatible_enable_cc_toolchain_resolution build --experimental_strict_conflict_checks # Performance build --jobs=auto build --local_cpu_resources=HOST_CPUS*.75 build --local_ram_resources=HOST_RAM*.75 # Caching build --disk_cache=~/.cache/bazel-disk build --repository_cache=~/.cache/bazel-repo # Remote caching (optional) build:remote-cache --remote_cache=grpcs://cache.example.com build:remote-cache --remote_upload_local_results=true build:remote-cache --remote_timeout=3600 # Remote execution (optional) build:remote-exec --remote_executor=grpcs://remote.example.com build:remote-exec --remote_instance_name=projects/myproject/instances/default build:remote-exec --jobs=500 # Platform configurations build:linux --platforms=//platforms:linux_x86_64 build:macos --platforms=//platforms:macos_arm64 # CI configuration build:ci --config=remote-cache build:ci --build_metadata=ROLE=CI build:ci --bes_results_url=https://results.example.com/invocation/ build:ci --bes_backend=grpcs://bes.example.com # Test settings test --test_output=errors test --test_summary=detailed # Coverage coverage --combined_report=lcov coverage --instrumentation_filter="//..." # Convenience aliases build:opt --compilation_mode=opt build:dbg --compilation_mode=dbg # Import user settings try-import %workspace%/user.bazelrc
python# libs/utils/BUILD.bazel load("@aspect_rules_ts//ts:defs.bzl", "ts_project") load("@aspect_rules_js//js:defs.bzl", "js_library") load("@npm//:defs.bzl", "npm_link_all_packages") npm_link_all_packages(name = "node_modules") ts_project( name = "utils_ts", srcs = glob(["src/**/*.ts"]), declaration = True, source_map = True, tsconfig = "//:tsconfig.json", deps = [ ":node_modules/@types/node", ], ) js_library( name = "utils", srcs = [":utils_ts"], visibility = ["//visibility:public"], ) # Tests load("@aspect_rules_jest//jest:defs.bzl", "jest_test") jest_test( name = "utils_test", config = "//:jest.config.js", data = [ ":utils", "//:node_modules/jest", ], node_modules = "//:node_modules", )
python# libs/ml/BUILD.bazel load("@rules_python//python:defs.bzl", "py_library", "py_test", "py_binary") load("@pip//:requirements.bzl", "requirement") py_library( name = "ml", srcs = glob(["src/**/*.py"]), deps = [ requirement("numpy"), requirement("pandas"), requirement("scikit-learn"), "//libs/utils:utils_py", ], visibility = ["//visibility:public"], ) py_test( name = "ml_test", srcs = glob(["tests/**/*.py"]), deps = [ ":ml", requirement("pytest"), ], size = "medium", timeout = "moderate", ) py_binary( name = "train", srcs = ["train.py"], deps = [":ml"], data = ["//data:training_data"], )
python# tools/bazel/rules/docker.bzl def _docker_image_impl(ctx): dockerfile = ctx.file.dockerfile base_image = ctx.attr.base_image layers = ctx.files.layers # Build the image output = ctx.actions.declare_file(ctx.attr.name + ".tar") args = ctx.actions.args() args.add("--dockerfile", dockerfile) args.add("--output", output) args.add("--base", base_image) args.add_all("--layer", layers) ctx.actions.run( inputs = [dockerfile] + layers, outputs = [output], executable = ctx.executable._builder, arguments = [args], mnemonic = "DockerBuild", progress_message = "Building Docker image %s" % ctx.label, ) return [DefaultInfo(files = depset([output]))] docker_image = rule( implementation = _docker_image_impl, attrs = { "dockerfile": attr.label( allow_single_file = [".dockerfile", "Dockerfile"], mandatory = True, ), "base_image": attr.string(mandatory = True), "layers": attr.label_list(allow_files = True), "_builder": attr.label( default = "//tools/docker:builder", executable = True, cfg = "exec", ), }, )
bash# Find all dependencies of a target bazel query "deps(//apps/web:web)" # Find reverse dependencies (what depends on this) bazel query "rdeps(//..., //libs/utils:utils)" # Find all targets in a package bazel query "//libs/..." # Find changed targets since commit bazel query "rdeps(//..., set($(git diff --name-only HEAD~1 | sed 's/.*/"&"/' | tr '\n' ' ')))" # Generate dependency graph bazel query "deps(//apps/web:web)" --output=graph | dot -Tpng > deps.png # Find all test targets bazel query "kind('.*_test', //...)" # Find targets with specific tag bazel query "attr(tags, 'integration', //...)" # Compute build graph size bazel query "deps(//...)" --output=package | wc -l
python# platforms/BUILD.bazel platform( name = "linux_x86_64", constraint_values = [ "@platforms//os:linux", "@platforms//cpu:x86_64", ], exec_properties = { "container-image": "docker://gcr.io/myproject/bazel-worker:latest", "OSFamily": "Linux", }, ) platform( name = "remote_linux", parents = [":linux_x86_64"], exec_properties = { "Pool": "default", "dockerNetwork": "standard", }, ) # toolchains/BUILD.bazel toolchain( name = "cc_toolchain_linux", exec_compatible_with = [ "@platforms//os:linux", "@platforms//cpu:x86_64", ], target_compatible_with = [ "@platforms//os:linux", "@platforms//cpu:x86_64", ], toolchain = "@remotejdk11_linux//:jdk", toolchain_type = "@bazel_tools//tools/jdk:runtime_toolchain_type", )
bash# Profile build bazel build //... --profile=profile.json bazel analyze-profile profile.json # Identify slow actions bazel build //... --execution_log_json_file=exec_log.json # Memory profiling bazel build //... --memory_profile=memory.json # Skip analysis cache bazel build //... --notrack_incremental_state
| Case | Status | Duration (ms) | Turns | Tokens | Tool calls | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Without | With | Δ | Without | With | Δ | Without | With | Δ | Without | With | Δ | ||
case-08 | pass→pass | 13,048 | 9,611 | -26% | 1 | 1 | 0% | 2,497 | 4,928 | +97% | 0 | 0 | — |
case-01 | fail→fail | 17,968 | 46,139 | +157% | 1 | 1 | 0% | 3,324 | 6,261 | +88% | 0 | 0 | — |
case-02 | fail→pass | 11,115 | 10,070 | -9% | 1 | 1 | 0% | 2,189 | 4,909 | +124% | 0 | 0 | — |
case-03 | fail→fail | 20,144 | 21,498 | +7% | 1 | 1 | 0% | 4,132 | 5,738 | +39% | 0 | 0 | — |
case-04 | fail→pass | 14,783 | 5,222 | -65% | 1 | 1 | 0% | 2,100 | 3,854 | +84% | 0 | 0 | — |
case-05 | pass→pass | 11,021 | 7,995 | -27% | 1 | 1 | 0% | 2,251 | 4,470 | +99% | 0 | 0 | — |
case-06 | fail→pass | 7,903 | 5,674 | -28% | 1 | 1 | 0% | 1,535 | 4,136 | +169% | 0 | 0 | — |
case-07 | fail→pass | 13,767 | 6,581 | -52% | 1 | 1 | 0% | 2,703 | 4,180 | +55% | 0 | 0 | — |
case-09 | pass→fail | 12,941 | 9,487 | -27% | 1 | 1 | 0% | 2,276 | 4,637 | +104% | 0 | 0 | — |
case-10 | fail→fail | 15,484 | 15,482 | -0% | 1 | 1 | 0% | 2,403 | 6,027 | +151% | 0 | 0 | — |
case-11 | pass→pass | 8,690 | 6,246 | -28% | 1 | 1 | 0% | 1,296 | 3,734 | +188% | 0 | 0 | — |
case-12 | pass→pass | 21,212 | 13,484 | -36% | 1 | 1 | 0% | 3,688 | 5,375 | +46% | 0 | 0 | — |
case-13 | pass→pass | 10,121 | 2,492 | -75% | 1 | 1 | 0% | 1,703 | 3,381 | +99% | 0 | 0 | — |
case-14 | pass→pass | 13,082 | 6,930 | -47% | 1 | 1 | 0% | 1,778 | 3,967 | +123% | 0 | 0 | — |
case-15 | fail→fail | 13,487 | 9,452 | -30% | 1 | 1 | 0% | 2,234 | 4,732 | +112% | 0 | 0 | — |
case-16 | pass→pass | 16,926 | 14,549 | -14% | 1 | 1 | 0% | 2,620 | 5,309 | +103% | 0 | 0 | — |
case-17 | pass→pass | 14,216 | 10,829 | -24% | 1 | 1 | 0% | 2,539 | 4,737 | +87% | 0 | 0 | — |
case-18 | fail→pass | 5,600 | 2,415 | -57% | 1 | 1 | 0% | 986 | 3,229 | +227% | 0 | 0 | — |
case-19 | pass→pass | 15,701 | 17,717 | +13% | 1 | 1 | 0% | 2,607 | 5,526 | +112% | 0 | 0 | — |
case-20 | pass→pass | 16,328 | 14,374 | -12% | 1 | 1 | 0% | 2,279 | 5,286 | +132% | 0 | 0 | — |
case-21 | pass→pass | 13,109 | 11,226 | -14% | 1 | 1 | 0% | 2,304 | 4,597 | +100% | 0 | 0 | — |
case-22 | pass→fail | 10,452 | 7,437 | -29% | 1 | 1 | 0% | 1,839 | 4,262 | +132% | 0 | 0 | — |
case-23 | pass→pass | 13,544 | 8,218 | -39% | 1 | 1 | 0% | 2,535 | 4,541 | +79% | 0 | 0 | — |
DecimalAI ran this skill against gemini-3.6-flash twice over the same eval suite — once with the skill loaded and once without — and compared the two runs case by case. 23 cases were attempted. The headline lift of +13 percentage points is the difference between those two pass rates over the 23 comparable cases. 2 cases got worse with the skill loaded, and they are included in that figure.
Without the skill loaded, the model failed this case. With it loaded, the same prompt on the same model passed. This is one improved case from the latest verified run; every case, including any that regressed, is in the table above.
Other measured skills in the registry, with their headline benchmark lift.