diff options
author | Qyriad <qyriad@qyriad.me> | 2024-05-30 17:10:10 -0600 |
---|---|---|
committer | Qyriad <qyriad@qyriad.me> | 2024-05-31 21:47:16 -0600 |
commit | e54d4c9381492d44a69469a0e719fea50e9914f3 (patch) | |
tree | 626b3ddceaefd2c2d133845a0248c2d126624907 /meson.build | |
parent | c7ca87461dff6892b166e46203024cb82bd89e55 (diff) |
build: fix static linking with a hack
This causes libstore, libexpr, libfetchers, and libutil to be linked
with -Wl,--whole-archive to executables, when building statically.
libstore for the store backends, libexpr for the primops, libfetchers
for the fetcher backends I assume(?), and libutil for the nix::logger
initializer (which notably shows in pre-main constructors when HOME is
not owned by the user. cursed.).
This workaround should be removed when #359 is fixed.
Fixes #306.
Change-Id: Ie9ef0154e09a6ed97920ee8ab23810ca5e2de84c
Diffstat (limited to 'meson.build')
-rw-r--r-- | meson.build | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/meson.build b/meson.build index 9db764f00..b98b1fb15 100644 --- a/meson.build +++ b/meson.build @@ -17,6 +17,19 @@ # # Finally, src/nix/meson.build defines the Nix command itself, relying on all prior meson files. # +# libstore, libexpr, and libfetchers have some special handling to make static builds work. +# Their use static constructors for dynamic registration of primops, store backends, etc +# gets borked during static link. We can't simply wholesale apply `link_whole :` either, +# because these libraries get linked multiple times since Lix's components are transitively +# dependent. So instead, each of those libraries have two dependency objects: +# liblix{store,expr,fetchers,util} and liblix{store,expr,fetchers,util}_mstatic ("maybe static"). +# The _mstatic versions should be used in the `dependencies :` arguments to ALL EXECUTABLES +# but executables ONLY. When we are not building statically (default_library != 'static'), +# they are equivalent. When we are building statically, the _mstatic version will be +# `link_whole :` rather than `link_with :`. +# FIXME: This hack should be removed when https://git.lix.systems/lix-project/lix/issues/359 +# is fixed. +# # Unit tests are setup in tests/unit/meson.build, under the test suite "check". # # Functional tests are a bit more complicated. Generally they're defined in @@ -79,6 +92,8 @@ if not fs.is_absolute(sysconfdir) sysconfdir = '/' / sysconfdir endif +is_static = get_option('default_library') == 'static' + # All of this has to go before the rest of the dependency checking, # so that internal-api-docs can be built with -Denable-build=false |