Xmake v2.7.6 released, adding Verilog and C++ Modules distribution support

Xmake  is a lightweight cross-platform build tool based on Lua.

It's very lightweight and doesn't have any dependencies because it has a built-in Lua runtime.

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 be quickly started in a short time, allowing users to focus more on actual project development superior.

We can use it to directly compile projects like Make/Ninja, or generate project files like CMake/Meson, and it also has a built-in package management system to help users solve the problem of integrated use of C/C++ dependent libraries.

At present, Xmake is mainly used to build C/C++ projects, but it also supports the construction of other native languages. It can realize mixed compilation with C/C++, and the compilation speed is also very fast, which can be equal to that of Ninja.

Xmake = Build backend + Project Generator + Package Manager + [Remote|Distributed] Build + Cache

Although not very accurate, we can still understand Xmake in the following way:

Xmake ≈ Make/Ninja + CMake/Meson + Vcpkg/Conan + distcc + ccache/sccache

Introduction of new features

Verilog Simulator Support

iVerilog Simulator

Through configuration, we can automatically pull the iverilog toolchain package, and then use the automatic binding toolchain to compile the project. add_requires("iverilog")  set_toolchains("@iverilog") 

add_requires("iverilog")
target("hello")
    add_rules("iverilog.binary")
    set_toolchains("@iverilog")
    add_files("src/*.v")

Set abstract configuration

add_requires("iverilog")
target("hello")
    add_rules("iverilog.binary")
    set_toolchains("@iverilog")
    add_files("src/*.v")
    add_defines("TEST")
    add_includedirs("inc")
    set_languages("v1800-2009")

We can set the language standard for switching Verilog by . set_languages("v1800-2009") 

Currently supported values ​​and mappings are as follows:

["v1364-1995"] = "-g1995"
["v1364-2001"] = "-g2001"
["v1364-2005"] = "-g2005"
["v1800-2005"] = "-g2005-sv"
["v1800-2009"] = "-g2009"
["v1800-2012"] = "-g2012"

Set custom flags

add_requires("iverilog")
target("hello")
    add_rules("iverilog.binary")
    set_toolchains("@iverilog")
    add_files("src/*.v")
    add_values("iverilogs.flags", "-DTEST")

construction project

$ xmake
checking for iverilog ... iverilog
checking for vvp ... vvp
[ 50%]: linking.iverilog hello.vvp
[100%]: build ok!

run the program

$ xmake run
hello world!
LXT2 info: dumpfile hello.vcd opened for output.
src/main.v:6: $finish called at 0 (1s)

More complete examples: iVerilog Examples

Verilator emulator

Through configuration, we can automatically pull the verilator toolchain package, and then use automatic binding to the toolchain to compile the project. add_requires("verilator")  set_toolchains("@verilator") 

add_requires("verilator")
target("hello")
    add_rules("verilator.binary")
    set_toolchains("@verilator")
    add_files("src/*.v")
    add_files("src/*.cpp")

verilator project, we need an additional file to participate in the compilation, as the entry code of the program. sim_main.cpp 

#include "hello.h"
#include "verilated.h"

int main(int argc, char** argv) {
    VerilatedContext* contextp = new VerilatedContext;
    contextp->commandArgs(argc, argv);
    hello* top = new hello{contextp};
    while (!contextp->gotFinish()) { top->eval(); }
    delete top;
    delete contextp;
    return 0;
}

Set abstract configuration

add_requires("verilator")
target("hello")
    add_rules("verilator.binary")
    set_toolchains("@verilator")
    add_files("src/*.v")
    add_defines("TEST")
    add_includedirs("inc")
    set_languages("v1800-2009")

We can set the language standard for switching Verilog by . set_languages("v1800-2009") 

Currently supported values ​​and mappings are as follows:

