xmake
xmake copied to clipboard
support code amalgamation
你在什么场景下需要该功能?
https://github.com/vinniefalco/Amalgamate
这个功能是一个把所有源文件集合成一个大文件.cpp的工具,实现思路大概是先做一个unity build文件( https://github.com/xmake-io/xmake/issues/1019 ),再把#include "xx"里面的xx直接替换成对应的文件内容(前提是文件不来自标准库或第三方库)。这个功能可以简化其他人使用代码的成本,而且在一些场景下(例如刷题网站的在线评测)具有特殊作用。可惜该项目最后一次更新是9年前了,里面的bug(例如处理Unicode有问题)一直没修,然后也没处理符号冲突的情况(加UNIQUE_ID)
描述可能的解决方案
添加一个新的plugin
xmake project -k amalgamate
在amalgamate/<target>/文件夹下放<target>.cpp以及<target>.h(如果是一个library target的话)
描述你认为的候选方案
add_rules("utils.install.amalgamate")
其他信息
这个功能和unity build有相同的限制,有不同define/rule的target不能amalgamate,等等。可作为Unity Build的后续工作
这种属于辅助工具类,直接放到 modules 里面就行了,走 import 或者 xmake l xxx 加载就行了
也放着吧 等有空再看看
加了个 cli.amalgamate 的命令脚本可以直接用
All targets
$ xmake l cli.amalgamate
build/tbox.c generated!
build/tbox.h generated!
For given target
$ xmake l cli.amalgamate tbox
build/tbox.c generated!
build/tbox.h generated!
With Unique ID
$ xmake l cli.amalgamate -u MY_UNIQUEU_ID
build/tbox.c generated!
build/tbox.h generated!
Set output directory
$ xmake l cli.amalgamate -o /xxx
/xxx/tbox.c generated!
/xxx/tbox.h generated!
如果有需要改进的,可以提pr到这里 帮忙改进下。https://github.com/xmake-io/xmake/blob/dev/xmake/modules/cli/amalgamate.lua
这块为什么是only for library呢?这项功能binary也会用到啊
我以为通常只有库会用到这玩意。那你可以提个 pr 改下
而且多层#include也没有处理,只替换了一层;没有判断include关系里面有没有环等
这一块我觉得可以单独做一个模块,
- target之间通过dep依赖的关系(要求无环)
- link之间通过linkdep依赖的关系
- amalgamation中文件之间的include关系(要求无环)
实际上都可以抽象成有向图,然后需要在图上判断环、有向图拓扑排序、求强连通分量等操作,这块应该都是通用的
而且多层#include也没有处理,只替换了一层;没有判断include关系里面有没有环等
有点复杂 暂时没空搞
这个先放着吧,等回头有时间了再搞搞
而且多层#include也没有处理,只替换了一层;没有判断include关系里面有没有环等
再试试,改进过了,走拓扑排序处理了下。。
Bot detected the issue body's language is not English, translate it automatically.
Moreover, the multi-layer #include is not processed, only one layer is replaced; it is not judged whether there are loops in the include relationship, etc.
Try again, it has been improved and processed by topological sorting. .