2
0

xmake.lua 13 KB

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