-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathxmake.lua
More file actions
237 lines (205 loc) · 8.48 KB
/
xmake.lua
File metadata and controls
237 lines (205 loc) · 8.48 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
set_policy("compatibility.version", "3.0")
add_requires("llvm", {
system = false,
configs = {
mode = get_config("mode"),
debug = is_mode("debug"),
shared = is_mode("debug") and not is_plat("windows"),
},
})
local sparse_checkout_list = {
"cmake",
"llvm",
"clang",
"clang-tools-extra",
"third-party",
}
-- TODO: If we need compiler-rt builtin-headers, then we need to enable them.
-- if is_mode("debug") then
-- table.insert(sparse_checkout_list, "runtimes")
-- table.insert(sparse_checkout_list, "compiler-rt")
-- end
package("llvm")
add_urls("https://github.com/llvm/llvm-project.git", {alias = "git", includes = sparse_checkout_list})
add_versions("git:21.1.4", "222fc11f2b8f25f6a0f4976272ef1bb7bf49521d")
add_versions("git:20.1.5", "llvmorg-20.1.5")
add_configs("mode", {description = "Build type", default = "releasedbg", type = "string", values = {"debug", "release", "releasedbg"}})
if is_plat("windows", "mingw") then
add_syslinks("version", "ntdll")
end
add_deps("cmake", "ninja", "python 3.x", {kind = "binary"})
if is_host("windows") then
set_policy("platform.longpaths", true)
end
on_install(function (package)
if not package:config("shared") then
package:add("defines", "CLANG_BUILD_STATIC")
end
io.replace("clang/CMakeLists.txt", "add_subdirectory(tools)",
"add_llvm_external_project(clang-tools-extra extra)\nadd_clang_subdirectory(libclang)", {plain = true})
local clang_tools = {
"clang-apply-replacements",
"clang-reorder-fields",
-- "modularize",
"clang-tidy",
"clang-change-namespace",
"clang-doc",
"clang-include-fixer",
"clang-move",
"clang-query",
"include-cleaner",
-- "pp-trace",
"tool-template",
}
for _, tool in ipairs(clang_tools) do
io.replace(format("clang-tools-extra/%s/CMakeLists.txt", tool), "add_subdirectory(tool)", "", {plain = true})
end
io.replace("clang-tools-extra/CMakeLists.txt", "add_subdirectory(modularize)", "", {plain = true})
io.replace("clang-tools-extra/CMakeLists.txt", "add_subdirectory(pp-trace)", "", {plain = true})
io.replace("clang-tools-extra/CMakeLists.txt", "add_subdirectory(tool-template)", "", {plain = true})
io.replace("llvm/tools/CMakeLists.txt", "add_llvm_tool_subdirectory(lto)", "", {plain = true})
io.replace("llvm/tools/CMakeLists.txt", "add_llvm_implicit_projects()", "", {plain = true})
local configs = {
"-DLLVM_ENABLE_ZLIB=OFF",
"-DLLVM_ENABLE_ZSTD=OFF",
"-DLLVM_ENABLE_LIBXML2=OFF",
"-DLLVM_ENABLE_BINDINGS=OFF",
"-DLLVM_ENABLE_IDE=ON",
"-DLLVM_ENABLE_ZSTD=OFF",
"-DLLVM_ENABLE_Z3_SOLVER=OFF",
"-DLLVM_ENABLE_LIBEDIT=OFF",
"-DLLVM_ENABLE_LIBPFM=OFF",
"-DLLVM_ENABLE_LIBXML2=OFF",
"-DLLVM_ENABLE_OCAMLDOC=OFF",
"-DLLVM_ENABLE_PLUGINS=OFF",
"-DLLVM_INCLUDE_UTILS=OFF",
"-DLLVM_INCLUDE_TESTS=OFF",
"-DLLVM_INCLUDE_EXAMPLES=OFF",
"-DLLVM_INCLUDE_BENCHMARKS=OFF",
"-DLLVM_INCLUDE_DOCS=OFF",
"-DLLVM_BUILD_UTILS=OFF",
"-DLLVM_BUILD_TOOLS=OFF",
-- "-DLLVM_INCLUDE_TOOLS=OFF",
"-DCLANG_BUILD_TOOLS=OFF",
"-DCLANG_INCLUDE_DOCS=OFF",
"-DCLANG_INCLUDE_TESTS=OFF",
"-DCLANG_TOOL_CLANG_IMPORT_TEST_BUILD=OFF",
"-DCLANG_TOOL_CLANG_LINKER_WRAPPER_BUILD=OFF",
"-DCLANG_TOOL_C_INDEX_TEST_BUILD=OFF",
"-DCLANG_TOOL_LIBCLANG_BUILD=OFF",
"-DCLANG_ENABLE_CLANGD=OFF",
"-DLLVM_BUILD_LLVM_C_DYLIB=OFF",
"-DLLVM_LINK_LLVM_DYLIB=OFF",
"-DLLVM_ENABLE_RTTI=OFF",
"-DLLVM_PARALLEL_LINK_JOBS=1",
-- Build job and link job together will oom
"-DCMAKE_JOB_POOL_LINK=console",
"-DLLVM_ENABLE_PROJECTS=clang;clang-tools-extra",
-- Build all targets, this will affect the builtin type generation.
-- Users might use a cross-compiler, and to ensure clang works in
-- that scenario, we have to build all targets.
"-DLLVM_TARGETS_TO_BUILD=all"
}
local build_type = {
["debug"] = "Debug",
["release"] = "Release",
["releasedbg"] = "RelWithDebInfo",
}
table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (build_type[package:config("mode")]))
table.insert(configs, "-DBUILD_SHARED_LIBS=" .. (package:config("shared") and "ON" or "OFF"))
table.insert(configs, "-DLLVM_ENABLE_LTO=" .. (package:config("lto") and "ON" or "OFF"))
if package:config("mode") == "debug" then
table.insert(configs, "-DLLVM_USE_SANITIZER=Address")
end
if package:is_plat("windows") then
table.insert(configs, "-DCMAKE_C_COMPILER=clang-cl")
table.insert(configs, "-DCMAKE_CXX_COMPILER=clang-cl")
elseif package:is_plat("linux") then
table.insert(configs, "-DLLVM_USE_LINKER=lld")
-- table.insert(configs, "-DLLVM_USE_SPLIT_DWARF=ON")
elseif package:is_plat("macosx") then
table.insert(configs, "-DCMAKE_OSX_ARCHITECTURES=arm64")
table.insert(configs, "-DCMAKE_LIBTOOL=/opt/homebrew/opt/llvm@20/bin/llvm-libtool-darwin")
table.insert(configs, "-DLLVM_USE_LINKER=lld")
table.insert(configs, "-DLLVM_ENABLE_LIBCXX=ON")
end
local opt = {}
opt.target = {
"LLVMSupport",
"LLVMFrontendOpenMP",
"clangAST",
"clangASTMatchers",
"clangBasic",
"clangDependencyScanning",
"clangDriver",
"clangFormat",
"clangFrontend",
"clangIndex",
"clangLex",
"clangSema",
"clangSerialization",
"clangTooling",
"clangToolingCore",
"clangToolingInclusions",
"clangToolingInclusionsStdlib",
"clangToolingSyntax",
"clangTidy",
"clangTidyUtils",
}
os.cd("llvm")
import("package.tools.cmake").install(package, configs, opt)
if package:is_plat("windows") then
for _, file in ipairs(os.files(package:installdir("bin/*"))) do
if not file:endswith(".dll") then
os.rm(file)
end
end
elseif package:is_plat("linux") then
os.rm(package:installdir("bin/*"))
end
local clang_include_dir = "../clang/lib/Sema"
local install_clang_include_dir = package:installdir("include/clang/Sema")
os.vcp(path.join(clang_include_dir, "CoroutineStmtBuilder.h"), install_clang_include_dir)
os.vcp(path.join(clang_include_dir, "TypeLocBuilder.h"), install_clang_include_dir)
os.vcp(path.join(clang_include_dir, "TreeTransform.h"), install_clang_include_dir)
local abi
local format
if package:is_plat("windows") then
abi = "msvc"
format = ".7z"
elseif package:is_plat("linux") then
abi = "gnu"
format = ".tar.xz"
elseif package:is_plat("macosx") then
abi = "apple"
format = ".tar.xz"
end
-- arch-plat-abi-mode
local archive_name = table.concat({
package:arch(),
package:plat(),
abi,
package:config("mode"),
}, "-")
if package:config("lto") then
archive_name = archive_name .. "-lto"
end
local archive_file = path.join(os.scriptdir(), "build/package", archive_name .. format)
local opt = {}
opt.recurse = true
opt.compress = "best"
opt.curdir = package:installdir()
local archive_dirs
if package:is_plat("windows") then
archive_dirs = "*"
elseif package:is_plat("linux", "macosx") then
-- workaround for tar
archive_dirs = {}
for _, dir in ipairs(os.dirs(path.join(opt.curdir, "*"))) do
table.insert(archive_dirs, path.filename(dir))
end
end
import("utils.archive").archive(archive_file, archive_dirs, opt)
local checksum = hash.sha256(archive_file)
print(checksum)
end)