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
This commit is contained in:
parent
c7ca87461d
commit
e54d4c9381
15
meson.build
15
meson.build
|
@ -17,6 +17,19 @@
|
||||||
#
|
#
|
||||||
# Finally, src/nix/meson.build defines the Nix command itself, relying on all prior meson files.
|
# 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".
|
# 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
|
# Functional tests are a bit more complicated. Generally they're defined in
|
||||||
|
@ -79,6 +92,8 @@ if not fs.is_absolute(sysconfdir)
|
||||||
sysconfdir = '/' / sysconfdir
|
sysconfdir = '/' / sysconfdir
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
is_static = get_option('default_library') == 'static'
|
||||||
|
|
||||||
# All of this has to go before the rest of the dependency checking,
|
# 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
|
# so that internal-api-docs can be built with -Denable-build=false
|
||||||
|
|
||||||
|
|
|
@ -162,6 +162,16 @@ liblixexpr = declare_dependency(
|
||||||
link_with : libexpr,
|
link_with : libexpr,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# FIXME: remove when https://git.lix.systems/lix-project/lix/issues/359 is fixed.
|
||||||
|
if is_static
|
||||||
|
liblixexpr_mstatic = declare_dependency(
|
||||||
|
include_directories : include_directories('.'),
|
||||||
|
link_whole : libexpr,
|
||||||
|
)
|
||||||
|
else
|
||||||
|
liblixexpr_mstatic = liblixexpr
|
||||||
|
endif
|
||||||
|
|
||||||
# FIXME: not using the pkg-config module because it creates way too many deps
|
# FIXME: not using the pkg-config module because it creates way too many deps
|
||||||
# while meson migration is in progress, and we want to not include boost here
|
# while meson migration is in progress, and we want to not include boost here
|
||||||
configure_file(
|
configure_file(
|
||||||
|
|
|
@ -56,3 +56,13 @@ liblixfetchers = declare_dependency(
|
||||||
include_directories : include_directories('.'),
|
include_directories : include_directories('.'),
|
||||||
link_with : libfetchers,
|
link_with : libfetchers,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# FIXME: remove when https://git.lix.systems/lix-project/lix/issues/359 is fixed.
|
||||||
|
if is_static
|
||||||
|
liblixfetchers_mstatic = declare_dependency(
|
||||||
|
include_directories : include_directories('.'),
|
||||||
|
link_whole : libfetchers,
|
||||||
|
)
|
||||||
|
else
|
||||||
|
liblixfetchers_mstatic = liblixfetchers
|
||||||
|
endif
|
||||||
|
|
|
@ -234,6 +234,16 @@ liblixstore = declare_dependency(
|
||||||
link_with : libstore,
|
link_with : libstore,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# FIXME: remove when https://git.lix.systems/lix-project/lix/issues/359 is fixed.
|
||||||
|
if is_static
|
||||||
|
liblixstore_mstatic = declare_dependency(
|
||||||
|
include_directories : include_directories('.'),
|
||||||
|
link_whole : libstore,
|
||||||
|
)
|
||||||
|
else
|
||||||
|
liblixstore_mstatic = liblixstore
|
||||||
|
endif
|
||||||
|
|
||||||
# FIXME: not using the pkg-config module because it creates way too many deps
|
# FIXME: not using the pkg-config module because it creates way too many deps
|
||||||
# while meson migration is in progress, and we want to not include boost here
|
# while meson migration is in progress, and we want to not include boost here
|
||||||
configure_file(
|
configure_file(
|
||||||
|
|
|
@ -155,3 +155,13 @@ liblixutil = declare_dependency(
|
||||||
include_directories : include_directories('.'),
|
include_directories : include_directories('.'),
|
||||||
link_with : libutil
|
link_with : libutil
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# FIXME: remove when https://git.lix.systems/lix-project/lix/issues/359 is fixed.
|
||||||
|
if is_static
|
||||||
|
liblixutil_mstatic = declare_dependency(
|
||||||
|
include_directories : include_directories('.'),
|
||||||
|
link_whole : libutil,
|
||||||
|
)
|
||||||
|
else
|
||||||
|
liblixutil_mstatic = liblixutil
|
||||||
|
endif
|
||||||
|
|
|
@ -81,10 +81,10 @@ nix = executable(
|
||||||
nix2_commands_sources,
|
nix2_commands_sources,
|
||||||
dependencies : [
|
dependencies : [
|
||||||
liblixcmd,
|
liblixcmd,
|
||||||
liblixutil,
|
liblixutil_mstatic,
|
||||||
liblixstore,
|
liblixstore_mstatic,
|
||||||
liblixexpr,
|
liblixexpr_mstatic,
|
||||||
liblixfetchers,
|
liblixfetchers_mstatic,
|
||||||
liblixmain,
|
liblixmain,
|
||||||
boehm,
|
boehm,
|
||||||
nlohmann_json,
|
nlohmann_json,
|
||||||
|
|
|
@ -64,7 +64,7 @@ libutil_tester = executable(
|
||||||
gtest,
|
gtest,
|
||||||
boehm,
|
boehm,
|
||||||
liblixutil,
|
liblixutil,
|
||||||
liblixexpr,
|
liblixexpr_mstatic,
|
||||||
liblixutil_test_support,
|
liblixutil_test_support,
|
||||||
nlohmann_json,
|
nlohmann_json,
|
||||||
],
|
],
|
||||||
|
@ -131,7 +131,7 @@ libstore_tester = executable(
|
||||||
dependencies : [
|
dependencies : [
|
||||||
liblixstore_test_support,
|
liblixstore_test_support,
|
||||||
liblixutil_test_support,
|
liblixutil_test_support,
|
||||||
liblixstore,
|
liblixstore_mstatic,
|
||||||
liblixutil,
|
liblixutil,
|
||||||
rapidcheck,
|
rapidcheck,
|
||||||
gtest,
|
gtest,
|
||||||
|
@ -194,10 +194,10 @@ libexpr_tester = executable(
|
||||||
dependencies : [
|
dependencies : [
|
||||||
liblixexpr_test_support,
|
liblixexpr_test_support,
|
||||||
liblixstore_test_support,
|
liblixstore_test_support,
|
||||||
liblixstore,
|
liblixstore_mstatic,
|
||||||
liblixutil,
|
liblixutil,
|
||||||
liblixexpr,
|
liblixexpr_mstatic,
|
||||||
liblixfetchers,
|
liblixfetchers_mstatic,
|
||||||
rapidcheck,
|
rapidcheck,
|
||||||
boehm,
|
boehm,
|
||||||
gtest,
|
gtest,
|
||||||
|
@ -225,8 +225,8 @@ libcmd_tester = executable(
|
||||||
liblixcmd,
|
liblixcmd,
|
||||||
liblixutil,
|
liblixutil,
|
||||||
liblixmain,
|
liblixmain,
|
||||||
liblixexpr,
|
liblixexpr_mstatic,
|
||||||
liblixstore,
|
liblixstore_mstatic,
|
||||||
gtest,
|
gtest,
|
||||||
boost,
|
boost,
|
||||||
],
|
],
|
||||||
|
|
Loading…
Reference in a new issue