summaryrefslogtreecommitdiffstats
path: root/SConstruct
diff options
context:
space:
mode:
authorRémi Verschelde <rverschelde@gmail.com>2023-08-14 13:02:40 +0200
committerRémi Verschelde <rverschelde@gmail.com>2023-08-16 10:23:34 +0200
commit3907e53ff68643785df0066be64fddce9f79919c (patch)
treeaeab699a5c6b3396835f3ba80faa8c682dbbdf2a /SConstruct
parent90f90cbcb0cf2c44a3114048accfd5b407c4ac98 (diff)
downloadredot-engine-3907e53ff68643785df0066be64fddce9f79919c.tar.gz
SCons: Disable C++ exception handling
Upon investigating the extremely slow MSVC build times in #80513, I noticed that while Godot policy is to never use exceptions, we weren't enforcing it with compiler flags, and thus still included exception handling code and stack unwinding. This is wasteful on multiple aspects: - Binary size: Around 20% binary size reduction with exceptions disabled for both MSVC and GCC binaries. - Compile time: * More than 50% build time reduction with MSVC. * 10% to 25% build time reduction with GCC + LTO. - Performance: Possibly, needs to be benchmarked. Since users may want to re-enable exceptions in their own thirdparty code or the libraries they compile with Godot, this behavior can be toggled with the `disable_exceptions` SCons option, which defaults to true.
Diffstat (limited to 'SConstruct')
-rw-r--r--SConstruct14
1 files changed, 11 insertions, 3 deletions
diff --git a/SConstruct b/SConstruct
index 6968967380..7ea056f839 100644
--- a/SConstruct
+++ b/SConstruct
@@ -193,6 +193,7 @@ opts.Add(BoolVariable("vulkan", "Enable the vulkan rendering driver", True))
opts.Add(BoolVariable("opengl3", "Enable the OpenGL/GLES3 rendering driver", True))
opts.Add(BoolVariable("openxr", "Enable the OpenXR driver", True))
opts.Add(BoolVariable("use_volk", "Use the volk library to load the Vulkan loader dynamically", True))
+opts.Add(BoolVariable("disable_exceptions", "Force disabling exception handling code", True))
opts.Add("custom_modules", "A list of comma-separated directory paths containing custom modules to build.", "")
opts.Add(BoolVariable("custom_modules_recursive", "Detect custom modules recursively for each specified path.", True))
@@ -710,6 +711,16 @@ if selected_platform in platform_list:
)
Exit(255)
+ # Disable exception handling. Godot doesn't use exceptions anywhere, and this
+ # saves around 20% of binary size and very significant build time (GH-80513).
+ if env["disable_exceptions"]:
+ if env.msvc:
+ env.Append(CPPDEFINES=[("_HAS_EXCEPTIONS", 0)])
+ else:
+ env.Append(CCFLAGS=["-fno-exceptions"])
+ elif env.msvc:
+ env.Append(CCFLAGS=["/EHsc"])
+
# Configure compiler warnings
if env.msvc: # MSVC
if env["warnings"] == "no":
@@ -739,9 +750,6 @@ if selected_platform in platform_list:
]
)
- # Set exception handling model to avoid warnings caused by Windows system headers.
- env.Append(CCFLAGS=["/EHsc"])
-
if env["werror"]:
env.Append(CCFLAGS=["/WX"])
else: # GCC, Clang