/xmake-skills:xmake-cxx-modulesfrom xmake-skills
Sets up C++20 modules with xmake: configures .mpp/.cppm/.ixx sources, enables build.c++.modules policy, handles per-compiler quirks (clang/gcc/msvc), moduleonly libraries, and module package distribution.
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.
Xmake has first-class C++20 modules support across GCC, Clang, and MSVC. It handles the BMI (Built Module Interface) cache, dependency scanning, and per-compiler flag differences automatically — you mostly just point it at the files and enable the policy.
build.c++.modules policy enabled.Project layout:
myapp/
├── xmake.lua
└── src/
├── main.cpp # importer (regular .cpp)
└── math.mpp # module interface
// src/math.mpp
export module math;
export int add(int a, int b) {
return a + b;
}
// src/main.cpp
import math;
#include <iostream>
int main() {
std::cout << add(2, 3) << "\n";
return 0;
}
-- xmake.lua
add_rules("mode.debug", "mode.release")
target("myapp")
set_kind("binary")
set_languages("c++20")
set_policy("build.c++.modules", true)
add_files("src/main.cpp", "src/math.mpp")
Build + run:
xmake f -m release
xmake
xmake run myapp
That's it — xmake scans the .mpp, builds the BMI, and links.
Xmake recognizes all common module interface extensions:
| Extension | Used by | Notes |
|---|---|---|
.mpp | xmake convention | Recommended — cross-compiler |
.cppm | Clang convention | Works everywhere with xmake |
.ixx | MSVC convention | Works everywhere with xmake |
.mxx | Alternative | Also recognized |
.cpp | Regular source | Only a module if it starts with module; or export module |
Use whichever you prefer; xmake treats them uniformly. .mpp is the xmake default in examples.
target("app")
set_kind("binary")
set_languages("c++20")
set_policy("build.c++.modules", true)
add_files("src/*.cpp", "src/*.mpp")
target("mylib")
set_kind("static") -- or "shared"
set_languages("c++20")
set_policy("build.c++.modules", true)
add_files("src/*.cpp", "src/*.mpp")
Consumers that add_deps("mylib") inherit the module search path automatically.
moduleonly — pure module libraryWhen a library has no non-module sources (no .cpp, only .mpp/.cppm), use moduleonly. Xmake skips the linker and just ships the BMI + sources.
target("math_modules")
set_kind("moduleonly")
set_languages("c++20")
add_files("src/*.mpp")
This is the right choice for header-only-style module libraries. Consumers still build the BMI but don't link anything.
For mixed header/module libs, keep headeronly for the header side and a separate moduleonly target for the module side:
target("mylib_headers")
set_kind("headeronly")
add_headerfiles("include/(**.h)")
target("mylib_modules")
set_kind("moduleonly")
set_languages("c++20")
add_files("src/*.mpp")
Xmake scans import ...; statements and orders compilation automatically. No manual dep lists needed:
// src/math.mpp
export module math;
export int add(int a, int b) { return a + b; }
// src/geometry.mpp
export module geometry;
import math; // xmake sees this, builds math first
export int perimeter(int w, int h) { return 2 * (w + h); }
target("app")
set_languages("c++20")
set_policy("build.c++.modules", true)
add_files("src/main.cpp", "src/math.mpp", "src/geometry.mpp")
// src/math/core.mpp
export module math:core;
export int add(int a, int b) { return a + b; }
// src/math/vec.mpp
export module math:vec;
export struct Vec { int x, y; };
// src/math.mpp (primary interface)
export module math;
export import :core;
export import :vec;
Just add them all to add_files — xmake handles partition ordering.
import std; / import std.compat; — supported where the compiler supports it:
import std; once libc++ modules are built.import std; out of the box.Enable in xmake:
target("app")
set_languages("c++23") -- std modules usually need c++23
set_policy("build.c++.modules", true)
set_policy("build.c++.modules.std", true)
add_files("src/*.cpp", "src/*.mpp")
// src/main.cpp
import std;
int main() { std::cout << "hi\n"; }
libc++ for import std;.-fmodules -fbuiltin-module-map as needed.xmake -rv and inspect..ixx is MSVC's natural extension but .mpp/.cppm also work.Stick with one toolchain per build. Mixing Clang BMIs with GCC/MSVC won't work — BMI format is compiler-specific.
Consuming a module package:
add_requires("fmt")
target("app")
set_languages("c++20")
set_policy("build.c++.modules", true)
add_files("src/main.cpp")
add_packages("fmt")
For a package that is modules-only, see xmake-private-packages:
package("foo")
set_kind("library", {moduleonly = true})
set_sourcedir(path.join(os.scriptdir(), "src"))
on_install(function (package)
import("package.tools.xmake").install(package, {})
end)
xmake -v # show actual compile commands (useful for BMI flags)
xmake -rv # verbose rebuild
xmake clean --all # drop BMI cache when debugging dep-order bugs
BMI files live under build/.gens/<target>/. Safe to delete — xmake will regenerate.
set_policy("build.c++.modules", true). Xmake then builds .mpp as regular C++ and ignores import. Symptom: "unresolved external" or import treated as an error.set_languages("c++17"). Modules require c++20 (or c++23 for std modules).xmake -rv or xmake clean --all.mylib built with Clang, app with GCC → BMI is unreadable. Rebuild all targets with one toolchain.moduleonly with regular sources. Xmake refuses to link — either split the .cpp into its own static/shared target, or drop moduleonly and use static.import std; on a compiler that doesn't support it. Even with the policy enabled, the compiler must ship libc++/MSVC std modules. Fall back to #include <iostream> if unsupported.a.mpp imports b, b.mpp imports a. C++20 modules forbid cycles — refactor one file into a partition or restructure.xmake-targetsxmake-toolchains, xmake-cross-compilationxmake-private-packagesxmake-build-optimizationWhat SKILL.md sets; muted values are Claude Code's defaults
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`.Other plugins' skills for the same job