coreos/go-systemd

sdjournal: pkg-config isn't queried for include paths

flokli opened this issue · 1 comments

Moved over from #141 (comment)

#141 moved libsystemd from being linked at build time to being dlopen-ed at runtime.

However, that PR entirely removed the pkg-config directive.

As pkg-config isn't only used for linker flags, but also for include paths, this breaks the build on systems that don't ship the systemd headers in the default include paths (such as NixOS):

# github.com/coreos/go-systemd/sdjournal
vendor/github.com/coreos/go-systemd/sdjournal/journal.go:27:11: fatal error: systemd/sd-journal.h: No such file or directory
   27 | // #include <systemd/sd-journal.h>
      |           ^~~~~~~~~~~~~~~~~~~~~~
compilation terminated.

One option might be to keep using pkg-config to discover include dirs, or ship the header files inline if we're relying on them.

Frankly, I'm not entirely sure about whether dlopen-ing libsystemd inside go-systemd is a good idea.

Usually, package managers use the library paths and NEEDED symbols in ELF headers to reason about runtime depenencies.

Switching from linking to dlopen causes this to not happen anymore, and leads to sudden, unexpected failures at runtime in any binaries that use go-systemd somewhere, if the dynamic linker can't find the library in the "common library paths" at runtime. Propagating these dependencies through sounds more desirable IMHO.

#141 originally just wanted to avoid linking against libsystemd at runtime, I wonder if this can be accomplished by passing some flags at build time, or is only required when compiling in the components that require libsystemd functionality in first place.

@flokli Thanks for all the digging (and nixpkgs work detailing your intermediate workarounds that led me here). Much <3 from a NixOS noob.