aboutsummaryrefslogtreecommitdiff
path: root/mesonbuild
diff options
context:
space:
mode:
Diffstat (limited to 'mesonbuild')
-rw-r--r--mesonbuild/backend/ninjabackend.py5
-rw-r--r--mesonbuild/compilers/c.py28
-rw-r--r--mesonbuild/mesonlib.py18
3 files changed, 42 insertions, 9 deletions
diff --git a/mesonbuild/backend/ninjabackend.py b/mesonbuild/backend/ninjabackend.py
index 493fc0d..9b215b2 100644
--- a/mesonbuild/backend/ninjabackend.py
+++ b/mesonbuild/backend/ninjabackend.py
@@ -2347,15 +2347,14 @@ rule FORTRAN_DEP_HACK%s
target_args = self.build_target_link_arguments(linker, target.link_whole_targets)
return linker.get_link_whole_for(target_args) if len(target_args) else []
- @staticmethod
@lru_cache(maxsize=None)
- def guess_library_absolute_path(linker, libname, search_dirs, patterns):
+ def guess_library_absolute_path(self, linker, libname, search_dirs, patterns):
for d in search_dirs:
for p in patterns:
trial = CCompiler._get_trials_from_pattern(p, d, libname)
if not trial:
continue
- trial = CCompiler._get_file_from_list(trial)
+ trial = CCompiler._get_file_from_list(self.environment, trial)
if not trial:
continue
# Return the first result
diff --git a/mesonbuild/compilers/c.py b/mesonbuild/compilers/c.py
index 0a90c8c..a591183 100644
--- a/mesonbuild/compilers/c.py
+++ b/mesonbuild/compilers/c.py
@@ -27,6 +27,7 @@ from . import compilers
from ..mesonlib import (
EnvironmentException, MesonException, version_compare, Popen_safe, listify,
for_windows, for_darwin, for_cygwin, for_haiku, for_openbsd,
+ darwin_get_object_archs
)
from .c_function_attributes import C_FUNC_ATTRIBUTES
@@ -980,10 +981,28 @@ class CCompiler(Compiler):
return [f.as_posix()]
@staticmethod
- def _get_file_from_list(files: List[str]) -> str:
+ def _get_file_from_list(env, files: List[str]) -> str:
+ '''
+ We just check whether the library exists. We can't do a link check
+ because the library might have unresolved symbols that require other
+ libraries. On macOS we check if the library matches our target
+ architecture.
+ '''
+ # If not building on macOS for Darwin, do a simple file check
+ if not env.machines.host.is_darwin() or not env.machines.build.is_darwin():
+ for f in files:
+ if os.path.isfile(f):
+ return f
+ # Run `lipo` and check if the library supports the arch we want
for f in files:
- if os.path.isfile(f):
+ if not os.path.isfile(f):
+ continue
+ archs = darwin_get_object_archs(f)
+ if archs and env.machines.host.cpu_family in archs:
return f
+ else:
+ mlog.debug('Rejected {}, supports {} but need {}'
+ .format(f, archs, env.machines.host.cpu_family))
return None
@functools.lru_cache()
@@ -1024,10 +1043,7 @@ class CCompiler(Compiler):
trial = self._get_trials_from_pattern(p, d, libname)
if not trial:
continue
- # We just check whether the library exists. We can't do a link
- # check because the library might have unresolved symbols that
- # require other libraries.
- trial = self._get_file_from_list(trial)
+ trial = self._get_file_from_list(env, trial)
if not trial:
continue
return [trial]
diff --git a/mesonbuild/mesonlib.py b/mesonbuild/mesonlib.py
index 5529ce4..09228dc 100644
--- a/mesonbuild/mesonlib.py
+++ b/mesonbuild/mesonlib.py
@@ -461,6 +461,24 @@ def exe_exists(arglist):
pass
return False
+lru_cache(maxsize=None)
+def darwin_get_object_archs(objpath):
+ '''
+ For a specific object (executable, static library, dylib, etc), run `lipo`
+ to fetch the list of archs supported by it. Supports both thin objects and
+ 'fat' objects.
+ '''
+ _, stdo, stderr = Popen_safe(['lipo', '-archs', objpath])
+ if not stdo:
+ mlog.debug('lipo {}: {}'.format(objpath, stderr))
+ return None
+ # Convert from lipo-style archs to meson-style CPUs
+ stdo = stdo.replace('i386', 'x86')
+ # Add generic name for armv7 and armv7s
+ if 'armv7' in stdo:
+ stdo += ' arm'
+ return stdo.split()
+
def detect_vcs(source_dir):
vcs_systems = [
dict(name = 'git', cmd = 'git', repo_dir = '.git', get_rev = 'git describe --dirty=+', rev_regex = '(.*)', dep = '.git/logs/HEAD'),