From c2c659db326591519d451d368c4e33c78bb9c1fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Verschelde?= Date: Thu, 21 Jul 2022 15:15:54 +0200 Subject: SCons: Refactor LTO options with `lto=` 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). --- platform/android/detect.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'platform/android/detect.py') diff --git a/platform/android/detect.py b/platform/android/detect.py index ad63821162..1d9bcdd932 100644 --- a/platform/android/detect.py +++ b/platform/android/detect.py @@ -47,6 +47,9 @@ def get_flags(): return [ ("arch", "arm64"), # Default for convenience. ("tools", False), + # Benefits of LTO for Android (size, performance) haven't been clearly established yet. + # So for now we override the default value which may be set when using `production=yes`. + ("lto", "none"), ] @@ -132,6 +135,15 @@ def configure(env): env.Append(CPPDEFINES=["_DEBUG"]) env.Append(CPPFLAGS=["-UNDEBUG"]) + # LTO + if env["lto"] != "none": + if env["lto"] == "thin": + env.Append(CCFLAGS=["-flto=thin"]) + env.Append(LINKFLAGS=["-flto=thin"]) + else: + env.Append(CCFLAGS=["-flto"]) + env.Append(LINKFLAGS=["-flto"]) + # Compiler configuration env["SHLIBSUFFIX"] = ".so" -- cgit v1.2.3