xmake.lua 9.1 KB

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