xmake.lua 10 KB

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