Scripts2026年5月1日·1 分钟阅读

xmake — Cross-Platform Build Utility in Lua

xmake is a lightweight, cross-platform build utility based on Lua that combines a build system, package manager, and project generator for C, C++, Rust, Go, and more.

Introduction

xmake is a build system and package manager driven by Lua-based build scripts. It offers a concise syntax for describing build targets, handles dependency management through its own package repository, and generates project files for IDEs like VS Code, Visual Studio, and Xcode.

What xmake Does

  • Builds C, C++, Objective-C, Rust, Go, D, and assembly projects with automatic toolchain detection
  • Manages dependencies via a built-in package manager with a repository of over 1,500 packages
  • Generates IDE project files (CMakeLists, Makefile, Ninja, VS solution) from a single xmake.lua
  • Supports cross-compilation for Android, iOS, embedded targets, and WASM out of the box
  • Provides an interactive configuration menu (xmake f --menu) similar to Linux kernel menuconfig

Architecture Overview

xmake uses a two-phase approach: first it configures the project by detecting toolchains and resolving dependencies, then it executes a parallel build graph. Build descriptions live in xmake.lua files written in a DSL built on top of Lua. The package manager resolves remote packages from xmake-repo or Conan/Vcpkg registries and caches them locally. A build cache and distributed compilation mode (via distcc integration) speed up large projects.

Self-Hosting & Configuration

  • Install via curl one-liner, Homebrew, Scoop, or build from source
  • Project configuration lives in a single xmake.lua file at the project root
  • Use xmake require to add third-party libraries; they are fetched, built, and cached automatically
  • Configure toolchains with xmake f --toolchain=clang or set cross-compilation targets
  • Integrate with CI by running xmake install -o /output to produce installable artifacts

Key Features

  • Lua-based build scripts that are concise and readable compared to CMake or Makefiles
  • Built-in package manager with a growing repository, plus integration with Conan and Vcpkg
  • Multi-language support: C, C++, Rust, Go, D, and more in a single project
  • One-command IDE project generation for VS, Xcode, CMake, and Ninja
  • Incremental builds with header dependency tracking and optional distributed compilation

Comparison with Similar Tools

  • CMake — industry standard with wider adoption, but more verbose and complex syntax
  • Meson — Python-based build system with similar speed goals, but no built-in package manager
  • Bazel — Google-scale build system with hermetic builds, but steep learning curve
  • Premake — Lua-based project generator, but focused on IDE file generation rather than building
  • SCons — Python-based build tool, mature but slower on large projects

FAQ

Q: Can xmake build existing CMake projects? A: xmake can import CMakeLists.txt and wrap CMake projects, letting you use xmake's package manager alongside existing CMake targets.

Q: Does xmake support Windows? A: Yes. It detects MSVC, MinGW, and Clang toolchains on Windows and supports building from cmd, PowerShell, or MSYS2.

Q: How does the package manager compare to Conan or Vcpkg? A: xmake's package manager is tightly integrated with the build system. It can also pull packages from Conan and Vcpkg registries as fallback sources.

Q: Is xmake suitable for large-scale projects? A: Yes. Its parallel build engine and distributed compilation support handle projects with thousands of source files efficiently.

Sources

讨论

登录后参与讨论。
还没有评论,来写第一条吧。

相关资产