Using ppx_tools.metaquot with jbuilder

We use ppx_tools.metaquot to write code like let x = [%expr 42]. Does anyone know how to compile this with jbuilder? I tried this workaround:

(jbuild_version 1)
(library (
  (name foo)
  (public_name foo)
  (libraries (compiler-libs))
  (preprocess (per_module
    (
      (action (with-stderr-to ${@} (run ocamlfind ocamlc -c -dsource -package ppx_tools.metaquot ${<})))
      (a)
    )
    (
      (pps (ppx_jane))
      (b)
    )
  ))
))

This kind of works but fails in our real code. The issue is my use of -c, which forces compilation too early (A depends on B, but jbuilder doesn’t compile B prior to the preprocessing step).

I tried doing only preprocessing by doing ocamlfind ppx_tools/ppx_metaquot ${<} ${@}, but I get the error Failure("Ast_mapper: OCaml version mismatch or malformed input"). It seems I don’t know how to invoke ppx_metaqout directly.

Finally, is ppx_tools.metaquot still recommended, or is there any alternative now?

Would ppx_tools_versioned help here? It’s using ocaml-migrate-parsetree which may ease jbuilder integration.

Yes, thanks. That resolves it.

1 Like