Collecting preprocessor output

I’m currently developing a PPX with Dune as my buildsystem. I have a simple test, but as my PPX grows I’d like to frequently check on the raw ocaml output. How would I do this? I don’t think I can do the trick mentioned in the manual (page 34 on ) because my PPX is invoked with a (preprocess (pps blah)) line.

1 Like

Hi Chris!

If you’d like to check the output of your ppx, it is available in the * files in the _build directory. Unfortunately it’s in a binary format, but you can parse and print it using the following mini-program (to be linked with compiler-libs.bytecomp):

let dump in_path =
  let ast = Pparse.read_ast Structure in_path in
  Format.printf "%a\n" Pprintast.structure ast

This is probably something that we can support better in dune, please open an issue if you have some ideas :slight_smile:


@emillon is that also the case when using (staged_pps ...)?

I don’t remember all the details of how (staged_pps) is implemented (maybe there’s an extra AST file), but if there’s a binary file you can read it using the above technique.

staged_pps is implemented using the -ppx argument of the compiler. It is difficult to share the preprocessing step when using staged_pps. The best one can do when using staged_pps is the following: grep for the exact compilation command in _build/log, copy&paste it in the terminal and add -dsource


Thanks @jeremiedimino, that’s extremely useful, I had forgotten about -dsource. Would it be useful to add a rule for a target in this case, so debugging would be easier?

[Such target should only be built when specifically request tho, not sure how easy it is to do that]

Thank you very much!