-
-
Notifications
You must be signed in to change notification settings - Fork 417
/
Copy pathxmake.lua
481 lines (448 loc) · 20.7 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
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
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
package("boost")
set_homepage("https://www.boost.org/")
set_description("Collection of portable C++ source libraries.")
set_license("BSL-1.0")
add_urls("https://github.com/boostorg/boost/releases/download/boost-$(version)/boost-$(version)-b2-nodocs.tar.gz")
add_urls("https://github.com/boostorg/boost/releases/download/boost-$(version)/boost-$(version).tar.gz")
add_urls("https://github.com/xmake-mirror/boost/releases/download/boost-$(version).tar.bz2", {alias = "mirror", version = function (version)
return version .. "/boost_" .. (version:gsub("%.", "_"))
end})
add_versions("1.85.0", "f4a7d3f81b8a0f65067b769ea84135fd7b72896f4f59c7f405086c8c0dc61434")
add_versions("1.84.0", "4d27e9efed0f6f152dc28db6430b9d3dfb40c0345da7342eaa5a987dde57bd95")
add_versions("1.83.0", "0c6049764e80aa32754acd7d4f179fd5551d8172a83b71532ae093e7384e98da")
add_versions("1.82.0", "b62bd839ea6c28265af9a1f68393eda37fab3611425d3b28882d8e424535ec9d")
add_versions("1.81.0", "121da556b718fd7bd700b5f2e734f8004f1cfa78b7d30145471c526ba75a151c")
add_versions("mirror:1.80.0", "1e19565d82e43bc59209a168f5ac899d3ba471d55c7610c677d4ccf2c9c500c0")
add_versions("mirror:1.79.0", "475d589d51a7f8b3ba2ba4eda022b170e562ca3b760ee922c146b6c65856ef39")
add_versions("mirror:1.78.0", "8681f175d4bdb26c52222665793eef08490d7758529330f98d3b29dd0735bccc")
add_versions("mirror:1.77.0", "fc9f85fc030e233142908241af7a846e60630aa7388de9a5fafb1f3a26840854")
add_versions("mirror:1.76.0", "f0397ba6e982c4450f27bf32a2a83292aba035b827a5623a14636ea583318c41")
add_versions("mirror:1.75.0", "953db31e016db7bb207f11432bef7df100516eeb746843fa0486a222e3fd49cb")
add_versions("mirror:1.74.0", "83bfc1507731a0906e387fc28b7ef5417d591429e51e788417fe9ff025e116b1")
add_versions("mirror:1.73.0", "4eb3b8d442b426dc35346235c8733b5ae35ba431690e38c6a8263dce9fcbb402")
add_versions("mirror:1.72.0", "59c9b274bc451cf91a9ba1dd2c7fdcaf5d60b1b3aa83f2c9fa143417cc660722")
add_versions("mirror:1.70.0", "430ae8354789de4fd19ee52f3b1f739e1fba576f0aded0897c3c2bc00fb38778")
if is_plat("mingw") and is_subhost("msys") then
add_extsources("pacman::boost")
elseif is_plat("linux") then
add_extsources("pacman::boost", "apt::libboost-all-dev")
elseif is_plat("macosx") then
add_extsources("brew::boost")
end
add_patches("1.75.0", path.join(os.scriptdir(), "patches", "1.75.0", "warning.patch"), "43ff97d338c78b5c3596877eed1adc39d59a000cf651d0bcc678cf6cd6d4ae2e")
if is_plat("linux") then
add_deps("bzip2", "zlib")
add_syslinks("pthread", "dl")
end
add_configs("pyver", {description = "python version x.y, etc. 3.10", default = "3.10"})
local libnames = {"atomic",
"charconv",
"chrono",
"cobalt",
"container",
"context",
"contract",
"coroutine",
"date_time",
"exception",
"fiber",
"filesystem",
"graph",
"graph_parallel",
"headers",
"iostreams",
"json",
"locale",
"log",
"math",
"mpi",
"nowide",
"program_options",
"python",
"random",
"regex",
"serialization",
"stacktrace",
"system",
"test",
"thread",
"timer",
"type_erasure",
"url",
"wave"}
add_configs("all", { description = "Enable all library modules support.", default = false, type = "boolean"})
add_configs("multi", { description = "Enable multi-thread support.", default = true, type = "boolean"})
for _, libname in ipairs(libnames) do
add_configs(libname, { description = "Enable " .. libname .. " library.", default = (libname == "filesystem"), type = "boolean"})
end
add_configs("zstd", {description = "enable zstd for iostreams", default = false, type = "boolean"})
add_configs("lzma", {description = "enable lzma for iostreams", default = false, type = "boolean"})
on_load(function (package)
local function get_linkname(package, libname)
local linkname
if package:is_plat("windows") then
linkname = (package:config("shared") and "boost_" or "libboost_") .. libname
else
linkname = "boost_" .. libname
end
if libname == "python" or libname == "numpy" then
linkname = linkname .. package:config("pyver"):gsub("%p+", "")
end
if package:config("multi") then
linkname = linkname .. "-mt"
end
if package:is_plat("windows") then
local vs_runtime = package:config("vs_runtime")
if package:config("shared") then
if package:debug() then
linkname = linkname .. "-gd"
end
elseif package:config("asan") or vs_runtime == "MTd" then
linkname = linkname .. "-sgd"
elseif vs_runtime == "MT" then
linkname = linkname .. "-s"
elseif package:config("asan") or vs_runtime == "MDd" then
linkname = linkname .. "-gd"
end
else
if package:debug() then
linkname = linkname .. "-d"
end
end
return linkname
end
-- we need the fixed link order
local sublibs = {log = {"log_setup", "log"},
python = {"python", "numpy"},
stacktrace = {"stacktrace_backtrace", "stacktrace_basic"}}
for _, libname in ipairs(libnames) do
local libs = sublibs[libname]
if libs then
for _, lib in ipairs(libs) do
package:add("links", get_linkname(package, lib))
end
else
package:add("links", get_linkname(package, libname))
end
end
-- disable auto-link all libs
if package:is_plat("windows") then
package:add("defines", "BOOST_ALL_NO_LIB")
end
if package:config("python") then
if not package:config("shared") then
package:add("defines", "BOOST_PYTHON_STATIC_LIB")
end
package:add("deps", "python " .. package:config("pyver") .. ".x", {configs = {headeronly = true}})
end
if package:config("zstd") then
package:add("deps", "zstd")
end
if package:config("lzma") then
package:add("deps", "xz")
end
if package:is_plat("windows") and package:version():le("1.85.0") then
local vs_toolset = package:toolchain("msvc"):config("vs_toolset")
if vs_toolset then
local vs_toolset_ver = import("core.base.semver").new(vs_toolset)
local minor = vs_toolset_ver:minor()
if minor and minor >= 40 then
package:add("patches", "<=1.85.0", "patches/1.85.0/fix-v144.patch", "1ba99cb2e2f03a4ba489a32596c62e1310b6c73ba4d19afa8796bcf180c84422")
end
end
end
end)
on_install("macosx", "linux", "windows", "bsd", "mingw", "cross", function (package)
import("core.base.option")
local function get_compiler(package, toolchain)
local cxx = package:build_getenv("cxx")
if package:is_plat("macosx") then
-- we uses ld/clang++ for link stdc++ for shared libraries
-- and we need `xcrun -sdk macosx clang++` to make b2 to get `-isysroot` automatically
local cc = package:build_getenv("ld")
if cc and cc:find("clang", 1, true) and cc:find("Xcode", 1, true) then
cc = "xcrun -sdk macosx clang++"
end
return format("using darwin : : %s ;", cc)
elseif package:is_plat("windows") then
local vs_toolset = toolchain:config("vs_toolset")
local msvc_ver = ""
local win_toolset = "msvc"
if toolchain:name() == "clang-cl" then
win_toolset = "clang-win"
cxx = cxx:gsub("(clang%-cl)$", "%1.exe", 1)
msvc_ver = ""
elseif vs_toolset then
local i = vs_toolset:find("%.")
msvc_ver = i and vs_toolset:sub(1, i + 1)
end
-- Specifying a version will disable b2 from forcing tools
-- from the latest installed msvc version.
return format("using %s : %s : \"%s\" ;", win_toolset, msvc_ver, cxx:gsub("\\", "\\\\"))
else
cxx = cxx:gsub("gcc$", "g++")
cxx = cxx:gsub("gcc%-", "g++-")
cxx = cxx:gsub("clang$", "clang++")
cxx = cxx:gsub("clang%-", "clang++-")
if cxx and cxx:find("clang", 1, true) then
return format("using clang : : \"%s\" ;", cxx:gsub("\\", "/"))
else
return format("using gcc : : \"%s\" ;", cxx:gsub("\\", "/"))
end
end
end
-- get host toolchain
import("core.tool.toolchain")
local host_toolchain
if package:is_plat("windows") then
host_toolchain = toolchain.load("msvc", {plat = "windows", arch = os.arch()})
if not host_toolchain:check() then
host_toolchain = toolchain.load("clang-cl", {plat = "windows", arch = os.arch()})
end
assert(host_toolchain:check(), "host msvc or clang-cl not found!")
end
-- force boost to compile with the desired compiler
local file = io.open("user-config.jam", "w")
if file then
file:write(get_compiler(package, host_toolchain))
file:close()
end
local bootstrap_argv =
{
"--prefix=" .. package:installdir(),
"--libdir=" .. package:installdir("lib"),
"--without-icu"
}
if package:has_tool("cxx", "clang", "clangxx") then
table.insert(bootstrap_argv, "--with-toolset=clang")
end
if package:is_plat("windows") then
-- for bootstrap.bat, all other arguments are useless
bootstrap_argv = { "msvc" }
os.vrunv("bootstrap.bat", bootstrap_argv, {envs = host_toolchain:runenvs()})
elseif package:is_plat("mingw") and is_host("windows") then
bootstrap_argv = { "gcc" }
os.vrunv("bootstrap.bat", bootstrap_argv)
-- todo looking for better solution to fix the confict between user-config.jam and project-config.jam
io.replace("project-config.jam", "using[^\n]+", "")
else
os.vrunv("./bootstrap.sh", bootstrap_argv)
end
-- get build toolchain
local build_toolchain
local build_toolset
local runenvs
if package:is_plat("windows") then
if package:has_tool("cxx", "clang_cl") then
build_toolset = "clang-win"
build_toolchain = package:toolchain("clang-cl")
elseif package:has_tool("cxx", "clang") then
build_toolset = "clang-win"
build_toolchain = package:toolchain("clang") or package:toolchain("llvm")
elseif package:has_tool("cxx", "cl") then
build_toolset = "msvc"
build_toolchain = package:toolchain("msvc")
end
if build_toolchain then
runenvs = build_toolchain:runenvs()
end
end
local function config_deppath(file, depname, rule)
local dep = package:dep(depname)
local info = dep:fetch({external = false})
if info then
local usingstr = format("\nusing %s : %s : <include>%s <search>%s <name>%s ;",
rule, dep:version(),
path.unix(info.includedirs[1]),
path.unix(info.linkdirs[1]),
info.links[1])
file:write(usingstr)
end
end
local file = io.open("user-config.jam", "w")
if file then
file:write(get_compiler(package, build_toolchain))
if package:config("lzma") then
config_deppath(file, "xz", "lzma")
end
if package:config("zstd") then
config_deppath(file, "zstd", "zstd")
end
file:close()
end
os.vrun("./b2 headers")
local njobs = option.get("jobs") or tostring(os.default_njob())
local argv =
{
"--prefix=" .. package:installdir(),
"--libdir=" .. package:installdir("lib"),
"-d2",
"-j" .. njobs,
"--hash",
"-q", -- quit on first error
"--layout=tagged-1.66", -- prevent -x64 suffix in case cmake can't find it
"--user-config=user-config.jam",
"install",
"threading=" .. (package:config("multi") and "multi" or "single"),
"debug-symbols=" .. (package:debug() and "on" or "off"),
"link=" .. (package:config("shared") and "shared" or "static"),
"variant=" .. (package:is_debug() and "debug" or "release"),
"runtime-debugging=" .. (package:is_debug() and "on" or "off")
}
local cxxflags = {}
if package:config("lzma") then
if package:is_plat("windows") and not package:dep("xz"):config("shared") then
table.insert(cxxflags, "-DLZMA_API_STATIC")
end
else
table.insert(argv, "-sNO_LZMA=1")
end
if not package:config("zstd") then
table.insert(argv, "-sNO_ZSTD=1")
end
if package:config("lto") then
table.insert(argv, "lto=on")
end
if package:is_arch("aarch64", "arm+.*") then
table.insert(argv, "architecture=arm")
end
if package:is_arch(".+64.*") then
table.insert(argv, "address-model=64")
else
table.insert(argv, "address-model=32")
end
local linkflags = {}
table.join2(cxxflags, table.wrap(package:config("cxflags")))
table.join2(cxxflags, table.wrap(package:config("cxxflags")))
if package:is_plat("windows") then
local vs_runtime = package:config("vs_runtime")
if package:config("shared") then
table.insert(argv, "runtime-link=shared")
elseif vs_runtime and vs_runtime:startswith("MT") then
table.insert(argv, "runtime-link=static")
else
table.insert(argv, "runtime-link=shared")
end
table.insert(argv, "toolset=" .. build_toolset)
table.insert(cxxflags, "-std:c++14")
elseif package:is_plat("mingw") then
table.insert(argv, "toolset=gcc")
elseif package:is_plat("macosx") then
table.insert(argv, "toolset=darwin")
-- fix macosx arm64 build issue https://github.com/microsoft/vcpkg/pull/18529
table.insert(cxxflags, "-std=c++14")
table.insert(cxxflags, "-arch")
table.insert(cxxflags, package:arch())
local xcode = package:toolchain("xcode") or import("core.tool.toolchain").load("xcode", {plat = package:plat(), arch = package:arch()})
if xcode:check() then
local xcode_dir = xcode:config("xcode")
local xcode_sdkver = xcode:config("xcode_sdkver")
local target_minver = xcode:config("target_minver")
if xcode_dir and xcode_sdkver then
local xcode_sdkdir = xcode_dir .. "/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX" .. xcode_sdkver .. ".sdk"
table.insert(cxxflags, "-isysroot")
table.insert(cxxflags, xcode_sdkdir)
end
if target_minver then
table.insert(cxxflags, "-mmacosx-version-min=" .. target_minver)
end
end
else
table.insert(cxxflags, "-std=c++14")
if package:config("pic") ~= false then
table.insert(cxxflags, "-fPIC")
end
end
if package.has_runtime and package:has_runtime("c++_shared", "c++_static") then
table.insert(cxxflags, "-stdlib=libc++")
table.insert(linkflags, "-stdlib=libc++")
if package:has_runtime("c++_static") then
table.insert(linkflags, "-static-libstdc++")
end
end
if package:config("asan") then
table.insert(cxxflags, "-fsanitize=address")
table.insert(linkflags, "-fsanitize=address")
end
if cxxflags then
table.insert(argv, "cxxflags=" .. table.concat(cxxflags, " "))
end
if linkflags then
table.insert(argv, "linkflags=" .. table.concat(linkflags, " "))
end
for _, libname in ipairs(libnames) do
if package:config("all") or package:config(libname) then
table.insert(argv, "--with-" .. libname)
end
end
if package:is_plat("linux") then
table.insert(argv, "pch=off")
end
local ok = os.execv("./b2", argv, {envs = runenvs, try = true, stdout = "boost-log.txt"})
if ok ~= 0 then
raise("boost build failed, please check log in " .. path.join(os.curdir(), "boost-log.txt"))
end
end)
on_test(function (package)
assert(package:check_cxxsnippets({test = [[
#include <boost/algorithm/string.hpp>
#include <string>
#include <vector>
static void test() {
std::string str("a,b");
std::vector<std::string> vec;
boost::algorithm::split(vec, str, boost::algorithm::is_any_of(","));
}
]]}, {configs = {languages = "c++14"}}))
assert(package:check_cxxsnippets({test = [[
#include <boost/unordered_map.hpp>
static void test() {
boost::unordered_map<std::string, int> map;
map["2"] = 2;
}
]]}, {configs = {languages = "c++14"}}))
if package:config("date_time") then
assert(package:check_cxxsnippets({test = [[
#include <boost/date_time/gregorian/gregorian.hpp>
static void test() {
boost::gregorian::date d(2010, 1, 30);
}
]]}, {configs = {languages = "c++14"}}))
end
if package:config("filesystem") then
assert(package:check_cxxsnippets({test = [[
#include <boost/filesystem.hpp>
#include <iostream>
static void test() {
boost::filesystem::path path("/path/to/directory");
if (boost::filesystem::exists(path)) {
std::cout << "Directory exists" << std::endl;
} else {
std::cout << "Directory does not exist" << std::endl;
}
}
]]}, {configs = {languages = "c++14"}}))
end
if package:config("iostreams") then
if package:config("zstd") then
assert(package:check_cxxsnippets({test = [[
#include <boost/iostreams/filter/zstd.hpp>
#include <boost/iostreams/filtering_stream.hpp>
static void test() {
boost::iostreams::filtering_ostream out;
out.push(boost::iostreams::zstd_compressor());
}
]]}, {configs = {languages = "c++14"}}))
end
if package:config("lzma") then
assert(package:check_cxxsnippets({test = [[
#include <boost/iostreams/filter/lzma.hpp>
#include <boost/iostreams/filtering_stream.hpp>
static void test() {
boost::iostreams::filtering_ostream out;
out.push(boost::iostreams::lzma_compressor());
}
]]}, {configs = {languages = "c++14"}}))
end
end
end)