aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorXavier Claessens <xavier.claessens@collabora.com>2019-09-18 21:12:55 -0400
committerXavier Claessens <xclaesse@gmail.com>2019-10-01 13:06:45 -0400
commitf396c71c52a7a3589c2998fce000843fc1e73835 (patch)
treec2790166411a7b1d657c825d9b7197abf00d4049
parent01569fee2e8130b3ac54659c119e73180d3dafee (diff)
downloadmeson-f396c71c52a7a3589c2998fce000843fc1e73835.zip
meson-f396c71c52a7a3589c2998fce000843fc1e73835.tar.gz
meson-f396c71c52a7a3589c2998fce000843fc1e73835.tar.bz2
Fix link_whole of static libraries
-rw-r--r--mesonbuild/build.py10
-rwxr-xr-xrun_unittests.py14
-rw-r--r--test cases/unit/69 static link/lib/func1.c9
-rw-r--r--test cases/unit/69 static link/lib/func2.c6
-rw-r--r--test cases/unit/69 static link/lib/meson.build8
-rw-r--r--test cases/unit/69 static link/meson.build7
-rw-r--r--test cases/unit/69 static link/test1.c7
7 files changed, 60 insertions, 1 deletions
diff --git a/mesonbuild/build.py b/mesonbuild/build.py
index e18e7ae..49d53c0 100644
--- a/mesonbuild/build.py
+++ b/mesonbuild/build.py
@@ -1099,7 +1099,15 @@ You probably should put it in link_with instead.''')
raise InvalidArguments(msg + ' This is not possible in a cross build.')
else:
mlog.warning(msg + ' This will fail in cross build.')
- self.link_whole_targets.append(t)
+ if isinstance(self, StaticLibrary):
+ # When we're a static library and we link_whole: to another static
+ # library, we need to add that target's objects to ourselves.
+ self.objects.append(t.extract_all_objects())
+ # Add internal and external deps
+ self.external_deps += t.external_deps
+ self.link_targets += t.link_targets
+ else:
+ self.link_whole_targets.append(t)
def add_pch(self, language, pchlist):
if not pchlist:
diff --git a/run_unittests.py b/run_unittests.py
index 5281aa9..67a3df7 100755
--- a/run_unittests.py
+++ b/run_unittests.py
@@ -5636,6 +5636,20 @@ c = ['{0}']
# TODO should someday be explicit about build platform only here
self.init(testdir, override_envvars=env)
+ def test_static_link(self):
+ # Build some libraries and install them
+ testdir = os.path.join(self.unit_test_dir, '69 static link/lib')
+ libdir = os.path.join(self.installdir, self.prefix[1:], self.libdir)
+ self.init(testdir)
+ self.install()
+
+ # Test that installed libraries works
+ self.new_builddir()
+ testdir = os.path.join(self.unit_test_dir, '69 static link')
+ self.init(testdir, extra_args=['-Dc_link_args="-L{}"'.format(libdir)])
+ self.build()
+ self.run_tests()
+
def should_run_cross_arm_tests():
return shutil.which('arm-linux-gnueabihf-gcc') and not platform.machine().lower().startswith('arm')
diff --git a/test cases/unit/69 static link/lib/func1.c b/test cases/unit/69 static link/lib/func1.c
new file mode 100644
index 0000000..cc934ad
--- /dev/null
+++ b/test cases/unit/69 static link/lib/func1.c
@@ -0,0 +1,9 @@
+int func1()
+{
+ return 1;
+}
+
+int func1b()
+{
+ return 1;
+}
diff --git a/test cases/unit/69 static link/lib/func2.c b/test cases/unit/69 static link/lib/func2.c
new file mode 100644
index 0000000..6b8f539
--- /dev/null
+++ b/test cases/unit/69 static link/lib/func2.c
@@ -0,0 +1,6 @@
+int func1();
+
+int func2()
+{
+ return func1() + 1;
+}
diff --git a/test cases/unit/69 static link/lib/meson.build b/test cases/unit/69 static link/lib/meson.build
new file mode 100644
index 0000000..0d7f108
--- /dev/null
+++ b/test cases/unit/69 static link/lib/meson.build
@@ -0,0 +1,8 @@
+project('test static link libs', 'c')
+
+# libfunc2 should contain both func1() and func2() symbols
+libfunc1 = static_library('func1', 'func1.c',
+ install : false)
+libfunc2 = static_library('func2', 'func2.c',
+ link_whole : libfunc1,
+ install : true)
diff --git a/test cases/unit/69 static link/meson.build b/test cases/unit/69 static link/meson.build
new file mode 100644
index 0000000..5126df6
--- /dev/null
+++ b/test cases/unit/69 static link/meson.build
@@ -0,0 +1,7 @@
+project('test static link', 'c')
+
+cc = meson.get_compiler('c')
+
+# Verify that installed libfunc2.a is usable
+func2_dep = cc.find_library('func2')
+test('test1', executable('test1', 'test1.c', dependencies : func2_dep))
diff --git a/test cases/unit/69 static link/test1.c b/test cases/unit/69 static link/test1.c
new file mode 100644
index 0000000..ffc9b9e
--- /dev/null
+++ b/test cases/unit/69 static link/test1.c
@@ -0,0 +1,7 @@
+int func1b();
+int func2();
+
+int main(int argc, char *argv[])
+{
+ return func2() + func1b() == 3 ? 0 : 1;
+}