-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathxmake.lua
More file actions
120 lines (109 loc) · 5.05 KB
/
xmake.lua
File metadata and controls
120 lines (109 loc) · 5.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
add_rules("mode.debug", "mode.release")
set_languages("c++23")
add_repositories("mcpplibs-index https://github.com/mcpplibs/mcpplibs-index.git")
add_requires("mcpplibs-capi-lua 0.0.2")
-- Data model (zero external deps)
target("mcpplibs-xpkg")
set_kind("static")
add_files("src/xpkg.cppm", {public = true, install = true})
set_policy("build.c++.modules", true)
-- Loader (parses .lua package files)
target("mcpplibs-xpkg-loader")
set_kind("static")
add_deps("mcpplibs-xpkg")
add_packages("mcpplibs-capi-lua", {public = true})
add_files("src/xpkg-loader.cppm", {public = true, install = true})
set_policy("build.c++.modules", true)
-- Index (pure C++ operations)
target("mcpplibs-xpkg-index")
set_kind("static")
add_deps("mcpplibs-xpkg")
add_files("src/xpkg-index.cppm", {public = true, install = true})
set_policy("build.c++.modules", true)
-- Lua stdlib module (generated from src/lua-stdlib/ at build time)
target("mcpplibs-xpkg-lua-stdlib")
set_kind("static")
add_files("src/xpkg-lua-stdlib.cppm", {public = true, install = true})
set_policy("build.c++.modules", true)
before_build(function(target)
local proj = target:scriptdir()
local outfile = path.join(proj, "src/xpkg-lua-stdlib.cppm")
local f = io.open(outfile, "w")
f:write("// Auto-generated by xmake before_build — do not edit manually\n")
f:write("module;\n")
f:write("export module mcpplibs.xpkg.lua_stdlib;\n")
f:write("import std;\n\n")
f:write("export namespace mcpplibs::xpkg::detail {\n\n")
-- MSVC C2026: string literal max 16380 bytes; split large files
local MSVC_LIMIT = 15000
local function embed(varname, rel_path)
local content = io.readfile(path.join(proj, rel_path))
if #content <= MSVC_LIMIT then
f:write("inline constexpr std::string_view " .. varname)
f:write(" = R\"__LUA__(\n")
f:write(content)
f:write("\n)__LUA__\";\n\n")
else
-- Split into chunks joined via operator+
local chunks = {}
local pos = 1
local idx = 0
while pos <= #content do
local chunk = content:sub(pos, pos + MSVC_LIMIT - 1)
-- Avoid splitting in the middle of a line
if pos + MSVC_LIMIT - 1 < #content then
local nl = chunk:reverse():find("\n")
if nl and nl < MSVC_LIMIT then
chunk = content:sub(pos, pos + MSVC_LIMIT - nl - 1)
end
end
local cname = varname .. "_" .. idx
f:write("inline constexpr std::string_view " .. cname)
f:write(" = R\"__LUA__(\n")
f:write(chunk)
f:write("\n)__LUA__\";\n\n")
chunks[#chunks + 1] = cname
pos = pos + #chunk
idx = idx + 1
end
-- Concatenate via a function
f:write("inline const std::string " .. varname .. "_storage = []{ std::string s;\n")
for _, c in ipairs(chunks) do
f:write(" s += " .. c .. ";\n")
end
f:write(" return s; }();\n")
f:write("inline const std::string_view " .. varname)
f:write(" = " .. varname .. "_storage;\n\n")
end
end
embed("prelude_lua", "src/lua-stdlib/prelude.lua")
embed("log_lua", "src/lua-stdlib/xim/libxpkg/log.lua")
embed("pkginfo_lua", "src/lua-stdlib/xim/libxpkg/pkginfo.lua")
embed("system_lua", "src/lua-stdlib/xim/libxpkg/system.lua")
embed("xvm_lua", "src/lua-stdlib/xim/libxpkg/xvm.lua")
embed("utils_lua", "src/lua-stdlib/xim/libxpkg/utils.lua")
embed("pkgmanager_lua", "src/lua-stdlib/xim/libxpkg/pkgmanager.lua")
embed("elfpatch_lua", "src/lua-stdlib/xim/libxpkg/elfpatch.lua")
embed("json_lua", "src/lua-stdlib/xim/libxpkg/json.lua")
embed("base64_lua", "src/lua-stdlib/xim/libxpkg/base64.lua")
f:write("} // namespace mcpplibs::xpkg::detail\n")
f:close()
cprint("${green}[xpkg]${clear} generated src/xpkg-lua-stdlib.cppm")
end)
-- Executor (runs package hooks via Lua)
target("mcpplibs-xpkg-executor")
set_kind("static")
add_deps("mcpplibs-xpkg", "mcpplibs-xpkg-lua-stdlib")
add_packages("mcpplibs-capi-lua", {public = true})
add_files("src/xpkg-executor.cppm", {public = true, install = true})
set_policy("build.c++.modules", true)
-- Aggregate target: add_deps("xpkg") to get all modules
target("xpkg")
set_kind("phony")
add_deps("mcpplibs-xpkg", "mcpplibs-xpkg-loader",
"mcpplibs-xpkg-index", "mcpplibs-xpkg-lua-stdlib",
"mcpplibs-xpkg-executor")
add_packages("mcpplibs-capi-lua", {public = true})
if not is_host("macosx") then
includes("examples", "tests")
end