summaryrefslogtreecommitdiff
path: root/SConstruct
diff options
context:
space:
mode:
authorRémi Verschelde <rverschelde@gmail.com>2022-07-21 15:15:54 +0200
committerRémi Verschelde <rverschelde@gmail.com>2022-09-08 10:00:02 +0200
commitc2c659db326591519d451d368c4e33c78bb9c1fa (patch)
tree3c93bbc143612aa2d5487b9c0918b74629bdd714 /SConstruct
parent69233093d7e6479b5130bf2c39cbf464a6809c1b (diff)
SCons: Refactor LTO options with `lto=<none|thin|full>`
Adds support for LTO on macOS and Android. We don't have much experience with LTO on these platforms so for now we keep it disabled by default even when `production=yes` is set. Similarly for iOS where we ship object files for the user to link in Xcode so LTO makes builds extremely slow to link. `production=yes` defaults to full LTO. ThinLTO is much faster for LLVM-based compilers but seems to produce bigger binaries (at least for the Web platform).
Diffstat (limited to 'SConstruct')
-rw-r--r--SConstruct62
1 files changed, 32 insertions, 30 deletions
diff --git a/SConstruct b/SConstruct
index ce586010f4..f7504f72e1 100644
--- a/SConstruct
+++ b/SConstruct
@@ -170,7 +170,7 @@ opts.Add(EnumVariable("arch", "CPU architecture", "auto", ["auto"] + architectur
opts.Add(EnumVariable("float", "Floating-point precision", "32", ("32", "64")))
opts.Add(EnumVariable("optimize", "Optimization type", "speed", ("speed", "size", "none")))
opts.Add(BoolVariable("production", "Set defaults to build Godot for use in production", False))
-opts.Add(BoolVariable("use_lto", "Use link-time optimization", False))
+opts.Add(EnumVariable("lto", "Link-time optimization (for production buids)", "none", ("none", "thin", "full")))
# Components
opts.Add(BoolVariable("deprecated", "Enable compatibility code for deprecated and removed features", True))
@@ -438,35 +438,6 @@ if selected_platform in platform_list:
)
env.SetOption("num_jobs", safer_cpu_count)
- # 'dev' and 'production' are aliases to set default options if they haven't been set
- # manually by the user.
- if env["dev"]:
- env["verbose"] = methods.get_cmdline_bool("verbose", True)
- env["warnings"] = ARGUMENTS.get("warnings", "extra")
- env["werror"] = methods.get_cmdline_bool("werror", True)
- if env["tools"]:
- env["tests"] = methods.get_cmdline_bool("tests", True)
- if env["production"]:
- env["use_static_cpp"] = methods.get_cmdline_bool("use_static_cpp", True)
- env["use_lto"] = methods.get_cmdline_bool("use_lto", True)
- env["debug_symbols"] = methods.get_cmdline_bool("debug_symbols", False)
- if not env["tools"] and env["target"] == "debug":
- print(
- "WARNING: Requested `production` build with `tools=no target=debug`, "
- "this will give you a full debug template (use `target=release_debug` "
- "for an optimized template with debug features)."
- )
- if env.msvc:
- print(
- "WARNING: For `production` Windows builds, you should use MinGW with GCC "
- "or Clang instead of Visual Studio, as they can better optimize the "
- "GDScript VM in a very significant way. MSVC LTO also doesn't work "
- "reliably for our use case."
- "If you want to use MSVC nevertheless for production builds, set "
- "`debug_symbols=no use_lto=no` instead of the `production=yes` option."
- )
- Exit(255)
-
env.extra_suffix = ""
if env["extra_suffix"] != "":
@@ -517,6 +488,37 @@ if selected_platform in platform_list:
# We apply it to CCFLAGS (both C and C++ code) in case it impacts C features.
env.Prepend(CCFLAGS=["/std:c++17"])
+ # 'dev' and 'production' are aliases to set default options if they haven't been set
+ # manually by the user.
+ if env["dev"]:
+ env["verbose"] = methods.get_cmdline_bool("verbose", True)
+ env["warnings"] = ARGUMENTS.get("warnings", "extra")
+ env["werror"] = methods.get_cmdline_bool("werror", True)
+ if env["tools"]:
+ env["tests"] = methods.get_cmdline_bool("tests", True)
+ if env["production"]:
+ env["use_static_cpp"] = methods.get_cmdline_bool("use_static_cpp", True)
+ env["lto"] = ARGUMENTS.get("lto", "full")
+ env["debug_symbols"] = methods.get_cmdline_bool("debug_symbols", False)
+ if not env["tools"] and env["target"] == "debug":
+ print(
+ "WARNING: Requested `production` build with `tools=no target=debug`, "
+ "this will give you a full debug template (use `target=release_debug` "
+ "for an optimized template with debug features)."
+ )
+ if env.msvc:
+ print(
+ "WARNING: For `production` Windows builds, you should use MinGW with GCC "
+ "or Clang instead of Visual Studio, as they can better optimize the "
+ "GDScript VM in a very significant way. MSVC LTO also doesn't work "
+ "reliably for our use case."
+ "If you want to use MSVC nevertheless for production builds, set "
+ "`debug_symbols=no lto=none` instead of the `production=yes` option."
+ )
+ Exit(255)
+ if env["lto"] != "none":
+ print("Using LTO: " + env["lto"])
+
# Enforce our minimal compiler version requirements
cc_version = methods.get_compiler_version(env) or {
"major": None,