From 3ba11d08fbc179c7518b770c5f2a8c82e74279bc Mon Sep 17 00:00:00 2001 From: Luflosi Date: Sat, 3 Oct 2020 22:40:07 +0200 Subject: [PATCH] Add flag to disable LTO Disabling Link Time Optimization is useful for Nix on Darwin because LTO is broken there and has been for a long time, see https://github.com/NixOS/nixpkgs/pull/19312. This is currently worked around in the Nix package with a patch that removes the lines that add -flto to the compiler flags. --- setup.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/setup.py b/setup.py index 8a75b30de..cc8a92f0f 100755 --- a/setup.py +++ b/setup.py @@ -63,6 +63,7 @@ class Options(argparse.Namespace): for_freeze: bool = False libdir_name: str = 'lib' extra_logging: List[str] = [] + link_time_optimization: bool = True update_check_interval: float = 24 egl_library: Optional[str] = None startup_notification_library: Optional[str] = None @@ -234,6 +235,7 @@ def init_env( debug: bool = False, sanitize: bool = False, native_optimizations: bool = True, + link_time_optimization: bool = True, profile: bool = False, egl_library: Optional[str] = None, startup_notification_library: Optional[str] = None, @@ -288,7 +290,7 @@ def init_env( cppflags += shlex.split(os.environ.get('CPPFLAGS', '')) cflags += shlex.split(os.environ.get('CFLAGS', '')) ldflags += shlex.split(os.environ.get('LDFLAGS', '')) - if not debug and not sanitize and not is_openbsd: + if not debug and not sanitize and not is_openbsd and link_time_optimization: # See https://github.com/google/sanitizers/issues/647 cflags.append('-flto') ldflags.append('-flto') @@ -705,7 +707,7 @@ def compile_kittens(compilation_database: CompilationDatabase) -> None: def init_env_from_args(args: Options, native_optimizations: bool = False) -> None: global env env = init_env( - args.debug, args.sanitize, native_optimizations, args.profile, + args.debug, args.sanitize, native_optimizations, args.link_time_optimization, args.profile, args.egl_library, args.startup_notification_library, args.canberra_library, args.extra_logging ) @@ -1151,6 +1153,13 @@ def option_parser() -> argparse.ArgumentParser: # {{{ help='The filename argument passed to dlopen for libcanberra.' ' This can be used to change the name of the loaded library or specify an absolute path.' ) + p.add_argument( + '--disable-link-time-optimization', + dest='link_time_optimization', + default=Options.link_time_optimization, + action='store_false', + help='Turn off Link Time Optimization (LTO).' + ) return p # }}}