Xmake is a lightweight cross platform construction tool based on Lua. It uses xmake.lua to maintain project construction. Compared with makefile/CMakeLists.txt, the configuration syntax is more concise and intuitive. It is very friendly to novices. It can get started quickly in a short time, allowing users to concentrate more energy on actual project development.
In this version, we officially switched the default Luajit runtime to Lua5.4 runtime, added mixed compilation support of Rust and C + +, and integrated package management support of Cargo.
In addition, we added a practical utils.glsl2spv rule to support the compilation of glsl shader and automatically generate the corresponding C-generation wharf file, which is convenient to quickly embed the compiled. SPV file data into the code.
- Project source code
- Official documents
- introductory course
Introduction to new features
Switch to Lua5.4 runtime by default
After several versions of iterative testing, we officially switched to Lua5.4 runtime in version 2.6.1.
However, this is completely insensitive to users, and basically there is no compatibility problem, because xmake encapsulates most interfaces, completely eliminating the compatibility problem between Lua versions.
In terms of construction performance, because the performance bottleneck of the construction mainly comes from the compiler, lua's own performance loss can be ignored. Moreover, xmake rewrites all lua's native io interfaces in c, and optimizes the time-consuming interfaces in c.
Therefore, through the comparative test, whether using Lua or Luajit, the time-consuming of building the project is basically the same, and there is no significant difference.
Why switch?
Because luajit basically does not support some new architectures, such as riscv and longarch, and the author of luajit basically does not maintain it, the progress of some new architecture support and stability repair is at a standstill.
In order to better support more platforms and obtain faster iterative maintenance, we choose to use Lua, which will bring many benefits.
Add Cargo package dependency
In this version, we have added the support of Cargo package dependency manager, but it is mainly used for Rust project at present.
example: https://github.com/xmake-io/xmake/tree/dev/tests/projects/rust/cargo_deps
add_rules("mode.release", "mode.debug") add_requires("cargo::base64 0.13.0") add_requires("cargo::flate2 1.0.17", {configs = {features = "zlib"}}) target("test") set_kind("binary") add_files("src/main.rs") add_packages("cargo::base64", "cargo::flate2")
Mixed compilation of Rust and C + +
Using cxxbridge to call rust in c++
Example: cxx_call_rust_library
add_rules("mode.debug", "mode.release") add_requires("cargo::cxx 1.0") target("foo") set_kind("static") add_files("src/foo.rs") set_values("rust.cratetype", "staticlib") add_packages("cargo::cxx") target("test") set_kind("binary") add_rules("rust.cxxbridge") add_deps("foo") add_files("src/main.cc") add_files("src/bridge.rsx")
foo.rs
#[cxx::bridge] mod foo { extern "Rust" { fn add(a: i32, b: i32) -> i32; } } pub fn add(a: i32, b: i32) -> i32 { return a + b; }
We also need to add the bridge file bridge.rsx to the c + + project
#[cxx::bridge] mod foo { extern "Rust" { fn add(a: i32, b: i32) -> i32; } }
main.cc
#include <stdio.h> #include "bridge.rs.h" int main(int argc, char** argv) { printf("add(1, 2) == %d\n", add(1, 2)); return 0; }
Calling C++ in Rust
Example: trust_ call_ cxx_ library
add_rules("mode.debug", "mode.release") target("foo") set_kind("static") add_files("src/foo.cc") target("test") set_kind("binary") add_deps("foo") add_files("src/main.rs")
main.rs
extern "C" { fn add(a: i32, b: i32) -> i32; } fn main() { unsafe { println!("add(1, 2) = {}", add(1, 2)); } }
foo.cc
extern "C" int add(int a, int b) { return a + b; }
New glsl shader compilation rule
We have added a compilation rule of utils.glsl2spv, which can introduce glsl shader files such as *. vert/*.frag into the project, and then realize automatic compilation to generate *. SPV files.
In addition, we also support binary embedded spv file data in the form of C/C + + header file, which is convenient for program use.
Compile to generate spv file
xmake will automatically call glslangValidator or glslc to compile shaders, generate. spv files, and then output them to the specified {outputdir = "build"} directory.
add_rules("mode.debug", "mode.release") add_requires("glslang", {configs = {binaryonly = true}}) target("test") set_kind("binary") add_rules("utils.glsl2spv", {outputdir = "build"}) add_files("src/*.c") add_files("src/*.vert", "src/*.frag") add_packages("glslang")
Note: add here_ Packages ("glslang") is mainly used to import and bind the glslang validator in the glslang package to ensure that xmake can always use it.
Of course, if you have installed it on your own system, you can also not bind this package, but I still suggest adding it.
Compile and generate c/c + + header files
We can also use the bin2c module internally to generate the corresponding binary header file from the compiled spv file, which is convenient for direct introduction into the user code. We only need to enable {bin2c = true}.: w
add_rules("mode.debug", "mode.release") add_requires("glslang", {configs = {binaryonly = true}}) target("test") set_kind("binary") add_rules("utils.glsl2spv", {bin2c = true}) add_files("src/*.c") add_files("src/*.vert", "src/*.frag") add_packages("glslang")
Then we can introduce this in the code:
static unsigned char g_test_vert_spv_data[] = { #include "test.vert.spv.h" }; static unsigned char g_test_frag_spv_data[] = { #include "test.frag.spv.h" };
Similar to the use of bin2c rules, see glsl2spv example for a complete example
Improving the construction of C++ Modules
In the last version, we refactored the C++20 Modules build support, and in this version, we continue to improve it.
For msvc compiler, we have been able to import std standard library module into the module. In addition, we fixed the problem that module import and compilation failed when there are dependencies between multiple target s.
Improve MDK program build configuration
In the last version, we added MDK program construction support. It should be noted that at present, some MDK programs use the MICROLIB runtime, which needs to be added by the compiler__ MICROLIB macro definition, linker plus -- library_type=microlib and other configurations.
In this version, we can use set_runtimes("microlib") is set directly to the microlib runtime library, and all relevant options can be set automatically.
Console Application
target("hello") add_deps("foo") add_rules("mdk.console") add_files("src/*.c", "src/*.s") add_includedirs("src/lib/cmsis") set_runtimes("microlib")
Static library program
add_rules("mode.debug", "mode.release") target("foo") add_rules("mdk.static") add_files("src/foo/*.c") set_runtimes("microlib")
Improve OpenMP project configuration
We have also improved the configuration of openmp project, which is more simplified and unified. We no longer need to configure additional rules. We can achieve the same effect only through a general openmp package.
add_requires("openmp") target("loop") set_kind("binary") add_files("src/*.cpp") add_packages("openmp")
In the previous version, we need this configuration. By comparison, we can see that the new configuration is more concise.
add_requires("libomp", {optional = true}) target("loop") set_kind("binary") add_files("src/*.cpp") add_rules("c++.openmp") add_packages("libomp")
Update content
New features
- #1799: support mixed Rust and C + + programs and integrated Cargo dependency library
- Add utils.glsl2spv rule to compile. vert/.frag shader file to generate spirv file and binary C header file
improvement
- Switch to Lua5.4 runtime by default
- #1776: improved system::find_package, which supports searching system libraries from environment variables
- #1786: improved apt:find_package, which supports searching alias packages
- #1819: add precompiled header to cmake generator
- Improving C++20 Modules to support std standard library for msvc
- #1792: adding custom commands to vs project builder
- #1835: improved MDK program construction support and added set_runtimes("microlib")
- #1858: improved the construction of c++20 modules and fixed the problem of cross target construction
- Add XMAKE_BINARY_REPO and xmake_ MAIN_ Setting environment variables for repo warehouse
- #1865: improving openmp project
- #1845: installing pdb files for static libraries
Bugs repair
- Fix the problem of parsing build string with 0 prefix in semantic version
- #50: fix rule and build bpf program bug s
- #1610: fix xmake f --menu, no response to key press under vscode terminal, and support virtual key press of conty terminal