Skip to content

Commit e55a48e

Browse files
committed
[3.x] Unify bits, macos_arch into arch, support non-x86 Linux
1 parent 07153d4 commit e55a48e

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-20.04
2222
platform: linux
2323
artifact-name: godot-cpp-linux-glibc2.31-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-2022
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-2022
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-13
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
@@ -2,6 +2,7 @@
22

33
import codecs
44
import os
5+
import platform
56
import sys
67
import subprocess
78
from binding_generator import scons_generate_bindings, scons_emit_files
@@ -91,15 +92,6 @@ if hasattr(os, "cpu_count") and env.GetOption("num_jobs") == altered_num_jobs:
9192
)
9293
env.SetOption("num_jobs", safer_cpu_count)
9394

94-
is64 = sys.maxsize > 2 ** 32
95-
if (
96-
env["TARGET_ARCH"] == "amd64"
97-
or env["TARGET_ARCH"] == "emt64"
98-
or env["TARGET_ARCH"] == "x86_64"
99-
or env["TARGET_ARCH"] == "arm64-v8a"
100-
):
101-
is64 = True
102-
10395
opts = Variables([], ARGUMENTS)
10496
opts.Add(
10597
EnumVariable(
@@ -110,7 +102,7 @@ opts.Add(
110102
ignorecase=2,
111103
)
112104
)
113-
opts.Add(EnumVariable("bits", "Target platform bits", "64" if is64 else "32", ("32", "64")))
105+
opts.Add(EnumVariable("bits", "Target platform bits", "auto", ("auto", "32", "64")))
114106
opts.Add(BoolVariable("use_llvm", "Use the LLVM compiler - only effective when targeting Linux or FreeBSD", False))
115107
opts.Add(BoolVariable("use_mingw", "Use the MinGW compiler instead of MSVC - only effective on Windows", False))
116108
# Must be the same setting as used for cpp_bindings
@@ -163,6 +155,25 @@ opts.Add(
163155

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

158+
# CPU architecture options.
159+
architectures = ["auto", "universal", "x86_32", "x86_64", "arm32", "arm64", "rv64", "ppc32", "ppc64", "wasm32"]
160+
architecture_aliases = {
161+
"x86": "x86_32",
162+
"x64": "x86_64",
163+
"amd64": "x86_64",
164+
"armv7": "arm32",
165+
"armv8": "arm64",
166+
"arm64v8": "arm64",
167+
"aarch64": "arm64",
168+
"rv": "rv64",
169+
"riscv": "rv64",
170+
"riscv64": "rv64",
171+
"ppcle": "ppc32",
172+
"ppc": "ppc32",
173+
"ppc64le": "ppc64",
174+
}
175+
opts.Add(EnumVariable("arch", "CPU architecture", "auto", architectures, architecture_aliases))
176+
166177
opts.Update(env)
167178
Help(opts.GenerateHelpText(env))
168179

@@ -173,16 +184,50 @@ if unknown:
173184
for item in unknown.items():
174185
print(" " + item[0] + "=" + item[1])
175186

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

185229
opts.Update(env)
230+
env["arch"] = env_arch
186231

187232
# Require C++14
188233
if host_platform == "windows" and env["platform"] == "windows" and not env["use_mingw"]:
@@ -203,26 +248,27 @@ if env["platform"] == "linux" or env["platform"] == "freebsd":
203248
elif env["target"] == "release":
204249
env.Append(CCFLAGS=["-O3"])
205250

206-
if env["bits"] == "64":
251+
if env["arch"] == "x86_64":
207252
env.Append(CCFLAGS=["-m64"])
208253
env.Append(LINKFLAGS=["-m64"])
209-
elif env["bits"] == "32":
254+
elif env["arch"] == "x86_32":
210255
env.Append(CCFLAGS=["-m32"])
211256
env.Append(LINKFLAGS=["-m32"])
212257

213258
elif env["platform"] == "osx":
214259
# Use Clang on macOS by default
215260
env["CXX"] = "clang++"
216261

217-
if env["bits"] == "32":
218-
raise ValueError("Only 64-bit builds are supported for the macOS target.")
262+
if env["arch"] not in ("universal", "x86_64", "arm64"):
263+
print("Only universal, x86_64, and arm64 are supported on macOS. Exiting.")
264+
Exit()
219265

220-
if env["macos_arch"] == "universal":
266+
if env["arch"] == "universal":
221267
env.Append(LINKFLAGS=["-arch", "x86_64", "-arch", "arm64"])
222268
env.Append(CCFLAGS=["-arch", "x86_64", "-arch", "arm64"])
223269
else:
224-
env.Append(LINKFLAGS=["-arch", env["macos_arch"]])
225-
env.Append(CCFLAGS=["-arch", env["macos_arch"]])
270+
env.Append(LINKFLAGS=["-arch", env["arch"]])
271+
env.Append(CCFLAGS=["-arch", env["arch"]])
226272

227273
if env["macos_deployment_target"] != "default":
228274
env.Append(CCFLAGS=["-mmacosx-version-min=" + env["macos_deployment_target"]])
@@ -289,12 +335,12 @@ elif env["platform"] == "windows":
289335

290336
elif host_platform == "linux" or host_platform == "freebsd" or host_platform == "osx":
291337
# Cross-compilation using MinGW
292-
if env["bits"] == "64":
338+
if env["arch"] == "x86_64":
293339
env["CXX"] = "x86_64-w64-mingw32-g++"
294340
env["AR"] = "x86_64-w64-mingw32-ar"
295341
env["RANLIB"] = "x86_64-w64-mingw32-ranlib"
296342
env["LINK"] = "x86_64-w64-mingw32-g++"
297-
elif env["bits"] == "32":
343+
elif env["arch"] == "x86_32":
298344
env["CXX"] = "i686-w64-mingw32-g++"
299345
env["AR"] = "i686-w64-mingw32-ar"
300346
env["RANLIB"] = "i686-w64-mingw32-ranlib"
@@ -304,6 +350,7 @@ elif env["platform"] == "windows":
304350
# Don't Clone the environment. Because otherwise, SCons will pick up msvc stuff.
305351
env = Environment(ENV=os.environ, tools=["mingw"])
306352
opts.Update(env)
353+
env["arch"] = env_arch
307354

308355
# Still need to use C++14.
309356
env.Append(CCFLAGS=["-std=c++14"])
@@ -332,6 +379,7 @@ elif env["platform"] == "android":
332379
# Don't Clone the environment. Because otherwise, SCons will pick up msvc stuff.
333380
env = Environment(ENV=os.environ, tools=["mingw"])
334381
opts.Update(env)
382+
env["arch"] = env_arch
335383

336384
# Long line hack. Use custom spawn, quick AR append (to avoid files with the same names to override each other).
337385
env["SPAWN"] = mySpawn
@@ -423,6 +471,10 @@ elif env["platform"] == "android":
423471
env.Append(CCFLAGS=["-O3"])
424472

425473
elif env["platform"] == "javascript":
474+
if env["arch"] != "wasm32":
475+
print("Only the WebAssembly architecture (wasm32) is supported on the web. Exiting.")
476+
Exit()
477+
426478
env["ENV"] = os.environ
427479
env["CC"] = "emcc"
428480
env["CXX"] = "em++"
@@ -487,18 +539,13 @@ sources = []
487539
add_sources(sources, "src/core", "cpp")
488540
sources.extend(f for f in bindings if str(f).endswith(".cpp"))
489541

490-
arch_suffix = env["bits"]
542+
arch_suffix = env["arch"]
491543
if env["platform"] == "android":
492544
arch_suffix = env["android_arch"]
493545
elif env["platform"] == "ios":
494546
arch_suffix = env["ios_arch"]
495547
if env["ios_simulator"]:
496548
arch_suffix += ".simulator"
497-
elif env["platform"] == "osx":
498-
if env["macos_arch"] != "universal":
499-
arch_suffix = env["macos_arch"]
500-
elif env["platform"] == "javascript":
501-
arch_suffix = "wasm"
502549
# Expose it to projects that import this env.
503550
env["arch_suffix"] = arch_suffix
504551

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)