dune
dune copied to clipboard
Configurator needs to access opam variables and pass custom flags to pkg-config
I've found this shell script for configuration in the wild:
export PKG_CONFIG_PATH="$(opam config var lib)/pkgconfig"
flags="$(pkg-config --static ocaml-freestanding --cflags)"
echo "($flags)"
Porting this to configurator is a problem because it's not possible to access opam variables and pass --static to pkg-config. We should support these features.
Seems good, however I suppose that we don't want to call opam inside configurator. Should we assume that PKG_CONFIG_PATH is already set by opam? Or maybe try to scan the library search path?
Seems good, however I suppose that we don't want to call opam inside configurator
So what should we do then? I don't think we can know upfront which opam vars to use.
Should we assume that PKG_CONFIG_PATH is already set by opam?
I suppose it's not being set today, but perhaps you're right that opam should improve this.
Or maybe try to scan the library search path?
What would scan it for? .pc files?
Ideally, yh opam should just set it. Otherwise we can use $OPAM_SWITCH_PREFIX/lib/pkgconfig.
What would scan it for? .pc files?
I was thinking of just adding dir ^ "/pkgconfig" for every dir in the library search path. At least it's not specific to opam.
I can work on this since we require this for mirage.
I need to pass variables to pkg-config too; for instance this is a typical invocation to generate C files from wayland protocol descriptions in a Makefile:
WAYLAND_FLAGS = $(shell pkg-config wayland-client --cflags --libs)
WAYLAND_PROTOCOLS_DIR = $(shell pkg-config wayland-protocols --variable=pkgdatadir)
WAYLAND_SCANNER = $(shell pkg-config wayland-scanner --variable=wayland_scanner)
at least dune-configurator could expose the path to pkg-config or a more generic query function.
I just ran into this too, trying to compile and link libpq statically with postgresql-ocaml.
In my case, the static build would need to call pkg-config --static libpq, which is not currently possible with Configurator.
https://github.com/ocaml/dune/pull/7734 provided a way to solve this e.g. in a musl+static switch by setting PKG_CONFIG_ARGN (in our example, to --static).