Skip to content

Commit

Permalink
Default libdir is "lib" when cross compiling. Closes mesonbuild#2535.
Browse files Browse the repository at this point in the history
  • Loading branch information
jpakkane authored and tbeloqui committed Aug 22, 2019
1 parent b384ace commit 0d25036
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
7 changes: 7 additions & 0 deletions docs/markdown/snippets/crosslib.md
Original file line number Diff line number Diff line change
@@ -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.
8 changes: 8 additions & 0 deletions mesonbuild/coredata.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,7 @@ def __init__(self, options):
# 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):
Expand Down Expand Up @@ -348,6 +349,13 @@ def __load_cross_file(filename):

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'
Expand Down
13 changes: 13 additions & 0 deletions run_unittests.py
Original file line number Diff line number Diff line change
Expand Up @@ -4528,6 +4528,7 @@ def test_ldflag_dedup(self):
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
Expand Down Expand Up @@ -4564,6 +4565,18 @@ def test_cross_file_overrides_always_args(self):
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
Expand Down

0 comments on commit 0d25036

Please sign in to comment.