xmake.lua 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. package("botan")
  2. set_homepage("https://botan.randombit.net")
  3. set_description("Cryptography Toolkit")
  4. set_license("BSD-2-Clause")
  5. set_urls("https://github.com/randombit/botan/archive/refs/tags/$(version).tar.gz",
  6. "https://github.com/randombit/botan.git")
  7. add_versions("3.8.1", "8eb79a49c1a3f7e5e7563c13752a37557de935cdac48d9221ea4b580158e8965")
  8. add_versions("3.7.1", "8d2a072c7cdca6cadd16f89bb966fce1b3ec77cb4614bf1d87dec1337a3d2330")
  9. add_versions("3.7.0", "ebd1b965ed2afa12dfaf47650187142cbe870b99528185c88ca7c0ac19307c6c")
  10. add_versions("3.6.1", "a6c4e8dcb6c7f4b9b67e2c8b43069d65b548970ca17847e3b1e031d3ffdd874a")
  11. add_versions("3.6.0", "950199a891fab62dca78780b36e12f89031c37350b2a16a2c35f2e423c041bad")
  12. add_versions("3.5.0", "7d91d3349e6029e1a6929a50ab587f9fd4e29a9af3f3d698553451365564001f")
  13. add_versions("3.4.0", "6ef2a16a0527b1cfc9648a644877f7b95c4d07e8ef237273b030c623418c5e5b")
  14. -- Backport MSVC flags regression after 3.5.0 (fixed in 3.7.0: https://github.com/randombit/botan/pull/4452)
  15. add_patches(">=3.6.0 <3.7.0", "patches/3.6.0/msvc-compiler-flags.patch", "fc41a662f34a5fa52b232b25a396f595984698dc0029e4aa75423c8c4782028c")
  16. add_configs("tools", {description = "Build tools.", default = false, type = "boolean"})
  17. add_configs("python", {description = "Enable python module", default = false, type = "boolean"})
  18. add_configs("endian", {description = [[The parameter should be either “little” or “big”. If not used then if the target architecture has a default, that is used. Otherwise left unspecified, which causes less optimal codepaths to be used but will work on either little or big endian.]], default = nil, type = "string", values = {"little", "big"}})
  19. add_configs("modules", {description = [[Enable modules, example: {configs = {modules = {"zlib", "lzma"}}}]], type = "table"})
  20. add_configs("minimal", {description = "Build a minimal version", default = true, type = "boolean"})
  21. if is_plat("wasm") then
  22. add_configs("shared", {description = "Build shared library.", default = false, type = "boolean", readonly = true})
  23. end
  24. add_deps("python 3.x", "ninja", {kind = "binary"})
  25. if is_plat("mingw") and is_subhost("msys") then
  26. add_extsources("pacman::libbotan")
  27. elseif is_plat("linux") then
  28. add_extsources("pacman::botan", "apt::libbotan-2-dev")
  29. elseif is_plat("macosx") then
  30. add_extsources("brew::botan")
  31. end
  32. if is_plat("linux", "bsd") then
  33. add_syslinks("pthread")
  34. end
  35. if on_check then
  36. on_check("windows", function (package)
  37. import("core.tool.toolchain")
  38. local msvc = toolchain.load("msvc", {plat = package:plat(), arch = package:arch()})
  39. if msvc then
  40. local vs = msvc:config("vs")
  41. assert(vs and tonumber(vs) >= 2022, "package(botan): current version need vs >= 2022")
  42. end
  43. end)
  44. end
  45. on_load(function (package)
  46. import("core.base.hashset")
  47. local major = "3"
  48. if package:version() then
  49. major = package:version():major()
  50. end
  51. package:add("includedirs", "include/botan-" .. major)
  52. local modules = package:config("modules")
  53. if modules then
  54. local deps = hashset.from(modules)
  55. if deps then
  56. for _, dep in ipairs({"boost", "bzip2", "lzma", "sqlite3", "zlib"}) do
  57. if deps:has(dep) then
  58. if dep == "boost" then
  59. package:add("deps", "boost", {configs = {filesystem = true}})
  60. elseif dep == "lzma" then
  61. package:add("deps", "xz")
  62. else
  63. package:add("deps", dep)
  64. end
  65. end
  66. end
  67. end
  68. end
  69. if not package:is_plat("windows") then
  70. -- Patch to support versions of ar that don't support response files (which are first used in 3.6.0)
  71. package:add("patches", ">=3.6.0", "patches/3.6.0/ar-response-files.patch", "864443a77921d9da970cebe5b413e8ee18c60205011364b7bb422a65193ecb5f")
  72. end
  73. end)
  74. on_install("windows", "linux", "macosx|native", "bsd", "mingw@windows", "msys", "wasm", function (package)
  75. -- https://botan.randombit.net/handbook/building.html
  76. local configs = {
  77. "configure.py",
  78. "--prefix=" .. package:installdir(),
  79. "--build-tool=ninja",
  80. "--without-documentation",
  81. }
  82. local cc
  83. local envs
  84. if package:is_plat("windows") then
  85. local msvc = package:toolchain("msvc")
  86. assert(msvc:check(), "vs not found!")
  87. local vs = msvc:config("vs")
  88. if tonumber(vs) < 2019 then
  89. raise("This version of Botan requires at least msvc 19.30")
  90. end
  91. envs = msvc:runenvs()
  92. table.insert(configs, "--msvc-runtime=" .. package:runtimes())
  93. if package:has_tool("cxx", "cl") then
  94. cc = "msvc"
  95. elseif package:has_tool("cxx", "clang_cl") then
  96. raise("Unsupported toolchains on windows")
  97. end
  98. else
  99. local cxx = package:build_getenv("cxx")
  100. if cxx:find("clang", 1, true) then
  101. cc = "clang"
  102. elseif cxx:find("gcc", 1, true) then
  103. cc = "gcc"
  104. end
  105. local cc_bin
  106. if package:is_plat("mingw") then
  107. cc = "gcc"
  108. cc_bin = cxx
  109. elseif package:is_plat("wasm") then
  110. cc = "emcc"
  111. cc_bin = cxx
  112. end
  113. end
  114. if cc then
  115. table.insert(configs, "--cc=" .. cc)
  116. end
  117. if cc_bin then
  118. table.insert(configs, "--cc-bin=" .. cc_bin)
  119. end
  120. if package:is_plat("wasm") then
  121. table.insert(configs, "--os=emscripten")
  122. table.insert(configs, "--cpu=wasm")
  123. else
  124. if package:is_plat("iphoneos") then
  125. table.insert(configs, "--os=ios")
  126. elseif not package:is_plat("bsd") then
  127. -- let configure.py detech bsd host name
  128. table.insert(configs, "--os=" .. package:plat())
  129. end
  130. local arch = package:arch()
  131. if arch == "arm64-v8a" then
  132. arch = "arm64"
  133. end
  134. table.insert(configs, "--cpu=" .. arch)
  135. end
  136. if package:is_debug() then
  137. table.insert(configs, "--debug-mode")
  138. end
  139. local targets = (package:config("shared") and "shared" or "static")
  140. if package:config("tools") then
  141. targets = targets .. ",cli"
  142. end
  143. table.insert(configs, "--build-targets=" .. targets)
  144. -- necessary functions were moved to a separate module in 3.7.0
  145. local modules = package:config("modules")
  146. local needs_os_utils = package:version():ge("3.7.0")
  147. if modules then
  148. if needs_os_utils and not table.contains(modules, "os_utils") then
  149. table.insert(modules, "os_utils")
  150. end
  151. table.insert(configs, "--enable-modules=" .. table.concat(modules, ","))
  152. elseif needs_os_utils then
  153. table.insert(configs, "--enable-modules=os_utils")
  154. end
  155. if not package:config("python") then
  156. table.insert(configs, "--no-install-python-module")
  157. end
  158. if package:config("endian") then
  159. table.insert(configs, "--with-endian=" .. package:config("endian"))
  160. end
  161. if package:config("minimal") then
  162. table.insert(configs, "--minimized-build")
  163. end
  164. local cxflags = {}
  165. table.join2(cxflags, table.wrap(package:config("cxflags")))
  166. table.join2(cxflags, table.wrap(package:config("cxxflags")))
  167. for _, flag in ipairs(cxflags) do
  168. table.insert(configs, "--extra-cxxflags=" .. flag)
  169. end
  170. for _, dep in ipairs({"boost", "bzip2", "xz", "sqlite3", "zlib"}) do
  171. local packagedep = package:dep(dep)
  172. if packagedep then
  173. local fetchinfo = packagedep:fetch()
  174. if fetchinfo then
  175. for _, includedir in ipairs(fetchinfo.includedirs or fetchinfo.sysincludedirs) do
  176. table.insert(configs, "--with-external-includedir=" .. includedir)
  177. end
  178. for _, linkdir in ipairs(fetchinfo.linkdirs) do
  179. table.insert(configs, "--with-external-libdir=" .. linkdir)
  180. end
  181. end
  182. end
  183. end
  184. os.vrunv("python3", configs, {envs = envs})
  185. import("package.tools.ninja").install(package, {}, {envs = envs})
  186. end)
  187. on_test(function (package)
  188. assert(package:check_cxxsnippets({test = [[
  189. #include <botan/hex.h>
  190. void test() {
  191. std::vector<uint8_t> key = Botan::hex_decode("000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F");
  192. }
  193. ]]}, {configs = {languages = "c++20"}}))
  194. if not package:is_cross() and package:config("tools") then
  195. os.vrun("botan-cli version")
  196. end
  197. end)