aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorXavier Claessens <xavier.claessens@collabora.com>2023-07-10 13:21:41 -0400
committerJussi Pakkanen <jpakkane@gmail.com>2023-07-10 23:12:24 +0300
commit1fef03c0f04e86300bee5ff3f628752d9e27304d (patch)
treeda30cc605ac56797cfa20fb7fdb2cfa87d8d55f7
parentcd63853ad2928023ea045fb331866d547e9f49fc (diff)
downloadmeson-1fef03c0f04e86300bee5ff3f628752d9e27304d.zip
meson-1fef03c0f04e86300bee5ff3f628752d9e27304d.tar.gz
meson-1fef03c0f04e86300bee5ff3f628752d9e27304d.tar.bz2
build: dependencies should come after link_with on link command
This fixes regression caused by https://github.com/mesonbuild/meson/commit/3162b901cab46d66a30c66a4406195523714ecdc that changes the order in which libraries are put on the link command. In addition, that commit was wrong because libraries from dependencies were processed before process_compiler() is called, which that commit wanted to avoid.
-rw-r--r--mesonbuild/build.py19
-rw-r--r--test cases/unit/113 complex link cases/meson.build11
-rw-r--r--unittests/linuxliketests.py1
3 files changed, 27 insertions, 4 deletions
diff --git a/mesonbuild/build.py b/mesonbuild/build.py
index eb13a89..3cb4a22 100644
--- a/mesonbuild/build.py
+++ b/mesonbuild/build.py
@@ -755,8 +755,19 @@ class BuildTarget(Target):
self.process_objectlist(objects)
self.process_kwargs(kwargs)
self.missing_languages = self.process_compilers()
- self.link(extract_as_list(kwargs, 'link_with'))
- self.link_whole(extract_as_list(kwargs, 'link_whole'))
+
+ # self.link_targets and self.link_whole_targets contains libraries from
+ # dependencies (see add_deps()). They have not been processed yet because
+ # we have to call process_compilers() first and we need to process libraries
+ # from link_with and link_whole first.
+ # See https://github.com/mesonbuild/meson/pull/11957#issuecomment-1629243208.
+ link_targets = extract_as_list(kwargs, 'link_with') + self.link_targets
+ link_whole_targets = extract_as_list(kwargs, 'link_whole') + self.link_whole_targets
+ self.link_targets.clear()
+ self.link_whole_targets.clear()
+ self.link(link_targets)
+ self.link_whole(link_whole_targets)
+
if not any([self.sources, self.generated, self.objects, self.link_whole_targets, self.structured_sources,
kwargs.pop('_allow_no_sources', False)]):
mlog.warning(f'Build target {name} has no sources. '
@@ -1337,8 +1348,8 @@ class BuildTarget(Target):
self.extra_files.extend(f for f in dep.extra_files if f not in self.extra_files)
self.add_include_dirs(dep.include_directories, dep.get_include_type())
self.objects.extend(dep.objects)
- self.link(dep.libraries)
- self.link_whole(dep.whole_libraries)
+ self.link_targets.extend(dep.libraries)
+ self.link_whole_targets.extend(dep.whole_libraries)
if dep.get_compile_args() or dep.get_link_args():
# Those parts that are external.
extpart = dependencies.InternalDependency('undefined',
diff --git a/test cases/unit/113 complex link cases/meson.build b/test cases/unit/113 complex link cases/meson.build
index 31753ed..04e6281 100644
--- a/test cases/unit/113 complex link cases/meson.build
+++ b/test cases/unit/113 complex link cases/meson.build
@@ -47,3 +47,14 @@ s1 = static_library('t7-s1', 's1.c')
s2 = static_library('t7-s2', 's2.c')
s3 = static_library('t7-s3', 's3.c', link_with: [s1, s2], install: true)
e = executable('t7-e1', 'main.c', link_with: s3)
+
+# Regression test: s3 should come last in the linker command. This seems to be
+# required for at least backward compatibility reasons:
+# https://github.com/mesonbuild/meson/pull/11957#issuecomment-1629243208
+s1 = static_library('t8-s1', 's1.c')
+s2 = static_library('t8-s2', 's2.c')
+s3 = static_library('t8-s3', 's3.c')
+e = executable('t8-e1', 'main.c',
+ link_with: [s1, s2],
+ dependencies: declare_dependency(link_with: s3),
+)
diff --git a/unittests/linuxliketests.py b/unittests/linuxliketests.py
index 745ee35..f322b02 100644
--- a/unittests/linuxliketests.py
+++ b/unittests/linuxliketests.py
@@ -1846,3 +1846,4 @@ class LinuxlikeTests(BasePlatformTests):
self.assertIn('build t5-e1: c_LINKER t5-e1.p/main.c.o | libt5-s1.so.p/libt5-s1.so.symbols libt5-s3.a\n', content)
self.assertIn('build t6-e1: c_LINKER t6-e1.p/main.c.o | libt6-s2.a libt6-s3.a\n', content)
self.assertIn('build t7-e1: c_LINKER t7-e1.p/main.c.o | libt7-s3.a\n', content)
+ self.assertIn('build t8-e1: c_LINKER t8-e1.p/main.c.o | libt8-s1.a libt8-s2.a libt8-s3.a\n', content)