Skip to content

Commit 1b74ca6

Browse files
committed
Unify bits, android_arch, macos_arch ios_arch into arch, support non-x86
Unify arguments and add support for ARM64 and RV64 Linux
1 parent 2eedcb0 commit 1b74ca6

File tree

5 files changed

+242
-183
lines changed

5 files changed

+242
-183
lines changed

.github/workflows/ci.yml

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,27 +21,27 @@ jobs:
2121
sudo apt-get update -qq
2222
sudo apt-get install -qqq build-essential pkg-config
2323
python -m pip install scons
24-
curl -LO https://downloads.tuxfamily.org/godotengine/3.4/Godot_v3.4-stable_linux_server.64.zip
25-
unzip Godot_v3.4-stable_linux_server.64.zip
24+
curl -LO https://downloads.tuxfamily.org/godotengine/3.5/beta1/Godot_v3.5-beta1_linux_server.64.zip
25+
unzip Godot_v3.5-beta1_linux_server.64.zip
2626
2727
- name: Build godot-cpp
2828
run: |
29-
scons target=release generate_bindings=yes -j $(nproc)
29+
scons target=release platform=linux arch=x86_64 generate_bindings=yes -j $(nproc)
3030
3131
- name: Upload artifact
3232
uses: actions/upload-artifact@v2
3333
with:
3434
name: godot-cpp-linux-glibc2.27-x86_64-release
35-
path: bin/libgodot-cpp.linux.release.64.a
35+
path: bin/libgodot-cpp.linux.release.x86_64.a
3636
if-no-files-found: error
3737

3838
- name: Build test GDNative library
3939
run: |
40-
scons target=release platform=linux bits=64 -j $(nproc) -C test
40+
scons target=release platform=linux arch=x86_64 -j $(nproc) -C test
4141
4242
- name: Run test GDNative library
4343
run: |
44-
./Godot_v3.4-stable_linux_server.64 --path test -s script.gd
44+
./Godot_v3.5-beta1_linux_server.64 --path test -s script.gd
4545
4646
windows-msvc:
4747
name: Build (Windows, MSVC)
@@ -69,7 +69,7 @@ jobs:
6969
uses: actions/upload-artifact@v2
7070
with:
7171
name: godot-cpp-windows-msvc2019-x86_64-release
72-
path: bin/libgodot-cpp.windows.release.64.lib
72+
path: bin/libgodot-cpp.windows.release.x86_64.lib
7373
if-no-files-found: error
7474

7575
windows-mingw:
@@ -103,7 +103,7 @@ jobs:
103103
uses: actions/upload-artifact@v2
104104
with:
105105
name: godot-cpp-linux-mingw-x86_64-release
106-
path: bin/libgodot-cpp.windows.release.64.a
106+
path: bin/libgodot-cpp.windows.release.x86_64.a
107107
if-no-files-found: error
108108

109109
macos:
@@ -123,23 +123,23 @@ jobs:
123123
- name: Install dependencies
124124
run: |
125125
python -m pip install scons
126-
curl -LO https://downloads.tuxfamily.org/godotengine/3.4/Godot_v3.4-stable_osx.universal.zip
127-
unzip Godot_v3.4-stable_osx.universal.zip
126+
curl -LO https://downloads.tuxfamily.org/godotengine/3.5/beta1/Godot_v3.5-beta1_osx.universal.zip
127+
unzip Godot_v3.5-beta1_osx.universal.zip
128128
129129
- name: Build godot-cpp
130130
run: |
131-
scons target=release generate_bindings=yes -j $(sysctl -n hw.logicalcpu)
131+
scons target=release platform=osx arch=universal -j $(sysctl -n hw.logicalcpu) generate_bindings=yes
132132
133133
- name: Upload artifact
134134
uses: actions/upload-artifact@v2
135135
with:
136136
name: godot-cpp-macos-universal-release
137-
path: bin/libgodot-cpp.osx.release.64.a
137+
path: bin/libgodot-cpp.osx.release.universal.a
138138
if-no-files-found: error
139139

140140
- name: Build test GDNative library
141141
run: |
142-
scons target=release platform=osx bits=64 macos_arch=universal -j $(sysctl -n hw.logicalcpu) -C test
142+
scons target=release platform=osx arch=universal -j $(sysctl -n hw.logicalcpu) -C test
143143
144144
- name: Run test GDNative library
145145
run: |

SConstruct

Lines changed: 88 additions & 58 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

@@ -9,6 +10,7 @@ if sys.version_info < (3,):
910
def decode_utf8(x):
1011
return x
1112

13+
1214
else:
1315
import codecs
1416

@@ -81,15 +83,6 @@ else:
8183

8284
env = Environment(ENV=os.environ)
8385

