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)
emillon
February 13, 2024, 9:32am
2
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?
emillon
February 13, 2024, 9:54am
4
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.
emillon
February 13, 2024, 10:10am
7
No, I won’t join your meeting link. I can’t help you more. If this is an assignment, ask your supervisor. Thanks
craff
April 2, 2024, 4:38am
8
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
Kakadu
April 2, 2024, 9:39am
9
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))