From 03e3dc72d2ea0cc8d0f770577f6c2c3e6f897d29 Mon Sep 17 00:00:00 2001 From: xpxz <97490782+heheda123123@users.noreply.github.com> Date: Wed, 15 Nov 2023 18:41:56 +0800 Subject: [PATCH 01/10] Fixing the parameters when using dynamic mbedtls lib --- packages/m/mbedtls/xmake.lua | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/m/mbedtls/xmake.lua b/packages/m/mbedtls/xmake.lua index 8503474c92f..69b35e8a02f 100644 --- a/packages/m/mbedtls/xmake.lua +++ b/packages/m/mbedtls/xmake.lua @@ -24,7 +24,8 @@ package("mbedtls") on_install(function (package) local configs = {"-DENABLE_TESTING=OFF", "-DENABLE_PROGRAMS=OFF", "-DMBEDTLS_FATAL_WARNINGS=OFF"} - table.insert(configs, "-DBUILD_SHARED_LIBS=" .. (package:config("shared") and "ON" or "OFF")) + table.insert(configs, "-DUSE_SHARED_MBEDTLS_LIBRARY=" .. (package:config("shared") and "ON" or "OFF")) + table.insert(configs, "-DUSE_STATIC_MBEDTLS_LIBRARY=" .. (package:config("shared") and "OFF" or "ON")) import("package.tools.cmake").install(package, configs) end) From 4c55946bc7ad17bcdb6abd4d1b221201de10a9b5 Mon Sep 17 00:00:00 2001 From: xpxz <97490782+heheda123123@users.noreply.github.com> Date: Wed, 15 Nov 2023 20:02:32 +0800 Subject: [PATCH 02/10] update mbedtls to 3.5.1 --- packages/m/mbedtls/xmake.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/m/mbedtls/xmake.lua b/packages/m/mbedtls/xmake.lua index 69b35e8a02f..ea7ddb4e345 100644 --- a/packages/m/mbedtls/xmake.lua +++ b/packages/m/mbedtls/xmake.lua @@ -8,6 +8,7 @@ package("mbedtls") end}) add_urls("https://github.com/Mbed-TLS/mbedtls.git") + add_versions("v3.5.1", "959a492721ba036afc21f04d1836d874f93ac124cf47cf62c9bcd3a753e49bdb") add_versions("v3.4.0", "9969088c86eb89f6f0a131e699c46ff57058288410f2087bd0d308f65e9fccb5") add_versions("v2.28.3", "0c0abbd6e33566c5c3c15af4fc19466c8edb62fa483d4ce98f1ba3f656656d2d") add_versions("v2.25.0", "6bf01ef178925f7db3c9027344a50855b116f2defe4a24cbdc0220111a371597") From 99d49c869beaebf651b4a7ea39ed108b98d131f4 Mon Sep 17 00:00:00 2001 From: xpxz <97490782+heheda123123@users.noreply.github.com> Date: Wed, 15 Nov 2023 20:48:23 +0800 Subject: [PATCH 03/10] Update xmake.lua --- packages/m/mbedtls/xmake.lua | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/packages/m/mbedtls/xmake.lua b/packages/m/mbedtls/xmake.lua index ea7ddb4e345..4017103c6fe 100644 --- a/packages/m/mbedtls/xmake.lua +++ b/packages/m/mbedtls/xmake.lua @@ -20,7 +20,9 @@ package("mbedtls") add_links("mbedtls", "mbedx509", "mbedcrypto") if is_plat("windows") then - add_syslinks("advapi32") + # https://github.com/Mbed-TLS/mbedtls/issues/1130 + add_configs("shared", {description = "Download shared binaries.", default = false, type = "boolean", readonly = true}) + add_syslinks("advapi32", "bcrypt") end on_install(function (package) @@ -32,5 +34,13 @@ package("mbedtls") on_test(function (package) assert(package:has_cfuncs("mbedtls_ssl_init", {includes = "mbedtls/ssl.h"})) + assert(package:check_cxxsnippets({test = [[ + void test() { + mbedtls_aes_context ctx; + + unsigned char key[32]; + mbedtls_aes_setkey_enc(&ctx, key, 256); + } + ]]}, {includes = "mbedtls/aes.h"})) end) From 44b31854b9c66aaaa940d8e155d95ff1dfc1afff Mon Sep 17 00:00:00 2001 From: xpxz <97490782+heheda123123@users.noreply.github.com> Date: Wed, 15 Nov 2023 20:51:16 +0800 Subject: [PATCH 04/10] Update xmake.lua --- packages/m/mbedtls/xmake.lua | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/packages/m/mbedtls/xmake.lua b/packages/m/mbedtls/xmake.lua index 4017103c6fe..c6826d538db 100644 --- a/packages/m/mbedtls/xmake.lua +++ b/packages/m/mbedtls/xmake.lua @@ -3,6 +3,11 @@ package("mbedtls") set_description("An SSL library") set_license("Apache-2.0") + if is_plat("windows") then + # https://github.com/Mbed-TLS/mbedtls/issues/1130 + add_configs("shared", {description = "Download shared binaries.", default = false, type = "boolean", readonly = true}) + end + add_urls("https://github.com/Mbed-TLS/mbedtls/archive/refs/tags/$(version).zip", {version = function (version) return version:ge("v2.23.0") and version or ("mbedtls-" .. tostring(version):sub(2)) end}) @@ -20,8 +25,6 @@ package("mbedtls") add_links("mbedtls", "mbedx509", "mbedcrypto") if is_plat("windows") then - # https://github.com/Mbed-TLS/mbedtls/issues/1130 - add_configs("shared", {description = "Download shared binaries.", default = false, type = "boolean", readonly = true}) add_syslinks("advapi32", "bcrypt") end From 6664a3728746fe2a7fd3c61c5b1bb023e4f5d1d5 Mon Sep 17 00:00:00 2001 From: xpxz <97490782+heheda123123@users.noreply.github.com> Date: Wed, 15 Nov 2023 20:53:04 +0800 Subject: [PATCH 05/10] Update xmake.lua --- packages/m/mbedtls/xmake.lua | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/m/mbedtls/xmake.lua b/packages/m/mbedtls/xmake.lua index c6826d538db..c7b65a45c5b 100644 --- a/packages/m/mbedtls/xmake.lua +++ b/packages/m/mbedtls/xmake.lua @@ -4,7 +4,6 @@ package("mbedtls") set_license("Apache-2.0") if is_plat("windows") then - # https://github.com/Mbed-TLS/mbedtls/issues/1130 add_configs("shared", {description = "Download shared binaries.", default = false, type = "boolean", readonly = true}) end From 9a4ef3a0164f77983b62fe1adcef8bad8c9c6e3d Mon Sep 17 00:00:00 2001 From: star9029 Date: Wed, 15 Nov 2023 23:54:24 +0800 Subject: [PATCH 06/10] hack for shared --- packages/m/mbedtls/xmake.lua | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/packages/m/mbedtls/xmake.lua b/packages/m/mbedtls/xmake.lua index c7b65a45c5b..bfea2598c54 100644 --- a/packages/m/mbedtls/xmake.lua +++ b/packages/m/mbedtls/xmake.lua @@ -3,10 +3,6 @@ package("mbedtls") set_description("An SSL library") set_license("Apache-2.0") - if is_plat("windows") then - add_configs("shared", {description = "Download shared binaries.", default = false, type = "boolean", readonly = true}) - end - add_urls("https://github.com/Mbed-TLS/mbedtls/archive/refs/tags/$(version).zip", {version = function (version) return version:ge("v2.23.0") and version or ("mbedtls-" .. tostring(version):sub(2)) end}) @@ -27,10 +23,26 @@ package("mbedtls") add_syslinks("advapi32", "bcrypt") end - on_install(function (package) + on_install("windows|x86", "windows|x64", "linux", "macosx", "bsd", "mingw", "msys", "android", "iphoneos", "cross", "wasm", function (package) + package:config_set("shared", true) local configs = {"-DENABLE_TESTING=OFF", "-DENABLE_PROGRAMS=OFF", "-DMBEDTLS_FATAL_WARNINGS=OFF"} - table.insert(configs, "-DUSE_SHARED_MBEDTLS_LIBRARY=" .. (package:config("shared") and "ON" or "OFF")) - table.insert(configs, "-DUSE_STATIC_MBEDTLS_LIBRARY=" .. (package:config("shared") and "OFF" or "ON")) + if package:config("shared") then + table.insert(configs, "-DUSE_SHARED_MBEDTLS_LIBRARY=ON") + table.insert(configs, "-DUSE_STATIC_MBEDTLS_LIBRARY=OFF") + if package:is_plat("windows") then + table.insert(configs, "-DCMAKE_WINDOWS_EXPORT_ALL_SYMBOLS=ON") + io.replace("library/constant_time_impl.h", "extern volatile", "volatile", {plain = true}) + io.replace("include/mbedtls/x509_crt.h", "extern const mbedtls_x509_crt_profile mbedtls_x509_crt_profile_suiteb;", "const mbedtls_x509_crt_profile mbedtls_x509_crt_profile_suiteb;", {plain = true}) + io.replace("include/mbedtls/x509_crt.h", "extern const mbedtls_x509_crt_profile mbedtls_x509_crt_profile_default;", "const mbedtls_x509_crt_profile mbedtls_x509_crt_profile_default;", {plain = true}) + elseif package:is_plat("mingw") then + io.replace("library/constant_time_impl.h", "inline volatile", "volatile", {plain = true}) + io.replace("include/mbedtls/x509_crt.h", "inline const mbedtls_x509_crt_profile mbedtls_x509_crt_profile_suiteb;", "const mbedtls_x509_crt_profile mbedtls_x509_crt_profile_suiteb;", {plain = true}) + io.replace("include/mbedtls/x509_crt.h", "inline const mbedtls_x509_crt_profile mbedtls_x509_crt_profile_default;", "const mbedtls_x509_crt_profile mbedtls_x509_crt_profile_default;", {plain = true}) + end + else + table.insert(configs, "-DUSE_SHARED_MBEDTLS_LIBRARY=OFF") + table.insert(configs, "-DUSE_STATIC_MBEDTLS_LIBRARY=ON") + end import("package.tools.cmake").install(package, configs) end) @@ -45,4 +57,3 @@ package("mbedtls") } ]]}, {includes = "mbedtls/aes.h"})) end) - From a9a996399e4f1c6d57e3a4cb977466b723d03176 Mon Sep 17 00:00:00 2001 From: star9029 Date: Thu, 16 Nov 2023 00:34:10 +0800 Subject: [PATCH 07/10] use dllimport --- packages/m/mbedtls/xmake.lua | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/packages/m/mbedtls/xmake.lua b/packages/m/mbedtls/xmake.lua index bfea2598c54..ffe239056db 100644 --- a/packages/m/mbedtls/xmake.lua +++ b/packages/m/mbedtls/xmake.lua @@ -24,20 +24,19 @@ package("mbedtls") end on_install("windows|x86", "windows|x64", "linux", "macosx", "bsd", "mingw", "msys", "android", "iphoneos", "cross", "wasm", function (package) - package:config_set("shared", true) local configs = {"-DENABLE_TESTING=OFF", "-DENABLE_PROGRAMS=OFF", "-DMBEDTLS_FATAL_WARNINGS=OFF"} if package:config("shared") then table.insert(configs, "-DUSE_SHARED_MBEDTLS_LIBRARY=ON") table.insert(configs, "-DUSE_STATIC_MBEDTLS_LIBRARY=OFF") if package:is_plat("windows") then table.insert(configs, "-DCMAKE_WINDOWS_EXPORT_ALL_SYMBOLS=ON") - io.replace("library/constant_time_impl.h", "extern volatile", "volatile", {plain = true}) - io.replace("include/mbedtls/x509_crt.h", "extern const mbedtls_x509_crt_profile mbedtls_x509_crt_profile_suiteb;", "const mbedtls_x509_crt_profile mbedtls_x509_crt_profile_suiteb;", {plain = true}) - io.replace("include/mbedtls/x509_crt.h", "extern const mbedtls_x509_crt_profile mbedtls_x509_crt_profile_default;", "const mbedtls_x509_crt_profile mbedtls_x509_crt_profile_default;", {plain = true}) + io.replace("library/constant_time_impl.h", "extern volatile", "__declspec(dllimport) volatile", {plain = true}) + io.replace("include/mbedtls/x509_crt.h", "extern const mbedtls_x509_crt_profile mbedtls_x509_crt_profile_suiteb;", "__declspec(dllimport) const mbedtls_x509_crt_profile mbedtls_x509_crt_profile_suiteb;", {plain = true}) + io.replace("include/mbedtls/x509_crt.h", "extern const mbedtls_x509_crt_profile mbedtls_x509_crt_profile_default;", "__declspec(dllimport) const mbedtls_x509_crt_profile mbedtls_x509_crt_profile_default;", {plain = true}) elseif package:is_plat("mingw") then - io.replace("library/constant_time_impl.h", "inline volatile", "volatile", {plain = true}) - io.replace("include/mbedtls/x509_crt.h", "inline const mbedtls_x509_crt_profile mbedtls_x509_crt_profile_suiteb;", "const mbedtls_x509_crt_profile mbedtls_x509_crt_profile_suiteb;", {plain = true}) - io.replace("include/mbedtls/x509_crt.h", "inline const mbedtls_x509_crt_profile mbedtls_x509_crt_profile_default;", "const mbedtls_x509_crt_profile mbedtls_x509_crt_profile_default;", {plain = true}) + io.replace("library/constant_time_impl.h", "__attribute__ ((dllimport)) volatile", "volatile", {plain = true}) + io.replace("include/mbedtls/x509_crt.h", "__attribute__ ((dllimport)) const mbedtls_x509_crt_profile mbedtls_x509_crt_profile_suiteb;", "const mbedtls_x509_crt_profile mbedtls_x509_crt_profile_suiteb;", {plain = true}) + io.replace("include/mbedtls/x509_crt.h", "__attribute__ ((dllimport)) const mbedtls_x509_crt_profile mbedtls_x509_crt_profile_default;", "const mbedtls_x509_crt_profile mbedtls_x509_crt_profile_default;", {plain = true}) end else table.insert(configs, "-DUSE_SHARED_MBEDTLS_LIBRARY=OFF") From bc02c3248b67825fe91178b6720d3161a5b95e17 Mon Sep 17 00:00:00 2001 From: star9029 Date: Thu, 16 Nov 2023 00:37:59 +0800 Subject: [PATCH 08/10] remove mingw code --- packages/m/mbedtls/xmake.lua | 4 ---- 1 file changed, 4 deletions(-) diff --git a/packages/m/mbedtls/xmake.lua b/packages/m/mbedtls/xmake.lua index ffe239056db..c02edd35920 100644 --- a/packages/m/mbedtls/xmake.lua +++ b/packages/m/mbedtls/xmake.lua @@ -33,10 +33,6 @@ package("mbedtls") io.replace("library/constant_time_impl.h", "extern volatile", "__declspec(dllimport) volatile", {plain = true}) io.replace("include/mbedtls/x509_crt.h", "extern const mbedtls_x509_crt_profile mbedtls_x509_crt_profile_suiteb;", "__declspec(dllimport) const mbedtls_x509_crt_profile mbedtls_x509_crt_profile_suiteb;", {plain = true}) io.replace("include/mbedtls/x509_crt.h", "extern const mbedtls_x509_crt_profile mbedtls_x509_crt_profile_default;", "__declspec(dllimport) const mbedtls_x509_crt_profile mbedtls_x509_crt_profile_default;", {plain = true}) - elseif package:is_plat("mingw") then - io.replace("library/constant_time_impl.h", "__attribute__ ((dllimport)) volatile", "volatile", {plain = true}) - io.replace("include/mbedtls/x509_crt.h", "__attribute__ ((dllimport)) const mbedtls_x509_crt_profile mbedtls_x509_crt_profile_suiteb;", "const mbedtls_x509_crt_profile mbedtls_x509_crt_profile_suiteb;", {plain = true}) - io.replace("include/mbedtls/x509_crt.h", "__attribute__ ((dllimport)) const mbedtls_x509_crt_profile mbedtls_x509_crt_profile_default;", "const mbedtls_x509_crt_profile mbedtls_x509_crt_profile_default;", {plain = true}) end else table.insert(configs, "-DUSE_SHARED_MBEDTLS_LIBRARY=OFF") From f0c0fa9c3528ff325de293312f22255089beb696 Mon Sep 17 00:00:00 2001 From: ruki Date: Wed, 15 Nov 2023 19:31:02 -0600 Subject: [PATCH 09/10] Update xmake.lua --- packages/m/mbedtls/xmake.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/m/mbedtls/xmake.lua b/packages/m/mbedtls/xmake.lua index c02edd35920..9a4a0793a9a 100644 --- a/packages/m/mbedtls/xmake.lua +++ b/packages/m/mbedtls/xmake.lua @@ -19,8 +19,8 @@ package("mbedtls") add_links("mbedtls", "mbedx509", "mbedcrypto") - if is_plat("windows") then - add_syslinks("advapi32", "bcrypt") + if is_plat("windows", "mingw") then + add_syslinks("ws2_32", "advapi32", "bcrypt") end on_install("windows|x86", "windows|x64", "linux", "macosx", "bsd", "mingw", "msys", "android", "iphoneos", "cross", "wasm", function (package) From dc500c4e133e8a122868e7efdf5ae6ae93909c22 Mon Sep 17 00:00:00 2001 From: ruki Date: Fri, 17 Nov 2023 09:22:09 -0600 Subject: [PATCH 10/10] Update xmake.lua --- packages/m/mbedtls/xmake.lua | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/packages/m/mbedtls/xmake.lua b/packages/m/mbedtls/xmake.lua index 9a4a0793a9a..ae7306b7ece 100644 --- a/packages/m/mbedtls/xmake.lua +++ b/packages/m/mbedtls/xmake.lua @@ -23,7 +23,7 @@ package("mbedtls") add_syslinks("ws2_32", "advapi32", "bcrypt") end - on_install("windows|x86", "windows|x64", "linux", "macosx", "bsd", "mingw", "msys", "android", "iphoneos", "cross", "wasm", function (package) + on_install("windows|x86", "windows|x64", "linux", "macosx", "bsd", "mingw", "android", "iphoneos", "cross", "wasm", function (package) local configs = {"-DENABLE_TESTING=OFF", "-DENABLE_PROGRAMS=OFF", "-DMBEDTLS_FATAL_WARNINGS=OFF"} if package:config("shared") then table.insert(configs, "-DUSE_SHARED_MBEDTLS_LIBRARY=ON") @@ -38,7 +38,11 @@ package("mbedtls") table.insert(configs, "-DUSE_SHARED_MBEDTLS_LIBRARY=OFF") table.insert(configs, "-DUSE_STATIC_MBEDTLS_LIBRARY=ON") end - import("package.tools.cmake").install(package, configs) + local cxflags + if package:is_plat("mingw") and package:is_arch("i386") then + cxflags = {"-maes", "-msse2", "-mpclmul"} + end + import("package.tools.cmake").install(package, configs, {cxflags = cxflags}) end) on_test(function (package)