From a6772e0d3f944da070f3f7ac63600a98d33af796 Mon Sep 17 00:00:00 2001 From: Twarit Waikar Date: Wed, 13 Oct 2021 00:39:23 +0530 Subject: [PATCH] Change macOS builds to use OpenSSL purely as a static lib --- .github/workflows/build.yml | 33 ++++++++------------------------- README.md | 2 +- SConstruct | 2 +- godot-git-plugin/SCsub | 2 ++ thirdparty/git2/SCsub | 19 +++++-------------- thirdparty/ssh2/SCsub | 19 +++++++++---------- 6 files changed, 26 insertions(+), 51 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index cf10db5..5f5182f 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -3,11 +3,11 @@ name: C/C++ CI on: [push, pull_request] jobs: - linux: + linux-x64: runs-on: ubuntu-18.04 steps: - uses: actions/checkout@v2 - - name: build-linux-release + - name: build-linux-release-x64 run: | git submodule update --init --recursive pip3 install --user scons @@ -15,12 +15,12 @@ jobs: ldd demo/addons/godot-git-plugin/linux/libgitapi.so - uses: actions/upload-artifact@v2 with: - name: godot-git-plugin-linux-release-${{ github.sha }} + name: godot-git-plugin-linux-release-x64-${{ github.sha }} if-no-files-found: error path: | demo/ - windows: + windows-x64: runs-on: windows-2019 steps: - uses: actions/checkout@v2 @@ -29,7 +29,7 @@ jobs: python-version: "3.x" architecture: "x64" - uses: ilammy/msvc-dev-cmd@v1 - - name: build-windows-release + - name: build-windows-release-x64 run: | git submodule update --init --recursive pip3 install --user scons @@ -37,7 +37,7 @@ jobs: dumpbin /dependents .\demo\addons\godot-git-plugin\win64\libgitapi.dll - uses: actions/upload-artifact@v2 with: - name: godot-git-plugin-windows-release-${{ github.sha }} + name: godot-git-plugin-windows-release-x64-${{ github.sha }} if-no-files-found: error path: | demo/ @@ -46,10 +46,10 @@ jobs: runs-on: macos-11 steps: - uses: actions/checkout@v2 - - name: build-macos-release + - name: build-macos-release-x64 run: | git submodule update --init --recursive - brew install scons openssl@1.1 + 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) otool -L demo/addons/godot-git-plugin/osx/libgitapi.dylib - uses: actions/upload-artifact@v2 @@ -58,20 +58,3 @@ jobs: if-no-files-found: error path: | demo/ - - macos-arm64: - runs-on: macos-11 - steps: - - uses: actions/checkout@v2 - - name: build-macos-release - run: | - git submodule update --init --recursive - brew install scons openssl@1.1 - 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=arm64 macos_ssl_path=/usr/local/opt/openssl@1.1/ use_llvm=yes -j $(sysctl -n hw.logicalcpu) - otool -L demo/addons/godot-git-plugin/osx/libgitapi.dylib - - uses: actions/upload-artifact@v2 - with: - name: godot-git-plugin-macos-release-arm64-${{ github.sha }} - if-no-files-found: error - path: | - demo/ diff --git a/README.md b/README.md index 35c9fd7..1245fb5 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` and use the `macos_ssl_path` SCons argument. +- 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 Linux users, `sudo apt-get install libssl-dev`, or local package manager equivalent. ### Build diff --git a/SConstruct b/SConstruct index ceba3ea..4a43d4a 100644 --- a/SConstruct +++ b/SConstruct @@ -28,7 +28,7 @@ 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.", - "/usr/local/opt/openssl/", PathVariable.PathAccept)) + "/usr/local/opt/openssl@1.1/", 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 097b2d7..2505552 100644 --- a/godot-git-plugin/SCsub +++ b/godot-git-plugin/SCsub @@ -31,6 +31,8 @@ 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"]) 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 c95eff5..cdd7a94 100644 --- a/thirdparty/git2/SCsub +++ b/thirdparty/git2/SCsub @@ -28,13 +28,6 @@ if env_git["bits"] == 64: elif env_git["bits"] == 32: env_git.Prepend(CPPDEFINES=["GIT_ARCH_32"]) -if env_git["platform"] == "windows": - env_git.Prepend(CPPDEFINES=["GIT_WINHTTP"]) - libgit2_sources += Glob("libgit2/src/win32/" + "*.c") - -if env_git["platform"] in ["linux", "osx"]: - libgit2_sources += Glob("libgit2/src/unix/" + "*.c") - env_git.Prepend( CPPPATH=[ "libgit2/include/", @@ -61,8 +54,10 @@ env_git.Prepend( ) if env_git["platform"] == "windows": + libgit2_sources += Glob("libgit2/src/win32/" + "*.c") env_git.Prepend( CPPDEFINES=[ + "GIT_WINHTTP", "HAVE_SYS_STAT_H", "HAVE_SYS_TYPES_H", "HAVE_WINDOWS_H", @@ -92,6 +87,7 @@ if env_git["platform"] == "windows": if env_git["platform"] in ["linux", "osx"]: env_git.Append(CCFLAGS="-fPIC") + libgit2_sources += Glob("libgit2/src/unix/" + "*.c") libgit2_sources += [ "libgit2/deps/ntlmclient/crypt_openssl.c", "libgit2/deps/ntlmclient/unicode_builtin.c" @@ -131,13 +127,8 @@ if env_git["platform"] in ["linux", "osx"]: ) if env_git["platform"] == "osx": - # We link to OpenSSL dynamically only on macOS to allow universal builds - env_git.Prepend( - CPPDEFINES=[ - "CRYPT_OPENSSL_DYNAMIC", - ("GIT_OPENSSL_DYNAMIC", "1"), - ] - ) 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.StaticLibrary(target="../bin/" + "git2", source=libgit2_sources) diff --git a/thirdparty/ssh2/SCsub b/thirdparty/ssh2/SCsub index 18d8d83..6d91596 100644 --- a/thirdparty/ssh2/SCsub +++ b/thirdparty/ssh2/SCsub @@ -106,16 +106,15 @@ 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"]) - # We only link to OpenSSL dynamic libraries on macOS when we are - # doing a universal build, otherwise we do a static link - if env_ssh2["macos_arch"] == "universal": - env_ssh2.Append(CPPDEFINES=[ - ("WORDS_BIGENDIAN", "1"), - ("AC_APPLE_UNIVERSAL_BUILD", 1) - ]) - else: - env_ssh2.Append(LIBPATH=[env_ssh2["macos_ssl_path"] + "lib/"]) - env_ssh2.Append(LIBS=["ssl", "crypto"]) + # TODO: Verify if this works on actual M1 hardware + if env_ssh2["macos_arch"] == "arm64": + env_ssh2.Append( + CPPDEFINES=[ + ("WORDS_BIGENDIAN", "1"), + # ("AC_APPLE_UNIVERSAL_BUILD", "1") + ]) env_ssh2.StaticLibrary(target="../bin/" + "ssh2", source=libssh2_sources)