diff --git a/glfw/glfw.py b/glfw/glfw.py index 354a8dcb6..450f58b6a 100755 --- a/glfw/glfw.py +++ b/glfw/glfw.py @@ -5,6 +5,7 @@ import json import os import re +import subprocess import sys from enum import Enum from typing import Any, Callable, Dict, List, NamedTuple, Optional, Sequence, Tuple @@ -79,10 +80,22 @@ class Env: self.vcs_rev = vcs_rev self.binary_arch = binary_arch self.native_optimizations = native_optimizations + self._cc_version_string = '' + + @property + def cc_version_string(self) -> str: + if not self._cc_version_string: + self._cc_version_string = subprocess.check_output(self.cc + ['--version']).decode() + return self._cc_version_string + + @property + def is_gcc(self) -> bool: + return '(GCC)' in self.cc_version_string def copy(self) -> 'Env': ans = Env(self.cc, list(self.cppflags), list(self.cflags), list(self.ldflags), dict(self.library_paths), list(self.ldpaths), self.ccver) ans.all_headers = list(self.all_headers) + ans._cc_version_string = self._cc_version_string ans.sources = list(self.sources) ans.wayland_packagedir = self.wayland_packagedir ans.wayland_scanner = self.wayland_scanner diff --git a/setup.py b/setup.py index 3754add48..d35d7182b 100755 --- a/setup.py +++ b/setup.py @@ -431,16 +431,6 @@ def set_arches(flags: List[str], *arches: str) -> None: flags.extend(('-arch', arch)) -def is_gcc(cc: Iterable[str]) -> bool: - - @lru_cache() - def f(cc: Tuple[str]) -> bool: - raw = subprocess.check_output(cc + ('--version',)).decode('utf-8').splitlines()[0] - return '(GCC)' in raw.split() - - return f(tuple(cc)) - - def init_env( debug: bool = False, sanitize: bool = False, @@ -465,7 +455,7 @@ def init_env( print('CC:', cc, ccver) stack_protector = first_successful_compile(cc, '-fstack-protector-strong', '-fstack-protector') missing_braces = '' - if ccver < (5, 2) and is_gcc(cc): + if ccver < (5, 2): missing_braces = '-Wno-missing-braces' df = '-g3' float_conversion = '' @@ -568,10 +558,13 @@ def init_env( if native_optimizations and ba.isa in (ISA.AMD64, ISA.X86): cflags.extend('-march=native -mtune=native'.split()) - return Env( + ans = Env( cc, cppflags, cflags, ldflags, library_paths, binary_arch=ba, native_optimizations=native_optimizations, ccver=ccver, ldpaths=ldpaths, vcs_rev=vcs_rev, ) + if verbose: + print(ans.cc_version_string) + return ans def kitty_env(args: Options) -> Env: @@ -714,7 +707,7 @@ def get_source_specific_cflags(env: Env, src: str) -> List[str]: ans.append('-msse4.2' if '128' in src else '-mavx2') if '256' in src: # We have manual vzeroupper so prevent compiler from emitting it causing duplicates - if is_gcc(env.cc): + if env.is_gcc: ans.append('-mno-vzeroupper') else: ans.append('-mllvm') @@ -1183,7 +1176,7 @@ def build_launcher(args: Options, launcher_dir: str = '.', bundle_type: str = 's sanitize_args = get_sanitize_args(env.cc, env.ccver) cflags.extend(sanitize_args) ldflags.extend(sanitize_args) - libs += ['-lasan'] if not is_macos and is_gcc(env.cc) else [] + libs += ['-lasan'] if not is_macos and env.is_gcc else [] else: cflags.append('-g') if args.profile: