xmake.lua 8.0 KB

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