-- Verilog
["v1364-1995"] = "+1364-1995ext+v",
["v1364-2001"] = "+1364-2001ext+v",
["v1364-2005"] = "+1364-2005ext+v",
-- SystemVerilog
["v1800-2005"] = "+1800-2005ext+v",
["v1800-2009"] = "+1800-2009ext+v",
["v1800-2012"] = "+1800-2012ext+v",
["v1800-2017"] = "+1800-2017ext+v",

Set custom flags

add_requires("verilator")
target("hello")
    add_rules("verilator.binary")
    set_toolchains("@verilator")
    add_files("src/*.v")
    add_files("src/*.cpp")
    add_values("verilator.flags", "--trace", "--timing")

construction project

$ xmake
[  0%]: compiling.verilog src/main.v
[ 15%]: cache compiling.release /Users/ruki/.xmake/packages/v/verilator/2023.1.10/cd2268409c1d44799288c7759b3cbd56/share/verilator/include/verilated.cpp
[ 15%]: cache compiling.release build/.gens/hello/macosx/x86_64/release/rules/verilator/hello___024root__Slow.cpp
[ 15%]: cache compiling.release build/.gens/hello/macosx/x86_64/release/rules/verilator/hello___024root__DepSet_h9053a130__0__Slow.cpp
[ 15%]: cache compiling.release build/.gens/hello/macosx/x86_64/release/rules/verilator/hello.cpp
[ 15%]: cache compiling.release /Users/ruki/.xmake/packages/v/verilator/2023.1.10/cd2268409c1d44799288c7759b3cbd56/share/verilator/include/verilated_threads.cpp
[ 15%]: cache compiling.release build/.gens/hello/macosx/x86_64/release/rules/verilator/hello__Syms.cpp
[ 15%]: cache compiling.release build/.gens/hello/macosx/x86_64/release/rules/verilator/hello___024root__DepSet_h07139e86__0.cpp
[ 15%]: cache compiling.release src/sim_main.cpp
[ 15%]: cache compiling.release build/.gens/hello/macosx/x86_64/release/rules/verilator/hello___024root__DepSet_h9053a130__0.cpp
[ 84%]: linking.release hello
[100%]: build ok!

run the program

$ xmake run
ruki-2:hello ruki$ xmake run
hello world!
- src/main.v:4: Verilog $finish

More complete examples: Verilator

Support for C++ Module distribution

Many thanks to Arthapz for continuing to help improve xmake's support for C++ Modules in the new version.  

Now, we can distribute C++ Modules as packages, and then quickly integrate and reuse them in other projects.

It is a prototype implementation based on the draft design for module distribution in p2473r1 .  

Make distribution C++ Modules package

We first use xmake.lua to build the maintenance module, and tell xmake which module files need to be installed for external distribution by specifying. {install = true}

add_rules("mode.release", "mode.debug")
set_languages("c++20")

target("foo")
    set_kind("static")
    add_files("*.cpp")
    add_files("*.mpp", { install = true })

Then, we make it into a package, which can be submitted to the xmake-repo warehouse, of course, it can also be directly made into a local package or a private warehouse package.  

Here, for the convenience of test verification, we just make it a local package. set_sourcedir 

package("foo")
    set_sourcedir(path.join(os.scriptdir(), "src"))
    on_install(function(package)
        import("package.tools.xmake").install(package, {})
    end)

Integrated C++ Modules package

Then, we use the package integration interface to quickly integrate and use the C++ Modules package. add_requires("foo") 

Since foo's module package is defined in a private warehouse, we import our own package warehouse. add_repositories("my-repo my-repo") 

If the package has been submitted to the xmake-repo official warehouse, there is no need to configure it additionally.

add_rules("mode.release", "mode.debug")
set_languages("c++20")

add_repositories("my-repo my-repo")
add_requires("foo", "bar")

target("packages")
    set_kind("binary")
    add_files("src/*.cpp")
    add_packages("foo", "bar")
    set_policy("build.c++.modules", true)

