技能 bazel-build-optimization
📦

bazel-build-optimization

安全

优化 Bazel 构建性能

也可从以下获取: wshobson

大型代码库中的 Bazel 构建可能既缓慢又复杂。本技能提供经过验证的模式,包括远程缓存、并行执行和自定义规则,可显著缩短构建时间。

支持: Claude Codex Code(CC)
🥉 75 青铜
1

下载技能 ZIP

2

在 Claude 中上传

前往 设置 → 功能 → 技能 → 上传技能

3

开启并开始使用

测试它

正在使用“bazel-build-optimization”。 Help me set up Bazel for a Python project with external dependencies

预期结果:

Here is a basic WORKSPACE.bazel configuration for Python:

```python
workspace(name = "myproject")

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

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()
```

Then create a BUILD.bazel file with py_library and py_test rules.

正在使用“bazel-build-optimization”。 How do I configure remote execution?

预期结果:

Add this to your .bazelrc for remote execution:

```bash
build:remote-exec --remote_executor=grpcs://remote.example.com
build:remote-exec --remote_instance_name=projects/myproject/instances/default
build:remote-exec --jobs=500
```

Security tips:
- Use TLS for remote endpoints
- Authenticate with OAuth or certificates
- Start with read-only remote cache before enabling execution

安全审计

安全
v1 • 2/25/2026

Static analysis detected 36 potential issues (external_commands, network, filesystem patterns), but all are false positives. The skill contains documentation and templates for Bazel build optimization with example commands and configuration snippets - no actual executable code with security implications. URLs are legitimate documentation links, filesystem references are standard Bazel cache paths, and cryptographic mentions are SHA256 checksums for download verification.

1
已扫描文件
400
分析行数
0
发现项
1
审计总数
未发现安全问题
审计者: claude

质量评分

38
架构
100
可维护性
87
内容
50
社区
100
安全
100
规范符合性

你能构建什么

为 CI/CD 流水线设置远程缓存

配置 Bazel 远程缓存以在 CI 运行器之间共享构建产物,将构建时间从数小时缩短到数分钟。

优化大型 TypeScript 代码库

应用最佳实践来组织 BUILD 文件、启用并行执行和配置磁盘缓存。

为 Docker 创建自定义构建规则

编写自定义 Bazel 规则以作为构建图的一部分构建 Docker 镜像,并进行正确的依赖跟踪。

试试这些提示

基础 Bazel 设置
Help me set up Bazel for a new monorepo. I need to configure WORKSPACE.bazel with rules for JavaScript and Python. What are the essential configurations?
启用远程缓存
I want to set up remote caching for our Bazel builds. We use Google Cloud. Show me the .bazelrc configuration needed and any security considerations.
编写自定义规则
Create a custom Bazel rule that builds a Docker image. The rule should accept a Dockerfile, base image, and layer files as inputs.
性能分析和优化构建
Our Bazel build takes 30 minutes. Help me profile it using bazel build --profile and identify the slowest actions. What optimizations should I try first?

最佳实践

  • 使用细粒度目标而非大型 glob 模式,以获得更好的增量构建
  • 尽早启用远程缓存 - 它能带来最大的性能提升
  • 在 WORKSPACE 中固定依赖项版本以确保可重现的构建

避免

  • 对 srcs 使用 glob(['**/*.python']) - 导致不必要的重新构建
  • 跳过 WORKSPACE 设置 - 导致依赖项解析不一致
  • 忽略构建警告 - 小问题会变成技术债务

常见问题

本技能会安装 Bazel 吗?
不,Bazel 必须预装在您的系统中。本技能帮助您在安装 Bazel 后对其进行配置和优化。
我可以将它用于非 Bazel 构建系统吗?
不,本技能专门针对 Bazel。它涵盖 WORKSPACE、BUILD 文件、.bazelrc 和 Bazel 特有的概念。
我可以节省多少构建时间?
使用远程缓存后,团队通常在首次构建后看到构建时间减少 50-90%。对于大型代码库,远程执行可以带来更大的改进。
远程缓存是否安全?
是的,只要正确配置 TLS 和身份验证即可。首先使用只读缓存来验证安全性,然后再启用写入访问。
这能帮助迁移到 Bazel 吗?
是的,本技能包含从其他构建系统迁移到 Bazel 以及设置初始 WORKSPACE 配置的指导。
支持哪些语言?
本技能涵盖 JavaScript/TypeScript、Python、Java、C++ 和 Docker。它展示了如何为每个语言生态系统配置规则。

开发者详情

文件结构

📄 SKILL.md