From 094424ce5082f0e99a37c1d7f5a6fa25855b8d1b Mon Sep 17 00:00:00 2001 From: bruvzg <7645683+bruvzg@users.noreply.github.com> Date: Tue, 9 Mar 2021 11:26:03 +0200 Subject: [PATCH] Add macOS ARM64 (Apple Silicon) support. --- .github/workflows/build.yml | 4 ++-- .gitmodules | 1 + README.md | 2 -- SConstruct | 13 ++++++++----- build_libs_mac.sh | 11 +++++++++-- godot-cpp | 2 +- godot-git-plugin/src/git_common.h | 2 ++ 7 files changed, 23 insertions(+), 12 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 08615414..8837773d 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -54,7 +54,7 @@ jobs: scons platform=windows target=release build-macos-debug: - runs-on: macos-latest + runs-on: macos-11 steps: - uses: actions/checkout@v2 - name: macOS Debug @@ -64,7 +64,7 @@ jobs: scons platform=osx target=debug use_llvm=yes build-macos-release: - runs-on: macos-latest + runs-on: macos-11 steps: - uses: actions/checkout@v2 - name: macOS Release diff --git a/.gitmodules b/.gitmodules index d6a8a29a..22572994 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,4 @@ [submodule "godot-cpp"] path = godot-cpp url = https://github.com/godotengine/godot-cpp + branch = 3.x diff --git a/README.md b/README.md index 0023643c..31ff3d8b 100644 --- a/README.md +++ b/README.md @@ -44,8 +44,6 @@ Required build tools: 2. Run ```. ./build_libs_mac.sh Release```. 3. Run ```scons platform=osx target=release```. -**Note:** [Compiling for the Apple Silicon architecture is not supported yet.](https://github.com/godotengine/godot-git-plugin/issues/68) - #### Debug build Replace `Release` with `Debug` and `release` with `debug` in the above instructions for a debug build. You will also have to do the same in the paths mentioned in `demo/git_api.gdnlib` before opening the demo project in Godot. diff --git a/SConstruct b/SConstruct index fa4a02c8..00b931c1 100644 --- a/SConstruct +++ b/SConstruct @@ -45,11 +45,11 @@ if env['platform'] == "osx": cpp_library += '.osx' libgit2_lib_path += 'osx/' if env['target'] in ('debug', 'd'): - env.Append(CCFLAGS = ['-g','-O2', '-arch', 'x86_64', '-std=c++17']) - env.Append(LINKFLAGS = ['-arch', 'x86_64']) + env.Append(CCFLAGS = ['-g','-O2', '-arch', 'x86_64', '-arch', 'arm64', '-std=c++17']) + env.Append(LINKFLAGS = ['-arch', 'x86_64', '-arch', 'arm64']) else: - env.Append(CCFLAGS = ['-g','-O3', '-arch', 'x86_64', '-std=c++17']) - env.Append(LINKFLAGS = ['-arch', 'x86_64']) + env.Append(CCFLAGS = ['-g','-O3', '-arch', 'x86_64', '-arch', 'arm64', '-std=c++17']) + env.Append(LINKFLAGS = ['-arch', 'x86_64', '-arch', 'arm64']) elif env['platform'] in ('x11', 'linux'): env['target_path'] += 'x11/' @@ -82,7 +82,10 @@ else: cpp_library += '.release' env['target_path'] += 'release/' -cpp_library += '.' + str(bits) +if env['platform'] == 'osx': + cpp_library += '.universal' +else: + cpp_library += '.' + str(bits) # make sure our binding library properly includes env.Append(CPPPATH=['.', godot_headers_path, cpp_bindings_path + 'include/', cpp_bindings_path + 'include/core/', cpp_bindings_path + 'include/gen/']) diff --git a/build_libs_mac.sh b/build_libs_mac.sh index c8d538b0..8358d7e9 100755 --- a/build_libs_mac.sh +++ b/build_libs_mac.sh @@ -1,3 +1,4 @@ +#!/bin/sh git submodule init; git submodule update --init --recursive; @@ -5,7 +6,7 @@ cd godot-git-plugin/thirdparty/libgit2/ mkdir build cd build/ rm -f CMakeCache.txt -cmake .. -DCMAKE_POSITION_INDEPENDENT_CODE=ON -DBUILD_SHARED_LIBS=OFF -DBUILD_CLAR=OFF -DBUILD_EXAMPLES=OFF -DUSE_SSH=OFF -DUSE_HTTPS=OFF -DUSE_BUNDLED_ZLIB=ON -DUSE_ICONV=OFF +cmake .. -DCMAKE_C_FLAGS="-arch arm64 -arch x86_64" -DCMAKE_POSITION_INDEPENDENT_CODE=ON -DBUILD_SHARED_LIBS=OFF -DBUILD_CLAR=OFF -DBUILD_EXAMPLES=OFF -DUSE_SSH=OFF -DUSE_HTTPS=OFF -DUSE_BUNDLED_ZLIB=ON -DUSE_ICONV=OFF cmake --build . --config $1 cd ../../../../ mkdir -p "demo/bin/osx/" @@ -20,5 +21,11 @@ fi cd godot-cpp/; CORES=$(grep -c ^processor /proc/cpuinfo 2>/dev/null || sysctl -n hw.ncpu) -scons platform=osx target=$1 generate_bindings=yes bits=64 -j$CORES; +scons platform=osx target=$1 generate_bindings=yes macos_arch=x86_64 -j$CORES; +scons platform=osx target=$1 generate_bindings=yes macos_arch=arm64 -j$CORES; +shopt -s nocasematch; if [[ "release" =~ "$1" ]]; then + lipo -create ./bin/libgodot-cpp.osx.release.64.a ./bin/libgodot-cpp.osx.release.arm64.a -output ./bin/libgodot-cpp.osx.release.universal.a +else + lipo -create ./bin/libgodot-cpp.osx.debug.64.a ./bin/libgodot-cpp.osx.debug.arm64.a -output ./bin/libgodot-cpp.osx.debug.universal.a +fi cd .. diff --git a/godot-cpp b/godot-cpp index d7c55b1a..99e9dd1d 160000 --- a/godot-cpp +++ b/godot-cpp @@ -1 +1 @@ -Subproject commit d7c55b1ab2606253e94db5ed3caf75f90a47d03c +Subproject commit 99e9dd1d9396ed3af40678263b509078e5265ffc diff --git a/godot-git-plugin/src/git_common.h b/godot-git-plugin/src/git_common.h index 7c15cd1d..17674535 100644 --- a/godot-git-plugin/src/git_common.h +++ b/godot-git-plugin/src/git_common.h @@ -1,6 +1,8 @@ #ifndef GIT_COMMON_H #define GIT_COMMON_H +#include + #include #include