forked from EndstoneMC/endstone
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathxmake.lua
135 lines (123 loc) · 5.15 KB
/
xmake.lua
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
add_rules("mode.debug", "mode.release")
add_repositories("LiteLDev-repo https://github.com/LiteLDev/xmake-repo.git")
add_requires("sentry-native")
add_requires("libbase64")
add_requires("boost 1.85.0")
add_requires("moodycamelconqueue")
add_requires("cpptrace 0.7.1")
add_requires("date 3.0.3")
add_requires("pybind11 2.13.6")
add_requires("toml++ v3.4.0")
add_requires("levilamina 42b75be796e8481394a8dd380c2500f76287919f")
add_requires("levibuildscript")
add_requires("python 3.12.3")
local python_libname = "python312"
-- Define common packages to avoid repetition
local common_packages = {
"libbase64", "boost", "moodycamelconqueue",
"cpptrace", "date", "toml++", "sentry-native", "levilamina"
}
local get_version = function (oss)
local tags = oss.iorun("git describe --tags --long")
local tag, num_commits, commit_hash = tags:match("v?(%S+)-(%d+)-g([a-f0-9]+)")
if tonumber(num_commits) > 0 then
tag = tag:match("(%S+)%.%d+")
tag = tag.."-dev"..num_commits
end
return tag
end
set_project("endstone")
set_languages("c++20")
set_runtimes("MD")
add_defines("PYBIND11_DETAILED_ERROR_MESSAGES", "NOMINMAX", "ENDSTONE_LL")
target("endstone_headers")
set_kind("headeronly")
set_languages("c++20")
add_includedirs("include", "src", "$(buildir)/generated", {public = true})
add_headerfiles("include/(**.h)")
on_load(function (target)
local toml = import("scripts.toml")
local symbols = toml.parse(io.readfile( "src/bedrock/symbol_generator/symbols.toml"))[target:plat()]
local count = 0
for _ in pairs(symbols) do count = count + 1 end
local file = assert(io.open("$(buildir)/generated/bedrock_symbols.generated.h", "w"), "Failed to open symbol file")
file:write("#pragma once\n\n")
file:write("// clang-format off\n")
file:write("#include <array>\n")
file:write("#include <string_view>\n\n")
file:write("static constexpr std::array<std::pair<std::string_view, std::size_t>, ")
file:write(count)
file:write("> symbols = {{\n")
for k, v in pairs(symbols) do
file:print(" { \"%s\", %d },", k, v)
end
file:write("}};\n")
file:write("// clang-format on\n")
file:close()
end)
target("endstone_python")
add_rules("python.library")
add_files("src/levi/memory_operators.cpp")
add_files("src/endstone/python/**.cpp")
add_deps("endstone_headers")
add_packages(common_packages)
add_packages("python", "pybind11", {links = python_libname})
set_symbols("debug")
after_build(function (target)
local file = assert(io.open("endstone/_internal/version.py", "w"))
file:write("TYPE_CHECKING = False\n")
file:write("if TYPE_CHECKING:\n")
file:write(" from typing import Tuple, Union\n")
file:write(" VERSION_TUPLE = Tuple[Union[int, str], ...]\n")
file:write("else:\n")
file:write(" VERSION_TUPLE = object\n\n")
file:write("version: str\n")
file:write("__version__: str\n")
file:write("__version_tuple__: VERSION_TUPLE\n")
file:write("version_tuple: VERSION_TUPLE\n\n")
local version = get_version(os)
file:print("__version__ = version = '%s'", version)
local major, minor, patch, suffix = version:match("(%d+)%.(%d+)%.(%d+)(.*)")
file:printf("__version_tuple__ = version_tuple = (%d, %d, %d", major, minor, patch)
if suffix == nil then
file:print(")")
else
file:print(", '%s')", suffix:sub(2))
end
file:close()
if not os.isdir("bin/EndstoneRuntime/Lib/endstone/_internal") then
os.mkdir("bin/EndstoneRuntime/Lib/endstone/_internal")
end
os.cp("endstone", "bin/EndstoneRuntime/Lib")
os.cp(target:targetfile(), "bin/EndstoneRuntime/Lib/endstone/_internal")
end)
target("endstone_core")
set_kind("static")
set_languages("c++20")
add_files("src/bedrock/**.cpp")
add_files("src/endstone/core/**.cpp")
add_files("src/levi/core/**.cpp")
remove_files("src/endstone/core/devtools/**.cpp")
remove_files("src/endstone/core/spdlog/**.cpp")
remove_files("src/endstone/core/logger_factory.cpp")
add_deps("endstone_headers")
add_packages(common_packages)
add_packages("python", "pybind11", {links = python_libname})
on_load(function (target)
target:add("defines", "ENDSTONE_VERSION=\""..get_version(os).."\"")
end)
target("endstone_runtime")
set_kind("shared")
on_load(function (target)
target:add("rules", "@levibuildscript/modpacker", {modName = "EndstoneRuntime", modVersion = get_version(os)})
end)
add_files("src/levi/memory_operators.cpp")
add_files("src/endstone/runtime/windows.cpp")
add_files("src/endstone/runtime/bedrock_hooks/**.cpp")
remove_files("src/endstone/runtime/bedrock_hooks/bedrock_event_logger.cpp")
add_files("src/levi/runtime/**.cpp")
add_deps("endstone_headers", "endstone_core")
add_packages(common_packages)
add_packages("python", "pybind11", {links = python_libname})
add_links("dbghelp", "ws2_32","Psapi")
set_symbols("debug")