xmake
基于LUA的跨平台构建实用程序
现代C/C ++构建工具:简单,快速,功能强大的依赖关系包集成
支持这个项目
通过成为赞助商来支持这个项目。您的徽标将在此处显示您网站的链接。
技术支援
您还可以考虑赞助我们通过GitHub赞助商计划获得额外的技术支持服务。如果这样做,则可以访问xmake -IO/技术支持库,该存储库具有以下好处:
简介(中文)
- xmake是基于LUA脚本语言的跨平台构建实用程序。
- xmake非常轻巧,并且在标准库之外没有依赖关系。
- 使用
xmake .lua文件以简单且可读性的语法维护项目构建。
xmake可用于直接构建源代码(例如使用Make或Ninja),也可以生成诸如CMAKE或MESON之类的项目源文件。它还具有内置软件包管理系统,可帮助用户集成C ++依赖关系。
xmake = Build backend + Project Generator + Package Manager + [Remote|Distributed] Build + Cache
尽管不那么精确,但仍然可以通过以下方式理解xmake :
xmake ≈ Make/Ninja + CMake/Meson + Vcpkg/Conan + distcc + ccache/sccache
如果您想了解更多信息,请参阅文档,github或gitee。欢迎您加入我们的社区。
可以在xmake -IO/ xmake -Repo上找到官方的xmake存储库。
安装
卷发
curl -fsSL https://x**mak*e.io/shget.text | bash
与Wget
wget https://x**mak*e.io/shget.text -O - | bash
与Powershell
irm https://x*make.*io/*psget.text | iex
其他安装方法
如果您不想使用上面的脚本安装xmake ,请访问安装指南以获取其他安装方法(从源,软件包管理器等构建)。
简单的项目描述
target ( \" console \" ) set_kind ( \" binary \" ) add_files ( \" src/*.c \" )
创建一个新的binary目标console ,并在src目录中添加所有以.c结尾的文件。
包装依赖性
add_requires ( \" tbox 1.6.* \" , \" zlib \" , \" libpng ~1.6 \" )
添加了Tbox V1.6,Zlib(任何版本)和libpng v1.6的要求。
官方xmake软件包存储库存在于: xmake -Repo
命令行接口参考
以下假设您当前在项目的根目录中。
建立一个项目
$ xmake
运行目标
$ xmake run console
调试目标
$ xmake run -d console
运行测试
$ xmake test
配置平台
xmake f -p [windows|linux|macosx|android|iphoneos ..] -a [x86|arm64 ..] -m [debug|release]
$ xmake \”>
$ xmake f -p [windows | linux | macosx | android | iphoneos ..] -a [x86 | arm64 ..] -m [debug | release] $ xmake
菜单配置
$ xmake f --menu
支持的平台
- Windows(X86,X64,ARM,ARM64,ARM64EC)
- MacOS(I386,X86_64,ARM64)
- Linux(I386,X86_64,ARM,ARM64,RISCV,MIPS,390X,SH4 …)
- *BSD(i386,x86_64)
- Android(X86,X86_64,ARMEABI,ARMEABI-V7A,ARM64-V8A)
- iOS(ARMV7,ARMV7S,ARM64,I386,X86_64)
- Watchos(ARMV7K,i386)
- appletvos(ARMV7,ARM64,I386,X86_64)
- Applexros(ARM64,X86_64)
- MSYS(i386,x86_64)
- mingw(i386,x86_64,ARM,ARM64)
- cygwin(i386,x86_64)
- WASM(WASM32,WASM64)
- haiku(i386,x86_64)
- 和谐(X86_64,ARMEABI-V7A,ARM64-V8A)
- 十字架(横链链..)
支持的工具链
xmake show -l toolchains
xcode Xcode IDE
msvc Microsoft Visual C/C++ Compiler
clang-cl LLVM Clang C/C++ Compiler compatible with msvc
yasm The Yasm Modular Assembler
clang A C language family frontend for LLVM
go Go Programming Language Compiler
dlang D Programming Language Compiler (Auto)
dmd D Programming Language Compiler
ldc The LLVM-based D Compiler
gdc The GNU D Compiler (GDC)
gfortran GNU Fortran Programming Language Compiler
zig Zig Programming Language Compiler
sdcc Small Device C Compiler
cuda CUDA Toolkit (nvcc, nvc, nvc++, nvfortran)
ndk Android NDK
rust Rust Programming Language Compiler
swift Swift Programming Language Compiler
llvm A collection of modular and reusable compiler and toolchain technologies
cross Common cross compilation toolchain
nasm NASM Assembler
gcc GNU Compiler Collection
mingw Minimalist GNU for Windows
gnu-rm GNU Arm Embedded Toolchain
envs Environment variables toolchain
fasm Flat Assembler
tinycc Tiny C Compiler
emcc A toolchain for compiling to asm.js and WebAssembly
icc Intel C/C++ Compiler
ifort Intel Fortran Compiler
ifx Intel LLVM Fortran Compiler
muslcc The musl-based cross-compilation toolchain
fpc Free Pascal Programming Language Compiler
wasi WASI-enabled WebAssembly C/C++ toolchain
nim Nim Programming Language Compiler
circle A new C++20 compiler
armcc ARM Compiler Version 5 of Keil MDK
armclang ARM Compiler Version 6 of Keil MDK
c51 Keil development tools for the 8051 Microcontroller Architecture
icx Intel LLVM C/C++ Compiler
dpcpp Intel LLVM C++ Compiler for data parallel programming model based on Khronos SYCL
masm32 The MASM32 SDK
iverilog Icarus Verilog
verilator Verilator open-source SystemVerilog simulator and lint system
cosmocc build-once run-anywhere
hdk Harmony SDK
ti-c2000 TI-CGT C2000 compiler
ti-c6000 TI-CGT C6000 compiler
iararm IAR ARM C/C++ Compiler
kotlin-native Kotlin Native Programming Language Compiler\”>
$ xmake show -l toolchains xcode Xcode IDE msvc Microsoft Visual C/C++ Compiler clang-cl LLVM Clang C/C++ Compiler compatible with msvc yasm The Yasm Modular Assembler clang A C language family frontend for LLVM go Go Programming Language Compiler dlang D Programming Language Compiler (Auto) dmd D Programming Language Compiler ldc The LLVM-based D Compiler gdc The GNU D Compiler (GDC) gfortran GNU Fortran Programming Language Compiler zig Zig Programming Language Compiler sdcc Small Device C Compiler cuda CUDA Toolkit (nvcc, nvc, nvc++, nvfortran) ndk Android NDK rust Rust Programming Language Compiler swift Swift Programming Language Compiler llvm A collection of modular and reusable compiler and toolchain technologies cross Common cross compilation toolchain nasm NASM Assembler gcc GNU Compiler Collection mingw Minimalist GNU for Windows gnu-rm GNU Arm Embedded Toolchain envs Environment variables toolchain fasm Flat Assembler tinycc Tiny C Compiler emcc A toolchain for compiling to asm.js and WebAssembly icc Intel C/C++ Compiler ifort Intel Fortran Compiler ifx Intel LLVM Fortran Compiler muslcc The musl-based cross-compilation toolchain fpc Free Pascal Programming Language Compiler wasi WASI-enabled WebAssembly C/C++ toolchain nim Nim Programming Language Compiler circle A new C++20 compiler armcc ARM Compiler Version 5 of Keil MDK armclang ARM Compiler Version 6 of Keil MDK c51 Keil development tools for the 8051 Microcontroller Architecture icx Intel LLVM C/C++ Compiler dpcpp Intel LLVM C++ Compiler for data parallel programming model based on Khronos SYCL masm32 The MASM32 SDK iverilog Icarus Verilog verilator Verilator open-source SystemVerilog simulator and lint system cosmocc build-once run-anywhere hdk Harmony SDK ti-c2000 TI-CGT C2000 compiler ti-c6000 TI-CGT C6000 compiler iararm IAR ARM C/C++ Compiler kotlin-native Kotlin Native Programming Language Compiler
支持的语言
- C和C ++
- Objective-C和Objective-C ++
- 迅速
- 集会
- 戈兰
- 锈
- Dlang
- Fortran
- 库达
- ZIG
- 瓦拉
- 帕斯卡
- 尼姆
- Verilog
- fasm
- nasm
- Yasm
- MASM32
- cppfront
- 科特林
特征
xmake展览:
- 简单而灵活的配置语法。
- 快速,无依赖性安装。
- 大多数支持平台的简单汇编。
- 通过智能分析跨工具链信息支持交叉兼容。
- 非常快速的并行汇编支持。
- 支持C ++模块(C ++ 20中的新模块)。
- 使用内置软件包管理器支持跨平台C/C ++依赖关系。
- 多语言汇编支持,包括混合语言项目。
- 各种项目生成器的丰富插件支持(例如Visual Studio/Makefiles/cmake/
compile_commands.json) - REPL交互式执行支持
- 通过自动分析标头文件的增量汇编支持
- 内置工具链管理
- 大量扩展模块
- 远程汇编支持
- 分布式汇编支持
- 本地和远程构建缓存支持
支持的项目类型
xmake支持以下类型的项目:
- 静态库
- 共享库
- 控制台/CLI应用程序
- CUDA计划
- QT应用程序
- WDK驱动程序(umdf/kmdf/wdm)
- winsdk应用程序
- MFC应用程序
- 达尔文应用程序(金属支撑)
- 框架和捆绑包(在达尔文)
- Swig模块(Lua,Python,…)
- Luarocks模块
- Protobuf程序
- LEX/YACC程序
- Linux内核模块
软件包管理
下载并构建
xmake可以自动获取并安装依赖项!
支持的软件包存储库
- 官方软件包存储库xmake -Repo(Tbox> 1.6.1)
- 官方软件包经理Xrepo
- 用户构建的存储库
- 柯南(柯南:: openssl/1.1.1g)
- conda(conda :: libpng 1.3.67)
- VCPKG(VCPKG:FFMPEG)
- Homebrew/Linuxbrew(Brew :: PCRE2/LIBPCRE2-8)
- Pacman on Archlinux/MSYS2(Pacman :: libcurl)
- apt on Ubuntu/debian(apt :: zlib1g-dev)
- clib(clib :: clibs/bytes@0.0.4)
- 配音(配音:: log 0.4.3)
- gentoo/linux(portage :: libhandy)上的端口
- Nimlang的灵活(Nimble :: Zip> 1.3)
- 生锈的货物(货物:: base64 0.13.0)
- zypper在opensuse上(zypper :: libsfml2 2.5)
包装管理功能
- 官方存储库提供了将近500多个软件包,并在所有受支持的平台上提供简单的汇编
- 完整的平台软件包支持,支持跨编译的依赖软件包
- 使用
xrepo env shell支持软件包虚拟环境 - Windows预先编译的软件包加速度(NT)
- 支持自行构建的软件包存储库和私人存储库部署
- 第三方软件包存储库支持存储库,例如:VCPKG,Conan,Conda等。
- 支持自动拉动远程工具链
- 支持依赖性版本锁定
处理体系结构
下面是一个图表,显示了xmake的架构,因此它的功能。
分布式汇编
- 跨平台支持。
- 支持MSVC,Clang,GCC和其他交叉兼容工具链。
- 支持为Android,Linux,Windows NT和Darwin主机构建。
- 除了编译工具链以外,没有其他依赖项。
- 支持构建服务器负载平衡计划。
- 支持大型文件的实时压缩传输(LZ4)。
- 为了方便和安全,几乎零配置成本,无需共享文件系统。
有关更多详细信息,请参见:分布式汇编
远程汇编
有关更多详细信息,请参见:远程汇编
本地/远程构建缓存
有关更多详细信息,请参见:构建缓存加速度
基准
xmake的速度与忍者相当!测试项目: xmake -core
多任务并行汇编
| 构建系统 | termux(8核/-J12) | 构建系统 | macOS(8核/-J12) |
|---|---|---|---|
| xmake | 24.890S | xmake | 12.264s |
| 忍者 | 25.682S | 忍者 | 11.327 |
| cmake(gen+make) | 5.416s+28.473s | cmake(gen+make) | 1.203s+14.030s |
| Cmake(Gen+Ninja) | 4.458+24.842s | Cmake(Gen+Ninja) | 0.988s+11.644s |
单个任务汇编
| 构建系统 | termux(-j1) | 构建系统 | macos(-j1) |
|---|---|---|---|
| xmake | 1M57.707S | xmake | 39.937 |
| 忍者 | 1M52.845S | 忍者 | 38.995S |
| cmake(gen+make) | 5.416S+2M10.539S | cmake(gen+make) | 1.203S+41.737S |
| Cmake(Gen+Ninja) | 4.458s+1M54.868S | Cmake(Gen+Ninja) | 0.988s+38.022s |
更多例子
调试和发布概况
add_rules ( \" mode.debug \" , \" mode.release \" ) target ( \" console \" ) set_kind ( \" binary \" ) add_files ( \" src/*.c \" ) if is_mode ( \" debug \" ) then add_defines ( \" DEBUG \" ) end
自定义脚本
target ( \" test \" ) set_kind ( \" binary \" ) add_files ( \" src/*.c \" ) after_build ( function ( target ) print ( \" hello: %s \" , target : name ()) os . exec ( \" echo %s \" , target : targetfile ()) end )
相关软件包的自动集成
在xmake -Repo或第三方存储库中下载并使用软件包:
add_requires ( \" tbox >1.6.1 \" , \" libuv master \" , \" vcpkg::ffmpeg \" , \" brew::pcre2/libpcre2-8 \" ) add_requires ( \" conan::openssl/1.1.1g \" , { alias = \" openssl \" , optional = true , debug = true }) target ( \" test \" ) set_kind ( \" binary \" ) add_files ( \" src/*.c \" ) add_packages ( \" tbox \" , \" libuv \" , \" vcpkg::ffmpeg \" , \" brew::pcre2/libpcre2-8 \" , \" openssl \" )
此外,我们还可以使用Xrepo命令快速安装依赖项。
QT QuickApp程序
target ( \" test \" ) add_rules ( \" qt.quickapp \" ) add_files ( \" src/*.cpp \" ) add_files ( \" src/qml.qrc \" )
CUDA计划
target ( \" test \" ) set_kind ( \" binary \" ) add_files ( \" src/*.cu \" ) add_cugencodes ( \" native \" ) add_cugencodes ( \" compute_35 \" )
WDK/UMDF驱动程序程序
target ( \" echo \" ) add_rules ( \" wdk.driver \" , \" wdk.env.umdf \" ) add_files ( \" driver/*.c \" ) add_files ( \" driver/*.inx \" ) add_includedirs ( \" exe \" ) target ( \" app \" ) add_rules ( \" wdk.binary \" , \" wdk.env.umdf \" ) add_files ( \" exe/*.cpp \" )
有关更多WDK驱动程序示例(UMDF/KMDF/WDM),请访问WDK程序示例
达尔文申请
target ( \" test \" ) add_rules ( \" xcode.application \" ) add_files ( \" src/*.m \" , \" src/**.storyboard \" , \" src/*.xcassets \" ) add_files ( \" src/Info.plist \" )
框架和捆绑程序(Darwin)
target ( \" test \" ) add_rules ( \" xcode.framework \" ) -- or xcode.bundle add_files ( \" src/*.m \" ) add_files ( \" src/Info.plist \" )
OpenMP程序
add_requires ( \" libomp \" , { optional = true }) target ( \" loop \" ) set_kind ( \" binary \" ) add_files ( \" src/*.cpp \" ) add_rules ( \" c++.openmp \" ) add_packages ( \" libomp \" )
ZIG程序
target ( \" test \" ) set_kind ( \" binary \" ) add_files ( \" src/main.zig \" )
自动获取远程工具链
获取特殊版本的LLVM
需要用LLM-10打包的叮当版本来编译项目。
add_requires ( \" llvm 10.x \" , { alias = \" llvm-10 \" }) target ( \" test \" ) set_kind ( \" binary \" ) add_files ( \" src/*.c \" ) set_toolchains ( \" llvm@llvm-10 \" )
获取交叉补偿工具链
我们还可以将指定的交叉补偿工具链插入其中以编译项目。
add_requires ( \" muslcc \" ) target ( \" test \" ) set_kind ( \" binary \" ) add_files ( \" src/*.c \" ) set_toolchains ( \" @muslcc \" )
获取工具链和软件包
我们还可以使用指定的muslcc交叉补偿工具链来编译和整合所有因软件包。
add_requires ( \" muslcc \" ) add_requires ( \" zlib \" , \" libogg \" , { system = false }) set_toolchains ( \" @muslcc \" ) target ( \" test \" ) set_kind ( \" binary \" ) add_files ( \" src/*.c \" ) add_packages ( \" zlib \" , \" libogg \" )
插件
生成IDE项目文件插件(makefile,VS2002 -VS2022 ..)
xmake -m \”debug,release\” # New vsproj generator (Recommended)
$ xmake project -k vs -m \”debug,release\”
$ xmake project -k cmake
$ xmake project -k ninja
$ xmake project -k compile_commands\”>
$ xmake project -k vs xmake -m \" debug,release \" # New vsproj generator (Recommended) $ xmake project -k vs -m \" debug,release \" $ xmake project -k cmake $ xmake project -k ninja $ xmake project -k compile_commands
运行自定义LUA脚本插件
xmake l ./test.lua
$ xmake l -c \”print(\’hello xmake !\’)\”
$ xmake l lib.detect.find_tool gcc
$ xmake l
> print(\”hello xmake !\”)
> {1, 2, 3}
< {
1,
2,
3
}\”>
$ xmake l ./test.lua $ xmake l -c \" print(\'hello xmake !\') \" $ xmake l lib.detect.find_tool gcc $ xmake l > print( \" hello xmake ! \" ) > {1, 2, 3} < { 1, 2, 3 }
要查看内置插件的列表,请访问内置插件。
请从插件存储库xmake -plugins下载并安装其他插件。
IDE/编辑器集成
- xmake -vscode
- xmake -Sublime
- xmake -Idea
- xmake .vim(第三方,谢谢@luzhlon)
- xmake -VisualStudio(第三方,谢谢 @helloworld886)
- xmake -QtCreator(第三方,谢谢@Arthapz)
xmake Gradle插件(JNI)
我们可以使用xmake -Gradle插件通过Gradle编译JNI库。
xmake-plugin\’ version \’1.1.5\’
}
android {
externalNativeBuild {
xmake {
path \”jni/ xmake .lua\”
}
}
}\”>
plugins {
id \'org.tboox.gradle- xmake -plugin\' version \'1.1.5\'
}
android {
externalNativeBuild {
xmake {
path \"jni/ xmake .lua\"
}
}
}
如果应用了gradle- xmake -plugin将自动注入xmake Build assemble 。
xmakeConfigureForArm64
> Task :nativelib: xmake BuildForArm64
>> xmake build
[ 50%]: cache compiling.debug nativelib.cc
[ 75%]: linking.debug libnativelib.so
[100%]: build ok!
>> install artifacts to /Users/ruki/projects/personal/ xmake -gradle/nativelib/libs/arm64-v8a
> Task :nativelib: xmake ConfigureForArmv7
> Task :nativelib: xmake BuildForArmv7
>> xmake build
[ 50%]: cache compiling.debug nativelib.cc
[ 75%]: linking.debug libnativelib.so
[100%]: build ok!
>> install artifacts to /Users/ruki/projects/personal/ xmake -gradle/nativelib/libs/armeabi-v7a
> Task :nativelib:preBuild
> Task :nativelib:assemble
> Task :app:assembleDebug\”>
$ ./gradlew app:assembleDebug > Task :nativelib: xmake ConfigureForArm64 > Task :nativelib: xmake BuildForArm64 >> xmake build [ 50%]: cache compiling.debug nativelib.cc [ 75%]: linking.debug libnativelib.so [100%]: build ok! >> install artifacts to /Users/ruki/projects/personal/ xmake -gradle/nativelib/libs/arm64-v8a > Task :nativelib: xmake ConfigureForArmv7 > Task :nativelib: xmake BuildForArmv7 >> xmake build [ 50%]: cache compiling.debug nativelib.cc [ 75%]: linking.debug libnativelib.so [100%]: build ok! >> install artifacts to /Users/ruki/projects/personal/ xmake -gradle/nativelib/libs/armeabi-v7a > Task :nativelib:preBuild > Task :nativelib:assemble > Task :app:assembleDebug
CI集成
github动作
如果您在CI管道中使用GitHub操作,则用于GITHUB操作的GitHub-Action-setup- xmake插件可以使您在最小的努力中使用xmake 。
xmake @v1
with:
xmake -version: latest\”>
uses : xmake -io/github-action-setup- xmake @v1 with : xmake -version : latest
谁在使用xmake ?
这里有使用xmake的人员和项目列表。
如果您使用的是xmake ,欢迎您通过PR提交信息,以便其他用户和开发人员可以评估兴趣。这也使用户可以更自信地使用xmake ,并使我们有动力继续维护它。
这将有助于xmake项目,并且它的社区变得更加强大和扩展!
联系人
- 电子邮件:waruqi@gmail.com
- 主页: xmake .io
- 社区
- 在Reddit上聊天
- 在电报上聊天
- 在不和谐上聊天
- QQ组上的聊天:343118190,662147501
- 源代码:Github,Gitee
- 微信公共:TBOOX-OS
谢谢
该项目的存在得益于所有贡献的人:
- titansnow:提供xmake徽标并安装脚本
- UAEL:提供语义版本库SV
- 机会Liu:改善CUDA,测试和CI
- XQ144:改进
xrepo env shell,并为xmake -Repo存储库贡献很多软件包。 - Star -Hengxing:为xmake -Repo存储库贡献了很多包装。
- Arthapz:贡献新的C ++模块实现。
- Sirlynix:贡献了许多包裹,让更多的人知道xmake 。
-
enderger:帮助平滑读书人英文翻译的边缘
