Skip to content

Commit 900a4d0

Browse files
committed
Unify bits, macos_arch into arch, support non-x86 Linux
1 parent 7c09b54 commit 900a4d0

File tree

3 files changed

+83
-36
lines changed

3 files changed

+83
-36
lines changed

.github/workflows/ci.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ jobs:
1717
fail-fast: false
1818
matrix:
1919
include:
20-
- name: 🐧 Linux (GCC)
20+
- name: 🐧 Linux (x86_64, GCC)
2121
os: ubuntu-18.04
2222
platform: linux
2323
artifact-name: godot-cpp-linux-glibc2.27-x86_64-release
24-
artifact-path: bin/libgodot-cpp.linux.release.64.a
24+
artifact-path: bin/libgodot-cpp.linux.release.x86_64.a
2525
godot_zip: Godot_v3.5-stable_linux_server.64.zip
2626
executable: Godot_v3.5-stable_linux_server.64
2727
cache-name: linux-x86_64
@@ -30,22 +30,22 @@ jobs:
3030
os: windows-2019
3131
platform: windows
3232
artifact-name: godot-cpp-windows-msvc2019-x86_64-release
33-
artifact-path: bin/libgodot-cpp.windows.release.64.lib
33+
artifact-path: bin/libgodot-cpp.windows.release.x86_64.lib
3434
cache-name: windows-x86_64-msvc
3535

3636
- name: 🏁 Windows (x86_64, MinGW)
3737
os: windows-2019
3838
platform: windows
3939
artifact-name: godot-cpp-linux-mingw-x86_64-release
40-
artifact-path: bin/libgodot-cpp.windows.release.64.a
40+
artifact-path: bin/libgodot-cpp.windows.release.x86_64.a
4141
flags: use_mingw=yes
4242
cache-name: windows-x86_64-mingw
4343

4444
- name: 🍎 macOS (universal)
4545
os: macos-11
4646
platform: osx
4747
artifact-name: godot-cpp-macos-universal-release
48-
artifact-path: bin/libgodot-cpp.osx.release.64.a
48+
artifact-path: bin/libgodot-cpp.osx.release.universal.a
4949
flags: macos_arch=universal
5050
godot_zip: Godot_v3.5-stable_osx.universal.zip
5151
executable: Godot.app/Contents/MacOS/Godot

SConstruct

Lines changed: 74 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#!/usr/bin/env python
22

33
import os
4+
import platform
45
import sys
56
import subprocess
67
from binding_generator import scons_generate_bindings, scons_emit_files
@@ -101,15 +102,6 @@ if hasattr(os, "cpu_count") and env.GetOption("num_jobs") == altered_num_jobs:
101102
)
102103
env.SetOption("num_jobs", safer_cpu_count)
103104

