Xmake v2.7.6 发布,新增 Verilog 和 C++ Modules 分发支持
Xmake 是一个基于 Lua 的轻量级跨平台构建工具。
它非常的轻量,没有任何依赖,因为它内置了 Lua 运行时。
它使用 xmake.lua 维护项目构建,相比 makefile/CMakeLists.txt,配置语法更加简洁直观,对新手非常友好,短时间内就能快速入门,能够让用户把更多的精力集中在实际的项目开发上。
我们能够使用它像 Make/Ninja 那样可以直接编译项目,也可以像 CMake/Meson 那样生成工程文件,另外它还有内置的包管理系统来帮助用户解决 C/C++ 依赖库的集成使用问题。
目前,Xmake 主要用于 C/C++ 项目的构建,但是同时也支持其他 native 语言的构建,可以实现跟 C/C++ 进行混合编译,同时编译速度也是非常的快,可以跟 Ninja 持平。
Xmake = Build backend + Project Generator + Package Manager + [Remote|Distributed] Build + Cache
尽管不是很准确,但我们还是可以把 Xmake 按下面的方式来理解:
Xmake ≈ Make/Ninja + CMake/Meson + Vcpkg/Conan + distcc + ccache/sccache

新特性介绍
Verilog 仿真程序支持
iVerilog 仿真器
通过 add_requires("iverilog") 配置,我们能够自动拉取 iverilog 工具链包,然后使用 set_toolchains("@iverilog") 自动绑定工具链来编译工程。
add_requires("iverilog")
target("hello")
add_rules("iverilog.binary")
set_toolchains("@iverilog")
add_files("src/*.v")
设置抽象配置
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")
我们可以通过 set_languages("v1800-2009") 来设置切换 Verilog 的语言标准。
目前支持的一些取值和映射关系如下:
["v1364-1995"] = "-g1995"
["v1364-2001"] = "-g2001"
["v1364-2005"] = "-g2005"
["v1800-2005"] = "-g2005-sv"
["v1800-2009"] = "-g2009"
["v1800-2012"] = "-g2012"
设置自定义 flags
add_requires("iverilog")
target("hello")
add_rules("iverilog.binary")
set_toolchains("@iverilog")
add_files("src/*.v")
add_values("iverilogs.flags", "-DTEST")
构建工程
$ xmake
checking for iverilog ... iverilog
checking for vvp ... vvp
[ 50%]: linking.iverilog hello.vvp
[100%]: build ok!
运行程序
$ xmake run
hello world!
LXT2 info: dumpfile hello.vcd opened for output.
src/main.v:6: $finish called at 0 (1s)
更多完整例子:iVerilog Examples
Verilator 仿真器
通过 add_requires("verilator") 配置,我们能够自动拉取 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 工程,我们需要一个额外的 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;
}
设置抽象配置
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")
我们可以通过 set_languages("v1800-2009") 来设置切换 Verilog 的语言标准。
目前支持的一些取值和映射关系如下:
-- 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",
设置自定义 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")
构建工程
$ 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!
运行程序
$ xmake run
ruki-2:hello ruki$ xmake run
hello world!
- src/main.v:4: Verilog $finish
更多完整例子:Verilator
支持 C++ Module 分发
非常感谢 Arthapz 在新版本中继续帮忙改进了 xmake 对 C++ Modules 的支持。
现在,我们可以将 C++ Modules 做成包进行分发,然后在其他项目中进行快速集成和复用。
它是基于 p2473r1 中对模块分发的设计草案做的一个原型实现。
制作分发 C++ Modules 包
我们先使用 xmake.lua 维护模块的构建,并通过指定 {install = true},来告诉 xmake 哪些模块文件需要安装对外分发。
add_rules("mode.release", "mode.debug")
set_languages("c++20")
target("foo")
set_kind("static")
add_files("*.cpp")
add_files("*.mpp", { install = true })
然后,我们把它做成包,可以提交到 xmake-repo 仓库,当然也可以直接做成本地包,或者私有仓库包。
这里,为了方便测试验证,我们仅仅通过 set_sourcedir 将它做成本地包。
package("foo")
set_sourcedir(path.join(os.scriptdir(), "src"))
on_install(function(package)
import("package.tools.xmake").install(package, {})
end)
集成 C++ Modules 包
然后,我们通过 add_requires("foo") 的包集成接口,对 C++ Modules 包进行快速集成使用。
由于 foo 的模块包,我们放在私有仓库中定义,所以我们通过 add_repositories("my-repo my-repo") 引入自己的包仓库。
如果,包已经提交到 xmake-repo 官方仓库,就不需要额外配置它。
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)
集成好包后,我们就可以执行 xmake 命令,一键下载、编译、集成 C++ Modules 包来使用。
$ 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!
注:每个包安装后,会在包路径下,存储维护模块的 meta-info 文件,这是 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":{}}
完整的例子工程见:C++ Modules 包分发例子工程
支持 C++23 Std Modules
Arthapz 也帮忙改进了对 C++23 Std Modules 的支持。
目前三个编译器对它的支持进展:
Msvc
最新 Visual Studio 17.5 preview 已经支持,并且非标准的 ifc std modules 将被废弃。
对于标准的 C++23 std modules,我们是这么引入的。
import std;
而对于 ifc std modules,我们需要这么写:
import std.core;
它不是 C++23 标准,仅仅 msvc 提供,对其他编译器并不兼容,以后新版本 msvc 中也会逐步废弃。
因此新版本 Xmake 将仅仅 C++23 std modules,不再支持废弃的 ifc std modules。
Clang
目前最新的 clang 似乎也还没完全支持 C++23 std modules,当前还是 draft patch 状态,#D135507。
但是,Xmake 也对它进行了支持,如果大家想要尝鲜,可以自行合入这个 patch,然后使用 xmake 来测试。
另外,低版本的 clang 也有对非标准的 std modules 做了实验性支持。
我们还是可以在低版本 clang 中尝试性使用 xmake 来构建 std modules,尽管它可能还只是个玩具(会遇到很多问题)。
相关讨论见:#3255
Gcc
目前还不支持。
Xrepo 自动补全支持
之前,我们仅仅支持 xmake 命令的不全,新版本中,我们还支持了 xrepo install 命令的不全,
可以自动搜索 xmake-repo 仓库的包,来不全我们的安装命令。
非常感谢 @glcraft 的贡献。
$ xrepo install libp
libpaper libpfm libpng libpqxx libpthread-stubs
libpcap libplist libpq libpsl
更新内容
新特性
- #3228: C++ modules 的安装发布,以及从包中导入 C++ modules 支持
- #3257: 增加对 iverilog 和 verilator 的支持
- 支持 xp 和 vc6.0
- #3214: xrepo install 的自动补全支持
改进
- #3255: 改进 clang libc++ 模块支持
- 支持使用 mingw 编译 xmake
- 改进 xmake 在 win xp 上的兼容性
- 如果外部依赖被启用,切换 json 模块到纯 lua 实现,移除对 lua-cjson 的依赖
Bugs 修复
- #3229: 修复 vs2015 下找不到 rc.exe 问题
- #3271: 修复支持带有空格的宏定义
- #3273: 修复 nim 链接错误
- #3286: 修复 compile_commands 对 clangd 的支持
Xmake v2.7.6 发布,新增 Verilog 和 C++ Modules 分发支持的更多相关文章
- xmake v2.3.7 发布, 新增 tinyc 和 emscripten 工具链支持
xmake 是一个基于 Lua 的轻量级跨平台构建工具,使用 xmake.lua 维护项目构建,相比 makefile/CMakeLists.txt,配置语法更加简洁直观,对新手非常友好,短时间内就能 ...
- xmake v2.2.9 发布, 新增c++20 modules的实验性支持
这个版本没啥太大新特性,主要对c++20 modules进行了实验性支持,目前支持clang/msvc编译器,除此之外改进了不少使用体验,并且提高了一些稳定性. 另外,这个版本新增了socket.io ...
- xmake v2.6.2 发布,新增 Linux 内核驱动模块构建支持
Xmake 是一个基于 Lua 的轻量级跨平台构建工具. 它非常的轻量,没有任何依赖,因为它内置了 Lua 运行时. 它使用 xmake.lua 维护项目构建,相比 makefile/CMakeLis ...
- xmake v2.5.8 发布,新增 Pascal/Swig 程序和 Lua53 运行时支持
xmake 是一个基于 Lua 的轻量级跨平台构建工具,使用 xmake.lua 维护项目构建,相比 makefile/CMakeLists.txt,配置语法更加简洁直观,对新手非常友好,短时间内就能 ...
- xmake v2.3.1 发布, 无缝对接其他构建系统
最近对xmake内部做了不少的重构来改进,并且新增了不少实用的新特性,欢迎来体验. 项目源码 官方文档 一些新特性: 一键编译其他构建系统维护的项目,实现无缝对接,并且支持交叉编译(比如autotoo ...
- xmake v2.3.4 发布, 更加完善的工具链支持
为了让xmake更好得支持交叉编译,这个版本我重构了整个工具链,使得工具链的切换更加的方便快捷,并且现在用户可以很方便地在xmake.lua中扩展自己的工具链. 关于平台的支持上,我们新增了对*BSD ...
- xmake v2.5.9 发布,改进 C++20 模块,并支持 Nim, Keil MDK 和 Unity Build
xmake 是一个基于 Lua 的轻量级跨平台构建工具,使用 xmake.lua 维护项目构建,相比 makefile/CMakeLists.txt,配置语法更加简洁直观,对新手非常友好,短时间内就能 ...
- xmake v2.5.7 发布,包依赖锁定和 Vala/Metal 语言编译支持
xmake 是一个基于 Lua 的轻量级跨平台构建工具,使用 xmake.lua 维护项目构建,相比 makefile/CMakeLists.txt,配置语法更加简洁直观,对新手非常友好,短时间内就能 ...
- xmake v2.6.1 发布,使用 Lua5.4 运行时,Rust 和 C++ 混合编译支持
xmake 是一个基于 Lua 的轻量级跨平台构建工具,使用 xmake.lua 维护项目构建,相比 makefile/CMakeLists.txt,配置语法更加简洁直观,对新手非常友好,短时间内就能 ...
- Xmake v2.7.3 发布,包组件和 C++ 模块增量构建支持
Xmake 是一个基于 Lua 的轻量级跨平台构建工具. 它非常的轻量,没有任何依赖,因为它内置了 Lua 运行时. 它使用 xmake.lua 维护项目构建,相比 makefile/CMakeLis ...
随机推荐
- Netty学习记录-入门篇
你如果,缓缓把手举起来,举到顶,再突然张开五指,那恭喜你,你刚刚给自己放了个烟花. 模块介绍 netty-bio: 阻塞型网络通信demo. netty-nio: 引入channel(通道).buff ...
- DQL语句
DQL语句 DQL(Data QueryLanguage )数据查询语言,基本结构是由SELECT子句,FROM子句,WHERE子句组成的查询块. 一.DQL概述 1.1.什么是DQL DQL:数据查 ...
- Java获取/resources目录下的资源文件方法
Web项目开发中,经常会有一些静态资源,被放置在resources目录下,随项目打包在一起,代码中要使用的时候,通过文件读取的方式,加载并使用: 今天总结整理了九种方式获取resources目录下文件 ...
- certutil做哈希校验并下载网络文件
微软Win系统自带,不需要安装的工具,但它是CMD命令行工具,关于命令行工具的说明和使用请参考我以前的文章 Windows系统的命令行(CLI)介绍及入门使用说明 . 这个微软自带的命令行工具叫做 c ...
- packet Capture 手机抓包工具
packet Capture packet Capture 是一款免root的app, 运行在安卓平台上,用于捕获http/https网络流量嗅探的应用程序 特点: 捕获网络数据包,并记录太慢,使用中 ...
- HTML5+CSS3常见布局方式
1.等高布局 1.1 代码 等高布局是指子元素在父元素中高度相等的布局方式 <div class="father"> <div class="f1&qu ...
- I-图的分割(二分+并查集)
图的分割 题目大意: 给你n个点,m条边的图,没有重环和自环,所有的点都联通 可以通过删除几条边使得整个图变成两个联通子图 求删除的边中最大边权的最小值 解题思路: 看到"最大边权的最小值& ...
- 「浙江理工大学ACM入队200题系列」问题 L: 零基础学C/C++85——完美数
本题是浙江理工大学ACM入队200题第八套中的L题 我们先来看一下这题的题面. 题面 题目描述 任何一个自然数的约数中都有1和它本身,我们把小于它本身的因数叫做这个自然数的真约数. 如6的所有真约数是 ...
- 【转】Linux文件权限
转载一篇写得非常详细的linux文件权限,方便自己查阅! 转载来源:https://www.cnblogs.com/keyi/p/8124841.html ---------------------- ...
- MindStudio模型训练场景精度比对全流程和结果分析
摘要:MindStudio是一套基于华为昇腾AI处理器开发的AI全栈开发平台 本文分享自华为云社区<MindStudio模型训练场景精度比对全流程和结果分析>,作者:yd_24730208 ...