xmake.lua 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. package("openssl3")
  2. set_homepage("https://www.openssl.org/")
  3. set_description("A robust, commercial-grade, and full-featured toolkit for TLS and SSL.")
  4. set_license("Apache-2.0")
  5. add_urls("https://github.com/openssl/openssl/archive/refs/tags/openssl-$(version).zip")
  6. add_versions("3.5.1", "9a1472b5e2a019f69da7527f381b873e3287348f3ad91783f83fff4e091ea4a8")
  7. add_versions("3.4.2", "d313ac2ee07ad0d9c6e9203c56a485b3ecacac61c18fe450fe3c1d4db540ad71")
  8. add_versions("3.3.4", "88c892a670df8924889f3bfd2f2dde822e1573a23dc4176556cb5170b40693ea")
  9. add_versions("3.3.2", "4cda357946f9dd5541b565dba35348d614288e88aeb499045018970c789c9d61")
  10. add_versions("3.3.1", "307284f39bfb7061229c57e263e707655aa80aa9950bf6def28ed63fec91a726")
  11. add_versions("3.2.5", "08a3fe150bd69a83ac64e222bdccf0698c493a94e161e4d080c82d1f308dc4e1")
  12. add_versions("3.1.8", "bbd5cbd8cc8ea852d31c001a9b767eadef0548b098e132b580a1f0c80d1778b7")
  13. add_versions("3.0.17", "1129500758754ce4ff7eba7e46403dd56d5aa0a4e517a8fff7dac6fe120d0461")
  14. add_versions("3.0.14", "9590b9ae18c4de183be74dfc9da5be1f1e8f85dd631a78bc74c0ebc3d7e27a93")
  15. add_versions("3.0.7", "fcb37203c6bf7376cfd3aeb0be057937b7611e998b6c0d664abde928c8af3eb7")
  16. add_versions("3.0.6", "9b45be41df0d6e9cf9e340a64525177662f22808ac69aee6bfb29c511284dae4")
  17. add_versions("3.0.5", "4313c91fb0412e6a600493eb7c59bd555c4ff2ea7caa247a98c8456ad6f9fc74")
  18. add_versions("3.0.4", "5b690a5c00e639f3817e2ee15c23c36874a1f91fa8c3a83bda3276d3d6345b76")
  19. add_versions("3.0.3", "9bc56fd035f980cf74605264b04d84497df657c4f7ca68bfa77512e745f6c1a6")
  20. add_versions("3.0.2", "ce3cbb41411731852e52bf96c06f097405c81ebf60ba81e0b9ca05d41dc92681")
  21. add_versions("3.0.1", "53d8121af1c33c62a05a5370e9ba40fcc237717b79a7d99009b0c00c79bd7d78")
  22. add_versions("3.0.0", "1bdb33f131af75330de94475563c62d6908ac1c18586f7f4aa209b96b0bfc2f9")
  23. -- https://github.com/microsoft/vcpkg/blob/11faa3f168ec2a2f77510b92a42fb5c8a7e28bd8/ports/openssl/command-line-length.patch
  24. add_patches("3.3.2", path.join(os.scriptdir(), "patches/3.3.2/command-line-length.patch"), "e969153046f22d6abbdedce19191361f20edf3814b3ee47fb79a306967e03d81")
  25. on_fetch("fetch")
  26. -- https://security.stackexchange.com/questions/173425/how-do-i-calculate-md2-hash-with-openssl
  27. add_configs("md2", {description = "Enable MD2 on OpenSSl3 or not", default = false, type = "boolean"})
  28. if is_plat("cross", "android", "iphoneos", "wasm") then
  29. add_configs("shared", {description = "Build shared library.", default = false, type = "boolean", readonly = true})
  30. end
  31. -- @see https://github.com/xmake-io/xmake-repo/pull/7797#issuecomment-3153471643
  32. if is_plat("windows") then
  33. add_configs("jom", {description = "Try using jom to compile in parallel.", default = true, type = "boolean"})
  34. end
  35. on_load(function (package)
  36. if not package:is_precompiled() then
  37. if package:is_plat("windows") then
  38. package:add("deps", "nasm")
  39. -- the perl executable found in GitForWindows will fail to build OpenSSL
  40. -- see https://github.com/openssl/openssl/blob/master/NOTES-PERL.md#perl-on-windows
  41. package:add("deps", "strawberry-perl", {system = false})
  42. if package:config("jom") then
  43. -- check xmake tool jom
  44. import("package.tools.jom", {try = true})
  45. if jom then
  46. package:add("deps", "jom", {private = true})
  47. end
  48. end
  49. elseif package:is_plat("android", "wasm") and is_subhost("windows") and os.arch() == "x64" then
  50. -- when building for android on windows, use msys2 perl instead of strawberry-perl to avoid configure issue
  51. package:add("deps", "msys2", {configs = {msystem = "MINGW64", base_devel = true}, private = true})
  52. end
  53. end
  54. -- @note we must use package:is_plat() instead of is_plat in description for supporting add_deps("openssl", {host = true}) in python
  55. if package:is_plat("windows") then
  56. package:add("links", "libssl", "libcrypto")
  57. else
  58. package:add("links", "ssl", "crypto")
  59. end
  60. if package:is_plat("windows", "mingw", "msys") then
  61. package:add("syslinks", "ws2_32", "user32", "crypt32", "advapi32")
  62. elseif package:is_plat("linux", "bsd", "cross") then
  63. package:add("syslinks", "pthread", "dl")
  64. end
  65. if package:is_plat("linux", "mingw", "msys") and package:is_arch("x86_64") then
  66. package:add("linkdirs", "lib64")
  67. end
  68. if package:is_plat("linux") then
  69. package:add("extsources", "apt::libssl-dev")
  70. end
  71. end)
  72. on_install("windows", function (package)
  73. import("package.tools.jom", {try = true})
  74. import("package.tools.nmake")
  75. local configs = {"Configure", "no-tests"}
  76. local target
  77. if package:is_arch("x86", "i386") then
  78. target = "VC-WIN32"
  79. elseif package:is_arch("arm64") then
  80. target = "VC-WIN64-ARM"
  81. elseif package:is_arch("arm.*") then
  82. target = "VC-WIN32-ARM"
  83. else
  84. target = "VC-WIN64A"
  85. end
  86. table.insert(configs, target)
  87. table.insert(configs, package:config("shared") and "shared" or "no-shared")
  88. table.insert(configs, "--prefix=" .. package:installdir())
  89. table.insert(configs, "--openssldir=" .. package:installdir())
  90. if package:config("md2") then
  91. table.insert(configs, "enable-md2")
  92. end
  93. if package:config("jom") and jom then
  94. table.insert(configs, "no-makedepend")
  95. end
  96. if package:is_debug() then
  97. table.insert(configs, "/FS")
  98. else
  99. io.replace("Configurations/10-main.conf", "/debug", "", {plain = true})
  100. io.replace("Configurations/10-main.conf", "/Zi", "", {plain = true})
  101. io.replace("Configurations/50-masm.conf", "/Zi", "", {plain = true})
  102. if package:version():gt("3.0.17") then
  103. io.replace("Configurations/50-win-clang-cl.conf", "/Zi", "", {plain = true})
  104. end
  105. io.replace("util/copy.pl", "if (-d $dest)", "if (! -e $_) { next; }\n\tif (-d $dest)", {plain = true})
  106. end
  107. os.vrunv("perl", configs)
  108. if package:config("jom") and jom then
  109. jom.build(package)
  110. jom.make(package, {"install_sw"})
  111. else
  112. nmake.build(package)
  113. nmake.make(package, {"install_sw"})
  114. end
  115. end)
  116. on_install("mingw", "msys", function (package)
  117. local configs = {"Configure", "no-tests"}
  118. table.insert(configs, package:is_arch("i386", "x86") and "mingw" or "mingw64")
  119. table.insert(configs, package:config("shared") and "shared" or "no-shared")
  120. local installdir = package:installdir()
  121. -- Use MSYS2 paths instead of Windows paths
  122. if is_subhost("msys") then
  123. installdir = installdir:gsub("(%a):[/\\](.+)", "/%1/%2"):gsub("\\", "/")
  124. end
  125. table.insert(configs, "--prefix=" .. installdir)
  126. table.insert(configs, "--openssldir=" .. installdir)
  127. if package:config("md2") then
  128. table.insert(configs, "enable-md2")
  129. end
  130. local buildenvs = import("package.tools.autoconf").buildenvs(package)
  131. buildenvs.RC = package:build_getenv("mrc")
  132. if is_subhost("msys") then
  133. local rc = buildenvs.RC
  134. if rc then
  135. rc = rc:gsub("(%a):[/\\](.+)", "/%1/%2"):gsub("\\", "/")
  136. buildenvs.RC = rc
  137. end
  138. end
  139. -- fix 'cp: directory fuzz does not exist'
  140. if package:config("shared") then
  141. os.mkdir("fuzz")
  142. end
  143. os.vrunv("perl", configs, {envs = buildenvs})
  144. import("package.tools.make").build(package)
  145. import("package.tools.make").make(package, {"install_sw"})
  146. if os.isdir(package:installdir("lib64")) and package:is_arch("x86_64") then
  147. os.trycp(path.join(package:installdir("lib64"), "*"), package:installdir("lib"))
  148. end
  149. end)
  150. on_install("linux", "macosx", "bsd", function (package)
  151. -- https://wiki.openssl.org/index.php/Compilation_and_Installation#PREFIX_and_OPENSSLDIR
  152. local buildenvs = import("package.tools.autoconf").buildenvs(package)
  153. local configs = {"--openssldir=" .. package:installdir(),
  154. "--prefix=" .. package:installdir()}
  155. table.insert(configs, package:config("shared") and "shared" or "no-shared")
  156. if package:debug() then
  157. table.insert(configs, "--debug")
  158. end
  159. if package:config("md2") then
  160. table.insert(configs, "enable-md2")
  161. end
  162. os.vrunv("./config", configs, {envs = buildenvs})
  163. local makeconfigs = {CFLAGS = buildenvs.CFLAGS, ASFLAGS = buildenvs.ASFLAGS}
  164. import("package.tools.make").build(package, makeconfigs)
  165. import("package.tools.make").make(package, {"install_sw"})
  166. if package:config("shared") then
  167. os.tryrm(path.join(package:installdir("lib"), "*.a"), path.join(package:installdir("lib64"), "*.a"))
  168. end
  169. if package:is_plat("linux") and os.isdir(package:installdir("lib64")) and package:is_arch("x86_64") then
  170. os.trycp(path.join(package:installdir("lib64"), "*"), package:installdir("lib"))
  171. end
  172. end)
  173. on_install("cross", "android", "iphoneos", "wasm", function (package)
  174. local target_arch = "generic32"
  175. if package:is_arch("x86_64") then
  176. target_arch = "x86_64"
  177. elseif package:is_arch("i386", "x86") then
  178. target_arch = "x86"
  179. elseif package:is_arch("arm64", "arm64-v8a") then
  180. target_arch = "aarch64"
  181. elseif package:is_arch("arm.*") then
  182. target_arch = "armv4"
  183. elseif package:is_arch(".*64") then
  184. target_arch = "generic64"
  185. end
  186. local target_plat = "linux"
  187. if package:is_plat("macosx") then
  188. target_plat = "darwin64"
  189. target_arch = "x86_64-cc"
  190. elseif package:is_plat("iphoneos") then
  191. local xcode = package:toolchain("xcode")
  192. local simulator = xcode and xcode:config("appledev") == "simulator"
  193. if simulator then
  194. target_plat = "iossimulator"
  195. target_arch = "xcrun"
  196. else
  197. if package:is_arch("arm64", "x86_64") then
  198. target_plat = "ios64"
  199. else
  200. target_plat = "ios"
  201. end
  202. target_arch = "cross"
  203. end
  204. end
  205. local target = target_plat .. "-" .. target_arch
  206. local configs = {target,
  207. "-DOPENSSL_NO_HEARTBEATS",
  208. "no-shared",
  209. "no-threads",
  210. "--openssldir=" .. package:installdir():gsub("\\", "/"),
  211. "--prefix=" .. package:installdir():gsub("\\", "/")}
  212. if package:config("md2") then
  213. table.insert(configs, "enable-md2")
  214. end
  215. if package:is_plat("wasm") then
  216. -- @see https://github.com/openssl/openssl/issues/12174
  217. table.insert(configs, "no-afalgeng")
  218. end
  219. local buildenvs = import("package.tools.autoconf").buildenvs(package)
  220. if (package:is_cross() and package:is_plat("android") and is_subhost("windows")) or
  221. package:is_plat("wasm") then
  222. buildenvs.CFLAGS = buildenvs.CFLAGS:gsub("\\", "/")
  223. buildenvs.CXXFLAGS = buildenvs.CXXFLAGS:gsub("\\", "/")
  224. buildenvs.CPPFLAGS = buildenvs.CPPFLAGS:gsub("\\", "/")
  225. buildenvs.ASFLAGS = buildenvs.ASFLAGS:gsub("\\", "/")
  226. os.vrunv("perl", table.join("./Configure", configs), {envs = buildenvs})
  227. else
  228. os.vrunv("./Configure", configs, {envs = buildenvs})
  229. end
  230. if is_host("windows") and package:is_plat("wasm") then
  231. io.replace("Makefile", "bat.exe", "bat", {plain = true})
  232. end
  233. local makeconfigs = {CFLAGS = buildenvs.CFLAGS, ASFLAGS = buildenvs.ASFLAGS}
  234. import("package.tools.make").build(package, makeconfigs)
  235. import("package.tools.make").make(package, {"install_sw"})
  236. end)
  237. on_test(function (package)
  238. assert(package:has_cfuncs("SSL_new", {includes = "openssl/ssl.h"}))
  239. end)