gn-deps-debugging
它能做什么
这个技能帮助你的 AI 查找并修复 GN 构建依赖错误。适合在构建大型项目时遇到头文件包含或依赖检查错误的开发者。
适用场景
- ✓当你的构建因 GN 依赖或包含可见性错误而失败时。
- ✓当 gn check 报告某个目标不允许使用某个头文件时。
- ✓当你需要修复构建目标之间的循环依赖时。
技能链接
https://github.com/chromium/chromium/blob/main/agents/skills/gn-deps-debugging/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“我的构建提示某个头文件对我的目标不可见。能找到正确的依赖来修复它吗?”
每周 5 个新技能,1 分钟读完。
工作原理
AI 读取具体的错误,找到拥有该文件的构建目标和拥有该头文件的目标,然后添加最小且正确的依赖。它会保持平台规则不变。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
GN Dependency Debugging
Fix Chromium GN dependency metadata, include visibility, and DEPS rule failures by correcting the dependency graph accurately, not by adding broad dependencies that only make errors disappear.
Core principles
- Read the exact error first. Identify the including source file, the included header, the failing target, and the diagnostic category before editing.
- Find both owning targets. Determine which GN target owns the including file and which GN target owns the included header.
- Prefer the narrowest dependency. Add the dependency to the smallest target that needs it, not a parent or aggregate target.
- Preserve platform conditions. If the failing include is in a
platform-specific file such as
*_win.cc, add the dependency inside the matching platform block such asif (is_win). - Use
depsfor implementation-only dependencies. If a symbol is used only in.ccfiles, keep the dependency private. - Use
public_depsonly for public API exposure. If a public header exposes a type from another target in its declarations or inline code, downstream consumers may need that dependency transitively. - Prefer forward declarations in headers. If a header only needs a pointer,
reference, or return type declaration, forward declare and move the include
to the
.ccfile when possible. - Do not paper over architecture issues. Circular dependencies usually indicate the need to split an interface target, move shared abstractions, or invert dependencies.
- Avoid
// nogncheck. Use it only for known GN limitations with conditional includes, and include the required bug reference if the local codebase already documents one.
Workflow
Capture the failing command and output.
- If the user provided a truncated error, ask for or rerun the relevant
gn checkor build command when an output directory and target are known. - Do not start a broad build just to reproduce unless the output directory and target are established.
- If the user provided a truncated error, ask for or rerun the relevant
Classify the failure.
- Read common-errors.md and map the diagnostic to one of the supported categories.
- Extract the including file, included header, and target names from the diagnostic.
Find the target that owns the including file.
- Inspect nearby
BUILD.gnfiles first. - Use GN queries when an output directory is known:
gn refs out/Default //path/to/file.cc --all - Prefer the most specific non-aggregate target that directly lists the file or owns the source set containing it.
- Check whether the file is platform-specific, such as
*_win.cc,*_mac.mm,*_linux.cc,*_android.cc, or*_ios.mm. Platform-specific files usually require platform-specific dependencies.
- Inspect nearby
Find the target that owns the included header.
- Search for the header in
BUILD.gnsources lists. - If several targets list it, prefer the public/interface target intended for consumers.
- Check whether the header belongs to a generated target, a
publicvariable, or a private implementation target.
- Search for the header in
Choose the correct fix.
- Read dependency-patterns.md for
depsvspublic_deps, forward declaration, DEPS, and cycle handling rules. - If the include appears only in
.cc, add a privatedepsentry. - If the include appears only in a platform-specific source file, add the
private
depsentry inside the matching platform condition, for exampleif (is_win). - If the include appears in a public header, first try to remove the include
using a forward declaration. If the header must expose the dependency, add
or promote the dependency to
public_deps. - If a
DEPSfile blocks the include, verify whether the dependency direction is allowed by the architecture before adding include rules. - If adding the dependency creates a cycle, stop and redesign the dependency
boundary instead of adding broader deps. When an output directory is known,
use
gn path <out_dir> //target_a //target_bto inspect the dependency chain that connects the targets.
- Read dependency-patterns.md for
Validate the narrow change.
- Run
git cl formatifBUILD.gnorDEPSfiles were edited. - Re-run the smallest relevant
gn checkor build command that reproduced the issue. - If
- Run
常见问题
什么是 GN?
GN 是大型软件项目使用的构建工具,用于决定代码文件如何编译和链接在一起。
为什么不直接添加一个大的依赖来消除错误?
宽泛的依赖可能掩盖真正的问题,还会拖慢构建。因此这个技能会要求最精确的修复方式。
什么时候不应使用这个技能?
它用于依赖和包含错误。对于编译、链接或运行时失败,应采用其他方法。
详情
作者的原始描述
Diagnose Chromium GN dependency and include-visibility failures, including BUILD.gn deps/public_deps, DEPS include rules, private headers, and circular dependencies. Use for build or gn check dependency errors, not C++/link/runtime/test failures.
repo: chromium/chromium
热度
- GitHub 星标
- 25k
- 排名
- #10058
- 许可证
- BSD-3-Clause
- 更新时间
- 2026/11/2
评论
- …
同一仓库的更多技能
fuzzing
25k帮你的智能体编写模糊测试,向代码输入大量随机数据,以找出 C++ 代码中的崩溃和错误。
java-memory-leaks
25k帮你的智能体通过读取 LeakCanary 的泄漏报告,查找并修复 Android 应用中的 Java 内存泄漏。
jni-type-conversion
25k帮你的智能体用更简单的 @JniType 注解,替换 Android 代码中手动的 Java 到 C++ 转换代码。
loadline
25k帮你的智能体运行 LoadLine 基准测试,衡量网页在 Android 和桌面版 Chrome 上的加载速度。