Debugs Buck2 build failures systematically by analyzing error logs, checking common issues (cache, visibility, cycles), and suggesting fixes. Use when builds fail, tests won't run, or Buck2 reports errors.
This skill provides systematic debugging for Buck2 build failures. It analyzes error logs, identifies common issues, and suggests concrete fixes. Instead of manually parsing verbose build output, use the build doctor script to diagnose problems quickly.
Use this skill when:
This skill provides:
scripts/build_doctor.py - Automated build diagnosticsreferences/common_errors.md - Error patterns and solutionsWhen a build fails:
# Run the build doctor
python3 scripts/build_doctor.py
# Or analyze specific target
python3 scripts/build_doctor.py //src/tools:mytool
# Verbose analysis
python3 scripts/build_doctor.py --verbose //src/tools:mytool
The script will:
Rust compilation failure:
Error: rustc failed with exit code 1
Diagnosis:
# See full error
python3 scripts/build_doctor.py --show-logs //target
# Check source files
buck2 query "//target" --output-attribute srcs
# Verify dependencies
buck2 query "deps('//target', 1)"
Common fixes:
Missing dependency:
Error: unresolved import `foo::bar`
Fix:
# Add to BUILD file deps:
deps = [
"//path/to:foo",
"third-party//crate:crate",
]
Circular dependency:
Error: cycle detected in dependency graph
Diagnosis:
# Find the cycle
python3 scripts/build_doctor.py --check-cycles //src/...
# Investigate specific path
buck2 query "allpaths('//target/a', '//target/b')"
buck2 query "allpaths('//target/b', '//target/a')"
Fix: Break the cycle by:
Cannot access target:
Error: //src/app:app cannot depend on //src/lib:internal (not visible)
Diagnosis:
# Check visibility settings
buck2 query "//src/lib:internal" --output-attribute visibility
# See who can access it
python3 scripts/build_doctor.py --check-visibility //src/lib:internal
Fix:
# In BUILD file, update visibility:
depot.rust_library(
name = "internal",
visibility = [
"//src/app/...", # Allow src/app access
# or
"PUBLIC", # Allow everyone
],
)
Undefined reference:
Error: undefined reference to `symbol`
Common causes:
Fix:
# Check all dependencies are present
buck2 query "deps('//target', 1)" --output-attribute deps
# For C++, check link order in BUILD
Tests won't run:
Error: No tests found
Diagnosis:
# Verify test target exists
buck2 targets //path:test
# Check test is properly defined
buck2 query "//path:test" --output-attribute buck.type
Fix:
# Ensure BUILD has test target:
depot.rust_test(
name = "test",
srcs = glob(["src/**/*.rs"]),
)
# Recent failures
buck2 log what-failed
# Or use build doctor
python3 scripts/build_doctor.py
# Full error output
buck2 log last
# Specific target
buck2 build //target -v 2 # Verbose mode
# Run automated checks
python3 scripts/build_doctor.py --all-checks //target
This checks:
# Inspect BUILD file
buck2 query "//target" --json | jq
# Check dependencies
buck2 query "deps('//target', 1)"
# Verify source files exist
buck2 query "//target" --output-attribute srcs
# Build single target
buck2 build //target
# Build with fresh cache
buck2 clean && buck2 build //target
# Skip cache
buck2 build //target --no-remote-cache
# Analyze last failure
python3 scripts/build_doctor.py
# Specific target
python3 scripts/build_doctor.py //src/tools:mytool
# Multiple targets
python3 scripts/build_doctor.py //src/tools:tool1 //src/lib:lib2
# Check cache issues
python3 scripts/build_doctor.py --check-cache
# Check visibility
python3 scripts/build_doctor.py --check-visibility //target
# Check for cycles
python3 scripts/build_doctor.py --check-cycles //src/...
# Run all checks
python3 scripts/build_doctor.py --all-checks //target
# Verbose output
python3 scripts/build_doctor.py --verbose //target
# Show build logs
python3 scripts/build_doctor.py --show-logs //target
# JSON output for scripting
python3 scripts/build_doctor.py --json //target
Error:
Error: No targets found matching //src/tools:missing
Causes:
Fix:
# List available targets
buck2 targets //src/tools:
# Check BUILD file exists
ls -la src/tools/BUILD
# Search for target
buck2 targets //... | grep missing
Error:
Warning: glob(["src/**/*.rs"]) matched no files
Causes:
Fix:
# Check directory structure
ls -la src/
# Verify glob pattern
# For Rust binary: src/main.rs
# For Rust library: src/lib.rs
Error (Rust):
Error: cannot find module `foo` in crate root
Fix:
mod foo; in lib.rs/main.rsError:
Error: feature `foo` is required
Fix:
# Add to BUILD file:
deps = [
"third-party//crate:crate[foo]", # Enable feature
]
Error:
Error: output directory already in use
Causes:
Fix:
# Kill buck daemon
buck2 kill
# Clean and rebuild
buck2 clean
buck2 build //target
Symptoms:
Diagnosis:
# Disable cache and test
buck2 build --no-remote-cache //target
# Check cache configuration
buck2 audit config cache
Fix:
# Clear local cache
buck2 clean
# For persistent issues, check .buckconfig
cat .buckconfig | grep -A5 cache
Symptoms:
Diagnosis:
# Build locally only
buck2 build --no-remote-execution //target
# Check platform configuration
buck2 audit config re
Fix:
Symptoms:
Diagnosis:
# Check what changed
buck2 explain //target
# Verify target determinism
buck2 build //target
buck2 build //target # Should be cached
Fix:
# Find what changed
jj diff --stat | cut -f2 | while read file; do
buck2 query "owner('$file')"
done | while read target; do
python3 scripts/build_doctor.py $target
done
# In CI pipeline
if ! buck2 build @targets; then
python3 scripts/build_doctor.py --json > diagnosis.json
cat diagnosis.json
exit 1
fi
# Diagnose failures in changed targets
TARGETS_FILE="$(mktemp "${TMPDIR:-/tmp}/tdutil-targets.XXXXXX")"
trap 'rm -f -- "$TARGETS_FILE"' EXIT
buck2 run root//buck/tools/tdutil:tdutil -- --output "$TARGETS_FILE" --universe depot//src/...
buck2 build "@$TARGETS_FILE" || {
python3 scripts/build_doctor.py --show-logs
}
# What failed recently
buck2 log what-failed
# Show last build log
buck2 log last
# Build with verbose output
buck2 build //target -v 2
# Clean everything
buck2 clean
# Kill buck daemon
buck2 kill
# Explain why rebuilding
buck2 explain //target
# 1. Clean build
buck2 clean && buck2 build //target
# 2. Kill daemon and retry
buck2 kill && buck2 build //target
# 3. Skip cache
buck2 build --no-remote-cache //target
# 4. Verbose output
buck2 build //target -v 2 2>&1 | tee build.log
# 5. Ignore broken targets during testing
buck2 test //... --keep-going
When builds fail, check:
buck2 targets //path:)buck2 clean)buck2 kill)buck2 cleanjj log to see what changedIf stuck after trying these steps:
buck2 build //target -v 2 2>&1 > error.logbuck2 query //target --jsonnpx skills add thoughtpolice/buck2-build-troubleshoot下载完整 Skill 目录,包含 SKILL.md 及所有相关文件
Search for places (restaurants, cafes, etc.) via Google Places API proxy on localhost.
Interact with GitHub using the `gh` CLI. Use `gh issue`, `gh pr`, `gh run`, and `gh api` for issues, PRs, CI runs, and advanced queries.
Create or update AgentSkills. Use when designing, structuring, or packaging skills with scripts, references, and assets.
Start voice calls via the OpenClaw voice-call plugin.
Notion API for creating and managing pages, databases, and blocks.
Gemini CLI for one-shot Q&A, summaries, and generation.
Category:developer