Skip to content

Commit c9eb393

Browse files
committed
Use mbedTLS instead of OpenSSL
Build dependencies using cmake
1 parent fd85a8e commit c9eb393

11 files changed

Lines changed: 96 additions & 326 deletions

File tree

.gitmodules

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
[submodule "godot-cpp"]
22
path = godot-cpp
33
url = https://github.com/godotengine/godot-cpp
4-
branch = 3.x
54
[submodule "thirdparty/git2/libgit2"]
65
path = thirdparty/git2/libgit2
76
url = https://github.com/libgit2/libgit2
87
ignore = untracked
98
[submodule "thirdparty/ssh2/libssh2"]
109
path = thirdparty/ssh2/libssh2
1110
url = https://github.com/libssh2/libssh2
12-
[submodule "thirdparty/openssl"]
13-
path = thirdparty/openssl
14-
url = https://github.com/openssl/openssl
11+
[submodule "thirdparty/mbedtls"]
12+
path = thirdparty/mbedtls
13+
url = https://github.com/Mbed-TLS/mbedtls.git

SConstruct

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,22 +29,19 @@ env.PrependENVPath("PATH", os.getenv("PATH")) # Prepend PATH, done upstream in
2929
if env["platform"] == "windows" and env.get("is_msvc", False):
3030
env.AppendUnique(LINKFLAGS=["/LTCG"])
3131

32-
# OpenSSL Builder
33-
env.Tool("openssl", toolpath=["tools"])
34-
35-
# SSH2 Builder
3632
env.Tool("cmake", toolpath=["tools"])
33+
env.Tool("mbedtls", toolpath=["tools"])
3734
env.Tool("ssh2", toolpath=["tools"])
3835
env.Tool("git2", toolpath=["tools"])
3936

4037
opts.Update(env)
4138

42-
ssl = env.OpenSSL()
43-
ssh2 = env.BuildSSH2(ssl)
44-
ssl += ssh2
45-
git2 = env.BuildGIT2(ssl)
39+
mbedtls = env.BuildMbedTLS()
40+
ssh2 = env.BuildSSH2(mbedtls)
41+
mbedtls += ssh2
42+
git2 = env.BuildGIT2(mbedtls)
4643

47-
Export("ssl")
44+
Export("mbedtls")
4845
Export("env")
4946

5047
SConscript("godot-git-plugin/SCsub")

godot-git-plugin/SCsub

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import os
44

55
env = {}
66
Import("env")
7-
Import("ssl")
7+
Import("mbedtls")
88

99
# Process some arguments
1010
if env["use_llvm"]:
@@ -46,7 +46,7 @@ env.Append(CPPPATH=[".", "src/"])
4646
env.Append(CPPPATH=["#thirdparty/git2/libgit2/include/"])
4747

