dune icon indicating copy to clipboard operation
dune copied to clipboard

Configurator needs to access opam variables and pass custom flags to pkg-config

Open rgrinberg opened this issue 7 years ago • 6 comments

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.

rgrinberg avatar Oct 23 '18 16:10 rgrinberg

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?

ghost avatar Oct 24 '18 09:10 ghost

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?

rgrinberg avatar Oct 24 '18 13:10 rgrinberg

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.

ghost avatar Oct 24 '18 16:10 ghost

I can work on this since we require this for mirage.

emillon avatar Nov 16 '18 16:11 emillon

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.

MisterDA avatar Jan 29 '22 13:01 MisterDA

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.

anmonteiro avatar Sep 04 '22 21:09 anmonteiro

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).

anmonteiro avatar May 18 '23 10:05 anmonteiro