/xmake-skills:xmake-build-optimizationfrom xmake-skills
Guides you through xmake build speedups in recommended order: parallel jobs, unity builds, precompiled headers, build cache, and profiling with XMAKE_PROFILE. Measure before and after to confirm gains.
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.
A roadmap for making an xmake build faster. Try them in order — each has a different cost/benefit. Measure before and after with XMAKE_PROFILE=perf:tag (or time xmake).
Don't guess where the time goes:
XMAKE_PROFILE=perf:tag xmake # compile vs link vs other
XMAKE_PROFILE=perf:process xmake # which subprocesses dominate
XMAKE_PROFILE=perf:call xmake # expensive Lua functions
XMAKE_PROFILE=trace xmake f -c # trace every subprocess in configure
time xmake --rebuild # total wall-clock
Profile before each change — "speedups" often turn out to be in the cache-hit, not the fix.
See xmake-troubleshooting for the full profiler reference.
xmake -j N # N parallel jobs
xmake -j $(nproc)
xmake -j $(sysctl -n hw.ncpu) # macOS
Default is already ⌈3/2 × ncpu⌉. Override for:
xmake f --ccache=y # default
xmake f --ccache=n # disable for debugging
Xmake ships a built-in cache since 2.6.6 — faster than external ccache, cross-platform (MSVC too). See xmake-build-cache.
Verify it's working — look for cache compiling.release in the output.
Compile multiple source files as one translation unit. Massive speedup (2–5×) for projects with hundreds of small files.
target("mylib")
add_rules("c++.unity_build", {batchsize = 8}) -- 8 files per unit
add_rules("c.unity_build")
add_files("src/*.cpp")
Pitfalls (usual unity-build ones):
static symbols clash with same-named symbols in another file in the same unit. Rename or exclude.Exclude problem files:
add_files("src/*.cpp")
add_files("src/legacy.cpp", {unity_ignored_files = true})
target("app")
set_pcxxheader("src/pch.hpp") -- C++ PCH
-- or:
set_pcheader("src/pch.h") -- C PCH
add_files("src/*.cpp")
Good fit when many files include the same heavy STL/boost/Qt header. PCH is compiled once and reused.
Before optimizing the compiler, remove files you don't need:
add_includedirs("include", {public = true}) only for the actual public dir — not src/.add_defines at target level is parsed once; target:add inside on_load runs per-target but is still cheaper than per-file.add_files("src/**/*.cpp") lets xmake hash once; listing 500 files explicitly is slower to parse.set_policy("build.warning", false) when CI checks warnings — don't re-emit warning diagnostics in the inner loop.If you use lots of packages, pull precompiled binaries instead of building from source:
xrepo install --precompiled fmt spdlog boost
Or project-level: packages that have prebuilt binaries are used automatically when available. xmake require --info <pkg> shows whether the precompiled variant exists.
Cache package installs in CI:
# GitHub Actions
- uses: actions/cache@v4
with:
path: |
~/.xmake/packages
~/.xmake/cache
key: xmake-${{ runner.os }}-${{ hashFiles('xmake.lua') }}
Linking often dominates build time for big projects.
target("app")
if is_mode("release") then
set_policy("build.optimization.lto", true)
end
LTO makes release builds slower but smaller/faster at runtime. Don't enable for debug builds.
lld instead of ldxmake f --ldflags="-fuse-ld=lld" # Linux/macOS with clang
xmake f --ldflags="-fuse-ld=mold" # even faster (Linux)
mold and lld can be 5–10× faster than BFD ld on large links.
Huge monolithic static libs link slowly. Split into a few shared or static targets with proper add_deps — xmake will only re-link what changed.
Hide symbols by default to shrink link work:
set_symbols("hidden")
-- or flags:
add_cxflags("-fvisibility=hidden", "-fvisibility-inlines-hidden")
Release isn't the bottleneck for daily dev — debug is.
if is_mode("debug") then
set_optimize("none") -- or "fast" for balanced
set_symbols("debug")
add_cxflags("-g1", {force = true}) -- minimal debug info
end
-g1 instead of -g cuts debug info size drastically.add_cxflags("-gsplit-dwarf") + add_ldflags("-Wl,--gdb-index").-fno-inline off if you don't need to step into inlined functions.Scale beyond one machine:
--distcc) — farm out compile jobs to a cluster. See xmake-distributed-compilation.--ccache) — share compiled objects across a team/CI. See xmake-build-cache.Both compose with the local cache and each other. Typical team setup:
xmake service --connect --distcc --ccache
The description-domain parse time and tool detection can dominate tiny projects.
xmake-style. Every parse re-runs top-level code.os.iorun / git at top level. Use on_load or a task.xmake f once, not per file. Configure caches to .xmake/; don't re-configure inside tight loops.add_moduledirs chains during steady-state builds — only needed while iterating on native modules.XMAKE_PROFILE=perf:tag xmake — know where time goes first.-jN — parallelism.--ccache=y and look for cache hits.--precompiled, CI cache for ~/.xmake/packages).lld / mold linker.-g3 can fight each other. Add one knob at a time.xmake-build-cachexmake-distributed-compilationxmake-remote-compilationxmake-troubleshootingxmake.lua parsing is slow → xmake-styleWhat SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
58 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`.npx claudepluginhub xmake-io/xmake-skills --plugin xmake-skillsOther plugins' skills for the same job