What is the simplest way to run pkg-config commands in a dune file [question]? #9070
Replies: 5 comments 1 reply
-
If this is not supported, then I would strongly suggest it as a feature request. |
Beta Was this translation helpful? Give feedback.
-
You can use dune's ExampleConsider the case where we want to link to some C code that uses Assume you have following file structure
The dune file in (executable
(name discover)
(libraries dune-configurator))
(rule
(targets cflags.sexp libs.sexp)
(action
(run %{dep:discover.exe}))) It declares an executable module C = Configurator.V1
let get_gtksourceview_pkg_conf c =
match C.Pkg_config.get c with
| None -> C.die "Could not find 'pkg-config'"
| Some pkg_conf -> (
match
C.Pkg_config.query_expr_err pkg_conf ~package:"gtksourceview-2.0"
~expr:""
with
| Ok cfg -> cfg
| Error err -> C.die "%s" err)
let () =
C.main ~args:[] ~name:"discover_gtksourceview_flags" @@ fun c ->
let C.Pkg_config.{ cflags; libs } = get_gtksourceview_pkg_conf c in
C.Flags.write_sexp "cflags.sexp" cflags;
C.Flags.write_sexp "libs.sexp" libs The user rule simply runs The dune file in (library
(name foo)
(libraries lablgtk2 lablgtk2.sourceview2)
; Pass flags to c compiler when constructing the library
; archive file for the C stubs. E.g. to pass -lbar to the linker.
(c_library_flags
(:standard
(:include flags/libs.sexp)))
(foreign_stubs
(language c)
(flags
(:include flags/cflags.sexp))
(names foo_c))) We use |
Beta Was this translation helpful? Give feedback.
-
this is too ugly |
Beta Was this translation helpful? Give feedback.
-
we should just specify in the dune file directly what is the command to run in order to get those flags |
Beta Was this translation helpful? Give feedback.
-
What a interesting argument... More seriously, nothing blocks you from having the pkg-config call directly in dune. There aren't variables, but the output can be put into a file which is used by another rule. |
Beta Was this translation helpful? Give feedback.
-
Hello,
To compile some C bindings, I would like dune to use the output of some pkg-config commands, such as:
Am I dreaming, or dune has not support for creating a variable whose content is the output
of a system command (like the back quoting mechanism in the bash shell) ?
Thanks,
F.
Beta Was this translation helpful? Give feedback.
All reactions