Skills DirectorySkills Directory
SkillsLearnSecurityCategoriesDocsBlogPro
Sign InSubmit Skill
Skills Directory

Security-tested agent skills for Claude, coding agents, and AI workflows.

Directory

  • Browse Skills
  • All Skills A–Z
  • Claude Skills
  • Claude Code Skills
  • Agent Skills
  • Categories
  • Authors
  • Submit a Skill

Learn

  • Learn Hub
  • Install Claude Skills
  • Write SKILL.md
  • Skills vs MCP
  • Directories Compared

Security

  • Security
  • Methodology
  • Secure Claude Skills
  • Security Badges
  • Chrome Extension
  • Skill Manager

Company

  • About
  • Community
  • Blog
  • API Docs
  • Advertise

2026 Skills Directory. All rights reserved.

ProTermsPrivacyRefunds
Back to skills

Bazel Build Optimization

ASecurity

当为大型 monorepo 配置 Bazel、接入远程缓存/远程执行或优化构建耗时时使用;产出 .bazelrc/WORKSPACE/BUILD 配置、查询脚本与性能剖析方案;不适用于非 Bazel 构建系统(Maven/Gradle/CMake 等)或单工程小项目。触发词:Bazel、monorepo、远程缓存

3 stars
0 votes
0 copies
1 views
Added 9/19/2026
ai-agentspythonbashdockergitbackendfullstackdevops

Works with

cursorcli

Security Analysis

A100/100

Scanned 9/19/2026

$npx -y skills add findscripter/everything-skills --skill bazel-build-optimization --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Bazel Build Optimization?

Add the live security badge to your README — it updates automatically with every re-scan.

