From 2095757996d1d02b9f8355cea56a3f51000155ea Mon Sep 17 00:00:00 2001 From: Twarit Waikar Date: Wed, 13 Oct 2021 02:21:31 +0530 Subject: [PATCH] Force static libssl.a and libcrypto.a linkage on macOS --- .github/workflows/build.yml | 2 +- README.md | 2 +- SConstruct | 7 ++++++- godot-git-plugin/SCsub | 7 +++++-- thirdparty/git2/SCsub | 7 ++++--- thirdparty/ssh2/SCsub | 7 ++++--- 6 files changed, 21 insertions(+), 11 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 5f5182f..baea548 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -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: diff --git a/README.md b/README.md index 1245fb5..ffd078c 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/SConstruct b/SConstruct index 4a43d4a..984603e 100644 --- a/SConstruct +++ b/SConstruct @@ -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) diff --git a/godot-git-plugin/SCsub b/godot-git-plugin/SCsub index 2505552..18f06b0 100644 --- a/godot-git-plugin/SCsub +++ b/godot-git-plugin/SCsub @@ -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"]) diff --git a/thirdparty/git2/SCsub b/thirdparty/git2/SCsub index cdd7a94..9d7359c 100644 --- a/thirdparty/git2/SCsub +++ b/thirdparty/git2/SCsub @@ -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) diff --git a/thirdparty/ssh2/SCsub b/thirdparty/ssh2/SCsub index 6d91596..82132ed 100644 --- a/thirdparty/ssh2/SCsub +++ b/thirdparty/ssh2/SCsub @@ -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":