Adding both action and PPS in preprocess - Dune file

Hey everyone,

I am new to OCaml and wanted to know how can i add two preprocess in my dune file. Here’s the dune file and my use case is to add (pps ppx_deriving_yojson) in preprocess -

(library
 (name ml)
 (wrapped false)
 (preprocess
  (action
   (run %{bin:cppo} %{env:CPPO_FLAGS=} %{input-file})))
 (flags
  (:standard -w +a-4-42-40-41-44-45-9-48-67-70))
 (libraries ext js_parser))

(ocamllex lexer)

This is not possible at the moment. See Preprocess using both cppo and PPXs · Issue #171 · ocaml/dune · GitHub. There’s an implementation at feat: allow preprocessing action chains before `pps` by anmonteiro · Pull Request #7373 · ocaml/dune · GitHub but which has stalled.

Is there any workaround for this? My usecase is to add (pps ppx_deriving_yojson) so that i can use [@@deriving to_yojson] on various types defined.

Or this there any other alternative that i can use to get json from any OCaml type?

you can try to separate the parts that require cppo from the parts that require ppx.

How to do that? This dune file is of a package that i have vendored and don’t know much about their implementation.

No, I won’t join your meeting link. I can’t help you more. If this is an assignment, ask your supervisor. Thanks

Hello,

I need this to.

To separate, you may use a dune rule that will transform a file.tmpl.ml => file.ml and then run all pps you need while compiling file.ml. Here is an example:

 (rule
  (targets server.ml)
  (deps server.tmpl.ml)
  (locks /port)
  (enabled_if (= %{system} "linux"))
  (action (with-stdout-to %{targets} (run %{bin:chaml} %{deps}))))

(executable
  (name server)
  (modules db server)
  (flags (:standard -dsource -w -32))
  (preprocess (pps safeDb.ppx))
  (libraries simple_httpd safeDb Inverter))            

Cheers,
Christophe

Folks, I think that everything should be already doable

(preprocess
 (pps
  someppx
   --
   -ppx-rewriter-switch 
   -pp  ; NB
   %{read:../config/which.cfg}/external_rewriter_executable.exe))