Security grade badge for Bazel Build Optimization
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/findscripter-bazel-build-optimization/badge)](https://www.skillsdirectory.com/skills/findscripter-bazel-build-optimization)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
Files
SKILL.md
---
name: bazel-build-optimization
title: Bazel 大型单仓构建优化
description: 当为大型 monorepo 配置 Bazel、接入远程缓存/远程执行或优化构建耗时时使用;产出 .bazelrc/WORKSPACE/BUILD 配置、查询脚本与性能剖析方案;不适用于非 Bazel 构建系统(Maven/Gradle/CMake 等)或单工程小项目。触发词:Bazel、monorepo、远程缓存
domain: 研发/devops
triggers: [Bazel, monorepo, 单仓, 远程缓存, remote cache, 远程执行, remote execution, 构建优化, BUILD.bazel, .bazelrc, bazel query, 构建变慢]
tags: [bazel, 构建优化, monorepo, 远程缓存, 远程执行, ci, 研发效能, misc]
level: 进阶
status: stable
agents: [claude-code, codex, cursor, gemini-cli]
tools: [bazel, git, dot]
requires: []
related: [turborepo-caching, monorepo-navigator, ci-cd-pipeline-builder, fullstack-project-scaffolder]
combines_with: [monorepo-navigator, ci-cd-pipeline-builder, docker-development-optimizer]
license: MIT
source: sickn33/agentic-awesome-skills
source_license: MIT
---
## 何时使用

适用:

- 为大型 monorepo(多语言、多团队)首次搭建或重构 Bazel。
- 接入远程缓存(remote cache)/ 远程执行(RBE),跨开发者和 CI 共享构建产物。
- 构建/测试耗时过长,需要定位慢 action、调资源并发、做增量优化。
- 编写自定义规则(rule/aspect),用 `bazel query` 做依赖与影响面分析。
- 从其他构建系统(Maven/Gradle/Make)迁移到 Bazel。

不该用(负边界):

- 任务与 Bazel 无关,或目标构建系统是 Maven/Gradle/CMake/npm scripts 等非 Bazel。
- 单一小工程、无跨模块复用诉求——引入 Bazel 的维护成本通常不划算。
- 需要环境特定的安全/合规评审:本技能产物须经本地实测验证,不能替代专家审查。

## 步骤

1. 明确目标与约束:语言栈、仓库规模、CI 平台、是否已有远程缓存/执行后端、可复现性要求。
2. 固定版本与目录骨架:写 `.bazelversion`、`WORKSPACE.bazel`(或 MODULE.bazel)、按目录粒度放 `BUILD.bazel`。
3. 写 `.bazelrc`:分离本地、`remote-cache`、`remote-exec`、`ci` 等 config,用 `--config=xxx` 切换。
4. 接缓存/执行:先上远程缓存(收益最稳),再按需上远程执行;用 platform + toolchain 描述执行环境。
5. 用 `bazel query` 做依赖/反向依赖/变更影响面分析,缩小 CI 构建范围。
6. 性能剖析:`--profile` + `analyze-profile` 找瓶颈,调 `--jobs`、本地资源、缓存命中。
7. 实测验证:清缓存冷构建 + 增量构建对比耗时与缓存命中率,再固化进 CI。

## 指令

骨架(关键文件):

```
workspace/
├── WORKSPACE.bazel    # 外部依赖
├── .bazelrc           # 构建配置(分 config)
├── .bazelversion      # 锁定 Bazel 版本
├── BUILD.bazel        # 根 BUILD
├── apps/web/BUILD.bazel
├── libs/utils/BUILD.bazel
└── tools/bazel/rules/ # 自定义规则
```

核心概念:Target(可构建单元)/ Package(含 BUILD 的目录)/ Label(`//path/to:target`)/ Rule(如何构建)/ Aspect(横切构建行为)。

`.bazelrc` 关键项(性能 + 缓存 + 远程,分 config):

```bash
# 性能
build --jobs=auto
build --local_cpu_resources=HOST_CPUS*.75
build --local_ram_resources=HOST_RAM*.75

# 本地缓存
build --disk_cache=~/.cache/bazel-disk
build --repository_cache=~/.cache/bazel-repo

# 远程缓存(可选)
build:remote-cache --remote_cache=grpcs://cache.example.com
build:remote-cache --remote_upload_local_results=true
build:remote-cache --remote_timeout=3600

# 远程执行(可选)
build:remote-exec --remote_executor=grpcs://remote.example.com
build:remote-exec --remote_instance_name=projects/myproject/instances/default
build:remote-exec --jobs=500

# CI 复用远程缓存 + BES 上报
build:ci --config=remote-cache
build:ci --bes_results_url=https://results.example.com/invocation/
build:ci --bes_backend=grpcs://bes.example.com

test --test_output=errors
try-import %workspace%/user.bazelrc
```

依赖与影响面分析(`bazel query`):

```bash
# 正向依赖 / 反向依赖
bazel query "deps(//apps/web:web)"
bazel query "rdeps(//..., //libs/utils:utils)"

# 自上次提交以来受影响的目标(用于 CI 增量构建)
bazel query "rdeps(//..., set($(git diff --name-only HEAD~1 | sed 's/.*/\"&\"/' | tr '\n' ' ')))"

# 所有测试目标 / 依赖图导出
bazel query "kind('.*_test', //...)"
bazel query "deps(//apps/web:web)" --output=graph | dot -Tpng > deps.png
```

性能剖析:

```bash
bazel build //... --profile=profile.json
bazel analyze-profile profile.json          # 找慢阶段
bazel build //... --execution_log_json_file=exec_log.json  # 定位慢 action
bazel build //... --memory_profile=memory.json
```

远程执行的 platform/toolchain(描述执行环境):

```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",
    },
)
```

## 示例

为含 TS 与 Python 的 monorepo 接入远程缓存并缩小 CI 构建范围:

1. `libs/utils/BUILD.bazel` 用 `ts_project` + `js_library` 声明库,`jest_test` 跑测试;`libs/ml/BUILD.bazel` 用 `py_library`/`py_test`,依赖经 `requirement("numpy")` 显式列出,并依赖 `//libs/utils:utils_py`。
2. `.bazelrc` 配 `build:remote-cache`,开发与 CI 均 `bazel build //... --config=remote-cache`,共享产物。
3. CI 上用上面的 `rdeps(... git diff ...)` 仅构建/测试受改动影响的目标,而非全量。
4. 上线前:清缓存冷构建一次记录基线耗时,再改一处增量构建,对比缓存命中率确认收益。

## 注意事项

推荐做法:

- 细粒度 target —— 缓存命中更高。
- 锁版本/钉依赖(`.bazelversion` + sha256)—— 可复现构建。
- 优先上远程缓存共享产物;按目录写 BUILD;用 `visibility` 约束架构。

避免:

- 别用 `glob` 收集 `deps`,依赖要显式。
- 别提交 `bazel-*` 软链目录,加进 `.gitignore`。
- 别跳过 WORKSPACE/MODULE 基础配置;别忽略构建告警(技术债)。
- 远程执行成本与运维高于远程缓存,先缓存后执行;产物务必本地实测,缺输入/权限/成功标准时停下来澄清。

## 互见

- Bazel 官方文档:https://bazel.build/docs
- 远程执行:https://bazel.build/docs/remote-execution
- rules_js:https://github.com/aspect-build/rules_js

---

采编自 sickn33/antigravity-awesome-skills(MIT)。

Attribution

findscripterfindscripter
View sourceSee grades on GitHubMore from findscripter →
SSkills DirectorySkills Directory

Ship a skill? Prove it's safe.

Free 120-pattern security scan, letter grade, and an embeddable README badge.

Submit a skill

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments (0)

No comments yet. Be the first to comment!

SSkills DirectorySkills Directory

Ship a skill? Prove it's safe.

Free 120-pattern security scan, letter grade, and an embeddable README badge.

Submit a skill

Related Skills

Caveman

Terse caveman voice: answer first, fluff gone, every technical fact kept. Use for /caveman, "caveman mode", "talk like caveman", "be brief", "less tokens". Stays on until "stop caveman" or "normal mode".

1100021 votes

Hyperplan

Adversarial multi-agent planning skill. Self-orchestrates 5 hostile category members (unspecified-low, unspecified-high, deep, ultrabrain, artistry) via team-mode for ruthless cross-critique debate, distills only the defensible insights, then MANDATORILY hands the distilled insight bundle to the `plan` agent for executable plan formalization. Use when planning needs maximum rigor and surfacing of weak assumptions, blind spots, and over-engineering. Triggers: 'hyperplan', 'hpp', '/hyperplan', ...

698621 votes

Writing Skills

Create and manage Claude Code skills in HASH repository following Anthropic best practices. Use when creating new skills, modifying skill-rules.json, understanding trigger patterns, working with hooks, debugging skill activation, or implementing progressive disclosure. Covers skill structure, YAML frontmatter, trigger types (keywords, intent patterns), UserPromptSubmit hook, and the 500-line rule. Includes validation and debugging with SKILL_DEBUG. Examples include rust-error-stack, cargo-dep...

3931 votes

Mcp Code Execution

Routes multi-tool workflows through MCP servers for large datasets and pipelines. Use when Bash tool overhead is limiting throughput on data-heavy tasks.

3421 votes

catchup

Recovers the conversation and failed tool calls of a previous Codex, Amp, Claude Code, Antigravity, Cline, Copilot CLI, Cursor, DeepSeek Harness, Grok Build, Kimi, OpenCode, Pi Agent, or ZCode session. Use when the user says "catch up", "what did the last session do", "get me up to speed", "I switched agents", asks to recover/summarize a previous session before continuing, or asks to diagnose or report a catchup failure. Do NOT use for the current conversation, git history, or any non-agent log.

741 votes
View all in ai-agents →