After the package is integrated, we can execute the command to download, compile, and integrate the C++ Modules package with one click. xmake 

$ xmake
checking for platform ... linux
checking for architecture ... x86_64
note: install or modify (m) these packages (pass -y to skip confirm)?
in my-repo:
  -> foo latest
  -> bar latest
please input: y (y/n/m)

  => install bar latest .. ok
  => install foo latest .. ok
[  0%]: generating.module.deps src/main.cpp
[  0%]: generating.module.deps /mnt/xmake/tests/projects/c++/modules/packages/build/.packages/b/bar/latest/4e0143c97b65425b855ad5fd03038b6a/modules/bar/bar.mpp
[  0%]: generating.module.deps /mnt/xmake/tests/projects/c++/modules/packages/build/.packages/f/foo/latest/4e0143c97b65425b855ad5fd03038b6a/modules/foo/foo.mpp
[ 14%]: compiling.module.release bar
[ 14%]: compiling.module.release foo
[ 57%]: compiling.release src/main.cpp
[ 71%]: linking.release packages
[100%]: build ok!

Note: After each package is installed, the meta-info file of the maintenance module will be stored in the package path. This is a format specification agreed in . Maybe it is not the final standard, but this does not affect us to use the module now distribution. p2473r1.pdf 

$ cat ./build/.packages/f/foo/latest/4e0143c97b65425b855ad5fd03038b6a/modules/foo/foo.mpp.meta-info
{"_VENDOR_extension":{"xmake":{"name":"foo","file":"foo.mpp"}},"definitions":{},"include_paths":{}}

For a complete example project see: C++ Modules Package Distribution Example Project

Support C++23 Std Modules

Arthapz  also helped improve support for C++23 Std Modules.

The current progress of the three compilers supporting it:

Msvc

The latest Visual Studio 17.5 preview already supports it, and the non-standard ifc std modules will be deprecated.

For the standard C++23 std modules, we introduced it like this.

import std;

And for ifc std modules, we need to write:

import std.core;

It is not a C++23 standard, it is only provided by msvc, and it is not compatible with other compilers, and it will be gradually discarded in new versions of msvc in the future. Therefore, the new version of Xmake will only support C++23 std modules and no longer support the obsolete ifc std modules.

Clang

At present, the latest clang does not seem to fully support C++23 std modules, and it is still in the draft patch state, #D135507 .

However, Xmake also supports it. If you want to try it out, you can integrate this patch by yourself, and then use xmake to test it.

In addition, lower versions of clang also have experimental support for non-standard std modules.

We can still try to use xmake to build std modules in lower versions of clang, although it may still be a toy (and will encounter many problems).

See related discussion: #3255

Gcc

Not yet supported.

Xrepo autocompletion support

Before, we only supported incomplete xmake commands. In the new version, we also support incomplete commands, which can automatically search for packages in the xmake-repo warehouse to complete our installation commands. xrepo install   

Many thanks to @glcraft for his contribution.

$ xrepo install libp
libpaper          libpfm            libpng            libpqxx           libpthread-stubs
libpcap           libplist          libpq             libpsl

update content

new features

  • #3228 : Install release of C++ modules, and import C++ modules support from packages
  • #3257 : Add support for iverilog and verilator
  • Support xp and vc6.0
  • #3214 : Autocompletion support for xrepo install

Improve

  • #3255 : Improve clang libc++ module support
  • Support compiling xmake with mingw
  • Improve the compatibility of xmake on win xp
  • If external dependencies are enabled, switch the json module to a pure lua implementation and remove the dependency on lua-cjson

Bug fixes

  • #3229 : Fix the problem that rc.exe cannot be found under vs2015
  • #3271 : Fix support for macro definitions with spaces
  • #3273 : Fix nim linking errors
  • #3286 : Fix compile_commands support for clangd

 

Guess you like

Origin www.oschina.net/news/226003