4848
lib_sources = Glob("src/*.cpp")
49-
env.Depends(lib_sources, ssl)
49+
env.Depends(lib_sources, mbedtls)
5050
library = env.SharedLibrary(
5151
target=env["target_path"] +
5252
"{}{}{}".format(env["target_name"], env["suffix"], env["SHLIBSUFFIX"]),

thirdparty/git2/libgit2

Submodule libgit2 updated 606 files

thirdparty/mbedtls

Submodule mbedtls added at 22098d4

thirdparty/openssl

Lines changed: 0 additions & 1 deletion
This file was deleted.

thirdparty/ssh2/libssh2

Submodule libssh2 updated 417 files

tools/git2.py

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,23 @@
44
def build_library(env, deps):
55
config = {
66
"CMAKE_BUILD_TYPE": "RelWithDebInfo" if env["debug_symbols"] else "Release",
7-
"OPENSSL_USE_STATIC_LIBS": 1,
8-
"OPENSSL_INCLUDE_DIR": env["SSL_INCLUDE"],
9-
"OPENSSL_SSL_LIBRARY": env["SSL_LIBRARY"],
10-
"OPENSSL_CRYPTO_LIBRARY": env["SSL_CRYPTO_LIBRARY"],
11-
"OPENSSL_ROOT_DIR": env["SSL_INSTALL"],
7+
"CMAKE_C_STANDARD": "99",
8+
"USE_SHARED_MBEDTLS_LIBRARY": 0,
9+
"USE_STATIC_MBEDTLS_LIBRARY": 1,
10+
"MBEDTLS_LIBRARY": env["MBEDTLS_LIBRARY"],
11+
"MBEDCRYPTO_LIBRARY": env["MBEDTLS_CRYPTO_LIBRARY"],
12+
"MBEDX509_LIBRARY": env["MBEDTLS_X509_LIBRARY"],
13+
"MBEDTLS_INCLUDE_DIR": env["MBEDTLS_INCLUDE"],
1214
"BUILD_TESTS": 0,
1315
"BUILD_CLI": 0,
1416
"BUILD_EXAMPLES": 0,
1517
"BUILD_FUZZERS": 0,
16-
"USE_SSH": 1,
17-
"USE_HTTPS": 1,
18-
"USE_SHA1": 1,
18+
"USE_SSH": "libssh2",
1919
"USE_BUNDLED_ZLIB": 1,
2020
"USE_HTTP_PARSER": "builtin",
2121
"REGEX_BACKEND": "builtin",
22-
"USE_HTTPS": "OpenSSL",
23-
"USE_SHA1": "OpenSSL",
22+
"USE_HTTPS": "mbedTLS",
23+
"USE_SHA1": "mbedTLS",
2424
"BUILD_SHARED_LIBS": 0,
2525
"LINK_WITH_STATIC_LIBRARIES": 1,
2626
"LIBSSH2_INCLUDE_DIR": env.Dir("#thirdparty/ssh2/libssh2/include").abspath,
@@ -31,8 +31,6 @@ def build_library(env, deps):
3131

3232
if env["platform"] != "windows":
3333
config["CMAKE_C_FLAGS"] = "-fPIC"
34-
else:
35-
config["OPENSSL_ROOT_DIR"] = env["SSL_BUILD"]
3634

3735
is_msvc = env.get("is_msvc", False)
3836
lib_ext = ".lib" if is_msvc else ".a"

tools/mbedtls.py

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
def build_library(env):
2+
mbedtls_bin = env.Dir("bin/thirdparty/mbedtls/{}/{}/install".format(env["platform"], env["arch"]))
3+
is_msvc = env.get("is_msvc", False)
4+
c_flags = "-DMBEDTLS_SSL_DTLS_SRTP"
5+
if env["platform"] == "linux":
6+
# This is needed on some arch when building with the godot buildroot toolchain
7+
c_flags += " -fPIC"
8+
elif env["platform"] == "windows" and not is_msvc:
9+
c_flags += " -D__USE_MINGW_ANSI_STDIO=0" # See https://github.com/Mbed-TLS/mbedtls/issues/10161
10+
11+
mbedtls_config = {
12+
"CMAKE_BUILD_TYPE": "RelWithDebInfo" if env["debug_symbols"] else "Release",
13+
"ENABLE_TESTING": 0,
14+
"ENABLE_PROGRAMS": 0,
15+
"CMAKE_INSTALL_PREFIX": env.Dir(mbedtls_bin).abspath,
16+
"CMAKE_C_FLAGS": c_flags,
17+
}
18+
lib_ext = ".lib" if is_msvc else ".a"
19+
lib_prefix = "" if is_msvc else "lib"
20+
mbedtls_libs = [
21+
"/install/lib/{}mbedtls{}".format(lib_prefix, lib_ext),
22+
"/install/lib/{}mbedx509{}".format(lib_prefix, lib_ext),
23+
"/install/lib/{}mbedcrypto{}".format(lib_prefix, lib_ext),
24+
]
25+
26+
mbedtls_cmake_config = [
27+
"/install/lib/cmake/MbedTLS/MbedTLSConfig.cmake",
28+
"/install/lib/cmake/MbedTLS/MbedTLSConfigVersion.cmake",
29+
"/install/lib/cmake/MbedTLS/MbedTLSTargets.cmake",
30+
]
31+
32+
# Build libdatachannel
33+
mbedtls = env.CMakeBuild(
34+
env.Dir("bin/thirdparty/mbedtls/"),
35+
env.Dir("thirdparty/mbedtls"),
36+
cmake_options=mbedtls_config,
37+
cmake_outputs=mbedtls_libs + mbedtls_cmake_config,
38+
install=True,
39+
)
40+
41+
# Configure env.
42+
if env["platform"] == "windows":
43+
env.PrependUnique(LIBS=["bcrypt", "ws2_32", "iphlpapi"])
44+
if env["platform"] == "linux":
45+
env.PrependUnique(LIBS=["pthread"])
46+
env.Prepend(LIBS=list(filter(lambda f: str(f).endswith(lib_ext), mbedtls)))
47+
env.Append(CPPPATH=[env.Dir("thirdparty/mbedtls/include")])
48+
49+
return mbedtls
50+
51+
52+
def exists(env):
53+
return "CMake" in env
54+
55+
56+
def generate(env):
57+
mbedtls_install_dir = "bin/thirdparty/mbedtls/{}/{}/install".format(env["platform"], env["arch"])
58+
lib_ext = ".lib" if env.get("is_msvc", False) else ".a"
59+
mbedtls = env.File(mbedtls_install_dir + "/lib/libmbedtls" + lib_ext)
60+
crypto = env.File(mbedtls_install_dir + "/lib/libmbedcrypto" + lib_ext)
61+
x509 = env.File(mbedtls_install_dir + "/lib/libmbedx509" + lib_ext)
62+
includes = env.Dir("thirdparty/mbedtls/include")
63+
env.AddMethod(build_library, "BuildMbedTLS")
64+
env["MBEDTLS_LIBRARY"] = mbedtls.abspath
65+
env["MBEDTLS_CRYPTO_LIBRARY"] = crypto.abspath
66+
env["MBEDTLS_X509_LIBRARY"] = x509.abspath
67+
env["MBEDTLS_INCLUDE"] = includes.abspath

0 commit comments

Comments
 (0)