Skip to content

Commit 64b2c9b

Browse files
committed
[SCons] Refactor targets, symbols, optimizations.
Now matches Godot `master` target names and supports the same flags with the following notable exceptions: - The default target is "template_debug", since it's compatible with editor builds (and TOOLS_ENABLED is never used internally). - separate_debug_symbols is still not supported, and will be done in a separate commit.
1 parent fa4d18f commit 64b2c9b

File tree

8 files changed

+109
-60
lines changed

8 files changed

+109
-60
lines changed

.github/workflows/ci.yml

+11-11
Original file line numberDiff line numberDiff line change
@@ -21,53 +21,53 @@ jobs:
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.x86_64.a
24+
artifact-path: bin/libgodot-cpp.linux.template_release.x86_64.a
2525
cache-name: linux-x86_64
2626

2727
- name: 🐧 Linux (GCC, Double Precision)
2828
os: ubuntu-18.04
2929
platform: linux
3030
artifact-name: godot-cpp-linux-glibc2.27-x86_64-double-release
31-
artifact-path: bin/libgodot-cpp.linux.release.x86_64.a
31+
artifact-path: bin/libgodot-cpp.linux.template_release.double.x86_64.a
3232
flags: float=64
3333
cache-name: linux-x86_64-f64
3434

3535
- name: 🏁 Windows (x86_64, MSVC)
3636
os: windows-2019
3737
platform: windows
3838
artifact-name: godot-cpp-windows-msvc2019-x86_64-release
39-
artifact-path: bin/libgodot-cpp.windows.release.x86_64.lib
39+
artifact-path: bin/libgodot-cpp.windows.template_release.x86_64.lib
4040
cache-name: windows-x86_64-msvc
4141

4242
- name: 🏁 Windows (x86_64, MinGW)
4343
os: windows-2019
4444
platform: windows
4545
artifact-name: godot-cpp-linux-mingw-x86_64-release
46-
artifact-path: bin/libgodot-cpp.windows.release.x86_64.a
46+
artifact-path: bin/libgodot-cpp.windows.template_release.x86_64.a
4747
flags: use_mingw=yes
4848
cache-name: windows-x86_64-mingw
4949

5050
- name: 🍎 macOS (universal)
5151
os: macos-11
5252
platform: macos
5353
artifact-name: godot-cpp-macos-universal-release
54-
artifact-path: bin/libgodot-cpp.macos.release.universal.a
54+
artifact-path: bin/libgodot-cpp.macos.template_release.universal.a
5555
flags: arch=universal
5656
cache-name: macos-universal
5757

5858
- name: 🤖 Android (arm64)
5959
os: ubuntu-18.04
6060
platform: android
6161
artifact-name: godot-cpp-android-arm64-release
62-
artifact-path: bin/libgodot-cpp.android.release.arm64.a
62+
artifact-path: bin/libgodot-cpp.android.template_release.arm64.a
6363
flags: ANDROID_NDK_ROOT=$ANDROID_NDK_LATEST_HOME arch=arm64
6464
cache-name: android-arm64
6565

6666
- name: 🍏 iOS (arm64)
6767
os: macos-11
6868
platform: ios
6969
artifact-name: godot-cpp-ios-arm64-release
70-
artifact-path: bin/libgodot-cpp.ios.release.arm64.a
70+
artifact-path: bin/libgodot-cpp.ios.template_release.arm64.a
7171
flags: arch=arm64
7272
cache-name: ios-arm64
7373

@@ -107,17 +107,17 @@ jobs:
107107

108108
- name: Build godot-cpp (debug)
109109
run: |
110-
scons platform=${{ matrix.platform }} target=debug ${{ matrix.flags }}
110+
scons platform=${{ matrix.platform }} target=template_debug ${{ matrix.flags }}
111111
112112
- name: Build test without rebuilding godot-cpp (debug)
113113
run: |
114114
cd test
115-
scons platform=${{ matrix.platform }} target=debug ${{ matrix.flags }} build_library=no
115+
scons platform=${{ matrix.platform }} target=template_debug ${{ matrix.flags }} build_library=no
116116
117-
- name: Build test and godot-cpp (release, with debug symbols)
117+
- name: Build test and godot-cpp (release)
118118
run: |
119119
cd test
120-
scons platform=${{ matrix.platform }} target=release debug_symbols=yes ${{ matrix.flags }}
120+
scons platform=${{ matrix.platform }} target=template_release ${{ matrix.flags }}
121121
122122
- name: Upload artifact
123123
uses: actions/upload-artifact@v3

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
include/gen
99
src/gen
1010

