aboutsummaryrefslogtreecommitdiff
path: root/mesonbuild/compilers
diff options
context:
space:
mode:
authorNirbheek Chauhan <nirbheek@centricular.com>2019-01-29 16:12:35 +0530
committerNirbheek Chauhan <nirbheek.chauhan@gmail.com>2019-01-31 20:36:49 +0000
commit50b863032ed3913b9737112b5250c2d35a7b9fb7 (patch)
tree8eb16694963e2a9ea6c0354026e709561ca39730 /mesonbuild/compilers
parent52936e4a4624e87b79bcaa2795751a037104ece0 (diff)
downloadmeson-50b863032ed3913b9737112b5250c2d35a7b9fb7.zip
meson-50b863032ed3913b9737112b5250c2d35a7b9fb7.tar.gz
meson-50b863032ed3913b9737112b5250c2d35a7b9fb7.tar.bz2
find_library: Check arch of libraries on Darwin
macOS provides the tool `lipo` to check the archs supported by an object (executable, static library, dylib, etc). This is especially useful for fat archives, but it also helps with thin archives. Without this, the linker will fail to link to the library we mistakenly 'found' like so: ld: warning: ignoring file /path/to/libfoo.a, missing required architecture armv7 in file /path/to/libfoo.a
Diffstat (limited to 'mesonbuild/compilers')
-rw-r--r--mesonbuild/compilers/c.py28
1 files changed, 22 insertions, 6 deletions
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]