]> www.infradead.org Git - users/sagi/libnvme.git/commitdiff
build: Allow static linking
authorDaniel Wagner <dwagner@suse.de>
Wed, 16 Nov 2022 13:17:15 +0000 (14:17 +0100)
committerDaniel Wagner <dwagner@suse.de>
Wed, 16 Nov 2022 13:34:33 +0000 (14:34 +0100)
To allow static linking, we have to make the libnss dependency
optional. This means the hostname IP resolution feature is not
available in this configuration.

Also the libystemd dependency check doesn't take into account that we
want to link statically. Lukily we just need this for an example.

Currently, the OpenSSL library build will fail in the example
(dependency on libnss) but the library is available to link.

Signed-off-by: Daniel Wagner <dwagner@suse.de>
.github/cross/ubuntu-static.txt [new file with mode: 0644]
.github/workflows/meson.yml
meson.build
src/nvme/util.c

diff --git a/.github/cross/ubuntu-static.txt b/.github/cross/ubuntu-static.txt
new file mode 100644 (file)
index 0000000..d4d6c9a
--- /dev/null
@@ -0,0 +1,6 @@
+[properties]
+c_args = '-static'
+cpp_args = c_args
+
+[binaries]
+c = '/usr/bin/gcc'
index 52b2b6ab1f148cb8274c887ee82dc7033c4e1edf..342f01aaa5ebf76b816ae31d3c43239bea88af94 100644 (file)
@@ -112,7 +112,7 @@ jobs:
           name: Linux_Meson_log
           path: build/meson-logs/meson-log.txt
 
-  build-static:
+  build-with-libray-static:
     runs-on: ubuntu-latest
     steps:
       - name: install libraries
@@ -134,6 +134,28 @@ jobs:
           name: Linux_Meson_log
           path: build/meson-logs/meson-log.txt
 
+  build-static:
+    runs-on: ubuntu-latest
+    steps:
+      - name: install libraries
+        run: sudo apt-get install -y libpam-dev libcap-ng-dev
+      - uses: actions/checkout@v3
+      - uses: actions/setup-python@v4
+        with:
+          python-version: '3.x'
+      - uses: BSFishy/meson-build@v1.0.3
+        with:
+          setup-options: --werror --wrap-mode=forcefallback --cross-file=.github/cross/ubuntu-static.txt --default-library=static
+          options: --verbose
+          action: test
+          meson-version: 0.61.2
+      # Preserve meson's log file on failure
+      - uses: actions/upload-artifact@v3
+        if: failure()
+        with:
+          name: Linux_Meson_log
+          path: build/meson-logs/meson-log.txt
+
   code-coverage:
     runs-on: ubuntu-latest
     steps:
index d40313a4d5493608b95a7e9163e33a16d1209cca..0951224169e02acbe297d8c7ea6b8dcdc84eac0c 100644 (file)
@@ -91,7 +91,20 @@ endif
 
 # Check for libsystemd availability. Optional, only required for MCTP dbus scan
 libsystemd_dep = dependency('libsystemd', version: '>219', required: false)
-conf.set('CONFIG_LIBSYSTEMD', libsystemd_dep.found(), description: 'Is libsystemd(>219) available?')
+if libsystemd_dep.found()
+  if cc.links('''#include <systemd/sd-bus.h>
+                 int main(void) {
+                     struct sd_bus *ret;
+                     return sd_bus_default(&ret);
+                 }
+               ''',
+              dependencies: libsystemd_dep,
+              name: 'Link check')
+       conf.set('CONFIG_LIBSYSTEMD', libsystemd_dep.found(), description: 'Is libsystemd(>219) available?')
+  else
+    libsystemd_dep = dependency('', required: false)
+  endif
+endif
 
 # local (cross-compilable) implementations of ccan configure steps
 conf.set10(
@@ -180,6 +193,19 @@ conf.set10(
     description: 'Is linux/mctp.h include-able?'
 )
 
+conf.set(
+    'HAVE_LIBNSS',
+    cc.links(
+      '''int main(int argc, char **argv) {
+             struct addrinfo hints, *result;
+             return getaddrinfo(argv[1], argv[2], &hints, &result);
+      }
+      ''',
+      name: 'havelibnss',
+    ),
+    description: 'Is network address and service translation available'
+)
+
 if cc.has_function_attribute('fallthrough')
   conf.set('fallthrough', '__attribute__((__fallthrough__))')
 else
index 049d949366a01e59b9e000fa42a111d95dae742c..cc6b2b1ca06dfaea940ddd5c7d42641605a70a58 100644 (file)
@@ -573,6 +573,7 @@ const char *nvme_errno_to_string(int status)
        return s;
 }
 
+#ifdef HAVE_LIBNSS
 char *hostname2traddr(struct nvme_root *r, const char *traddr)
 {
        struct addrinfo *host_info, hints = {.ai_family = AF_UNSPEC};
@@ -617,6 +618,18 @@ free_addrinfo:
        return ret_traddr;
 }
 
+#else  /* !HAVE_LIBNSS */
+
+char *hostname2traddr(struct nvme_root *r, const char *traddr)
+{
+       nvme_msg(NULL, LOG_ERR, "No support for hostname IP address resolution; " \
+               "recompile with libnss support.\n");
+
+       errno = -ENOTSUP;
+       return NULL;
+}
+#endif /* HAVE_LIBNSS */
+
 char *startswith(const char *s, const char *prefix)
 {
        size_t l;