Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing the parameters when using dynamic mbedtls lib #2830

Closed
wants to merge 10 commits into from
36 changes: 30 additions & 6 deletions packages/m/mbedtls/xmake.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -18,17 +19,40 @@ package("mbedtls")

add_links("mbedtls", "mbedx509", "mbedcrypto")

if is_plat("windows") then
add_syslinks("advapi32")
if is_plat("windows", "mingw") then
add_syslinks("ws2_32", "advapi32", "bcrypt")
end

on_install(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"}
table.insert(configs, "-DBUILD_SHARED_LIBS=" .. (package:config("shared") and "ON" or "OFF"))
import("package.tools.cmake").install(package, configs)
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", "__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})
end
else
table.insert(configs, "-DUSE_SHARED_MBEDTLS_LIBRARY=OFF")
table.insert(configs, "-DUSE_STATIC_MBEDTLS_LIBRARY=ON")
end
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)
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)

Loading