/xmake-skills:xmake-graph-modulefrom xmake-skills
Provides a generic graph/DAG data structure for xmake scripts with topological sort, cycle detection, cloning, and reversing. Use when you need a graph but not the async job scheduler.
Ships in xmake-skills. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
core.base.graph — Graph Data Structurecore.base.graph is xmake's general-purpose graph module. It implements both directed and undirected graphs with topological sort and cycle detection. Use it when you need to model dependencies / relationships in a custom script but don't want to run them as async jobs (for that, use async.jobgraph, which wraps this).
Must be imported:
import("core.base.graph")
local dag = graph.new(true) -- directed (DAG)
local ug = graph.new(false) -- undirected
g:add_vertex("a")
g:add_vertex("b")
g:add_vertex("c")
g:add_edge("a", "b") -- a → b (directed)
g:add_edge("b", "c")
print(g:has_vertex("a")) -- true
print(g:has_edge("a", "b")) -- true
print(#g:vertices()) -- 3
Vertices can be any value (strings, numbers, tables — anything you can use as a table key).
add_edge auto-adds endpoints:
local g = graph.new(true)
g:add_edge("a", "b") -- "a" and "b" added automatically
g:add_edge("b", "c")
for _, v in ipairs(g:vertices()) do print(v) end
for _, e in ipairs(g:edges()) do
print(e:from(), "->", e:to())
end
for _, e in ipairs(g:adjacent_edges("a")) do
print(e:to()) -- outgoing edges from "a"
end
g:remove_vertex("a") -- also removes incident edges
g:clear() -- reset
print(g:empty()) -- true
local g = graph.new(true)
g:add_edge("parse", "analyze")
g:add_edge("analyze", "optimize")
g:add_edge("optimize", "emit")
local order, has_cycle = g:topo_sort()
if has_cycle then
raise("cycle detected!")
end
for _, v in ipairs(order) do
print(v) -- parse, analyze, optimize, emit
end
topo_sort() returns (list, has_cycle). If there's a cycle, use find_cycle() to get the offending path:
local cycle = g:find_cycle()
if cycle then
raise("cycle: %s", table.concat(cycle, " -> "))
end
For work loops where you want to process vertices as their dependencies become ready:
g:partial_topo_sort_reset()
while true do
local v, has_cycle = g:partial_topo_sort_next()
if has_cycle then raise("cycle") end
if not v then break end
process(v)
g:partial_topo_sort_remove(v) -- mark done, unblock dependents
end
Use this when processing is interleaved with new information (e.g. parallel workers feeding back completion signals).
local copy = g:clone() -- deep copy
local rev = g:reverse() -- reverse all edges (directed only)
g:dump() -- debug dump to stdout
print(g:is_directed())
task("pipeline")
on_run(function ()
import("core.base.graph")
local g = graph.new(true)
for _, step in ipairs(pipeline_steps) do
g:add_vertex(step.name)
for _, dep in ipairs(step.deps or {}) do
g:add_edge(dep, step.name)
end
end
local order, cycle = g:topo_sort()
if cycle then
raise("pipeline has a cycle")
end
for _, name in ipairs(order) do
run_step(name)
end
end)
import("core.base.graph")
import("core.project.project")
local g = graph.new(true)
for name, target in pairs(project.targets()) do
g:add_vertex(name)
for _, dep in ipairs(target:get("deps") or {}) do
g:add_edge(dep, name)
end
end
local cycle = g:find_cycle()
if cycle then
cprint("${red}cycle: %s", table.concat(cycle, " -> "))
end
-- print dependency-order build plan
for _, name in ipairs(g:topo_sort()) do
print(name)
end
rule("codegen")
before_build(function (target)
import("core.base.graph")
local g = graph.new(true)
-- add edges based on #include scan of generated files
...
if g:find_cycle() then
raise("include cycle in generated headers")
end
end)
graph vs async.jobgraph| Feature | core.base.graph | async.jobgraph |
|---|---|---|
| Data structure | generic DAG / undirected | DAG tailored to jobs |
| Vertex payload | any value | name + job function |
| Execution | none — you iterate yourself | scheduled by async.runjobs |
| Groups | not built in | yes |
| Cycle detection | find_cycle() / topo_sort() | yes |
Rule of thumb:
core.base.graph.async.jobgraph (which uses core.base.graph internally).topo_sort() on an undirected graph. Doesn't make sense; xmake raises. Use graph.new(true) for topo sort.g:add_edge("a", "a") is a cycle. find_cycle() will flag it.xmake-async-jobsxmake-targets, xmake-scriptingxmake-rules and xmake-async-jobsWhat SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
xmake, graph, dag, topological-sort, cycle-detection, build-automation
npx claudepluginhub xmake-io/xmake-skills --plugin xmake-skills58 skills in this plugin
/xmake-addon-developmentUse when writing an Xmake addon — the `addon.lua` manifest, the payload layout (plugins/rules/toolchains/modules/includes/templates), `@self` references, shipping package definitions with an addon, `add_globalmodules`, testing it locally, and publishing it to xmake-repo as an `addon` kind package./xmake-addonsUse when installing or using an Xmake addon — `xmake addon --install/--list/--remove/--upgrade/--search`, declaring `add_addons(...)` in a project, and referencing addon payloads with `@addon/<name>/<rule>`, `@addon.<name>.<module>` or `@self`. For writing and publishing one, see xmake-addon-development./xmake-async-jobsUse when running parallel / async work inside xmake scripts — `async.runjobs` for parallel job execution, `async.jobgraph` (DAG) for dependency-ordered jobs, `async.jobpool` (tree structure), `core.base.scheduler` coroutine scheduling, semaphores, and `on_build_files(..., {jobgraph = true})` in rules. For running external compile jobs faster, see `xmake-build-optimization`./xmake-basicsUse when the user is starting a new Xmake project, installing Xmake, or needs the minimal xmake.lua structure. Covers installation, `xmake create`, the project layout, and the smallest valid xmake.lua./xmake-build-cacheUse when configuring or debugging xmake's local build cache (built-in, replaces ccache) or the remote compile cache service (shared across machines via `xmake service --ccache`). Covers enabling/disabling, fallbacks to external ccache, remote cache server/client setup, and cache cleaning./xmake-build-optimizationUse when a project builds slowly and you want to make it faster — parallel jobs, unity build, precompiled headers, build cache, LTO, link-time improvements, binary package cache, and profiling with `XMAKE_PROFILE=perf:*`. Covers idiomatic xmake speedups and the order to try them.Other plugins' skills for the same job