summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Seifert <16636962+SoapGentoo@users.noreply.github.com>2023-11-18 01:08:41 -0800
committerGitHub <noreply@github.com>2023-11-18 11:08:41 +0200
commit8928669a69f63311d9c6db59b3f7b3c83a85ca24 (patch)
treeacbf648aba5d830e6af94e1dae1b1ccc8beb2013
parent2b494083956d46f7935f40a92b2c283b7fad6b7a (diff)
downloadmeson-8928669a69f63311d9c6db59b3f7b3c83a85ca24.tar.gz
Fix unity builds (#12452)
* unity builds: correct integer ceiling division * edge case failure with unity builds: - static archive bar that gets installed, that links with another static archive foo that does not get installed - the number of files in static archive foo is divisible by unity_size would yield an error with ninja: ninja: error: 'subprojects/foo/src/libfoo.a.p/meson-generated_foo-unity1.cpp.o', needed by 'src/libbar.a', missing and no known rule to make it * unity builds: test for build failure when #files is divisible by unity_size
-rw-r--r--mesonbuild/backend/backends.py2
-rw-r--r--test cases/common/272 unity/meson.build13
-rw-r--r--test cases/common/272 unity/slib.c6
-rw-r--r--test cases/common/272 unity/slib1.c3
-rw-r--r--test cases/common/272 unity/slib2.c3
-rw-r--r--test cases/common/272 unity/test.json5
6 files changed, 31 insertions, 1 deletions
diff --git a/mesonbuild/backend/backends.py b/mesonbuild/backend/backends.py
index b8b958883..2c24e4c31 100644
--- a/mesonbuild/backend/backends.py
+++ b/mesonbuild/backend/backends.py
@@ -920,7 +920,7 @@ class Backend:
if comp.language in LANGS_CANT_UNITY:
sources += srcs
continue
- for i in range(len(srcs) // unity_size + 1):
+ for i in range((len(srcs) + unity_size - 1) // unity_size):
_src = self.get_unity_source_file(extobj.target,
comp.get_default_suffix(), i)
sources.append(_src)
diff --git a/test cases/common/272 unity/meson.build b/test cases/common/272 unity/meson.build
new file mode 100644
index 000000000..9acb9b8fe
--- /dev/null
+++ b/test cases/common/272 unity/meson.build
@@ -0,0 +1,13 @@
+project('unity', 'c',
+ default_options : [
+ 'unity_size=2'])
+
+if get_option('unity') != 'on'
+ error('MESON_SKIP_TEST: unity builds not enabled')
+endif
+
+slib_notinstalled = static_library('slib_notinstalled',
+ # test depends on the number of files being divisible by unity_size
+ ['slib1.c', 'slib2.c'])
+
+slib_installed = static_library('slib_installed', ['slib1.c', 'slib2.c'], link_with : slib_notinstalled, install : true)
diff --git a/test cases/common/272 unity/slib.c b/test cases/common/272 unity/slib.c
new file mode 100644
index 000000000..d7053366a
--- /dev/null
+++ b/test cases/common/272 unity/slib.c
@@ -0,0 +1,6 @@
+int func1(void);
+int func2(void);
+
+int static_lib_func(void) {
+ return func1() + func2();
+}
diff --git a/test cases/common/272 unity/slib1.c b/test cases/common/272 unity/slib1.c
new file mode 100644
index 000000000..35304eed6
--- /dev/null
+++ b/test cases/common/272 unity/slib1.c
@@ -0,0 +1,3 @@
+int func1(void) {
+ return 1;
+}
diff --git a/test cases/common/272 unity/slib2.c b/test cases/common/272 unity/slib2.c
new file mode 100644
index 000000000..5badf23bc
--- /dev/null
+++ b/test cases/common/272 unity/slib2.c
@@ -0,0 +1,3 @@
+int func2(void) {
+ return 2;
+}
diff --git a/test cases/common/272 unity/test.json b/test cases/common/272 unity/test.json
new file mode 100644
index 000000000..0a10fddb5
--- /dev/null
+++ b/test cases/common/272 unity/test.json
@@ -0,0 +1,5 @@
+{
+ "installed": [
+ {"type": "file", "file": "usr/lib/libslib_installed.a"}
+ ]
+}