From: Daniel Wagner Date: Wed, 16 Nov 2022 13:17:15 +0000 (+0100) Subject: build: Allow static linking X-Git-Tag: v1.3~29^2 X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=0a921130d088f4ed9adb4ca256f3396122ad5c53;p=users%2Fsagi%2Flibnvme.git build: Allow static linking 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 --- diff --git a/.github/cross/ubuntu-static.txt b/.github/cross/ubuntu-static.txt new file mode 100644 index 00000000..d4d6c9a5 --- /dev/null +++ b/.github/cross/ubuntu-static.txt @@ -0,0 +1,6 @@ +[properties] +c_args = '-static' +cpp_args = c_args + +[binaries] +c = '/usr/bin/gcc' diff --git a/.github/workflows/meson.yml b/.github/workflows/meson.yml index 52b2b6ab..342f01aa 100644 --- a/.github/workflows/meson.yml +++ b/.github/workflows/meson.yml @@ -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: diff --git a/meson.build b/meson.build index d40313a4..09512241 100644 --- a/meson.build +++ b/meson.build @@ -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 + 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 diff --git a/src/nvme/util.c b/src/nvme/util.c index 049d9493..cc6b2b1c 100644 --- a/src/nvme/util.c +++ b/src/nvme/util.c @@ -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;