]> git.ipfire.org Git - thirdparty/systemd.git/commit
meson: Extract objects instead of creating intermediate static libraries
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Wed, 7 May 2025 20:55:15 +0000 (22:55 +0200)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Mon, 12 May 2025 11:35:50 +0000 (13:35 +0200)
commit6350d2dbd97746440b9c8303ddc140ffda568732
treeb6a84b62d0016ff222c94b9fddffed0155cfa612
parentd8def5dc8745c3d77cf49ad5abbb6719ffd94035
meson: Extract objects instead of creating intermediate static libraries

Currently, when we want to add unit tests for code that is compiled into
an executable, we either compile the code at least twice (once for the
executable, and once for each test that uses it) or we create a static
library which is then used by both the executable and all the tests.

Both of these options are not ideal, compiling source files more than
once slows down the build for no reason and creating the intermediate
static libraries takes a lot of boilerplate.

Instead, let's use the extract_objects() method that meson exposes on
build targets. This allows us to extract the objects corresponding to
specific source files and use them in other executables. Because we
define all executables upfront into a dictionary, we integrate this into
the dictionary approach by adding two new fields:

- 'extract' takes a list of files for which objects should be extracted.
  The extracted objects are stored in a dict keyed by the executable name
  from which they were extracted.
- 'objects' takes the name of an executable from which the extracted
  objects should be added to the current executable.

One side effect of this approach is that we can't build test executables
anymore without building the main executable, so we stop building test
executables unless we're also building the main executable. This allows
us to switch to using subdir_done() in all of these subdirectories to skip
parsing them if the corresponding component is disabled.

These changes get me down from 2439 => 2403 ninja targets on a full rebuild
from scratch.
25 files changed:
meson.build
rules.d/meson.build
src/analyze/meson.build
src/busctl/meson.build
src/coredump/meson.build
src/home/meson.build
src/import/meson.build
src/journal-remote/meson.build
src/journal/meson.build
src/locale/meson.build
src/login/meson.build
src/machine/meson.build
src/network/meson.build
src/nspawn/meson.build
src/nsresourced/meson.build
src/oom/meson.build
src/resolve/meson.build
src/shutdown/meson.build
src/sleep/meson.build
src/timesync/meson.build
src/tmpfiles/meson.build
src/udev/meson.build
src/vmspawn/meson.build
src/xdg-autostart-generator/meson.build
tools/oss-fuzz.sh