buck2-rule-basics
Guide users through writing their first Buck2 rule to learn fundamental concepts including rules, actions, targets, configurations, analysis, and select(). Use this skill when users want to learn Buck2 basics hands-on or need help understanding rule writing.
Install / Use
npx skills add Microck/ordinary-claude-skills --skill buck2-rule-basicsInstalls into whichever agent you are using.
SKILL.md
Installable skill definition
Quality Score
Category
Content & MediaSupported Platforms
Tags
Our assessment of buck2-rule-basics
buck2-rule-basics scores 83/100 on our quality scale, 896th of 1,187 Content & Media skills we index.
Its SKILL.md is 25 KB long, well organised into 58 sections with 37 code examples: a thorough specification that gives an agent plenty to work with.
It has 399 GitHub stars, a meaningful sign that others use it.
Maintenance, license and trust
- The repository was last updated 30 days ago, so buck2-rule-basics is actively maintained.
- No license is declared. By default that means all rights are reserved: you can read it, but reusing or redistributing it is not clearly permitted. Ask the author before building on it commercially.
- Its trust signals score 88/100, with 1 caution from licensing, adoption, age or documentation. These come from repository metadata, not a code audit — read the skill file before letting an agent act on it.
buck2-rule-basics compared with similar skills
All 4 of these similar skills score higher than buck2-rule-basics; compare them before choosing.
| Skill | Score | Stars | Updated | Format |
|---|---|---|---|---|
| buck2-rule-basics (this skill)by Microck | 83 | 399 | 30d ago | SKILL.md |
| siyuanby siyuan-note | 100 | 46.6k | today | MCP Server |
| algorithmic-artby anthropics | 100 | 177.9k | 14d ago | SKILL.md |
| pptxby anthropics | 100 | 177.9k | 14d ago | SKILL.md |
| designby nextlevelbuilder | 100 | 130.2k | 15d ago | SKILL.md |
Frequently asked questions
- How do I install buck2-rule-basics?
- Run
npx skills add Microck/ordinary-claude-skills --skill buck2-rule-basics. The install tabs above show the steps for each supported agent. - Which AI agents does buck2-rule-basics work with?
- It is written for Universal, as a SKILL.md file. Other agents that read the same format can often use it too.
- Is buck2-rule-basics safe to use?
- It declares no license and scores 88/100 on trust signals. Skills are instructions an agent will follow, so read the file before installing it and do not approve commands you do not understand.
- Is buck2-rule-basics still maintained?
- The repository was last updated 30 days ago, so buck2-rule-basics is actively maintained.
Skill content
View source on GitHubname: buck2-rule-basics description: Guide users through writing their first Buck2 rule to learn fundamental concepts including rules, actions, targets, configurations, analysis, and select(). Use this skill when users want to learn Buck2 basics hands-on or need help understanding rule writing.
@nolint
Buck2 Rule Basics - Interactive Tutorial
Overview
This is an interactive, step-by-step tutorial that teaches Buck2 fundamentals through hands-on practice. You'll guide users through writing a simple text processing rule that converts text to uppercase, explaining core concepts as they encounter them.
Reference Materials
This skill includes additional reference documentation that you can use to answer deeper questions:
-
references/concepts.md- Deep dive into Buck2 core concepts including:- The Buck2 build model (load, configuration, analysis, execution phases)
- Targets in depth (unconfigured vs configured, cells, dependencies)
- Artifacts (source vs build artifacts, bound vs unbound)
- Actions (properties, caching, inputs/outputs)
- Providers (built-in and custom, provider propagation)
- Configurations (platforms, select() resolution, multi-platform builds)
- Analysis phase details
- Build graph structure and queries (uquery, cquery, aquery)
-
references/advanced_patterns.md- Production-ready patterns including:- Custom providers (library with transitive headers)
- Transitive dependencies (collection patterns, transitive sets/tsets)
- Toolchain dependencies (defining and using toolchains)
- Multiple outputs (output directories, sub-targets)
- Command line building (complex commands, conditional arguments)
- Configuration-dependent rules
- Testing rules (test runners, test data)
When to use these references:
- User asks "how does X work in Buck2?" → Check
concepts.md - User asks "what's the best way to do Y?" → Check
advanced_patterns.md - User wants to go beyond the tutorial → Direct them to these files
- User encounters advanced concepts → Read relevant sections to explain
Always read from these files when users ask questions that go beyond the basic tutorial content.
Critical: Interactive Teaching Approach
DO NOT dump all content at once! This is an interactive tutorial. Follow these rules:
1. Always Start by Assessing Current State
When the skill launches, FIRST check what the user has already done:
- Check if tutorial directory exists and what files are present
- Read existing files to understand their progress
- Determine which step they're on (or if starting fresh)
- Ask the user if they want to start from scratch or continue
2. Present One Step at a Time
- Introduce ONE concept/step
- Implement the code for that step
- Test it together
- Explain what happened
- Show file changes: After each step, summarize what files were created/modified
- Remind about editor: Tell users they can open the files in their editor to see the changes
- STOP and wait for user confirmation to continue
3. Use AskUserQuestion Between Major Steps
After completing each major step (1-8), ask the user:
- Do they understand the concept?
- Are they ready to move to the next step?
- Do they want to explore more about the current topic?
4. Be Adaptive
- If user seems confused, provide more examples
- If they're advanced, offer to skip basic explanations
- If they want to experiment, encourage it and help debug
- If they ask questions, answer them before moving forward
5. Track Progress Visually
Use TodoWrite to show:
- Which steps are completed ✓
- Current step (in progress)
- Upcoming steps
- This helps users see the journey
Important: Use System Buck2 Command
This tutorial uses the system buck2 command, NOT ./buck2.py.
- Use:
buck2 build,buck2 test,buck2 cquery, etc. - Do NOT use:
./buck2.py(that's for Buck2 development/self-bootstrap)
This ensures the tutorial works for all users with Buck2 installed.
Tutorial Structure
The tutorial has 8 progressive steps:
Step 0: Setup
Create a new directory for the tutorial and navigate into it:
Run this:
mkdir 'buck2-tutorial'
cd buck2-tutorial
All following steps will be done in this directory.
Step 1: Create Minimal Rule Stub - Returns empty DefaultInfo() Step 2: Add Source File Attribute - Accept input files Step 3: Declare Output Artifact - Promise to produce output (will error) Step 4: Create an Action - Actually produce the output Step 5: Understanding Targets - Unconfigured vs Configured Step 6: Add Configuration Support - Use select() for platform-specific behavior Step 7: Add Dependencies - Make rules compose Step 8: Rules vs Macros - Understand the difference
Step-by-Step Implementation Guide
Initial Setup (Always Do First)
# 1. Determine working directory
# 2. Check if user has existing tutorial files
# 3. Create todo list showing all 8 steps
# 4. Ask user if they want to start fresh or continue
Create todo list:
TodoWrite with 8 items (all pending initially)
Check existing state:
- Does `uppercase.bzl` exist?
- Does `BUCK` exist?
- Does `input.txt` exist?
- If yes, read them to determine current step
Ask user:
AskUserQuestion:
- "Start from scratch (will backup existing files)"
- "Continue from where I left off"
- "Review a specific step"
Step 1: Create the Minimal Rule Stub
Goal: Get the simplest possible Buck2 rule working.
What to do:
- Create
uppercase.bzlwith minimal implementation - Create
BUCKfile with target definition - Build it with
buck2 build - Observe success (with warning about no outputs)
Code to create:
uppercase.bzl:
# uppercase.bzl
def _uppercase_impl(ctx: AnalysisContext) -> list[Provider]:
"""Rule implementation function - called during analysis phase."""
return [DefaultInfo()]
uppercase = rule(
impl = _uppercase_impl,
attrs = {},
)
BUCK:
load(":uppercase.bzl", "uppercase")
uppercase(name = "hello")
Testing:
buck2 build :hello
# Expected: SUCCESS with warning "target does not have any outputs"
Key concepts to explain AFTER successful build:
- Rule: Defined with
rule()function - Implementation function: Takes
AnalysisContext, returnsProviderlist - Analysis phase: This runs during planning, not execution
- DefaultInfo provider: Minimum provider every rule must return
Before moving on:
AskUserQuestion:
question: "Ready to move to Step 2 where we'll accept input files?"
options:
- "Yes, let's continue"
- "Explain these concepts more"
- "Let me experiment first"
Step 2: Add Source File Attribute
Goal: Make the rule accept an input file.
What to do:
- Update
uppercase.bzlto addsrcattribute - Update
BUCKto pass a source file - Create
input.txttest file - Build again
Update uppercase.bzl:
def _uppercase_impl(ctx: AnalysisContext) -> list[Provider]:
# Access the source file attribute
src = ctx.attrs.src # This is an Artifact
return [DefaultInfo()]
uppercase = rule(
impl = _uppercase_impl,
attrs = {
"src": attrs.source(), # Declares this rule accepts a source file
},
)
Update BUCK:
load(":uppercase.bzl", "uppercase")
uppercase(
name = "hello",
src = "input.txt",
)
Create input.txt:
hello world
Testing:
buck2 build :hello
# Expected: SUCCESS (still no outputs, but accepts input now)
Key concepts to explain:
- Attributes: Defined in
attrs={}, accessed viactx.attrs - attrs.source(): Declares an attribute accepting a source file
- Artifact: Represents a file (input or output)
Before moving on:
AskUserQuestion:
question: "Ready for Step 3 where we'll declare an output file?"
options:
- "Yes, continue"
- "I have questions about attributes"
Step 3: Declare Output Artifact
Goal: Declare that we'll produce an output (will cause expected error).
What to do:
- Update implementation to declare output
- Return it in DefaultInfo
- Build and expect failure
- Explain why it fails (declared but not produced)
Update uppercase.bzl implementation:
def _uppercase_impl(ctx: AnalysisContext) -> list[Provider]:
src = ctx.attrs.src
# Declare an output artifact
output = ctx.actions.declare_output("result.txt")
# Return it as the default output
return [DefaultInfo(default_output = output)]
Testing:
buck2 build :hello
# Expected: ERROR - "Artifact must be bound by now"
Explain the error: This error is expected and good! We declared an output but haven't created an action to produce it. Buck2 is telling us: "You promised an output, but didn't say how to make it!"
Key concepts to explain:
- ctx.actions.declare_output(): Declares an artifact that will be produced
- default_output: The main output users get when building
- Declaration vs Production: We declared it exists, but haven't created it yet
Before moving on:
AskUserQuestion:
question: "This error is expected! Ready for Step 4 where we'll fix it by creating an action?"
options:
- "Yes, let's create the action"
- "Why did we get this error exactly?"
Step 4: Create an Action
Goal: Actually produce the output file by running a command.
What to do:
- Add shell script to transform input → output
- Register action with
ctx.actions.run() - Build and see it succeed
- Check the output file content
Update uppercase.bzl implementation:
def _uppercase_impl(ctx: AnalysisContext) -> list[Provider]:
src = ctx.attrs.src
output = ctx.actions.declare_output("result.txt")
# Create a shell script that will run
# Use Python to uppercase the file and write to output
script = """
python3 -c "import sys; print(open(sys.argv[1]).read().upper(), end='')" "$1" > "$2"
"""
# Register the action with Buck2
ctx.actions.run(
cmd_args([
"/bin/bash",
"-c",
script,
"--",
src, # Input artifact
output.as_output(), # Output artifact
]),
category = "uppercase", # Shows in buck2 output
)
return [DefaultInfo(default_output = output)]
Testing:
buck2 build :hello --show-full-output
# Expected: SUCCESS with output path shown
# Check the content
cat <output-path>
# Expected: HELLO WORLD
Key concepts to explain:
- Action: A command Buck2 will execute (bash script + Python)
- cmd_args(): Builds command line, handles artifacts properly
- artifact.as_output(): Marks artifact as output (Buck2 creates parent dirs)
- ctx.actions.run(): Registers action - doesn't execute yet, just declares
- Shell redirection: Use
>in shell scripts (Buck2 doesn't support redirect_stdout) - Lazy execution: Buck2 decides when/if to run based on what's needed
Before moving on:
AskUserQuestion:
question: "Great! Your rule now works. Ready to learn about targets and configurations?"
options:
- "Yes, let's learn about targets"
- "Let me try modifying the rule first"
Step 5: Understanding Targets
Goal: Understand target names, unconfigured vs configured targets.
What to do:
- List available targets with
buck2 targets - Understand the anatomy of target names
- Query the target in unconfigured mode (
uquery) - Query the target in configured mode (
cquery) - Compare the differences
Run commands:
# List all targets in the current package
buck2 targets :
# Expected output shows targets like:
# fbcode//buck2/buck2-tutorial:hello
#
Truncated for display — read the full file on GitHub.
Related Skills
siyuan
46.6kAn open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作
algorithmic-art
177.9kCreating algorithmic art using p5.js with seeded randomness and interactive parameter exploration. Use this when users request creating art using code, generative art, algorithmic art, flow fields, or particle systems.
pptx
177.9kUse this skill any time a .pptx or .potx file is involved in any way — as input, output, or both. This includes: creating slide decks, pitch decks, or presentations; reading, parsing, or extracting text from any .pptx or .potx file (even if the extracted content will be used elsewhere, like in an em…
design
130.2kComprehensive design skill: brand identity, design tokens, UI styling, logo generation (55 styles, Gemini, Atlas Cloud, or MuAPI AI), corporate identity program (50 deliverables, CIP mockups), HTML presentations (Chart.js), banner design (22 styles, social/ads/web/print), icon design (15 styles, SVG…
Languages
Trust signals
From repository metadata: license, adoption, age and documentation. Not a code audit — see the Safety scan above for what the skill file itself contains.