104-
is64 = sys.maxsize > 2 ** 32
105-
if (
106-
env["TARGET_ARCH"] == "amd64"
107-
or env["TARGET_ARCH"] == "emt64"
108-
or env["TARGET_ARCH"] == "x86_64"
109-
or env["TARGET_ARCH"] == "arm64-v8a"
110-
):
111-
is64 = True
112-
113105
opts = Variables([], ARGUMENTS)
114106
opts.Add(
115107
EnumVariable(
@@ -120,7 +112,7 @@ opts.Add(
120112
ignorecase=2,
121113
)
122114
)
123-
opts.Add(EnumVariable("bits", "Target platform bits", "64" if is64 else "32", ("32", "64")))
115+
opts.Add(EnumVariable("bits", "Target platform bits", "auto", ("auto", "32", "64")))
124116
opts.Add(BoolVariable("use_llvm", "Use the LLVM compiler - only effective when targeting Linux or FreeBSD", False))
125117
opts.Add(BoolVariable("use_mingw", "Use the MinGW compiler instead of MSVC - only effective on Windows", False))
126118
# Must be the same setting as used for cpp_bindings
@@ -173,6 +165,25 @@ opts.Add(
173165

174166
opts.Add(BoolVariable("build_library", "Build the godot-cpp library.", True))
175167

168+
# CPU architecture options.
169+
architectures = ["auto", "universal", "x86_32", "x86_64", "arm32", "arm64", "rv64", "ppc32", "ppc64", "wasm32"]
170+
architecture_aliases = {
171+
"x86": "x86_32",
172+
"x64": "x86_64",
173+
"amd64": "x86_64",
174+
"armv7": "arm32",
175+
"armv8": "arm64",
176+
"arm64v8": "arm64",
177+
"aarch64": "arm64",
178+
"rv": "rv64",
179+
"riscv": "rv64",
180+
"riscv64": "rv64",
181+
"ppcle": "ppc32",
182+
"ppc": "ppc32",
183+
"ppc64le": "ppc64",
184+
}
185+
opts.Add(EnumVariable("arch", "CPU architecture", "auto", architectures, architecture_aliases))
186+
176187
opts.Update(env)
177188
Help(opts.GenerateHelpText(env))
178189

@@ -183,16 +194,50 @@ if unknown:
183194
for item in unknown.items():
184195
print(" " + item[0] + "=" + item[1])
185196

197+
# Compatibility with old bits argument on Windows/Linux.
198+
# Not needed on macOS or web. Android and iOS don't use env["arch"].
199+
if env["platform"] in ["windows", "linux"]:
200+
if env["bits"] == "64":
201+
env["arch"] = "x86_64"
202+
elif env["bits"] == "32":
203+
env["arch"] = "x86_32"
204+
205+
# Process CPU architecture argument.
206+
if env["arch"] == "auto":
207+
# Use env["arch"] on all platforms except Android and iOS.
208+
# For macOS, default arch to macos_arch, which defaults to universal (compat with old argument).
209+
# For the web (javascript), default arch to wasm32.
210+
# For Windows and Linux, default arch to the host architecture.
211+
if env["platform"] == "osx":
212+
env["arch"] = env["macos_arch"]
213+
elif env["platform"] == "javascript":
214+
env["arch"] = "wasm32"
215+
else:
216+
host_machine = platform.machine().lower()
217+
if host_machine in architectures:
218+
env["arch"] = host_machine
219+
elif host_machine in architecture_aliases.keys():
220+
env["arch"] = architecture_aliases[host_machine]
221+
elif "86" in host_machine:
222+
# Catches x86, i386, i486, i586, i686, etc.
223+
env["arch"] = "x86_32"
224+
else:
225+
print("Unsupported CPU architecture: " + host_machine)
226+
Exit()
227+
228+
env_arch = env["arch"]
229+
186230
# This makes sure to keep the session environment variables on Windows.
187231
# This way, you can run SCons in a Visual Studio 2017 prompt and it will find
188232
# all the required tools
189233
if host_platform == "windows" and env["platform"] != "android":
190-
if env["bits"] == "64":
234+
if env["arch"] == "x86_64":
191235
env = Environment(TARGET_ARCH="amd64")
192-
elif env["bits"] == "32":
236+
elif env["arch"] == "x86_32":
193237
env = Environment(TARGET_ARCH="x86")
194238

195239
opts.Update(env)
240+
env["arch"] = env_arch
196241

197242
# Require C++14
198243
if host_platform == "windows" and env["platform"] == "windows" and not env["use_mingw"]:
@@ -213,26 +258,27 @@ if env["platform"] == "linux" or env["platform"] == "freebsd":
213258
elif env["target"] == "release":
214259
env.Append(CCFLAGS=["-O3"])
215260

216-
if env["bits"] == "64":
261+
if env["arch"] == "x86_64":
217262
env.Append(CCFLAGS=["-m64"])
218263
env.Append(LINKFLAGS=["-m64"])
219-
elif env["bits"] == "32":
264+
elif env["arch"] == "x86_32":
220265
env.Append(CCFLAGS=["-m32"])
221266
env.Append(LINKFLAGS=["-m32"])
222267

223268
elif env["platform"] == "osx":
224269
# Use Clang on macOS by default
225270
env["CXX"] = "clang++"
226271

227-
if env["bits"] == "32":
228-
raise ValueError("Only 64-bit builds are supported for the macOS target.")
272+
if env["arch"] not in ("universal", "x86_64", "arm64"):
273+
print("Only universal, x86_64, and arm64 are supported on macOS. Exiting.")
274+
Exit()
229275

230-
if env["macos_arch"] == "universal":
276+
if env["arch"] == "universal":
231277
env.Append(LINKFLAGS=["-arch", "x86_64", "-arch", "arm64"])
232278
env.Append(CCFLAGS=["-arch", "x86_64", "-arch", "arm64"])
233279
else:
234-
env.Append(LINKFLAGS=["-arch", env["macos_arch"]])
235-
env.Append(CCFLAGS=["-arch", env["macos_arch"]])
280+
env.Append(LINKFLAGS=["-arch", env["arch"]])
281+
env.Append(CCFLAGS=["-arch", env["arch"]])
236282

237283
if env["macos_deployment_target"] != "default":
238284
env.Append(CCFLAGS=["-mmacosx-version-min=" + env["macos_deployment_target"]])
@@ -299,12 +345,12 @@ elif env["platform"] == "windows":
299345

300346
elif host_platform == "linux" or host_platform == "freebsd" or host_platform == "osx":
301347
# Cross-compilation using MinGW
302-
if env["bits"] == "64":
348+
if env["arch"] == "x86_64":
303349
env["CXX"] = "x86_64-w64-mingw32-g++"
304350
env["AR"] = "x86_64-w64-mingw32-ar"
305351
env["RANLIB"] = "x86_64-w64-mingw32-ranlib"
306352
env["LINK"] = "x86_64-w64-mingw32-g++"
307-
elif env["bits"] == "32":
353+
elif env["arch"] == "x86_32":
308354
env["CXX"] = "i686-w64-mingw32-g++"
309355
env["AR"] = "i686-w64-mingw32-ar"
310356
env["RANLIB"] = "i686-w64-mingw32-ranlib"
@@ -314,6 +360,7 @@ elif env["platform"] == "windows":
314360
# Don't Clone the environment. Because otherwise, SCons will pick up msvc stuff.
315361
env = Environment(ENV=os.environ, tools=["mingw"])
316362
opts.Update(env)
363+
env["arch"] = env_arch
317364

318365
# Still need to use C++14.
319366
env.Append(CCFLAGS=["-std=c++14"])
@@ -342,6 +389,7 @@ elif env["platform"] == "android":
342389
# Don't Clone the environment. Because otherwise, SCons will pick up msvc stuff.
343390
env = Environment(ENV=os.environ, tools=["mingw"])
344391
opts.Update(env)
392+
env["arch"] = env_arch
345393

346394
# Long line hack. Use custom spawn, quick AR append (to avoid files with the same names to override each other).
347395
env["SPAWN"] = mySpawn
@@ -433,6 +481,10 @@ elif env["platform"] == "android":
433481
env.Append(CCFLAGS=["-O3"])
434482

435483
elif env["platform"] == "javascript":
484+
if env["arch"] != "wasm32":
485+
print("Only the WebAssembly architecture (wasm32) is supported on the web. Exiting.")
486+
Exit()
487+
436488
env["ENV"] = os.environ
437489
env["CC"] = "emcc"
438490
env["CXX"] = "em++"
@@ -497,18 +549,13 @@ sources = []
497549
add_sources(sources, "src/core", "cpp")
498550
sources.extend(f for f in bindings if str(f).endswith(".cpp"))
499551

500-
arch_suffix = env["bits"]
552+
arch_suffix = env["arch"]
501553
if env["platform"] == "android":
502554
arch_suffix = env["android_arch"]
503555
elif env["platform"] == "ios":
504556
arch_suffix = env["ios_arch"]
505557
if env["ios_simulator"]:
506558
arch_suffix += ".simulator"
507-
elif env["platform"] == "osx":
508-
if env["macos_arch"] != "universal":
509-
arch_suffix = env["macos_arch"]
510-
elif env["platform"] == "javascript":
511-
arch_suffix = "wasm"
512559
# Expose it to projects that import this env.
513560
env["arch_suffix"] = arch_suffix
514561

test/gdexample.gdnlib

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ reloadable=false
77

88
[entry]
99

10-
X11.64="res://bin/libgdexample.linux.release.64.so"
11-
Server.64="res://bin/libgdexample.linux.release.64.so"
12-
Windows.64="res://bin/libgdexample.windows.release.64.dll"
13-
OSX.64="res://bin/libgdexample.osx.release.64.dylib"
10+
X11.64="res://bin/libgdexample.linux.release.x86_64.so"
11+
Server.64="res://bin/libgdexample.linux.release.x86_64.so"
12+
Windows.64="res://bin/libgdexample.windows.release.x86_64.dll"
13+
OSX.64="res://bin/libgdexample.osx.release.universal.dylib"
1414

1515
[dependencies]
1616

0 commit comments

Comments
 (0)