I have a custom code generator that I call via jbuilder like described in the documentation Using a custom code generator but I have to specify manually the targets in the jbuild file like:
It’s not possible to do that directly at the moment. You could use the OCaml Syntax to generate the jbuild file, however it is a bit ad-hoc and we are planning to remove it eventually. Could you describe your use case a bit more in detail so that I can understand why this is needed?
I try to build a generator of Ctypes bindings for GLib2 based on GObject-Introspection (note that this is a personnal project, maybe it’s not worth wasting your time on that, https://github.com/cedlemo/OCaml-GLib2)
I have in my repository a generator/gen.ml
module BG = GI_bindings_generator
module Loader = BG.Loader
let data_structures = ["Error"; "Rand"; "Date"; "DateTime"; "TimeVal"; "TimeZone"]
let () =
let files_suffix = "Raw" in
let _ = Loader.write_constant_bindings_for "GLib" ~files_suffix [] [] in
let _ = Loader.write_enum_and_flag_bindings_for "GLib" in
Loader.write_bindings_for "GLib" data_structures
the Loader.write_enum_and_flag_bindings function create bindings for all the C enums and flags of GLib. Those bindings are numerous and depend on the version of the GLib used to generate the bindings that is why I asked if it would be possible to generate the list of targets at build time.
I though that maybe I could use an :include generated_targets.sexp like in the example of the C flags with jbuilder
I see. You could generate this file and use an include stanza (https://dune.readthedocs.io/en/latest/jbuild.html#include). However the generated file would have to be committed. Eventually, dune will support including generated files in jbuild files.
I think this is a very important use-case to support eventually. Automatic generation of bindings is the only way OCaml’s small community can handle creating bindings for rapidly changing libraries.
This is a bit OT. My main issue with CTypes has been dealing with the lifetimes when strings have to be moved between OCaml and C, especially when they are used inside structs. Do you know how ctypes_of_clang behaves in that case?