11+
# Build configuarion.
12+
/custom.py
13+
1114
# Misc
1215
logs/*
1316
*.log

SConstruct

+28-11
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,17 @@ if env.GetOption("num_jobs") == altered_num_jobs:
4848
)
4949
env.SetOption("num_jobs", safer_cpu_count)
5050

51+
# Custom options and profile flags.
52+
customs = ["custom.py"]
53+
profile = ARGUMENTS.get("profile", "")
54+
if profile:
55+
if os.path.isfile(profile):
56+
customs.append(profile)
57+
elif os.path.isfile(profile + ".py"):
58+
customs.append(profile + ".py")
59+
opts = Variables(customs, ARGUMENTS)
60+
5161
platforms = ("linux", "macos", "windows", "android", "ios", "javascript")
52-
opts = Variables([], ARGUMENTS)
5362
opts.Add(
5463
EnumVariable(
5564
"platform",
@@ -60,8 +69,12 @@ opts.Add(
6069
)
6170
)
6271

63-
# Must be the same setting as used for cpp_bindings
64-
opts.Add(EnumVariable("target", "Compilation target", "debug", allowed_values=("debug", "release"), ignorecase=2))
72+
# Editor and template_debug are compatible (i.e. you can use the same binary for Godot editor builds and Godot debug templates).
73+
# Godot release templates are only compatible with "template_release" builds.
74+
# For this reason, we default to template_debug builds, unlike Godot which defaults to editor builds.
75+
opts.Add(
76+
EnumVariable("target", "Compilation target", "template_debug", ("editor", "template_release", "template_debug"))
77+
)
6578
opts.Add(
6679
PathVariable(
6780
"headers_dir", "Path to the directory containing Godot headers", "godot-headers", PathVariable.PathIsDir
@@ -156,13 +169,9 @@ if env.get("is_msvc", False):
156169
else:
157170
env.Append(CXXFLAGS=["-std=c++17"])
158171

159-
if env["target"] == "debug":
160-
env.Append(CPPDEFINES=["DEBUG_ENABLED", "DEBUG_METHODS_ENABLED"])
161-
162172
if env["float"] == "64":
163173
env.Append(CPPDEFINES=["REAL_T_IS_DOUBLE"])
164174

165-
166175
# Generate bindings
167176
env.Append(BUILDERS={"GenerateBindings": Builder(action=scons_generate_bindings, emitter=scons_emit_files)})
168177
json_api_file = ""
@@ -198,13 +207,21 @@ add_sources(sources, "src/core", "cpp")
198207
add_sources(sources, "src/variant", "cpp")
199208
sources.extend([f for f in bindings if str(f).endswith(".cpp")])
200209

201-
env["arch_suffix"] = env["arch"]
210+
suffix = ".{}.{}".format(env["platform"], env["target"])
211+
if env.dev_build:
212+
suffix += ".dev"
213+
if env["float"] == "64":
214+
suffix += ".double"
215+
suffix += "." + env["arch"]
202216
if env["ios_simulator"]:
203-
env["arch_suffix"] += ".simulator"
217+
suffix += ".simulator"
218+
219+
# Expose it when included from another project
220+
env["suffix"] = suffix
204221

205222
library = None
206-
env["OBJSUFFIX"] = ".{}.{}.{}{}".format(env["platform"], env["target"], env["arch_suffix"], env["OBJSUFFIX"])
207-
library_name = "libgodot-cpp.{}.{}.{}{}".format(env["platform"], env["target"], env["arch_suffix"], env["LIBSUFFIX"])
223+
env["OBJSUFFIX"] = suffix + env["OBJSUFFIX"]
224+
library_name = "libgodot-cpp{}{}".format(suffix, env["LIBSUFFIX"])
208225

209226
if env["build_library"]:
210227
library = env.StaticLibrary(target=env.File("bin/%s" % library_name), source=sources)

test/SConstruct

+1-3
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,7 @@ if env["platform"] == "macos":
2525
)
2626
else:
2727
library = env.SharedLibrary(
28-
"demo/bin/libgdexample.{}.{}.{}{}".format(
29-
env["platform"], env["target"], env["arch_suffix"], env["SHLIBSUFFIX"]
30-
),
28+
"demo/bin/libgdexample{}{}".format(env["suffix"], env["SHLIBSUFFIX"]),
3129
source=sources,
3230
)
3331

test/demo/bin/libgdexample.osx.debug.framework/Resources/Info.plist test/demo/bin/libgdexample.osx.template_debug.framework/Resources/Info.plist

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
<plist version="1.0">
44
<dict>
55
<key>CFBundleExecutable</key>
6-
<string>libgdexample.debug</string>
6+
<string>libgdexample.template_debug</string>
77
<key>CFBundleIdentifier</key>
88
<string>org.godotengine.libgdexample</string>
99
<key>CFBundleInfoDictionaryVersion</key>
1010
<string>6.0</string>
1111
<key>CFBundleName</key>
12-
<string>libgdexample.osx.debug</string>
12+
<string>libgdexample.macos.template_debug</string>
1313
<key>CFBundlePackageType</key>
1414
<string>FMWK</string>
1515
<key>CFBundleShortVersionString</key>

test/demo/bin/libgdexample.osx.release.framework/Resources/Info.plist test/demo/bin/libgdexample.osx.template_release.framework/Resources/Info.plist

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
<plist version="1.0">
44
<dict>
55
<key>CFBundleExecutable</key>
6-
<string>libgdexample.release</string>
6+
<string>libgdexample.template_release</string>
77
<key>CFBundleIdentifier</key>
88
<string>org.godotengine.libgdexample</string>
99
<key>CFBundleInfoDictionaryVersion</key>
1010
<string>6.0</string>
1111
<key>CFBundleName</key>
12-
<string>libgdexample.osx.release</string>
12+
<string>libgdexample.macos.template_release</string>
1313
<key>CFBundlePackageType</key>
1414
<string>FMWK</string>
1515
<key>CFBundleShortVersionString</key>

test/demo/example.gdextension

+12-12
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@ entry_symbol = "example_library_init"
44

55
[libraries]
66

7-
macos.debug = "res://bin/libgdexample.macos.debug.framework"
8-
macos.release = "res://bin/libgdexample.macos.release.framework"
9-
windows.debug.x86_32 = "res://bin/libgdexample.windows.debug.x86_32.dll"
10-
windows.release.x86_32 = "res://bin/libgdexample.windows.release.x86_32.dll"
11-
windows.debug.x86_64 = "res://bin/libgdexample.windows.debug.x86_64.dll"
12-
windows.release.x86_64 = "res://bin/libgdexample.windows.release.x86_64.dll"
13-
linux.debug.x86_64 = "res://bin/libgdexample.linux.debug.x86_64.so"
14-
linux.release.x86_64 = "res://bin/libgdexample.linux.release.x86_64.so"
15-
linux.debug.arm64 = "res://bin/libgdexample.linux.debug.arm64.so"
16-
linux.release.arm64 = "res://bin/libgdexample.linux.release.arm64.so"
17-
linux.debug.rv64 = "res://bin/libgdexample.linux.debug.rv64.so"
18-
linux.release.rv64 = "res://bin/libgdexample.linux.release.rv64.so"
7+
macos.debug = "res://bin/libgdexample.macos.template_debug.framework"
8+
macos.release = "res://bin/libgdexample.macos.template_release.framework"
9+
windows.debug.x86_32 = "res://bin/libgdexample.windows.template_debug.x86_32.dll"
10+
windows.release.x86_32 = "res://bin/libgdexample.windows.template_release.x86_32.dll"
11+
windows.debug.x86_64 = "res://bin/libgdexample.windows.template_debug.x86_64.dll"
12+
windows.release.x86_64 = "res://bin/libgdexample.windows.template_release.x86_64.dll"
13+
linux.debug.x86_64 = "res://bin/libgdexample.linux.template_debug.x86_64.so"
14+
linux.release.x86_64 = "res://bin/libgdexample.linux.template_release.x86_64.so"
15+
linux.debug.arm64 = "res://bin/libgdexample.linux.template_debug.arm64.so"
16+
linux.release.arm64 = "res://bin/libgdexample.linux.template_release.arm64.so"
17+
linux.debug.rv64 = "res://bin/libgdexample.linux.template_debug.rv64.so"
18+
linux.release.rv64 = "res://bin/libgdexample.linux.template_release.rv64.so"

tools/targets.py

+50-19
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,88 @@
11
import os
22
import sys
3+
from SCons.Script import ARGUMENTS
34
from SCons.Variables import *
5+
from SCons.Variables.BoolVariable import _text2bool
6+
7+
8+
def get_cmdline_bool(option, default):
9+
"""We use `ARGUMENTS.get()` to check if options were manually overridden on the command line,
10+
and SCons' _text2bool helper to convert them to booleans, otherwise they're handled as strings.
11+
"""
12+
cmdline_val = ARGUMENTS.get(option)
13+
if cmdline_val is not None:
14+
return _text2bool(cmdline_val)
15+
else:
16+
return default
417

518

619
def options(opts):
720
opts.Add(
821
EnumVariable(
922
"optimize",
1023
"The desired optimization flags",
11-
"auto",
12-
("auto", "none", "debug", "speed", "size", "0", "1", "2", "3"),
24+
"speed_trace",
25+
("none", "custom", "debug", "speed", "speed_trace", "size"),
1326
)
1427
)
15-
opts.Add(BoolVariable("debug_symbols", "Add debugging symbols to release builds", False))
28+
opts.Add(BoolVariable("debug_symbols", "Build with debugging symbols", True))
29+
opts.Add(BoolVariable("dev_build", "Developer build with dev-only debugging code (DEV_ENABLED)", False))
1630

1731

1832
def exists(env):
1933
return True
2034

2135

2236
def generate(env):
23-
if env["optimize"] == "auto":
24-
env["optimize"] = "speed" if env["target"] == "release" else "debug"
25-
env["debug_symbols"] = env["debug_symbols"] or env["target"] == "debug"
37+
env.dev_build = env["dev_build"]
38+
env.debug_features = env["target"] in ["editor", "template_debug"]
39+
env.editor_build = env["target"] == "editor"
40+
41+
if env.editor_build:
42+
env.AppendUnique(CPPDEFINES=["TOOLS_ENABLED"])
43+
44+
if env.debug_features:
45+
env.AppendUnique(CPPDEFINES=["DEBUG_ENABLED", "DEBUG_METHODS_ENABLED"])
46+
47+
if env.dev_build:
48+
opt_level = "none"
49+
env.AppendUnique(CPPDEFINES=["DEV_ENABLED"])
50+
elif env.debug_features:
51+
opt_level = "speed_trace"
52+
else: # Release
53+
opt_level = "speed"
54+
55+
env["optimize"] = ARGUMENTS.get("optimize", opt_level)
56+
env["debug_symbols"] = get_cmdline_bool("debug_symbols", env.dev_build)
2657

2758
if "is_msvc" in env and env["is_msvc"]:
2859
if env["debug_symbols"]:
29-
env.Append(CCFLAGS=["/Z7", "/D_DEBUG"])
60+
env.Append(CCFLAGS=["/Zi", "/FS"])
3061
env.Append(LINKFLAGS=["/DEBUG:FULL"])
31-
else:
32-
env.Append(CCFLAGS=["/Z7", "/DNDEBUG"])
3362

34-
if env["optimize"] == "speed":
63+
if env["optimize"] == "speed" or env["optimize"] == "speed_trace":
3564
env.Append(CCFLAGS=["/O2"])
65+
env.Append(LINKFLAGS=["/OPT:REF"])
3666
elif env["optimize"] == "size":
37-
env.Append(CCFLAGS=["/Os"])
38-
elif env["optimize"] == "debug":
39-
env.Append(CCFLAGS=["/Od"])
40-
elif env["optimize"] == "none":
67+
env.Append(CCFLAGS=["/O1"])
68+
env.Append(LINKFLAGS=["/OPT:REF"])
69+
elif env["optimize"] == "debug" or env["optimize"] == "none":
4170
env.Append(CCFLAGS=["/Od"])
42-
else:
43-
env.Append(CCFLAGS=["/O%s" % env["optimize"]])
4471
else:
4572
if env["debug_symbols"]:
46-
env.Append(CCFLAGS=["-g"])
73+
if env.dev_build:
74+
env.Append(CCFLAGS=["-g3"])
75+
else:
76+
env.Append(CCFLAGS=["-g2"])
4777

4878
if env["optimize"] == "speed":
4979
env.Append(CCFLAGS=["-O3"])
80+
# `-O2` is friendlier to debuggers than `-O3`, leading to better crash backtraces.
81+
elif env["optimize"] == "speed_trace":
82+
env.Append(CCFLAGS=["-O2"])
5083
elif env["optimize"] == "size":
5184
env.Append(CCFLAGS=["-Os"])
5285
elif env["optimize"] == "debug":
5386
env.Append(CCFLAGS=["-Og"])
5487
elif env["optimize"] == "none":
5588
env.Append(CCFLAGS=["-O0"])
56-
else:
57-
env.Append(CCFLAGS=["-O%s" % env["optimize"]])

0 commit comments

Comments
 (0)