add xmake rule codegen
This commit is contained in:
parent
545a72a5de
commit
27648e1b41
1
.gitignore
vendored
1
.gitignore
vendored
@ -8,3 +8,4 @@ vsxmake*/
|
|||||||
|
|
||||||
|
|
||||||
engine/logs/zengine.log
|
engine/logs/zengine.log
|
||||||
|
tools/
|
||||||
|
|||||||
34
.vscode/launch.json
vendored
Normal file
34
.vscode/launch.json
vendored
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
{
|
||||||
|
// 使用 IntelliSense 了解相关属性。
|
||||||
|
// 悬停以查看现有属性的描述。
|
||||||
|
// 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
|
||||||
|
"version": "0.2.0",
|
||||||
|
"configurations": [
|
||||||
|
{
|
||||||
|
"type": "lua",
|
||||||
|
"request": "launch",
|
||||||
|
"tag": "normal",
|
||||||
|
"name": "LuaPanda",
|
||||||
|
"description": "通用模式,通常调试项目请选择此模式 | launchVer:3.2.0",
|
||||||
|
"cwd": "${workspaceFolder}",
|
||||||
|
"luaFileExtension": "",
|
||||||
|
"connectionPort": 8818,
|
||||||
|
"stopOnEntry": true,
|
||||||
|
"useCHook": true,
|
||||||
|
"autoPathMode": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "lua",
|
||||||
|
"request": "launch",
|
||||||
|
"tag": "independent_file",
|
||||||
|
"name": "LuaPanda-IndependentFile",
|
||||||
|
"description": "独立文件调试模式,使用前请参考文档",
|
||||||
|
"luaPath": "",
|
||||||
|
"packagePath": [],
|
||||||
|
"luaFileExtension": "",
|
||||||
|
"connectionPort": 8820,
|
||||||
|
"stopOnEntry": true,
|
||||||
|
"useCHook": true
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
34
engine/.vscode/launch.json
vendored
Normal file
34
engine/.vscode/launch.json
vendored
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
{
|
||||||
|
// 使用 IntelliSense 了解相关属性。
|
||||||
|
// 悬停以查看现有属性的描述。
|
||||||
|
// 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
|
||||||
|
"version": "0.2.0",
|
||||||
|
"configurations": [
|
||||||
|
{
|
||||||
|
"type": "lua",
|
||||||
|
"request": "launch",
|
||||||
|
"tag": "normal",
|
||||||
|
"name": "LuaPanda",
|
||||||
|
"description": "通用模式,通常调试项目请选择此模式 | launchVer:3.2.0",
|
||||||
|
"cwd": "${workspaceFolder}",
|
||||||
|
"luaFileExtension": "",
|
||||||
|
"connectionPort": 8818,
|
||||||
|
"stopOnEntry": true,
|
||||||
|
"useCHook": true,
|
||||||
|
"autoPathMode": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "lua",
|
||||||
|
"request": "launch",
|
||||||
|
"tag": "independent_file",
|
||||||
|
"name": "LuaPanda-IndependentFile",
|
||||||
|
"description": "独立文件调试模式,使用前请参考文档",
|
||||||
|
"luaPath": "",
|
||||||
|
"packagePath": [],
|
||||||
|
"luaFileExtension": "",
|
||||||
|
"connectionPort": 8820,
|
||||||
|
"stopOnEntry": true,
|
||||||
|
"useCHook": true
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
@ -6,10 +6,12 @@
|
|||||||
#include <functional>
|
#include <functional>
|
||||||
using Ubpa::Name;
|
using Ubpa::Name;
|
||||||
using Ubpa::type_name;
|
using Ubpa::type_name;
|
||||||
|
consteval Name FName(const char* buf) {
|
||||||
|
return Name(buf);
|
||||||
|
}
|
||||||
namespace refl {
|
namespace refl {
|
||||||
using Offset = uint32_t;
|
using Offset = uint32_t;
|
||||||
using Method = void*;
|
using Method = void*;
|
||||||
|
|
||||||
struct MemberData {
|
struct MemberData {
|
||||||
Offset offset;
|
Offset offset;
|
||||||
Any value;
|
Any value;
|
||||||
|
|||||||
34
engine/3rdparty/zlib/test/refl/vertex.h
vendored
34
engine/3rdparty/zlib/test/refl/vertex.h
vendored
@ -21,7 +21,7 @@ struct vec3 : public vec3_parent {
|
|||||||
float y = 2;
|
float y = 2;
|
||||||
__cppast(Meta = { 0.f})
|
__cppast(Meta = { 0.f})
|
||||||
float z = 3;
|
float z = 3;
|
||||||
string name{ "hellohellohellohellohellohello" };
|
string name{ "hello" };
|
||||||
__cppast(Meta = { {3,4} })
|
__cppast(Meta = { {3,4} })
|
||||||
int norm(int x1, int& x2)override {
|
int norm(int x1, int& x2)override {
|
||||||
int tmp = x1 * 2 + 1;
|
int tmp = x1 * 2 + 1;
|
||||||
@ -32,8 +32,8 @@ struct vec3 : public vec3_parent {
|
|||||||
}
|
}
|
||||||
virtual float norm1(int& x1) {
|
virtual float norm1(int& x1) {
|
||||||
x1 = x1 * x * y * z;
|
x1 = x1 * x * y * z;
|
||||||
//x = x1;
|
x = x1;
|
||||||
//y = x1 - 1;
|
y = x1 - 1;
|
||||||
//z = x1 - 10;
|
//z = x1 - 10;
|
||||||
//cout << x1 << "::norm1" << endl;
|
//cout << x1 << "::norm1" << endl;
|
||||||
return x1;
|
return x1;
|
||||||
@ -53,19 +53,18 @@ struct vec3_Static_Meta {
|
|||||||
};
|
};
|
||||||
consteval static auto __MakeStaticFields() {
|
consteval static auto __MakeStaticFields() {
|
||||||
return std::array{
|
return std::array{
|
||||||
StaticMemberField(&vec3::x, "x", {0.f,vec4{}}),
|
StaticMemberField(&vec3::x, FName("x"), {0.f,vec4{}}),
|
||||||
StaticMemberField(&vec3::y, "y", {0.f,{}}),
|
StaticMemberField(&vec3::y, FName("y"), {0.f,{}}),
|
||||||
StaticMemberField(&vec3::z, "z", {0.f,{}}),
|
StaticMemberField(&vec3::z, FName("z"), {0.f,{}}),
|
||||||
StaticMethodField(&vec3::norm, "norm", {{10,9},{}}),
|
StaticMethodField(&vec3::norm, FName("norm"), {{10,9},{}}),
|
||||||
StaticMethodField(&vec3::norm1, "norm1", {{10},{}}),
|
StaticMethodField(&vec3::norm1, FName("norm1"), {{10},{}}),
|
||||||
StaticMethodField(&vec3::norm2, "norm2", {{10},{}}),
|
StaticMethodField(&vec3::norm2, FName("norm2"), {{10},{}}),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
consteval static int Size() {
|
consteval static int Size() {
|
||||||
return fetch_meta_size<vec3_Static_Meta>();
|
return fetch_meta_size<vec3_Static_Meta>();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
constexpr int size = vec3_Static_Meta::Size();
|
|
||||||
struct vec3_Meta : public Meta{
|
struct vec3_Meta : public Meta{
|
||||||
using MyStatic = vec3_Static_Meta;
|
using MyStatic = vec3_Static_Meta;
|
||||||
using MyUClass = UClass_Meta<vec3, vec3_parent>;
|
using MyUClass = UClass_Meta<vec3, vec3_parent>;
|
||||||
@ -73,12 +72,13 @@ struct vec3_Meta : public Meta{
|
|||||||
static auto __MakeFields() {
|
static auto __MakeFields() {
|
||||||
char* memory = &s_data[0];
|
char* memory = &s_data[0];
|
||||||
return std::array{
|
return std::array{
|
||||||
MemberField(&vec3::x, "x",memory, {0.f,vec4{}}),
|
MemberField(&vec3::x, FName("x"),memory, {0.f,vec4{}}),
|
||||||
MemberField(&vec3::y, "y",memory, {0.f,{}}),
|
MemberField(&vec3::y, FName("y"),memory, {0.f,{}}),
|
||||||
MemberField(&vec3::z, "z",memory, {0.f,{}}),
|
MemberField(&vec3::z, FName("z"),memory, {0.f,{}}),
|
||||||
MethodField(&vec3::norm, "norm", memory, {{10,9},{}}),
|
MethodField(&vec3::norm, FName("norm"), memory, {{10,9},{}}),
|
||||||
MethodField(&vec3::norm1, "norm1",memory, {{10},{}}),
|
MethodField(&vec3::norm1, FName("norm1"),memory, {{10},{}}),
|
||||||
MethodField(&vec3::norm2, "norm2",memory, {{10},{}}),
|
MethodField(&vec3::norm2, FName("norm2"),memory, {{10},{}}),
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
#include "meta_vertex.inl"
|
||||||
8
engine/3rdparty/zlib/test/refl_01.cpp
vendored
8
engine/3rdparty/zlib/test/refl_01.cpp
vendored
@ -5,19 +5,19 @@ vec3 v;
|
|||||||
constexpr int smeta = sizeof(vec3_Meta);
|
constexpr int smeta = sizeof(vec3_Meta);
|
||||||
constexpr int scls = sizeof(decltype(*cls));
|
constexpr int scls = sizeof(decltype(*cls));
|
||||||
auto ov = cls->New((void*)&v);
|
auto ov = cls->New((void*)&v);
|
||||||
constexpr Name func("norm");
|
constexpr Name func = FName("norm");
|
||||||
void TestRefl1(benchmark::State& state) {
|
void TestRefl1(benchmark::State& state) {
|
||||||
int x = 1, y = 2;
|
int x = 1, y = 2;
|
||||||
for (auto _ : state) {
|
for (auto _ : state) {
|
||||||
std::array<Any, 4> arr{&x, ov.ptr};
|
std::array<Any, 4> arr{&x, ov.ptr};
|
||||||
svector<Any> svec(&arr.front(), arr.size(), 2);
|
svector<Any> svec(&arr.front(), arr.size(), 2);
|
||||||
ov.Invoke("norm", svec);
|
ov.Invoke(FName("norm"), svec);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
BENCHMARK(TestRefl1);
|
BENCHMARK(TestRefl1);
|
||||||
void TestRefl2(benchmark::State& state) {
|
void TestRefl2(benchmark::State& state) {
|
||||||
int x = 1, y = 2;
|
int x = 1, y = 2;
|
||||||
constexpr auto id = GetStaticFieldID<vec3_Meta>(func);
|
constexpr auto id = GetStaticFieldID<vec3_Meta>(FName("norm"));
|
||||||
auto field = cls->GetField(id);
|
auto field = cls->GetField(id);
|
||||||
for (auto _ : state) {
|
for (auto _ : state) {
|
||||||
std::array<Any, 4> arr{&x, ov.ptr};
|
std::array<Any, 4> arr{&x, ov.ptr};
|
||||||
@ -28,7 +28,7 @@ void TestRefl2(benchmark::State& state) {
|
|||||||
BENCHMARK(TestRefl2);
|
BENCHMARK(TestRefl2);
|
||||||
void TestRefl3(benchmark::State& state) {
|
void TestRefl3(benchmark::State& state) {
|
||||||
int x = 1, y = 2;
|
int x = 1, y = 2;
|
||||||
constexpr auto id = GetStaticFieldID<vec3_Meta>(func);
|
constexpr auto id = GetStaticFieldID<vec3_Meta>(FName("norm"));
|
||||||
auto field = cls->GetField(id);
|
auto field = cls->GetField(id);
|
||||||
for (auto _ : state) {
|
for (auto _ : state) {
|
||||||
field->Invoke({ &x,ov.ptr, x, y });
|
field->Invoke({ &x,ov.ptr, x, y });
|
||||||
|
|||||||
3
engine/3rdparty/zlib/xmake.lua
vendored
3
engine/3rdparty/zlib/xmake.lua
vendored
@ -31,6 +31,9 @@ target("zlib_test")
|
|||||||
-- add_files("test/04promise.cpp")
|
-- add_files("test/04promise.cpp")
|
||||||
|
|
||||||
target("refl_zlib")
|
target("refl_zlib")
|
||||||
|
add_rules("c++.codegen",{
|
||||||
|
files = {"test/refl/*.h", "test/refl/*.hpp"}
|
||||||
|
})
|
||||||
set_kind("binary")
|
set_kind("binary")
|
||||||
add_deps("zlib")
|
add_deps("zlib")
|
||||||
add_packages("benchmark")
|
add_packages("benchmark")
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
includes("3rdparty/xmake.lua")
|
includes("3rdparty/xmake.lua")
|
||||||
includes("xmake/**xmake.lua")
|
includes("xmake/xmake.lua")
|
||||||
--includes("test/**xmake.lua")
|
--includes("test/**xmake.lua")
|
||||||
target("zengine")
|
target("zengine")
|
||||||
set_kind("binary")
|
set_kind("binary")
|
||||||
|
|||||||
45
engine/xmake/gen/meta_refl.lua
Normal file
45
engine/xmake/gen/meta_refl.lua
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
import("core.project.depend")
|
||||||
|
function cmd_compile(genfile, sourcefile)
|
||||||
|
print(os.programdir())
|
||||||
|
import("find_sdk")
|
||||||
|
local meta = find_sdk.find_my_program("refl")
|
||||||
|
argv = {"build", sourcefile, "--output=" .. genfile}
|
||||||
|
print("cmd_compile", genfile)
|
||||||
|
os.execv(meta.program, argv, {envs = {PATH = meta.sdkdir}})
|
||||||
|
return argv
|
||||||
|
end
|
||||||
|
|
||||||
|
function _listen_gen_file(target, batch)
|
||||||
|
genfile, sourcefile = batch[1], batch[2]
|
||||||
|
local dependfile = target:dependfile(genfile)
|
||||||
|
depend.on_changed(
|
||||||
|
function()
|
||||||
|
cmd_compile(genfile, sourcefile)
|
||||||
|
end,
|
||||||
|
{dependfile = dependfile, files = sourcefile}
|
||||||
|
)
|
||||||
|
end
|
||||||
|
function gen(target)
|
||||||
|
local gen_batch = target:data("codegen.batch")
|
||||||
|
if not gen_batch then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
for _, batch in ipairs(gen_batch) do
|
||||||
|
if batch[2] then
|
||||||
|
_listen_gen_file(target, batch)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function main(target, headerfiles)
|
||||||
|
local sourcedir = path.join(target:autogendir({root = true}), target:plat(), "inl")
|
||||||
|
target:add("includedirs", sourcedir, {public = true})
|
||||||
|
local gen_batch = {}
|
||||||
|
for idx, headerfile in pairs(headerfiles) do
|
||||||
|
-- batch
|
||||||
|
sourcefile = path.join(sourcedir, "meta_" .. path.basename(headerfile) .. ".inl")
|
||||||
|
table.insert(gen_batch, {sourcefile, headerfile})
|
||||||
|
end
|
||||||
|
-- save unit batch
|
||||||
|
target:data_set("codegen.batch", gen_batch)
|
||||||
|
end
|
||||||
18
engine/xmake/gen/xmake.lua
Normal file
18
engine/xmake/gen/xmake.lua
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
rule("c++.codegen")
|
||||||
|
set_extensions(".inl")
|
||||||
|
after_load(function (target)
|
||||||
|
import("meta_refl")
|
||||||
|
local headerfiles = {}
|
||||||
|
local files = target:extraconf("rules", "c++.codegen", "files")
|
||||||
|
for _, file in ipairs(files) do
|
||||||
|
local p = path.join(target:scriptdir(), file)
|
||||||
|
for __, filepath in ipairs(os.files(p)) do
|
||||||
|
table.insert(headerfiles, filepath)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
meta_refl(target, headerfiles)
|
||||||
|
end)
|
||||||
|
on_config(function (target)
|
||||||
|
print("c++.codegen on_config")
|
||||||
|
import("meta_refl").gen(target)
|
||||||
|
end)
|
||||||
28
engine/xmake/modules/find_sdk.lua
Normal file
28
engine/xmake/modules/find_sdk.lua
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
function find_my_program(name, sdkdir, use_next)
|
||||||
|
import("lib.detect.find_file")
|
||||||
|
import("lib.detect.find_program")
|
||||||
|
import("lib.detect.find_tool")
|
||||||
|
|
||||||
|
local sdkdir = sdkdir or path.join(os.projectdir(), "tools")
|
||||||
|
local tool = find_tool(name, {pathes = {sdkdir, "/usr/local/bin"}})
|
||||||
|
local prog = tool and tool.program or find_program(name, {pathes = {sdkdir, "/usr/local/bin"}})
|
||||||
|
prog = prog or find_file(name, {sdkdir})
|
||||||
|
if (prog == nil) then
|
||||||
|
if os.host() ~= "windows" then
|
||||||
|
local outdata, errdata = os.iorun("which " .. name)
|
||||||
|
if (errdata ~= nil or errdata ~= "") then
|
||||||
|
prog = string.gsub(outdata, "%s+", "")
|
||||||
|
end
|
||||||
|
else
|
||||||
|
prog = find_file(name .. ".exe", {sdkdir})
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if (prog == nil) then
|
||||||
|
if not use_next then
|
||||||
|
return find_my_program(name, path.join(sdkdir, name), true)
|
||||||
|
end
|
||||||
|
print(name .. "_f not found! under " .. sdkdir)
|
||||||
|
return
|
||||||
|
end
|
||||||
|
return {program = prog, sdkdir = sdkdir}
|
||||||
|
end
|
||||||
2
engine/xmake/xmake.lua
Normal file
2
engine/xmake/xmake.lua
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
includes("*/xmake.lua")
|
||||||
|
add_moduledirs(path.join(os.projectdir(), "engine/xmake/modules"))
|
||||||
Loading…
Reference in New Issue
Block a user