ocaml / dune

A composable build system for OCaml.
https://dune.build/
MIT License
1.63k stars 408 forks source link

[extension] Add `(pkg_config ...)` field. #1906

Open ejgallego opened 5 years ago

ejgallego commented 5 years ago

As suggested in https://github.com/ocaml/dune/pull/1886 , adding a field for automatically importing pkg_config build flags could be convenient and save quite a few boilerplate for C users.

The idea would be to have a new feature:

(using pkg_config)

which would extend the (library ...) stanza to add a field:

(pkg_config gtk+-3.0 >= 3.18)

Such field should unsugar to something similar to:

(rule
 (targets
   cflag-gtk+-3.0.sexp
   clink-gtk+-3.0.sexp)
 (action (run ./dune_config.exe -pkg gtk+-3.0 -version 3.18)))
...
 (c_flags         (:include cflag-gtk+-3.0.sexp))
 (c_library_flags (:include clink-gtk+-3.0.sexp))

where dune_config is the straightforward call to configurator [that could be embedded by dune avoiding the .exe and intermediate file of course]

rgrinberg commented 5 years ago

I like the feature, but I'm not sure we should have a field like "pkg-config". A field like (c_libraries ..) should be sufficient in my opinion. The version querying scheme if supported could be generalized to OCaml libraries as well by the way.

ejgallego commented 5 years ago

c_libraries could indeed work, what should happen if pkg config is not available tho?

I actually thought about querying ocaml libs, but I am not sure what the version story is here, right? It looks like that should be sorted first in dune?

rgrinberg commented 5 years ago

c_libraries could indeed work, what should happen if pkg config is not available tho?

Just fail. Eventually, I think it would be desirable to implement pkg-config in dune itself. It's far simpler than ocamlfind actually.

I actually thought about querying ocaml libs, but I am not sure what the version story is here, right? It looks like that should be sorted first in dune?

What's the difference? Every OCaml library has a version. Yes, there's no standard for the versions but we can use the same comparison that opam uses.

ejgallego commented 5 years ago

Some recent information about the status of pkg-config on cygwin: https://github.com/coq/coq/issues/9760