]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
daemon/meson.build: add install_rpath to kresd docs-develop-shar-t8zrsp/deployments/3691
authorOto Šťáva <oto.stava@nic.cz>
Fri, 5 Apr 2024 09:57:22 +0000 (11:57 +0200)
committerOto Šťáva <oto.stava@nic.cz>
Fri, 5 Apr 2024 09:57:22 +0000 (11:57 +0200)
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
daemon/meson.build
meson.build
meson_options.txt
utils/cache_gc/meson.build
utils/client/meson.build

index 6cc1f9da9d26e65431fd6e675f1b99cb3f962a81..475cf3c8643556518b6f596fcf7c24e002e70eac 100644 (file)
@@ -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
index 68a2646682a134b9178770c3154f6fbe84c4a0f8..8446b8294b52f82cfae2f676f8a941634b2b629a 100644 (file)
@@ -65,4 +65,5 @@ kresd = executable(
   export_dynamic: true,
   install: true,
   install_dir: get_option('sbindir'),
+  install_rpath: rpath,
 )
index 8e22e17b81db5cf1663dbff059ffa434dcbd521c..d6f9be3845b17420fa8a3f84a13656538c2ddbb6 100644 (file)
@@ -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')
index 576d385ac858cecf33ed8f75d8eb4d310f4d78bd..f09f46d4926e0208dea9ec41bd70c738ed9bb199 100644 (file)
@@ -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',
+)
index 40e127d2dcfbbe56f9e1ef75baee15ba6984b9fa..4c82b8dac07068d30eb5e068065f59a602098f75 100644 (file)
@@ -21,6 +21,7 @@ if build_utils
     ],
     install: true,
     install_dir: get_option('sbindir'),
+    install_rpath: rpath,
   )
 
 integr_tests += [
index 761c2cdd3e3e6860fd963fbe86afe48e998ed06a..795cca32b767b236fe0e066f791d8fca17cb44ee 100644 (file)
@@ -33,5 +33,6 @@ if build_client
     ],
     install: true,
     install_dir: get_option('sbindir'),
+    install_rpath: rpath,
   )
 endif