xmake is a lightweight cross-platform build tool based on Lua. It uses xmake.lua to maintain project builds. Compared with makefile/CMakeLists.txt, the configuration syntax is more Concise and intuitive, very friendly to novices, can get started quickly in a short time, allowing users to focus more on the actual project development.
With the continuous iterative development of xmake in recent years, xmake has harvested 2.9K stars, 300+ forks, 30+ contributors on Github, and handled 900+ issues, 5400+ Commits, and active users are also growing.
Now, the xmake v2.3.7 version is released. In the new version, we mainly improved the stability and compatibility of xmake itself. Through two months of continuous iteration, we have fixed various user feedback problems, user experience and The stability has been greatly improved.
In addition, we also added support for TinyC and Emscripten (WebAssembly) compilation tool chains in this version.
Especially for the windows platform, we provide an additional xmake-tinyc installation package, which has a built-in tinyc compiler, so that users can completely escape the bloated vs environment, one-click installation, out of the box, only 5M installation package is needed Simple C programs can be developed, and a complete set of winapi header files are also included.
Finally, we also improved the trybuild mode compilation. Through xmake, third-party projects maintained by autotools/cmake can be quickly compiled, and cross-compilation environments such as android/ios/mingw can be quickly connected to achieve rapid migration and compilation.
In the new version, we submitted the xmake installation package to windows winget and ubuntu ppa repositories, we can install xmake more conveniently and quickly.
winget install xmake
sudo add-apt-repository ppa:xmake-io/xmake
sudo apt update
sudo apt install xmake
Of course, we also support many other installation methods. For detailed installation methods for other platforms, see: Installation Document.
Currently we have supported a lot of toolchain environments, and in this version, we have added support for TinyC and Emscripten (WebAssembly) compilation toolchains. We can quickly switch to the corresponding toolchain to compile with the following command.
xmake f --toolchain=[tinyc|emscripten]
xmake
In the new version, we also provide two additional installation packages, built-in and integrated TinyC compilation environment, the entire installation package only needs 5M, and also contains winsdk api.
The installation package can be found in the github/releases directory of xmake.
Through this installation package, we can completely get rid of the bloated vs development environment (several G) by compiling and developing C programs, realize one-click installation, and use it out of the box. It is very useful for us to brush leetcode and write some C test code. Yes, there is no need to install the entire vs for this particular installation.
In addition, if we want to view all toolchains supported by xmake, we can execute the following command, and the compilation configuration of xmake f -p cross --sdk=/xxx
can support more general cross toolchains.
$ xmake show -l toolchains
xcode Xcode IDE
vs VisualStudio IDE
yasm The Yasm Modular Assembler
clang A C language family frontend for LLVM
go Go Programming Language Compiler
dlang D Programming Language Compiler
gfortran GNU Fortran Programming Language Compiler
zig Zig Programming Language Compiler
sdcc Small Device C Compiler
cuda CUDA Toolkit
ndk Android NDK
rust Rust 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
tinyc Tiny C Compiler
emcc A toolchain for compiling to asm.js and WebAssembly
This version focuses on some improvements to the support of other languages, such as fortran compilation support, experimental support for zig language, and third-party dependency package support and cross-compilation support for golang/dlang.
Although, xmake focuses on c/c++ build support, other languages support xmake will also make some improvements from time to time. Its main purpose is not to replace their official build system, but only to support mixed compilation with c/c++ , To better serve c/c++ projects, After all, some c/c++ projects still occasionally call code interfaces of other languages, such as mixed calls with languages such as cuda, dlang, objc, swift, asm, etc., so xmake still provides some basic compilation support for them.
In addition, regarding c/c++, we also support the header file dependency format of the new /sourceDependencies xxx.json
output in the vs preview version (this is more reliable and stable for multi-language header file dependency detection).
Starting from this version, we have fully supported the use of the gfortran compiler to compile fortran projects, we can quickly create an empty project based on fortran by using the following command:
$ xmake create -l fortran -t console test
Its xmake.lua content is as follows:
add_rules("mode.debug", "mode.release")
target("test")
set_kind("binary")
add_files("src/*.f90")
More code examples can be viewed here: Fortran Examples
The main work of this version is to continue to improve the support of the tool chain. Although the previous version achieved modular tool chain extension through refactoring, for one compilation, I want to flexibly switch the compilation on the cross tool chain/Host tool chain. Not very good support, so this version focuses on improving the support of this piece.
In addition, this version also improves the problem of slow downloading of remote dependent packages integrated using add_requires
, adding proxy settings and local package retrieval multiplexing support to improve this problem. Of course, the best way is to get a domestic CDN to speed up the download, but this cost is too high, for the time being not toss.
There are some minor changes and bug fixes, you can see the updated content at the bottom of the article.
For an example of this, please refer to the luajit project. The compilation process needs to first compile the two targets minilua/buildvm under the host platform, and then generate the jit code corresponding to the target platform through minilua/buildvm to participate in the compilation of the overall luajit library.
Therefore, the entire compilation process needs to use the host tool chain for a specific target, and then use the cross tool chain to complete the compilation for other targets.
So how should we configure xmake.lua to achieve this way, one is to set the specified host toolchain for a specific target through the set_toolchains
interface, for example:
target("buildvm")
set_kind("binary")
add_files("src/*.c")
set_toolchains("xcode", {plat = os.host(), arch = os.arch()})
target("luajit")
set_kind("static")
add_deps("buildvm")
add_files("src/*.c")
If you are currently in cross-compilation mode, even if you execute the following command to configure the android compilation platform, its buildvm is still using xcode to compile the macOS target program, only the luajit library is compiled using the ndk toolchain:
$ xmake f -p android --ndk=/xxxx
However, this is not particularly convenient, especially when cross-platform compilation, pc tool chains of different platforms are different, there are msvc, xcode, clang, etc., you need to judge the platform to specify.
We can also continue to generalize and let xmake automatically select the currently available Host toolchain for different platforms, instead of explicitly specifying a specific toolchain, and improve it to the following version:
target("buildvm")
set_kind("binary")
add_files("src/*.c")
set_plat(os.host())
set_host(os.arch())
target("luajit")
set_kind("static")
add_deps("buildvm")
add_files("src/*.c")
By using set_plat and set_arch interface, directly set a specific target to the host platform, you can automatically select the host tool chain internally.
For a complete configuration example of this piece, you can refer to: https://github.com/xmake-io/xmake-repo/blob/master/packages/l/luajit/port/xmake.lua
In order to make xmake better support cross-compilation, this version I refactored the entire tool chain, making the tool chain switching more convenient and fast, and now users can easily extend their tool chain in xmake.lua.
With regard to platform support, we have added support for *BSD systems. In addition, this version also adds a ninja theme style to achieve ninja-like compilation progress display, for example:
LTUI is a cross-platform character terminal UI interface library based on lua.
This framework originates from the requirement of graphical menu configuration in xmake, similar to the menuconf of linux kernel to configure the compilation parameters, so based on curses and lua, a complete set of cross Character terminal ui library of the platform. The style and style are basically completely referenced by kconfig-frontends. Of course, users can also customize different ui styles.
In addition, LTUI is completely cross-platform, and the terminal terminal on Windows is also fully supported. On Windows, ltui will use pdcurses to draw windows.
However, the previous version did not support the layout adjustment with the size of the terminal window to automatically adjust the layout. If the window becomes larger, the entire view there will still retain the original size. In the current v1.7 version, I have carried out partial refactoring to support the window Resize and adaptive adjustment of all views layout.
previous version:
new version: