xmake.lua 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. package("llvm")
  2. set_kind("toolchain")
  3. set_homepage("https://llvm.org/")
  4. set_description("The LLVM Compiler Infrastructure")
  5. if is_plat("windows") then
  6. if is_arch("x86") then
  7. set_urls("https://github.com/xmake-mirror/llvm-windows/releases/download/$(version)/clang+llvm-$(version)-win32.zip")
  8. add_versions("11.0.0", "268043ae0b656cf6272ccb9b8e3f21f51170b74ed8997ddc0b99587983b821ca")
  9. add_versions("14.0.0", "63afc3c472cb279978c5a7efc25b8783a700aeb416df67886b7057eba52a8742")
  10. add_versions("15.0.7", "8dbabb2194404220f8641b4b18b24b36eca0ae751380c23fc7743097e205b95f")
  11. add_versions("16.0.6", "5e1f560f75e7a4c7a6509cf7d9a28b4543e7afcb4bcf4f747e9f208f0efa6818")
  12. else
  13. set_urls("https://github.com/xmake-mirror/llvm-windows/releases/download/$(version)/clang+llvm-$(version)-win64.zip")
  14. add_versions("11.0.0", "db5b3a44f8f784ebc71f716b54eb63c0d8d21aead12449f36291ab00820271c7")
  15. add_versions("14.0.0", "c1e1ddf11aa73c58073956d9217086550544328ed5e6ec64c1a709badb231711")
  16. add_versions("15.0.7", "7d29ca82f8b73e9973209e90428ec9f3fbd3b01925bd26e34f59e959e9ea7eb3")
  17. add_versions("16.0.6", "7adb1a630b6cc676a4b983aca9b01e67f770556c6e960e9ee9aa7752c8beb8a3")
  18. end
  19. elseif is_plat("macosx") then
  20. if is_arch("x86_64") then
  21. set_urls("https://github.com/llvm/llvm-project/releases/download/llvmorg-$(version).tar.xz", {version = function (version)
  22. if version:lt("15.0") then
  23. return version .. "/clang+llvm-" .. version .. "-x86_64-apple-darwin"
  24. else
  25. return version .. "/clang+llvm-" .. version .. "-x86_64-apple-darwin21.0"
  26. end
  27. end})
  28. add_versions("11.0.0", "b93886ab0025cbbdbb08b46e5e403a462b0ce034811c929e96ed66c2b07fe63a")
  29. add_versions("13.0.0", "d051234eca1db1f5e4bc08c64937c879c7098900f7a0370f3ceb7544816a8b09")
  30. add_versions("14.0.0", "cf5af0f32d78dcf4413ef6966abbfd5b1445fe80bba57f2ff8a08f77e672b9b3")
  31. add_versions("15.0.7", "d16b6d536364c5bec6583d12dd7e6cf841b9f508c4430d9ee886726bd9983f1c")
  32. elseif is_arch("arm64") then
  33. set_urls("https://github.com/llvm/llvm-project/releases/download/llvmorg-$(version)/clang+llvm-$(version)-arm64-apple-darwin21.0.tar.xz")
  34. add_versions("15.0.0", "cfd5c3fa07d7fccea0687f5b4498329a6172b7a15bbc45b547d0ac86bd3452a5")
  35. end
  36. elseif is_plat("bsd") then
  37. if is_arch("x86_64") then
  38. set_urls("https://github.com/llvm/llvm-project/releases/download/llvmorg-$(version)/clang+llvm-$(version)-amd64-unknown-freebsd13.tar.xz")
  39. add_versions("14.0.0", "b68d73fd57be385e7f06046a87381f7520c8861f492c294e6301d2843d9a1f57")
  40. elseif is_arch("i386") then
  41. set_urls("https://github.com/llvm/llvm-project/releases/download/llvmorg-$(version)/clang+llvm-$(version)-i386-unknown-freebsd13.tar.xz")
  42. add_versions("14.0.0", "81f49eb466ce9149335ac8918a5f02fa724d562a94464ed13745db0165b4a220")
  43. end
  44. else
  45. set_urls("https://github.com/llvm/llvm-project/releases/download/llvmorg-$(version)/llvm-project-$(version).src.tar.xz")
  46. add_versions("11.0.0", "b7b639fc675fa1c86dd6d0bc32267be9eb34451748d2efd03f674b773000e92b")
  47. add_versions("14.0.0", "35ce9edbc8f774fe07c8f4acdf89ec8ac695c8016c165dd86b8d10e7cba07e23")
  48. add_versions("15.0.7", "8b5fcb24b4128cf04df1b0b9410ce8b1a729cb3c544e6da885d234280dedeac6")
  49. add_versions("16.0.5", "37f540124b9cfd4680666e649f557077f9937c9178489cea285a672e714b2863")
  50. add_versions("16.0.6", "ce5e71081d17ce9e86d7cbcfa28c4b04b9300f8fb7e78422b1feb6bc52c3028e")
  51. end
  52. add_configs("shared", {description = "Build shared library.", default = false, type = "boolean", readonly = true})
  53. add_configs("all", {description = "Enable all projects.", default = false, type = "boolean"})
  54. add_configs("bolt", {description = "Enable bolt project.", default = false, type = "boolean"})
  55. add_configs("clang", {description = "Enable clang project.", default = true, type = "boolean"})
  56. add_configs("clang-tools-extra", {description = "Enable extra clang tools project.", default = false, type = "boolean"})
  57. add_configs("libclc", {description = "Enable libclc project.", default = false, type = "boolean"})
  58. add_configs("lld", {description = "Enable lld project.", default = false, type = "boolean"})
  59. add_configs("lldb", {description = "Enable lldb project.", default = false, type = "boolean"})
  60. add_configs("polly", {description = "Enable polly project.", default = false, type = "boolean"})
  61. add_configs("pstl", {description = "Enable pstl project.", default = false, type = "boolean"})
  62. add_configs("mlir", {description = "Enable mlir project.", default = false, type = "boolean"})
  63. add_configs("flang", {description = "Enable flang project.", default = false, type = "boolean"})
  64. add_configs("compiler-rt", {description = "Enable compiler-rt project.", default = true, type = "boolean"})
  65. add_configs("libunwind", {description = "Enable libunwind runtime.", default = true, type = "boolean"})
  66. add_configs("libc", {description = "Enable libc runtime.", default = false, type = "boolean"})
  67. add_configs("libcxx", {description = "Enable libcxx runtime.", default = true, type = "boolean"})
  68. add_configs("libcxxabi", {description = "Enable libcxxabi runtime.", default = true, type = "boolean"})
  69. add_configs("openmp", {description = "Enable openmp runtime.", default = false, type = "boolean"})
  70. on_load(function (package)
  71. if package:is_plat("linux") then
  72. package:add("deps", "cmake")
  73. package:add("deps", "python 3.x", {kind = "binary", host = true})
  74. package:add("deps", "zlib", "libffi", {host = true})
  75. package:add("deps", "binutils", {host = true}) -- needed for gold and strip
  76. end
  77. if package:is_plat("linux", "bsd") then
  78. if package:config("openmp") then
  79. package:add("deps", "libelf", {host = true})
  80. end
  81. end
  82. -- add components
  83. if package:is_library() then
  84. local components = {"mlir", "clang", "libunwind"}
  85. for _, name in ipairs(components) do
  86. if package:config(name) or package:config("all") then
  87. package:add("components", name, {deps = "base"})
  88. end
  89. end
  90. package:add("components", "base", {default = true})
  91. end
  92. end)
  93. on_fetch("fetch")
  94. on_install("macosx", "windows", "msys", "bsd", function (package)
  95. os.cp("*", package:installdir())
  96. end)
  97. on_install("linux", function (package)
  98. local projects = {
  99. "bolt",
  100. "clang",
  101. "clang-tools-extra",
  102. "libclc",
  103. "lld",
  104. "lldb",
  105. "openmp",
  106. "polly",
  107. "pstl",
  108. "mlir",
  109. "flang",
  110. "compiler-rt",
  111. "openmp"
  112. }
  113. local projects_enabled = {}
  114. if package:config("all") then
  115. table.insert(projects_enabled, "all")
  116. else
  117. for _, project in ipairs(projects) do
  118. if package:config(project) then
  119. table.insert(projects_enabled, project)
  120. end
  121. end
  122. end
  123. local runtimes = {
  124. "libc",
  125. "libunwind",
  126. "libcxx",
  127. "libcxxabi"
  128. }
  129. local runtimes_enabled = {}
  130. for _, runtime in ipairs(runtimes) do
  131. if package:config(runtime) then
  132. table.insert(runtimes_enabled, runtime)
  133. end
  134. end
  135. local configs = {
  136. "-DCMAKE_BUILD_TYPE=Release",
  137. "-DLLVM_ENABLE_PROJECTS=" .. table.concat(projects_enabled, ";"),
  138. "-DLLVM_ENABLE_RUNTIMES=" .. table.concat(runtimes_enabled, ";"),
  139. "-DLLVM_POLLY_LINK_INTO_TOOLS=ON",
  140. "-DLLVM_BUILD_EXTERNAL_COMPILER_RT=ON",
  141. "-DLLVM_LINK_LLVM_DYLIB=ON",
  142. "-DLLVM_ENABLE_EH=ON",
  143. "-DLLVM_ENABLE_FFI=ON",
  144. "-DLLVM_ENABLE_RTTI=ON",
  145. "-DLLVM_INCLUDE_DOCS=OFF",
  146. "-DLLVM_INCLUDE_TESTS=OFF",
  147. "-DLLVM_INSTALL_UTILS=ON",
  148. "-DLLVM_ENABLE_Z3_SOLVER=OFF",
  149. "-DLLVM_OPTIMIZED_TABLEGEN=ON",
  150. "-DLLVM_TARGETS_TO_BUILD=all",
  151. "-DFFI_INCLUDE_DIR=" .. package:dep("libffi"):installdir("include"),
  152. "-DFFI_LIBRARY_DIR=" .. package:dep("libffi"):installdir("lib"),
  153. "-DLLDB_USE_SYSTEM_DEBUGSERVER=ON",
  154. "-DLLDB_ENABLE_PYTHON=OFF",
  155. "-DLLDB_ENABLE_LUA=OFF",
  156. "-DLLDB_ENABLE_LZMA=OFF",
  157. "-DLIBOMP_INSTALL_ALIASES=OFF"
  158. }
  159. table.insert(configs, "-DLLVM_CREATE_XCODE_TOOLCHAIN=" .. (package:is_plat("macosx") and "ON" or "OFF")) -- TODO
  160. table.insert(configs, "-DLLVM_BUILD_LLVM_C_DYLIB=" .. (package:is_plat("macosx") and "ON" or "OFF"))
  161. if package:has_tool("cxx", "clang", "clangxx") then
  162. table.insert(configs, "-DLLVM_ENABLE_LIBCXX=ON")
  163. else
  164. table.insert(configs, "-DLLVM_ENABLE_LIBCXX=OFF")
  165. table.insert(configs, "-DCLANG_DEFAULT_CXX_STDLIB=libstdc++")
  166. -- enable llvm gold plugin for LTO
  167. table.insert(configs, "-DLLVM_BINUTILS_INCDIR=" .. package:dep("binutils"):installdir("include"))
  168. end
  169. os.cd("llvm")
  170. import("package.tools.cmake").install(package, configs)
  171. end)
  172. on_component("mlir", "components.mlir")
  173. on_component("clang", "components.clang")
  174. on_component("libunwind", "components.libunwind")
  175. on_component("base", "components.base")
  176. on_test(function (package)
  177. if package:is_toolchain() and not package:is_cross() then
  178. if not package:is_plat("windows") then
  179. os.vrun("llvm-config --version")
  180. end
  181. if package:config("clang") then
  182. os.vrun("clang --version")
  183. end
  184. end
  185. end)