Xmake is a lightweight cross-platform build tool based on Lua, using xmake. Lua maintenance project construction, compared to makefile/ cmakelists.txt configuration syntax is more concise and intuitive, very friendly to beginners, in a short time can be quickly started. Can let the user focus more energy on the actual project development.
With this release, we officially switched from the default Luajit runtime to the Lua5.4 runtime, added mixed compilation support for Rust and C++, and we integrated Cargo’s package management support.
In addition, we have added a useful utils. Glsl2spv rule, which supports the compilation of GLSL shader and automatically generates corresponding C generation dock files, so that the compiled.spv file data can be embedded into the code quickly.
- Program source code
- The official documentation
- An introductory course
New Features
Switch to Lua5.4 runtime by default
After several iterations of testing, we officially switched to the Lua5.4 runtime in version 2.6.1.
However, this is completely insensitive to the user and there are basically no compatibility issues because Xmake encapsulates most of the interfaces, eliminating compatibility issues between Lua versions.
In terms of build performance, since the build performance bottleneck is mainly from the compiler, Lua’s own performance loss is completely negligible, and Xmake rewrites all of Lua’s native IO interfaces in C, and optimizes the time-consuming interfaces in C.
As a result, the time it took to build a project was roughly the same whether Lua was used or Luajit was not significantly different by comparison tests.
Why switch?
Due to Luajit’s lack of support for some new architectures, such as RISCV and Lonngarch, and the Luajit authors have barely maintained it, some new architecture support and stability fixes are at a standstill.
In order to be able to better support more platforms and get faster iterative maintenance, we chose to use Lua for many benefits.
Add Cargo package dependencies
In this release, we have added support for the Cargo package dependency manager, but for now it is mainly used for Rust projects.
Example: github.com/xmake-io/xm…
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")
Copy the code
Rust and C++ mixed compilation
Call rust in c++ using cxxbridge
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")
Copy the code
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;
}
Copy the code
We also need to add the bridge file bridge.rsx to our c++ project
#[cxx::bridge]
mod foo {
extern "Rust" {
fn add(a: i32, b: i32) - >i32; }}Copy the code
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;
}
Copy the code
Calling C++ in Rust
Example: rust_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")
Copy the code
main.rs
extern "C" {
fn add(a: i32, b: i32) - >i32;
}
fn main() {
unsafe {
println!("add(1, 2) = {}", add(1.2)); }}Copy the code
foo.cc
extern "C" int add(int a, int b) {
return a + b;
}
Copy the code
New GLSL Shader compilation rule
Vert /*. Frag GLSL shader files in your project, and then automatically compile *. SPV files.
In addition, we also support C/C++ header, binary embedded SPV file data, easy to use programs.
Compile and generate SPV files
Xmake automatically calls glslangValidator or GLSLC to compile shaders to generate.spv files and 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")
Copy the code
Note that add_packages(” GLslang “) is used to introduce and bind the glslangValidator in the GLslang package, ensuring that Xmake will always be able to use it.
Of course, if you already have it installed on your own system, you don’t have to bundle it, but I recommend adding it anyway.
Compile to generate c/ C ++ header files
We can also use the bin2c module internally to generate the corresponding binary header file from the SPV file, which is easy to import directly into the user code. We just 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")
Copy the code
Then we can introduce it in code like this:
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"
};
Copy the code
See glsl2spv example for a complete example of the bin2c rule
Improved C++ Modules build
In the last release, we refactored the C++20 Modules build support, and in this release, we continue to improve it.
For the MSVC compiler, we have been able to import STD library modules into modules, and we have fixed an issue where module import compilation failed when there were dependencies between multiple targets.
Improved MDK program build configuration
In the last release, we added support for building MDK programs. It should be noted that some MDK programs currently use microlib runtime, which requires compiler plus __MICROLIB macro definition, linker plus –library_type=microlib and other configurations.
In this version, we can set the microlib runtime library directly with set_runtimes(“microlib”), which automatically sets all the relevant options.
Console program
target("hello")
add_deps("foo")
add_rules("mdk.console")
add_files("src/*.c"."src/*.s")
add_includedirs("src/lib/cmsis")
set_runtimes("microlib")
Copy the code
Static library program
add_rules("mode.debug"."mode.release")
target("foo")
add_rules("mdk.static")
add_files("src/foo/*.c")
set_runtimes("microlib")
Copy the code
Improved OpenMP project configuration
We have also improved the configuration of the OpenMP project to make it simpler and more uniform. We no longer need to configure rules, but can achieve the same effect through a common OpenMP package.
add_requires("openmp")
target("loop")
set_kind("binary")
add_files("src/*.cpp")
add_packages("openmp")
Copy the code
In the previous version, we had to do this configuration, but the new configuration is much more concise.
add_requires("libomp", {optional = true})
target("loop")
set_kind("binary")
add_files("src/*.cpp")
add_rules("c++.openmp")
add_packages("libomp")
Copy the code
Update the content
New features
- #1799: support for mixing Rust and C++ programs, as well as integration with Cargo dependency libraries
- add
utils.glsl2spv
Rule de-compiling.vert/The. Frag shader file generates spirv files and binary C header files
To improve the
- Switch to Lua5.4 runtime by default
- #1776: Improved system::find_package to support system library lookup from environment variables
- #1786: Improved APT :find_package to support finding alias packages
- #1819: Add precompiled headers to the Cmake generator
- Improved C++20 Modules to support the STD library for MSVC
- #1792: Add custom commands to the VS project generator
- # 1835: Improved MDK program building support, added
set_runtimes("microlib")
- #1858: improved build c++20 modules, fixed cross-target build issues
- Add XMAKEBINARYREPO and XMAKE_BINARY_REPO and XMAKEBINARYREPO and XMAKE_MAIN_REPO repositories to set environment variables
- #1865: Improved OpenMP project
- #1845: Install PDB files for static libraries
Bugs fix
- Fixed parsing build strings prefixed with 0 in semantic versions
- #50: Fix rule and build BPF bugs
- # 1610Repair:
xmake f --menu
There is no response for pressing keys in vscode terminal, and ConPTY terminal virtual keys are supported