Force static libssl.a and libcrypto.a linkage on macOS

This commit is contained in:
Twarit Waikar
2021-10-13 02:21:31 +05:30
parent b914319c20
commit 2095757996
6 changed files with 21 additions and 11 deletions

View File

@@ -50,7 +50,7 @@ jobs:
run: |
git submodule update --init --recursive
brew install scons
scons platform=osx target=release bits=64 godot_cpp=yes generate_bindings=yes use_custom_api_file=yes custom_api_file=api.ci.json macos_arch=x86_64 macos_ssl_path=/usr/local/opt/openssl@1.1/ use_llvm=yes -j $(sysctl -n hw.logicalcpu)
scons platform=osx target=release bits=64 godot_cpp=yes generate_bindings=yes use_custom_api_file=yes custom_api_file=api.ci.json macos_arch=x86_64 use_llvm=yes -j $(sysctl -n hw.logicalcpu)
otool -L demo/addons/godot-git-plugin/osx/libgitapi.dylib
- uses: actions/upload-artifact@v2
with:

View File

@@ -19,7 +19,7 @@ This section onwards is only meant to be used if you intend to compile the plugi
- [SCons](https://scons.org/pages/download.html) (v3.0.1+)
- C++17 and C90 compilers detectable by SCons and present in `PATH`.
- For Mac users, run `brew install openssl@1.1` and use the `macos_ssl_path` SCons argument which should contain the path to where Homebrew installed the OpenSSL library.
- For Mac users, run `brew install openssl@1.1`.
- For Linux users, `sudo apt-get install libssl-dev`, or local package manager equivalent.
### Build

View File

@@ -27,8 +27,13 @@ opts.Add(PathVariable("target_name", "The library name.",
opts.Add(EnumVariable("bits", "The bit architecture.", "64", ["64"]))
opts.Add(EnumVariable("macos_arch", "Target macOS architecture",
"universal", ["universal", "x86_64", "arm64"]))
opts.Add(PathVariable("macos_ssl_path", "Path to OpenSSL libraries - only used in macOS builds.",
opts.Add(PathVariable("macos_openssl", "Path to OpenSSL libraries - only used in macOS builds.",
"/usr/local/opt/openssl@1.1/", PathVariable.PathAccept))
opts.Add(PathVariable("macos_openssl_static_ssl", "Path to OpenSSL libssl.a library - only used in macOS builds.",
"/usr/local/opt/openssl@1.1/lib/libssl.1.1.a", PathVariable.PathAccept))
opts.Add(PathVariable("macos_openssl_static_crypto", "Path to OpenSSL libcrypto.a library - only used in macOS builds.",
"/usr/local/opt/openssl@1.1/lib/libcrypto.1.1.a", PathVariable.PathAccept))
# Updates the environment with the option variables.
opts.Update(env)

View File

@@ -31,8 +31,11 @@ if not os.path.isdir(env["target_path"]):
if env["platform"] == "osx":
env["target_path"] += "osx/"
cpp_library += ".osx"
env.Append(LIBPATH=[env["macos_ssl_path"] + "lib/"])
env.Append(LIBS=["ssl", "crypto"])
# Force static linkage (https://stackoverflow.com/a/2995999/7370948)
static_ssl = File(env["macos_openssl_static_ssl"])
static_crypto = File(env["macos_openssl_static_crypto"])
env.Append(LIBS=[static_ssl, static_crypto])
if env["target"] in ("debug", "d"):
env.Append(CCFLAGS=["-g", "-O2", "-std=c++17"])

View File

@@ -127,8 +127,9 @@ if env_git["platform"] in ["linux", "osx"]:
)
if env_git["platform"] == "osx":
env_git.Prepend(CPPPATH=[env_git["macos_ssl_path"] + "include/"])
env_git.Append(LIBPATH=[env_git["macos_ssl_path"] + "lib/"])
env_git.Append(LIBS=["ssl"])
env_git.Prepend(CPPPATH=[env_git["macos_openssl"] + "include/"])
static_ssl = File(env_git["macos_openssl_static_ssl"])
static_crypto = File(env_git["macos_openssl_static_crypto"])
env_git.Append(LIBS=[static_ssl, static_crypto])
env_git.StaticLibrary(target="../bin/" + "git2", source=libgit2_sources)

View File

@@ -105,9 +105,10 @@ if env_ssh2["platform"] in ["linux", "osx"]:
)
if env_ssh2["platform"] == "osx":
env_ssh2.Append(CPPPATH=[env_ssh2["macos_ssl_path"] + "include/"])
env_ssh2.Append(LIBPATH=[env_ssh2["macos_ssl_path"] + "lib/"])
env_ssh2.Append(LIBS=["ssl", "crypto"])
env_ssh2.Append(CPPPATH=[env_ssh2["macos_openssl"] + "include/"])
static_ssl = File(env_ssh2["macos_openssl_static_ssl"])
static_crypto = File(env_ssh2["macos_openssl_static_crypto"])
env_ssh2.Append(LIBS=[static_ssl, static_crypto])
# TODO: Verify if this works on actual M1 hardware
if env_ssh2["macos_arch"] == "arm64":