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
|
-- Copyright Epic Games, Inc. All Rights Reserved.
target("zenserver")
set_kind("binary")
if enable_unity then
add_rules("c++.unity_build", {batchsize = 4})
end
add_deps("zencore",
"zencompute",
"zenhttp",
"zennet",
"zenremotestore",
"zenstore",
"zentelemetry",
"zenutil")
if is_plat("windows") then
add_deps("zenvfs")
end
add_headerfiles("**.h")
add_rules("utils.bin2c", {extensions = {".zip"}})
add_files("**.cpp")
add_files("frontend/html.zip")
add_files("zenserver.cpp", {unity_ignored = true })
add_includedirs(".")
set_symbols("debug")
add_deps("protozero", "asio", "cxxopts")
add_deps("sol2")
add_packages("http_parser")
add_packages("json11")
add_packages("lua")
add_packages("consul")
add_packages("oidctoken")
add_packages("nomad")
if has_config("zenmimalloc") then
add_packages("mimalloc")
end
if has_config("zensentry") then
add_packages("sentry-native")
end
if has_config("zenhorde") then
add_deps("zenhorde")
end
if has_config("zennomad") then
add_deps("zennomad")
end
if is_mode("release") then
set_optimize("fastest")
end
if is_plat("windows") then
add_ldflags("/subsystem:console,5.02")
add_ldflags("/MANIFEST:EMBED")
add_ldflags("/LTCG")
add_files("zenserver.rc")
add_cxxflags("/bigobj")
add_links("delayimp", "projectedfslib")
add_ldflags("/delayload:ProjectedFSLib.dll")
else
remove_files("windows/**")
end
if is_plat("macosx") then
add_ldflags("-framework CoreFoundation")
add_ldflags("-framework CoreGraphics")
add_ldflags("-framework CoreText")
add_ldflags("-framework Foundation")
add_ldflags("-framework Security")
add_ldflags("-framework SystemConfiguration")
end
on_load(function(target)
local html_dir = path.join(os.projectdir(), "src/zenserver/frontend/html")
local zip_path = path.join(os.projectdir(), "src/zenserver/frontend/html.zip")
-- Check if zip needs regeneration
local need_update = not os.isfile(zip_path)
if not need_update then
local zip_mtime = os.mtime(zip_path)
for _, file in ipairs(os.files(path.join(html_dir, "**"))) do
if os.mtime(file) > zip_mtime then
need_update = true
break
end
end
end
if need_update then
print("Regenerating frontend zip...")
os.tryrm(zip_path)
import("detect.tools.find_7z")
local cmd_7z = find_7z()
if cmd_7z then
os.execv(cmd_7z, {"a", "-mx0", zip_path, path.join(html_dir, ".")})
else
import("detect.tools.find_zip")
local zip_cmd = find_zip()
if zip_cmd then
local oldir = os.cd(html_dir)
os.execv(zip_cmd, {"-r", "-0", zip_path, "."})
os.cd(oldir)
else
raise("Unable to find a suitable zip tool (need 7z or zip)")
end
end
end
end)
-- to work around some unfortunate Ctrl-C behaviour on Linux/Mac due to
-- our use of setsid() at startup we pass in `--no-detach` to zenserver
-- ensure that it recieves signals when the user requests termination
on_run(function(target)
-- the following is roughly cribbed from xmake/actions/run/xmake.lua
-- it would be nicer if we had the option of amending the arguments
-- via before_run for instance, but I can't figure out a way to do that
import("core.base.option")
-- get the run directory of target
local rundir = target:rundir()
-- get the absolute target file path
local targetfile = path.absolute(target:targetfile())
-- get run arguments
local args = table.wrap(option.get("arguments") or target:get("runargs"))
table.insert(args, "--detach=false")
-- debugging?
if option.get("debug") then
debugger.run(targetfile, args, {curdir = rundir})
else
os.execv(targetfile, args, {curdir = rundir, detach = option.get("detach")})
end
end)
after_build(function (target)
local function copy_if_newer(src_file, dst_file, file_description)
if not os.exists(src_file) then
print("Source file '" .. src_file .. "' does not exist, cannot copy " .. file_description)
return
end
local should_copy = false
if not os.exists(dst_file) then
should_copy = true
else
local src_size = os.filesize(src_file)
local dst_size = os.filesize(dst_file)
local src_mtime = os.mtime(src_file)
local dst_mtime = os.mtime(dst_file)
if src_size ~= dst_size or src_mtime > dst_mtime then
should_copy = true
end
end
if should_copy then
os.cp(src_file, dst_file)
print("Copied '" .. file_description .. "' to output directory")
end
end
if has_config("zensentry") then
local pkg = target:pkg("sentry-native")
if pkg then
local installdir = pkg:installdir()
local crashpad_handler = "crashpad_handler"
if is_plat("windows") then
crashpad_handler = "crashpad_handler.exe"
end
local crashpad_handler_path = path.join(installdir, "bin/" .. crashpad_handler)
copy_if_newer(crashpad_handler_path, path.join(target:targetdir(), crashpad_handler), crashpad_handler)
if is_plat("windows") then
local crashpad_wer_path = path.join(installdir, "bin/crashpad_wer.dll")
copy_if_newer(crashpad_wer_path, path.join(target:targetdir(), "crashpad_wer.dll"), "crashpad_wer.dll")
end
end
end
local consul_pkg = target:pkg("consul")
if consul_pkg then
local installdir = consul_pkg:installdir()
local consul_bin = "consul"
if is_plat("windows") then
consul_bin = "consul.exe"
end
copy_if_newer(path.join(installdir, "bin", consul_bin), path.join(target:targetdir(), consul_bin), consul_bin)
end
local oidctoken_pkg = target:pkg("oidctoken")
if oidctoken_pkg then
local installdir = oidctoken_pkg:installdir()
local oidctoken_bin = "OidcToken"
if is_plat("windows") then
oidctoken_bin = "OidcToken.exe"
end
copy_if_newer(path.join(installdir, "bin", oidctoken_bin), path.join(target:targetdir(), oidctoken_bin), oidctoken_bin)
end
local nomad_pkg = target:pkg("nomad")
if nomad_pkg then
local installdir = nomad_pkg:installdir()
local nomad_bin = "nomad"
if is_plat("windows") then
nomad_bin = "nomad.exe"
end
copy_if_newer(path.join(installdir, "bin", nomad_bin), path.join(target:targetdir(), nomad_bin), nomad_bin)
end
end)
|