xmake.lua 9.4 KB

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