dependencies/llvm: strip default include dirs

Fixes an issue with rust.bindgen if a cmake LLVM dependency with the
system include_type is getting used as a dependency.
pull/11492/merge
Karol Herbst 2 years ago committed by Dylan Baker
parent f02e26877d
commit 8284be8139
  1. 13
      mesonbuild/dependencies/base.py
  2. 3
      mesonbuild/dependencies/dev.py
  3. 14
      mesonbuild/environment.py
  4. 4
      mesonbuild/linkers/linkers.py

@ -552,9 +552,20 @@ def strip_system_libdirs(environment: 'Environment', for_machine: MachineChoice,
in the system path, and a different version not in the system path if they in the system path, and a different version not in the system path if they
want to link against the non-system path version. want to link against the non-system path version.
""" """
exclude = {f'-L{p}' for p in environment.get_compiler_system_dirs(for_machine)} exclude = {f'-L{p}' for p in environment.get_compiler_system_lib_dirs(for_machine)}
return [l for l in link_args if l not in exclude] return [l for l in link_args if l not in exclude]
def strip_system_includedirs(environment: 'Environment', for_machine: MachineChoice, include_args: T.List[str]) -> T.List[str]:
"""Remove -I<system path> arguments.
leaving these in will break builds where user want dependencies with system
include-type used in rust.bindgen targets as if will cause system headers
to not be found.
"""
exclude = {f'-I{p}' for p in environment.get_compiler_system_include_dirs(for_machine)}
return [i for i in include_args if i not in exclude]
def process_method_kw(possible: T.Iterable[DependencyMethods], kwargs: T.Dict[str, T.Any]) -> T.List[DependencyMethods]: def process_method_kw(possible: T.Iterable[DependencyMethods], kwargs: T.Dict[str, T.Any]) -> T.List[DependencyMethods]:
method = kwargs.get('method', 'auto') # type: T.Union[DependencyMethods, str] method = kwargs.get('method', 'auto') # type: T.Union[DependencyMethods, str]
if isinstance(method, DependencyMethods): if isinstance(method, DependencyMethods):

@ -31,7 +31,7 @@ from mesonbuild.interpreterbase.decorators import FeatureDeprecated
from .. import mesonlib, mlog from .. import mesonlib, mlog
from ..environment import get_llvm_tool_names from ..environment import get_llvm_tool_names
from ..mesonlib import version_compare, version_compare_many, search_version, stringlistify, extract_as_list from ..mesonlib import version_compare, version_compare_many, search_version, stringlistify, extract_as_list
from .base import DependencyException, DependencyMethods, detect_compiler, strip_system_libdirs, SystemDependency, ExternalDependency, DependencyTypeName from .base import DependencyException, DependencyMethods, detect_compiler, strip_system_includedirs, strip_system_libdirs, SystemDependency, ExternalDependency, DependencyTypeName
from .cmake import CMakeDependency from .cmake import CMakeDependency
from .configtool import ConfigToolDependency from .configtool import ConfigToolDependency
from .factory import DependencyFactory from .factory import DependencyFactory
@ -438,6 +438,7 @@ class LLVMDependencyCMake(CMakeDependency):
defs = defs[0].split(' ') defs = defs[0].split(' ')
temp = ['-I' + x for x in inc_dirs] + defs temp = ['-I' + x for x in inc_dirs] + defs
self.compile_args += [x for x in temp if x not in self.compile_args] self.compile_args += [x for x in temp if x not in self.compile_args]
self.compile_args = strip_system_includedirs(env, self.for_machine, self.compile_args)
if not self._add_sub_dependency(threads_factory(env, self.for_machine, {})): if not self._add_sub_dependency(threads_factory(env, self.for_machine, {})):
self.is_found = False self.is_found = False
return return

@ -838,7 +838,7 @@ class Environment:
def get_datadir(self) -> str: def get_datadir(self) -> str:
return self.coredata.get_option(OptionKey('datadir')) return self.coredata.get_option(OptionKey('datadir'))
def get_compiler_system_dirs(self, for_machine: MachineChoice): def get_compiler_system_lib_dirs(self, for_machine: MachineChoice):
for comp in self.coredata.compilers[for_machine].values(): for comp in self.coredata.compilers[for_machine].values():
if comp.id == 'clang': if comp.id == 'clang':
index = 1 index = 1
@ -857,6 +857,18 @@ class Environment:
out = out.split('\n')[index].lstrip('libraries: =').split(':') out = out.split('\n')[index].lstrip('libraries: =').split(':')
return [os.path.normpath(p) for p in out] return [os.path.normpath(p) for p in out]
def get_compiler_system_include_dirs(self, for_machine: MachineChoice):
for comp in self.coredata.compilers[for_machine].values():
if comp.id == 'clang':
break
elif comp.id == 'gcc':
break
else:
# This option is only supported by gcc and clang. If we don't get a
# GCC or Clang compiler return and empty list.
return []
return comp.get_default_include_dirs()
def need_exe_wrapper(self, for_machine: MachineChoice = MachineChoice.HOST): def need_exe_wrapper(self, for_machine: MachineChoice = MachineChoice.HOST):
value = self.properties[for_machine].get('needs_exe_wrapper', None) value = self.properties[for_machine].get('needs_exe_wrapper', None)
if value is not None: if value is not None:

@ -1487,9 +1487,9 @@ class AIXDynamicLinker(PosixDynamicLinkerMixin, DynamicLinker):
all_paths.add(os.path.join(build_dir, p)) all_paths.add(os.path.join(build_dir, p))
# We should consider allowing the $LIBPATH environment variable # We should consider allowing the $LIBPATH environment variable
# to override sys_path. # to override sys_path.
sys_path = env.get_compiler_system_dirs(self.for_machine) sys_path = env.get_compiler_system_lib_dirs(self.for_machine)
if len(sys_path) == 0: if len(sys_path) == 0:
# get_compiler_system_dirs doesn't support our compiler. # get_compiler_system_lib_dirs doesn't support our compiler.
# Use the default system library path # Use the default system library path
all_paths.update(['/usr/lib', '/lib']) all_paths.update(['/usr/lib', '/lib'])
else: else:

Loading…
Cancel
Save