84-
is64 = sys.maxsize > 2 ** 32
85-
if (
86-
env["TARGET_ARCH"] == "amd64"
87-
or env["TARGET_ARCH"] == "emt64"
88-
or env["TARGET_ARCH"] == "x86_64"
89-
or env["TARGET_ARCH"] == "arm64-v8a"
90-
):
91-
is64 = True
92-
9386
opts = Variables([], ARGUMENTS)
9487
opts.Add(
9588
EnumVariable(
@@ -100,7 +93,6 @@ opts.Add(
10093
ignorecase=2,
10194
)
10295
)
103-
opts.Add(EnumVariable("bits", "Target platform bits", "64" if is64 else "32", ("32", "64")))
10496
opts.Add(BoolVariable("use_llvm", "Use the LLVM compiler - only effective when targeting Linux or FreeBSD", False))
10597
opts.Add(BoolVariable("use_mingw", "Use the MinGW compiler instead of MSVC - only effective on Windows", False))
10698
# Must be the same setting as used for cpp_bindings
@@ -123,18 +115,8 @@ opts.Add(
123115
ignorecase=2,
124116
)
125117
)
126-
opts.Add(
127-
EnumVariable(
128-
"android_arch",
129-
"Target Android architecture",
130-
"armv7",
131-
["armv7", "arm64v8", "x86", "x86_64"],
132-
)
133-
)
134118
opts.Add("macos_deployment_target", "macOS deployment target", "default")
135119
opts.Add("macos_sdk_path", "macOS SDK path", "")
136-
opts.Add(EnumVariable("macos_arch", "Target macOS architecture", "universal", ["universal", "x86_64", "arm64"]))
137-
opts.Add(EnumVariable("ios_arch", "Target iOS architecture", "arm64", ["armv7", "arm64", "x86_64"]))
138120
opts.Add(BoolVariable("ios_simulator", "Target iOS Simulator", False))
139121
opts.Add(
140122
"IPHONEPATH",
@@ -144,7 +126,7 @@ opts.Add(
144126
opts.Add(
145127
"android_api_level",
146128
"Target Android API level",
147-
"18" if ARGUMENTS.get("android_arch", "armv7") in ["armv7", "x86"] else "21",
129+
"18" if "32" in ARGUMENTS.get("arch", "arm32") else "21",
148130
)
149131
opts.Add(
150132
"ANDROID_NDK_ROOT",
@@ -159,19 +141,64 @@ opts.Add(
159141
)
160142
)
161143

144+
# CPU architecture options.
145+
architecture_array = ["", "universal", "x86_32", "x86_64", "arm32", "arm64", "rv64", "ppc32", "ppc64", "wasm32"]
146+
architecture_aliases = {
147+
"x64": "x86_64",
148+
"amd64": "x86_64",
149+
"armv7": "arm32",
150+
"armv8": "arm64",
151+
"arm64v8": "arm64",
152+
"aarch64": "arm64",
153+
"rv": "rv64",
154+
"riscv": "rv64",
155+
"riscv64": "rv64",
156+
"ppcle": "ppc32",
157+
"ppc": "ppc32",
158+
"ppc64le": "ppc64",
159+
}
160+
opts.Add(EnumVariable("arch", "CPU architecture", "", architecture_array, architecture_aliases))
161+
162162
opts.Update(env)
163163
Help(opts.GenerateHelpText(env))
164164

165+
# Process CPU architecture argument.
166+
if env["arch"] == "":
167+
# No architecture specified. Default to universal if building for macOS,
168+
# arm64 if building for mobile, wasm32 if building for web,
169+
# otherwise default to the host architecture.
170+
if env["platform"] == "osx":
171+
env["arch"] = "universal"
172+
elif env["platform"] in ["android", "ios"]:
173+
env["arch"] = "arm64"
174+
elif env["platform"] == "javascript":
175+
env["arch"] = "wasm32"
176+
else:
177+
host_machine = platform.machine().lower()
178+
if host_machine in architecture_array:
179+
env["arch"] = host_machine
180+
elif host_machine in architecture_aliases.keys():
181+
env["arch"] = architecture_aliases[host_machine]
182+
elif "86" in host_machine:
183+
# Catches x86, i386, i486, i586, i686, etc.
184+
env["arch"] = "x86_32"
185+
else:
186+
print("Unsupported CPU architecture: " + host_machine)
187+
Exit()
188+
189+
env_arch = env["arch"]
190+
165191
# This makes sure to keep the session environment variables on Windows.
166192
# This way, you can run SCons in a Visual Studio 2017 prompt and it will find
167193
# all the required tools
168194
if host_platform == "windows" and env["platform"] != "android":
169-
if env["bits"] == "64":
195+
if env["arch"] == "x86_64":
170196
env = Environment(TARGET_ARCH="amd64")
171-
elif env["bits"] == "32":
197+
elif env["arch"] == "x86_32":
172198
env = Environment(TARGET_ARCH="x86")
173199

174200
opts.Update(env)
201+
env["arch"] = env_arch
175202

176203
if env["platform"] == "linux" or env["platform"] == "freebsd":
177204
if env["use_llvm"]:
@@ -185,26 +212,33 @@ if env["platform"] == "linux" or env["platform"] == "freebsd":
185212
elif env["target"] == "release":
186213
env.Append(CCFLAGS=["-O3"])
187214

188-
if env["bits"] == "64":
189-
env.Append(CCFLAGS=["-m64"])
190-
env.Append(LINKFLAGS=["-m64"])
191-
elif env["bits"] == "32":
192-
env.Append(CCFLAGS=["-m32"])
193-
env.Append(LINKFLAGS=["-m32"])
215+
if env_arch == "x86_64":
216+
env.Append(CCFLAGS=["-m64", "-march=x86-64"])
217+
env.Append(LINKFLAGS=["-m64", "-march=x86-64"])
218+
elif env_arch == "x86_32":
219+
env.Append(CCFLAGS=["-m32", "-march=i686"])
220+
env.Append(LINKFLAGS=["-m32", "-march=i686"])
221+
elif env_arch == "arm64":
222+
env.Append(CCFLAGS=["-march=armv8-a"])
223+
env.Append(LINKFLAGS=["-march=armv8-a"])
224+
elif env_arch == "rv64":
225+
env.Append(CCFLAGS=["-march=rv64gc"])
226+
env.Append(LINKFLAGS=["-march=rv64gc"])
194227

195228
elif env["platform"] == "osx":
196229
# Use Clang on macOS by default
197230
env["CXX"] = "clang++"
198231

199-
if env["bits"] == "32":
200-
raise ValueError("Only 64-bit builds are supported for the macOS target.")
232+
if env["arch"] not in ("universal", "x86_64", "arm64"):
233+
print("Only universal, x86_64, and arm64 are supported on macOS. Exiting.")
234+
Exit()
201235

202-
if env["macos_arch"] == "universal":
236+
if env["arch"] == "universal":
203237
env.Append(LINKFLAGS=["-arch", "x86_64", "-arch", "arm64"])
204238
env.Append(CCFLAGS=["-arch", "x86_64", "-arch", "arm64"])
205239
else:
206-
env.Append(LINKFLAGS=["-arch", env["macos_arch"]])
207-
env.Append(CCFLAGS=["-arch", env["macos_arch"]])
240+
env.Append(LINKFLAGS=["-arch", env["arch"]])
241+
env.Append(CCFLAGS=["-arch", env["arch"]])
208242

209243
env.Append(CCFLAGS=["-std=c++14"])
210244

@@ -251,11 +285,15 @@ elif env["platform"] == "ios":
251285
env["AR"] = compiler_path + "ar"
252286
env["RANLIB"] = compiler_path + "ranlib"
253287

254-
env.Append(CCFLAGS=["-std=c++14", "-arch", env["ios_arch"], "-isysroot", sdk_path])
288+
if env["arch"] == "arm32":
289+
env.Append(CCFLAGS=["-arch", "armv7"])
290+
env.Append(LINKFLAGS=["-arch", "armv7"])
291+
else:
292+
env.Append(CCFLAGS=["-arch", env["arch"]])
293+
env.Append(LINKFLAGS=["-arch", env["arch"]])
294+
env.Append(CCFLAGS=["-std=c++14", "-isysroot", sdk_path])
255295
env.Append(
256296
LINKFLAGS=[
257-
"-arch",
258-
env["ios_arch"],
259297
"-framework",
260298
"Cocoa",
261299
"-Wl,-undefined,dynamic_lookup",
@@ -281,12 +319,12 @@ elif env["platform"] == "windows":
281319

282320
elif host_platform == "linux" or host_platform == "freebsd" or host_platform == "osx":
283321
# Cross-compilation using MinGW
284-
if env["bits"] == "64":
322+
if env["arch"] == "x86_64":
285323
env["CXX"] = "x86_64-w64-mingw32-g++"
286324
env["AR"] = "x86_64-w64-mingw32-ar"
287325
env["RANLIB"] = "x86_64-w64-mingw32-ranlib"
288326
env["LINK"] = "x86_64-w64-mingw32-g++"
289-
elif env["bits"] == "32":
327+
elif env["arch"] == "x86_32":
290328
env["CXX"] = "i686-w64-mingw32-g++"
291329
env["AR"] = "i686-w64-mingw32-ar"
292330
env["RANLIB"] = "i686-w64-mingw32-ranlib"
@@ -296,6 +334,7 @@ elif env["platform"] == "windows":
296334
# Don't Clone the environment. Because otherwise, SCons will pick up msvc stuff.
297335
env = Environment(ENV=os.environ, tools=["mingw"])
298336
opts.Update(env)
337+
env["arch"] = env_arch
299338
# env = env.Clone(tools=['mingw'])
300339

301340
env["SPAWN"] = mySpawn
@@ -318,6 +357,7 @@ elif env["platform"] == "android":
318357
# Don't Clone the environment. Because otherwise, SCons will pick up msvc stuff.
319358
env = Environment(ENV=os.environ, tools=["mingw"])
320359
opts.Update(env)
360+
env["arch"] = env_arch
321361
# env = env.Clone(tools=['mingw'])
322362

323363
env["SPAWN"] = mySpawn
@@ -330,7 +370,7 @@ elif env["platform"] == "android":
330370

331371
# Validate API level
332372
api_level = int(env["android_api_level"])
333-
if env["android_arch"] in ["x86_64", "arm64v8"] and api_level < 21:
373+
if "64" in env["arch"] and api_level < 21:
334374
print("WARN: 64-bit Android architectures require an API level of at least 21; setting android_api_level=21")
335375
env["android_api_level"] = "21"
336376
api_level = 21
@@ -339,9 +379,7 @@ elif env["platform"] == "android":
339379
toolchain = env["ANDROID_NDK_ROOT"] + "/toolchains/llvm/prebuilt/"
340380
if host_platform == "windows":
341381
toolchain += "windows"
342-
import platform as pltfm
343-
344-
if pltfm.machine().endswith("64"):
382+
if platform.machine().endswith("64"):
345383
toolchain += "-x86_64"
346384
elif host_platform == "linux":
347385
toolchain += "linux-x86_64"
@@ -351,21 +389,21 @@ elif env["platform"] == "android":
351389

352390
# Get architecture info
353391
arch_info_table = {
354-
"armv7": {
392+
"arm32": {
355393
"march": "armv7-a",
356394
"target": "armv7a-linux-androideabi",
357395
"tool_path": "arm-linux-androideabi",
358396
"compiler_path": "armv7a-linux-androideabi",
359397
"ccflags": ["-mfpu=neon"],
360398
},
361-
"arm64v8": {
399+
"arm64": {
362400
"march": "armv8-a",
363401
"target": "aarch64-linux-android",
364402
"tool_path": "aarch64-linux-android",
365403
"compiler_path": "aarch64-linux-android",
366404
"ccflags": [],
367405
},
368-
"x86": {
406+
"x86_32": {
369407
"march": "i686",
370408
"target": "i686-linux-android",
371409
"tool_path": "i686-linux-android",
@@ -380,7 +418,7 @@ elif env["platform"] == "android":
380418
"ccflags": [],
381419
},
382420
}
383-
arch_info = arch_info_table[env["android_arch"]]
421+
arch_info = arch_info_table[env["arch"]]
384422

385423
# Setup tools
386424
env["CC"] = toolchain + "/bin/clang"
@@ -406,6 +444,7 @@ elif env["platform"] == "android":
406444
env.Append(CCFLAGS=["-O3"])
407445

408446
elif env["platform"] == "javascript":
447+
env["arch"] = "wasm32"
409448
env["ENV"] = os.environ
410449
env["CC"] = "emcc"
411450
env["CXX"] = "em++"
@@ -414,7 +453,7 @@ elif env["platform"] == "javascript":
414453
env.Append(CPPFLAGS=["-s", "SIDE_MODULE=1"])
415454
env.Append(LINKFLAGS=["-s", "SIDE_MODULE=1"])
416455
env["SHOBJSUFFIX"] = ".bc"
417-
env["SHLIBSUFFIX"] = ".wasm"
456+
env["SHLIBSUFFIX"] = ".wasm32"
418457
# Use TempFileMunge since some AR invocations are too long for cmd.exe.
419458
# Use POSIX-style paths, required with TempFileMunge.
420459
env["ARCOM_POSIX"] = env["ARCOM"].replace("$TARGET", "$TARGET.posix").replace("$SOURCES", "$SOURCES.posix")
@@ -473,16 +512,7 @@ sources = []
473512
add_sources(sources, "src/core", "cpp")
474513
add_sources(sources, "src/gen", "cpp")
475514

476-
arch_suffix = env["bits"]
477-
if env["platform"] == "android":
478-
arch_suffix = env["android_arch"]
479-
elif env["platform"] == "ios":
480-
arch_suffix = env["ios_arch"]
481-
elif env["platform"] == "osx":
482-
if env["macos_arch"] != "universal":
483-
arch_suffix = env["macos_arch"]
484-
elif env["platform"] == "javascript":
485-
arch_suffix = "wasm"
515+
arch_suffix = env["arch"]
486516

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

0 commit comments

Comments
 (0)