-
Notifications
You must be signed in to change notification settings - Fork 60
Expand file tree
/
Copy pathxmake.lua
More file actions
335 lines (285 loc) · 9.71 KB
/
xmake.lua
File metadata and controls
335 lines (285 loc) · 9.71 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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
-- 定义项目
set_project("tiny-lsm")
set_version("0.0.1")
set_languages("c++20")
add_rules("mode.debug", "mode.release", "mode.coverage")
-- 在 coverage 模式下设置 flags
if is_mode("coverage") then
add_cxxflags("--coverage")
add_ldflags("--coverage")
end
add_repositories("local-repo build")
add_requires("gtest")
add_requires("asio")
add_requires("pybind11")
add_requires("spdlog", { system = false })
add_requires("toml11", { system = false })
if is_mode("debug") then
add_defines("LSM_DEBUG")
end
target("logger")
set_kind("static")
add_files("src/logger/*.cpp")
add_packages("spdlog")
add_includedirs("include", {public = true})
target("config")
set_kind("static")
add_files("src/config/*.cpp")
add_packages("toml11", "spdlog")
add_includedirs("include", {public = true})
target("utils")
set_kind("static")
add_files("src/utils/*.cpp")
add_packages("toml11", "spdlog")
add_includedirs("include", {public = true})
target("vlog")
set_kind("static")
add_deps("utils", "config")
add_files("src/vlog/*.cpp")
add_packages("toml11", "spdlog")
add_includedirs("include", {public = true})
target("iterator")
set_kind("static")
add_files("src/iterator/*.cpp")
add_packages("toml11", "spdlog")
add_includedirs("include", {public = true})
target("skiplist")
set_kind("static")
add_files("src/skiplist/*.cpp")
add_packages("toml11", "spdlog")
add_includedirs("include", {public = true})
target("memtable")
set_kind("static")
add_deps("skiplist", "iterator", "config", "sst")
add_packages("toml11", "spdlog")
add_files("src/memtable/*.cpp")
add_includedirs("include", {public = true})
target("block")
set_kind("static")
add_deps("config")
add_files("src/block/*.cpp")
add_packages("toml11", "spdlog")
add_includedirs("include", {public = true})
target("sst")
set_kind("static")
add_deps("block", "utils", "iterator", "vlog")
add_files("src/sst/*.cpp")
add_packages("toml11", "spdlog")
add_includedirs("include", {public = true})
target("wal")
set_kind("static")
add_deps("sst", "memtable")
add_files("src/wal/*.cpp")
add_packages("toml11", "spdlog")
add_includedirs("include", {public = true})
target("lsm")
set_kind("static")
add_deps("sst", "memtable", "wal", "logger")
add_files("src/lsm/*.cpp")
add_packages("toml11", "spdlog")
add_includedirs("include", {public = true})
target("redis")
set_kind("static")
add_deps("lsm")
add_files("src/redis_wrapper/*.cpp")
add_packages("toml11", "spdlog")
add_includedirs("include", {public = true})
-- ============ 共享库目标(供外部使用) ============
target("lsm_shared")
set_kind("shared")
add_files("src/logger/*.cpp", "src/config/*.cpp", "src/utils/*.cpp",
"src/vlog/*.cpp",
"src/iterator/*.cpp", "src/skiplist/*.cpp", "src/memtable/*.cpp",
"src/block/*.cpp", "src/sst/*.cpp", "src/wal/*.cpp", "src/lsm/*.cpp",
"src/redis_wrapper/*.cpp")
add_packages("toml11", "spdlog")
add_includedirs("include", {public = true}) -- 确保包含路径正确
set_targetdir("$(buildir)/lib")
if is_plat("windows") then
set_extension(".dll")
add_defines("TINYLSM_EXPORTS")
add_cxxflags("/LD")
else
set_extension(".so")
end
on_install(function (target)
os.cp("include", path.join(target:installdir(), "include/tiny-lsm"))
local libfile = target:targetfile()
if is_plat("windows") then
os.cp(libfile, path.join(target:installdir(), "bin"))
local implib = path.join(path.directory(libfile), target:name() .. ".lib")
if os.isfile(implib) then
os.cp(implib, path.join(target:installdir(), "lib"))
end
else
os.cp(libfile, path.join(target:installdir(), "lib"))
end
end)
-- ============ 测试目标 ============
target("test_config")
set_kind("binary")
set_group("tests")
add_files("test/test_config.cpp")
add_deps("logger", "config")
add_packages("gtest", "toml11", "spdlog")
add_includedirs("include", {public = true})
target("test_skiplist")
set_kind("binary")
set_group("tests")
add_files("test/test_skiplist.cpp")
add_deps("logger", "skiplist")
add_packages("gtest", "toml11", "spdlog")
add_includedirs("include", {public = true})
target("test_memtable")
set_kind("binary")
set_group("tests")
add_files("test/test_memtable.cpp")
add_deps("logger", "memtable")
add_packages("gtest", "toml11", "spdlog")
add_includedirs("include", {public = true})
target("test_block")
set_kind("binary")
set_group("tests")
add_files("test/test_block.cpp")
add_deps("logger", "block")
add_packages("gtest", "toml11", "spdlog")
add_includedirs("include", {public = true})
target("test_blockmeta")
set_kind("binary")
set_group("tests")
add_files("test/test_blockmeta.cpp")
add_deps("logger", "block")
add_packages("gtest", "toml11", "spdlog")
add_includedirs("include", {public = true})
target("test_utils")
set_kind("binary")
set_group("tests")
add_files("test/test_utils.cpp")
add_deps("logger", "utils")
add_packages("gtest", "toml11", "spdlog")
add_includedirs("include", {public = true})
target("test_sst")
set_kind("binary")
set_group("tests")
add_files("test/test_sst.cpp")
add_deps("logger", "sst")
add_packages("gtest", "toml11", "spdlog")
add_includedirs("include", {public = true})
target("test_lsm")
set_kind("binary")
set_group("tests")
add_files("test/test_lsm.cpp")
add_deps("logger", "lsm", "memtable", "iterator")
add_packages("gtest", "toml11", "spdlog")
add_includedirs("include", {public = true})
target("test_block_cache")
set_kind("binary")
set_group("tests")
add_files("test/test_block_cache.cpp")
add_deps("logger", "block")
add_includedirs("include", {public = true})
add_packages("gtest", "toml11", "spdlog")
target("test_compact")
set_kind("binary")
set_group("tests")
add_files("test/test_compact.cpp")
add_deps("logger", "lsm", "memtable", "iterator")
add_packages("gtest", "toml11", "spdlog")
add_includedirs("include", {public = true})
target("test_redis")
set_kind("binary")
set_group("tests")
add_files("test/test_redis.cpp")
add_deps("logger", "redis", "memtable", "iterator")
add_includedirs("include", {public = true})
add_packages("gtest", "toml11", "spdlog")
target("test_wal")
set_kind("binary")
set_group("tests")
add_files("test/test_wal.cpp")
add_deps("logger", "wal", "lsm")
add_includedirs("include", {public = true})
add_packages("gtest", "toml11", "spdlog")
target("test_wisckey")
set_kind("binary")
set_group("tests")
add_files("test/test_wisckey.cpp")
add_deps("logger", "lsm", "memtable", "iterator")
add_packages("gtest", "toml11", "spdlog")
add_includedirs("include", {public = true})
-- ============ 可执行目标 ============
target("example")
set_kind("binary")
add_files("example/main.cpp")
add_deps("logger", "config", "utils", "iterator", "skiplist",
"memtable", "block", "sst", "wal", "lsm", "redis")
add_includedirs("include") -- 显式添加包含路径
set_targetdir("$(buildir)/bin")
target("debug")
set_kind("binary")
add_files("example/debug.cpp")
add_deps("logger", "config", "utils", "iterator", "skiplist",
"memtable", "block", "sst", "wal", "lsm", "redis")
add_includedirs("include") -- 显式添加包含路径
set_targetdir("$(buildir)/bin")
target("server")
set_kind("binary")
add_files("server/src/*.cpp")
add_deps("redis")
add_includedirs("include", {public = true})
add_packages("asio")
set_targetdir("$(buildir)/bin")
-- ============ Python 绑定 ============
-- 根据平台选择合适的lsm_pybind目标
if is_plat("windows") then
target("lsm_pybind")
set_kind("shared")
add_files("sdk/lsm_pybind.cpp")
add_packages("pybind11")
add_deps("lsm") -- Windows下使用原来的依赖
add_includedirs("include", {public = true})
set_targetdir("$(buildir)/lib")
set_filename("lsm_pybind.pyd")
add_cxxflags("/LD")
else
-- Unix/Linux/macOS平台
target("lsm_pybind")
set_kind("shared")
add_files("sdk/lsm_pybind.cpp")
add_packages("pybind11")
add_deps("lsm_shared") -- Unix下使用共享库依赖
add_includedirs("include", {public = true})
set_targetdir("$(buildir)/lib")
set_filename("lsm_pybind.so")
add_ldflags("-Wl,-rpath,$ORIGIN")
add_defines("TINYLSM_EXPORT=__attribute__((visibility(\"default\")))")
add_cxxflags("-fvisibility=hidden")
end
-- ============ 测试任务 ============
task("run-all-tests")
set_category("plugin")
set_menu {
usage = "xmake run-all-tests",
description = "Build and run all test binaries"
}
on_run(function ()
import("core.project.project")
local targets = project.targets()
local test_targets = {}
for name, _ in pairs(targets) do
if name:startswith("test_") then
table.insert(test_targets, name)
end
end
table.sort(test_targets)
if #test_targets == 0 then
print("\27[33m[Warning] No test targets found.\27[0m")
return
end
for _, name in ipairs(test_targets) do
print("\27[32m>> Running\27[0m " .. name)
os.execv("xmake", {"run", name})
print("")
end
print("\27[32mAll tests finished.\27[0m")
end)