From da5da5977ab975480570b06b72df98318f2efd23 Mon Sep 17 00:00:00 2001 From: Jussi Pakkanen Date: Thu, 27 Dec 2018 23:43:35 +0200 Subject: [PATCH] Default libdir is "lib" when cross compiling. Closes #2535. --- docs/markdown/snippets/crosslib.md | 7 +++++++ mesonbuild/coredata.py | 8 ++++++++ run_unittests.py | 13 +++++++++++++ 3 files changed, 28 insertions(+) create mode 100644 docs/markdown/snippets/crosslib.md diff --git a/docs/markdown/snippets/crosslib.md b/docs/markdown/snippets/crosslib.md new file mode 100644 index 000000000..14fcc81cf --- /dev/null +++ b/docs/markdown/snippets/crosslib.md @@ -0,0 +1,7 @@ +## Libdir defaults to `lib` when cross compiling + +Previously `libdir` defaulted to the value of the build machine such +as `lib/x86_64-linux-gnu`, which is almost always incorrect when cross +compiling. It now defaults to plain `lib` when cross compiling. Native +builds remain unchanged and will point to the current system's library +dir. diff --git a/mesonbuild/coredata.py b/mesonbuild/coredata.py index d70c23038..4e2f3e008 100644 --- a/mesonbuild/coredata.py +++ b/mesonbuild/coredata.py @@ -299,6 +299,7 @@ class CoreData: # Only to print a warning if it changes between Meson invocations. self.pkgconf_envvar = os.environ.get('PKG_CONFIG_PATH', '') self.config_files = self.__load_config_files(options.native_file) + self.libdir_cross_fixup() @staticmethod def __load_config_files(filenames): @@ -348,6 +349,13 @@ class CoreData: raise MesonException('Cannot find specified cross file: ' + filename) + def libdir_cross_fixup(self): + # By default set libdir to "lib" when cross compiling since + # getting the "system default" is always wrong on multiarch + # platforms as it gets a value like lib/x86_64-linux-gnu. + if self.cross_file is not None: + self.builtins['libdir'].value = 'lib' + def sanitize_prefix(self, prefix): if not os.path.isabs(prefix): raise MesonException('prefix value {!r} must be an absolute path' diff --git a/run_unittests.py b/run_unittests.py index f8ede9b89..be7ae5765 100755 --- a/run_unittests.py +++ b/run_unittests.py @@ -4528,6 +4528,7 @@ endian = 'little' max_count = max(max_count, line.count(search_term)) self.assertEqual(max_count, 1, 'Export dynamic incorrectly deduplicated.') + class LinuxCrossArmTests(BasePlatformTests): ''' Tests that cross-compilation to Linux/ARM works @@ -4564,6 +4565,18 @@ class LinuxCrossArmTests(BasePlatformTests): self.assertRegex(compdb[0]['command'], '-D_FILE_OFFSET_BITS=64.*-U_FILE_OFFSET_BITS') self.build() + def test_cross_libdir(self): + # When cross compiling "libdir" should default to "lib" + # rather than "lib/x86_64-linux-gnu" or something like that. + testdir = os.path.join(self.common_test_dir, '1 trivial') + self.init(testdir) + for i in self.introspect('--buildoptions'): + if i['name'] == 'libdir': + self.assertEqual(i['value'], 'lib') + return + self.assertTrue(False, 'Option libdir not in introspect data.') + + class LinuxCrossMingwTests(BasePlatformTests): ''' Tests that cross-compilation to Windows/MinGW works