Skip to content

Commit

Permalink
compilers: avoid one or more version_compare per target
Browse files Browse the repository at this point in the history
version_compare can take a few milliseconds.  If you have a thousand object files
or a multiple thereof, it adds up.

Signed-off-by: Paolo Bonzini <[email protected]>
  • Loading branch information
bonzini committed Nov 7, 2024
1 parent aeec7ff commit 8c0faca
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
5 changes: 3 additions & 2 deletions mesonbuild/backend/ninjabackend.py
Original file line number Diff line number Diff line change
Expand Up @@ -623,6 +623,7 @@ def generate(self, capture: bool = False, vslite_ctx: T.Optional[T.Dict] = None)
if ninja is None:
raise MesonException('Could not detect Ninja v1.8.2 or newer')
(self.ninja_command, self.ninja_version) = ninja
self.ninja_has_dyndeps = mesonlib.version_compare(self.ninja_version, '>=1.10.0')
outfilename = os.path.join(self.environment.get_build_dir(), self.ninja_filename)
tempfilename = outfilename + '~'
with open(tempfilename, 'w', encoding='utf-8') as outfile:
Expand Down Expand Up @@ -1089,7 +1090,7 @@ def generate_target(self, target) -> None:
self.add_build(elem)

def should_use_dyndeps_for_target(self, target: 'build.BuildTarget') -> bool:
if mesonlib.version_compare(self.ninja_version, '<1.10.0'):
if not self.ninja_has_dyndeps:
return False
if 'fortran' in target.compilers:
return True
Expand Down Expand Up @@ -2451,7 +2452,7 @@ def use_dyndeps_for_fortran(self) -> bool:
'''Use the new Ninja feature for scanning dependencies during build,
rather than up front. Remove this and all old scanning code once Ninja
minimum version is bumped to 1.10.'''
return mesonlib.version_compare(self.ninja_version, '>=1.10.0')
return self.ninja_has_dyndeps

def generate_fortran_dep_hack(self, crstr: str) -> None:
if self.use_dyndeps_for_fortran():
Expand Down
9 changes: 6 additions & 3 deletions mesonbuild/compilers/mixins/gnu.py
Original file line number Diff line number Diff line change
Expand Up @@ -550,16 +550,19 @@ def __init__(self, defines: T.Optional[T.Dict[str, str]]):
super().__init__()
self.defines = defines or {}
self.base_options.update({OptionKey('b_colorout'), OptionKey('b_lto_threads')})
self._has_color_support = mesonlib.version_compare(self.version, '>=4.9.0')
self._has_wpedantic_support = mesonlib.version_compare(self.version, '>=4.8.0')
self._has_lto_auto_support = mesonlib.version_compare(self.version, '>=10.0')

def get_colorout_args(self, colortype: str) -> T.List[str]:
if mesonlib.version_compare(self.version, '>=4.9.0'):
if self._has_color_support:
return gnu_color_args[colortype][:]
return []

def get_warn_args(self, level: str) -> T.List[str]:
# Mypy doesn't understand cooperative inheritance
args = super().get_warn_args(level)
if mesonlib.version_compare(self.version, '<4.8.0') and '-Wpedantic' in args:
if not self._has_wpedantic_support and '-Wpedantic' in args:
# -Wpedantic was added in 4.8.0
# https://gcc.gnu.org/gcc-4.8/changes.html
args[args.index('-Wpedantic')] = '-pedantic'
Expand Down Expand Up @@ -612,7 +615,7 @@ def get_prelink_args(self, prelink_name: str, obj_list: T.List[str]) -> T.List[s

def get_lto_compile_args(self, *, threads: int = 0, mode: str = 'default') -> T.List[str]:
if threads == 0:
if mesonlib.version_compare(self.version, '>= 10.0'):
if self._has_lto_auto_support:
return ['-flto=auto']
# This matches clang's behavior of using the number of cpus
return [f'-flto={multiprocessing.cpu_count()}']
Expand Down
3 changes: 2 additions & 1 deletion mesonbuild/compilers/vala.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ def __init__(self, exelist: T.List[str], version: str, for_machine: MachineChoic
self.version = version
self.base_options = {OptionKey('b_colorout')}
self.force_link = False
self._has_color_support = version_compare(self.version, '>=0.37.1')

def needs_static_linker(self) -> bool:
return False # Because compiles into C.
Expand Down Expand Up @@ -80,7 +81,7 @@ def get_werror_args(self) -> T.List[str]:
return ['--fatal-warnings']

def get_colorout_args(self, colortype: str) -> T.List[str]:
if version_compare(self.version, '>=0.37.1'):
if self._has_color_support:
return ['--color=' + colortype]
return []

Expand Down

0 comments on commit 8c0faca

Please sign in to comment.