2
0

xmake.lua 9.3 KB

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