Skip to main content
STX is not yet available on xrepo, but you can easily add it as a custom package definition.

Requirements

C++23 standard is required. For C++ Modules support, you need:
  • Xmake 2.8.0+
  • Clang 16+, GCC 14+, or MSVC 19.34+

Custom Package Definition

Add this package definition to your xmake.lua file:
1

Define the STX package

xmake.lua
package("zethcxx.stx")
    set_kind("library", { headeronly = true })
    set_urls("https://github.com/zethcxx/stx.git")

    add_versions( "v1.0.0", "v1.0.0" ) -- Or commit hash
    add_versions( "v2.0.0", "v2.0.0" )

    add_configs( "use_modules", {
        builtin = false,
        default = false,
        type    = "boolean",
        description = "Use C++ Modules"
    })

    on_install( function( package )
        local configs = {}

        if package:config( "use_modules" ) then
            configs.use_modules = true
        end

        import("package.tools.xmake").install( package, configs )
    end)

    on_load( function( package )
        package:add("includedirs", "include")

        if package:config("use_modules") then
            package:add("cxxmodules", "modules/stx/*.cppm")
        end
    end)

    on_test( function (package)
        package:check_cxxsnippets({ 
            test = "import lbyte.stx; int main() { return 0; }"
        }, { 
            configs = { languages = "c++23" }
        })
    end)
package_end()
2

Add as dependency

add_requires( "zethcxx.stx v2.0.0" )

target("your-target")
    set_kind("binary")
    set_languages("cxx23")
    add_files("src/*.cpp")
    add_packages("zethcxx.stx")
3

Build your project

xmake

Usage in Code

#include <lbyte/stx.hpp>
// or for core only:
// #include <lbyte/stx/core.hpp>

using namespace stx;

auto main() -> int {
    // Use STX utilities
    return 0;
}

Package Configuration

Config OptionTypeDefaultDescription
use_modulesbooleanfalseEnable C++23 modules instead of header-only

Module Policies

When using C++ Modules with Xmake, you may need to configure these policies:
-- Enable C++ modules compilation
set_policy("build.c++.modules", true)

-- Disable standard library modules if encountering errors
set_policy("build.c++.modules.std", false)
The build.c++.modules.std policy can be disabled if you encounter issues with standard library module compilation. This is a known workaround for certain compiler configurations.

Version Specification

You can specify versions using:
  • Git tags: "v2.0.0", "v1.0.0"
  • Commit hashes: Replace version string with full commit SHA
add_versions( "v2.0.0", "abc123def456..." )  -- Using commit hash

Alternative: Local Package

If you prefer to vendor STX locally:
target("your-target")
    set_kind("binary")
    set_languages("cxx23")
    add_files("src/*.cpp")
    add_includedirs("extern/stx/include")

Next Steps

CMake Integration

Learn how to use STX with CMake

C++ Modules Setup

Detailed modules configuration and troubleshooting

Build docs developers (and LLMs) love