From 6ca12b77569611922be142edc05959ae78905e07 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Oto=20=C5=A0=C5=A5=C3=A1va?= Date: Fri, 5 Apr 2024 11:57:22 +0200 Subject: [PATCH] daemon/meson.build: add install_rpath to kresd This fixes the default use-case for developers when they put their install prefix somewhere where the system `LD_LIBRARY_PATH` does not point. Before this, `kresd` would fail to start after `ninja install` because it would not be able to find the `libkres.so` library. The original workaround to this was to use `meson configure -Ddefault_library=static`, but firstly, we would like it to be working with the default settings, and secondly, we would like to have it as similar to what most users will encounter as possible. --- .gitlab-ci.yml | 10 ++++++---- daemon/meson.build | 1 + meson.build | 14 ++++++++++++++ meson_options.txt | 12 ++++++++++++ utils/cache_gc/meson.build | 1 + utils/client/meson.build | 1 + 6 files changed, 35 insertions(+), 4 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 6cc1f9da9..475cf3c86 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -106,7 +106,7 @@ archive: build: <<: *build script: - - meson build_ci --default-library=static --prefix=$PREFIX -Dmalloc=disabled -Dwerror=true -Dextra_tests=enabled + - meson build_ci --prefix=$PREFIX -Dmalloc=disabled -Dwerror=true -Dextra_tests=enabled - ninja -C build_ci - ninja -C build_ci install >/dev/null - ${MESON_TEST} --suite unit --suite config --suite dnstap --no-suite snowflake @@ -115,7 +115,7 @@ build-knot32: <<: *build image: $CI_REGISTRY/knot/knot-resolver/ci/debian-11:knot-3.2 script: - - meson build_ci_knot32 --default-library=static --prefix=$PREFIX -Dmalloc=disabled -Dwerror=true -Dextra_tests=enabled + - meson build_ci_knot32 --prefix=$PREFIX -Dmalloc=disabled -Dwerror=true -Dextra_tests=enabled - ninja -C build_ci_knot32 - ninja -C build_ci_knot32 install >/dev/null - ${MESON_TEST} --suite unit --suite config --suite dnstap --no-suite snowflake @@ -123,7 +123,9 @@ build-knot32: build-asan: <<: *build script: - # "undefined" sanitizer causes C++ issues when loading ahocorasick.so in CI + # issues with UBSan and ASan in CI: + # - `ahocorasick.so` causes C++ problems + # - `--default-library=shared` causes link problems - CC=clang CXX=clang++ CFLAGS=-fno-sanitize-recover=all CXXFLAGS=-fno-sanitize=undefined meson build_ci_asan --default-library=static --prefix=$PREFIX -Dmalloc=jemalloc -Db_sanitize=address,undefined -Dextra_tests=enabled - ninja -C build_ci_asan - ninja -C build_ci_asan install >/dev/null @@ -170,7 +172,7 @@ sonarcloud: - tags - master@knot/knot-resolver script: - - meson build_sonarcloud --default-library=static --prefix=$PREFIX -Dmalloc=disabled + - meson build_sonarcloud --prefix=$PREFIX -Dmalloc=disabled - build-wrapper-linux-x86-64 --out-dir bw-output ninja -C build_sonarcloud - > sonar-scanner diff --git a/daemon/meson.build b/daemon/meson.build index 68a264668..8446b8294 100644 --- a/daemon/meson.build +++ b/daemon/meson.build @@ -65,4 +65,5 @@ kresd = executable( export_dynamic: true, install: true, install_dir: get_option('sbindir'), + install_rpath: rpath, ) diff --git a/meson.build b/meson.build index 8e22e17b8..d6f9be384 100644 --- a/meson.build +++ b/meson.build @@ -59,6 +59,20 @@ systemd_unit_dir = prefix / 'lib' / 'systemd' / 'system' systemd_tmpfiles_dir = prefix / 'lib' / 'tmpfiles.d' systemd_sysusers_dir = prefix / 'lib' / 'sysusers.d' +## RPath +# When installing from sources into a non-standard prefix and the library is +# shared/dynamic, we need to set the executables' RPATH so that they can find +# `libkresd`, otherwise running them will fail with dynamic linkage errors +auto_prefixes = ['/', '/usr', '/usr/local'] +rpath_opt = get_option('install_rpath') +if (get_option('default_library') == 'static' or + rpath_opt == 'disabled' or + (rpath_opt == 'auto' and prefix in auto_prefixes)) + rpath = '' +else + rpath = prefix / get_option('libdir') +endif + ## Trust anchors managed_ta = get_option('managed_ta') == 'enabled' keyfile_default = etc_dir / get_option('keyfile_default') diff --git a/meson_options.txt b/meson_options.txt index 576d385ac..f09f46d49 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -217,3 +217,15 @@ option( value: 'auto', description: 'cmocka unit tests', ) + +option( + 'install_rpath', + type: 'combo', + choices: [ + 'auto', + 'enabled', + 'disabled', + ], + value: 'auto', + description: 'add rpath to the knot resolver executables', +) diff --git a/utils/cache_gc/meson.build b/utils/cache_gc/meson.build index 40e127d2d..4c82b8dac 100644 --- a/utils/cache_gc/meson.build +++ b/utils/cache_gc/meson.build @@ -21,6 +21,7 @@ if build_utils ], install: true, install_dir: get_option('sbindir'), + install_rpath: rpath, ) integr_tests += [ diff --git a/utils/client/meson.build b/utils/client/meson.build index 761c2cdd3..795cca32b 100644 --- a/utils/client/meson.build +++ b/utils/client/meson.build @@ -33,5 +33,6 @@ if build_client ], install: true, install_dir: get_option('sbindir'), + install_rpath: rpath, ) endif -- 2.47.2