How to pass CFLAGS into a dune project?

Is there a way to pass compiler flags to an existing dune based project? The documentaton does not seem to cover this.

I’m looking for the equivalent of ‘env CFLAGS=“some string” ./configure’. Right now projects can query pkg-config to receive at least the most required CFLAGS/LDFLAGS.

The ‘dune build --verbose’ output has ‘ocamlc_cflags’, which contains the CFLAGS used for ocaml itself. It seems there is no way to access it.

Was it ever considered to inject CFLAGS into projects?

When writing e.g. C bindings, you can do this. If your question is about how to override this directly when invoking dune, I don’t know if it’s possible.

It should be possible to inject CFLAGS from outside.

Meanwhile, while debugging something else, I noticed that gcc is indeed invoked with the same CFLAGS that were used to build ocaml itself. This is good enough for my use case.