Skip to content

Commit

Permalink
Fix unity builds (#12452)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
SoapGentoo authored Nov 18, 2023
1 parent 2b49408 commit 8928669
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 1 deletion.
2 changes: 1 addition & 1 deletion mesonbuild/backend/backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -920,7 +920,7 @@ def _determine_ext_objs(self, extobj: 'build.ExtractedObjects', proj_dir_to_buil
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)
Expand Down
13 changes: 13 additions & 0 deletions test cases/common/272 unity/meson.build
Original file line number Diff line number Diff line change
@@ -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)
6 changes: 6 additions & 0 deletions test cases/common/272 unity/slib.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
int func1(void);
int func2(void);

int static_lib_func(void) {
return func1() + func2();
}
3 changes: 3 additions & 0 deletions test cases/common/272 unity/slib1.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
int func1(void) {
return 1;
}
3 changes: 3 additions & 0 deletions test cases/common/272 unity/slib2.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
int func2(void) {
return 2;
}
5 changes: 5 additions & 0 deletions test cases/common/272 unity/test.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"installed": [
{"type": "file", "file": "usr/lib/libslib_installed.a"}
]
}

0 comments on commit 8928669

Please sign in to comment.