From 67f9109d1f47f4f351ae8ae16281bb2bd9203fd7 Mon Sep 17 00:00:00 2001 From: Fabio Alessandrelli Date: Wed, 29 Sep 2021 22:19:36 +0200 Subject: [PATCH 1/2] [OSX] Add universal build support. --- .github/workflows/ci.yml | 4 ++-- SConstruct | 21 ++++++++++++++------- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index fecd62e..a4b2703 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -116,13 +116,13 @@ jobs: - name: Build godot-cpp run: | - scons target=release generate_bindings=yes -j $(sysctl -n hw.logicalcpu) + scons target=release generate_bindings=yes macos_arch=x86_64 -j $(sysctl -n hw.logicalcpu) - name: Upload artifact uses: actions/upload-artifact@v2 with: name: godot-cpp-macos-x86_64-release - path: bin/libgodot-cpp.osx.release.64.a + path: bin/libgodot-cpp.osx.release.x86_64.a if-no-files-found: error macos-arm64: diff --git a/SConstruct b/SConstruct index a6f792c..ac76579 100644 --- a/SConstruct +++ b/SConstruct @@ -78,7 +78,7 @@ elif sys.platform == "darwin": elif sys.platform == "win32" or sys.platform == "msys": host_platform = "windows" else: - raise ValueError("Could not detect platform automatically, please specify with " "platform=") + raise ValueError("Could not detect platform automatically, please specify with platform=") env = Environment(ENV=os.environ) @@ -124,7 +124,7 @@ opts.Add( opts.Add(EnumVariable("android_arch", "Target Android architecture", "armv7", ["armv7", "arm64v8", "x86", "x86_64"])) opts.Add("macos_deployment_target", "macOS deployment target", "default") opts.Add("macos_sdk_path", "macOS SDK path", "") -opts.Add(EnumVariable("macos_arch", "Target macOS architecture", "x86_64", ["x86_64", "arm64"])) +opts.Add(EnumVariable("macos_arch", "Target macOS architecture", "universal", ["universal", "x86_64", "arm64"])) opts.Add(EnumVariable("ios_arch", "Target iOS architecture", "arm64", ["armv7", "arm64", "x86_64"])) opts.Add(BoolVariable("ios_simulator", "Target iOS Simulator", False)) opts.Add( @@ -187,7 +187,14 @@ elif env["platform"] == "osx": if env["bits"] == "32": raise ValueError("Only 64-bit builds are supported for the macOS target.") - env.Append(CCFLAGS=["-std=c++17", "-arch", env["macos_arch"]]) + if env["macos_arch"] == "universal": + env.Append(LINKFLAGS=["-arch", "x86_64", "-arch", "arm64"]) + env.Append(CCFLAGS=["-arch", "x86_64", "-arch", "arm64"]) + else: + env.Append(LINKFLAGS=["-arch", env["macos_arch"]]) + env.Append(CCFLAGS=["-arch", env["macos_arch"]]) + + env.Append(CCFLAGS=["-std=c++17"]) if env["macos_deployment_target"] != "default": env.Append(CCFLAGS=["-mmacosx-version-min=" + env["macos_deployment_target"]]) @@ -199,8 +206,6 @@ elif env["platform"] == "osx": env.Append( LINKFLAGS=[ - "-arch", - env["macos_arch"], "-framework", "Cocoa", "-Wl,-undefined,dynamic_lookup", @@ -454,10 +459,12 @@ add_sources(sources, "gen/src/classes", "cpp") arch_suffix = env["bits"] if env["platform"] == "android": arch_suffix = env["android_arch"] -if env["platform"] == "ios": +elif env["platform"] == "ios": arch_suffix = env["ios_arch"] -if env["platform"] == "javascript": +elif env["platform"] == "javascript": arch_suffix = "wasm" +elif env["platform"] == "osx": + arch_suffix = env["macos_arch"] library = env.StaticLibrary( target="bin/" + "libgodot-cpp.{}.{}.{}{}".format(env["platform"], env["target"], arch_suffix, env["LIBSUFFIX"]), From 480ad9ffed6a151c896ce1da24902f13dc1d69ed Mon Sep 17 00:00:00 2001 From: Fabio Alessandrelli Date: Wed, 29 Sep 2021 22:31:49 +0200 Subject: [PATCH 2/2] [CI] Make OSX universal build instead 2 builds. --- .github/workflows/ci.yml | 40 +++------------------------------------- 1 file changed, 3 insertions(+), 37 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a4b2703..bef4cfe 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -97,8 +97,8 @@ jobs: if-no-files-found: error macos: - name: Build (macOS, Clang) - runs-on: macos-10.15 + name: Build (macOS, Clang, universal / x86_64 + arm64) + runs-on: macos-11 steps: - name: Checkout uses: actions/checkout@v2 @@ -116,41 +116,7 @@ jobs: - name: Build godot-cpp run: | - scons target=release generate_bindings=yes macos_arch=x86_64 -j $(sysctl -n hw.logicalcpu) - - - name: Upload artifact - uses: actions/upload-artifact@v2 - with: - name: godot-cpp-macos-x86_64-release - path: bin/libgodot-cpp.osx.release.x86_64.a - if-no-files-found: error - - macos-arm64: - name: Build (macOS, Clang, cross-compile arm64) - runs-on: macos-latest - steps: - - name: Checkout - uses: actions/checkout@v2 - with: - submodules: recursive - - - name: Set up Python (for SCons) - uses: actions/setup-python@v2 - with: - python-version: '3.x' - - - name: Install dependencies - run: | - python -m pip install scons - - - name: Build godot-cpp - run: | - # The default SDK in github the actions environemnt seems to have problems compiling for arm64. - # Use the latest 11.x SDK. - SDK_BASE=/Library/Developer/CommandLineTools/SDKs - SDK_VER=$(ls $SDK_BASE | grep "MacOSX11." | sort -r | head -n1) - echo $SDK_BASE/$SDK_VER/ - scons target=release generate_bindings=yes macos_arch=arm64 macos_deployment_target=10.15 macos_sdk_path="$SDK_BASE/$SDK_VER/" -j $(sysctl -n hw.logicalcpu) + scons target=release generate_bindings=yes -j $(sysctl -n hw.logicalcpu) static-checks: name: Static Checks (clang-format)