Skip to content

Commit 230fd4b

Browse files
authored
Merge pull request #634 from Faless/osx/universal
2 parents ad11bbb + 480ad9f commit 230fd4b

File tree

2 files changed

+16
-43
lines changed

2 files changed

+16
-43
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,8 @@ jobs:
9797
if-no-files-found: error
9898

9999
macos:
100-
name: Build (macOS, Clang)
101-
runs-on: macos-10.15
100+
name: Build (macOS, Clang, universal / x86_64 + arm64)
101+
runs-on: macos-11
102102
steps:
103103
- name: Checkout
104104
uses: actions/checkout@v2
@@ -118,40 +118,6 @@ jobs:
118118
run: |
119119
scons target=release generate_bindings=yes -j $(sysctl -n hw.logicalcpu)
120120
121-
- name: Upload artifact
122-
uses: actions/upload-artifact@v2
123-
with:
124-
name: godot-cpp-macos-x86_64-release
125-
path: bin/libgodot-cpp.osx.release.64.a
126-
if-no-files-found: error
127-
128-
macos-arm64:
129-
name: Build (macOS, Clang, cross-compile arm64)
130-
runs-on: macos-latest
131-
steps:
132-
- name: Checkout
133-
uses: actions/checkout@v2
134-
with:
135-
submodules: recursive
136-
137-
- name: Set up Python (for SCons)
138-
uses: actions/setup-python@v2
139-
with:
140-
python-version: '3.x'
141-
142-
- name: Install dependencies
143-
run: |
144-
python -m pip install scons
145-
146-
- name: Build godot-cpp
147-
run: |
148-
# The default SDK in github the actions environemnt seems to have problems compiling for arm64.
149-
# Use the latest 11.x SDK.
150-
SDK_BASE=/Library/Developer/CommandLineTools/SDKs
151-
SDK_VER=$(ls $SDK_BASE | grep "MacOSX11." | sort -r | head -n1)
152-
echo $SDK_BASE/$SDK_VER/
153-
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)
154-
155121
static-checks:
156122
name: Static Checks (clang-format)
157123
runs-on: ubuntu-20.04

SConstruct

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ elif sys.platform == "darwin":
7878
elif sys.platform == "win32" or sys.platform == "msys":
7979
host_platform = "windows"
8080
else:
81-
raise ValueError("Could not detect platform automatically, please specify with " "platform=<platform>")
81+
raise ValueError("Could not detect platform automatically, please specify with platform=<platform>")
8282

8383
env = Environment(ENV=os.environ)
8484

@@ -124,7 +124,7 @@ opts.Add(
124124
opts.Add(EnumVariable("android_arch", "Target Android architecture", "armv7", ["armv7", "arm64v8", "x86", "x86_64"]))
125125
opts.Add("macos_deployment_target", "macOS deployment target", "default")
126126
opts.Add("macos_sdk_path", "macOS SDK path", "")
127-
opts.Add(EnumVariable("macos_arch", "Target macOS architecture", "x86_64", ["x86_64", "arm64"]))
127+
opts.Add(EnumVariable("macos_arch", "Target macOS architecture", "universal", ["universal", "x86_64", "arm64"]))
128128
opts.Add(EnumVariable("ios_arch", "Target iOS architecture", "arm64", ["armv7", "arm64", "x86_64"]))
129129
opts.Add(BoolVariable("ios_simulator", "Target iOS Simulator", False))
130130
opts.Add(
@@ -187,7 +187,14 @@ elif env["platform"] == "osx":
187187
if env["bits"] == "32":
188188
raise ValueError("Only 64-bit builds are supported for the macOS target.")
189189

190-
env.Append(CCFLAGS=["-std=c++17", "-arch", env["macos_arch"]])
190+
if env["macos_arch"] == "universal":
191+
env.Append(LINKFLAGS=["-arch", "x86_64", "-arch", "arm64"])
192+
env.Append(CCFLAGS=["-arch", "x86_64", "-arch", "arm64"])
193+
else:
194+
env.Append(LINKFLAGS=["-arch", env["macos_arch"]])
195+
env.Append(CCFLAGS=["-arch", env["macos_arch"]])
196+
197+
env.Append(CCFLAGS=["-std=c++17"])
191198

192199
if env["macos_deployment_target"] != "default":
193200
env.Append(CCFLAGS=["-mmacosx-version-min=" + env["macos_deployment_target"]])
@@ -199,8 +206,6 @@ elif env["platform"] == "osx":
199206

200207
env.Append(
201208
LINKFLAGS=[
202-
"-arch",
203-
env["macos_arch"],
204209
"-framework",
205210
"Cocoa",
206211
"-Wl,-undefined,dynamic_lookup",
@@ -454,10 +459,12 @@ add_sources(sources, "gen/src/classes", "cpp")
454459
arch_suffix = env["bits"]
455460
if env["platform"] == "android":
456461
arch_suffix = env["android_arch"]
457-
if env["platform"] == "ios":
462+
elif env["platform"] == "ios":
458463
arch_suffix = env["ios_arch"]
459-
if env["platform"] == "javascript":
464+
elif env["platform"] == "javascript":
460465
arch_suffix = "wasm"
466+
elif env["platform"] == "osx":
467+
arch_suffix = env["macos_arch"]
461468

462469
library = env.StaticLibrary(
463470
target="bin/" + "libgodot-cpp.{}.{}.{}{}".format(env["platform"], env["target"], arch_suffix, env["LIBSUFFIX"]),

0 commit comments

Comments
 (0)