How to use jbuild and ppx_driver with ppx_deriving

I have been trying to use jbuilder along with ppx_deriving ( ppx_deriving_yojson

specifically) but have been stuck for over an hour. My current approach is a jbuild

file containing the following:

(jbuild_version 1)
(executables
((names (my-binary))
(libraries
 (ppx_deriving
  ppx_deriving_yojson
  cohttp
  yojson))
(preprocess (pps (ppx_deriving_yojson ppx_driver.runner)))))

      

But this leads to

Command [5] exited with code 1:
$ (cd _build/default && ../.ppx/default/ppx_deriving_yojson+ppx_driver.runner/ppx.exe --dump-ast -o src/my_file.pp.ml --impl src/my_file.ml)
File "src/my_file.ml", line 16, characters 5-13:
Error: Attribute `deriving' was not used

      

Running the generated ppx_driver

in _build/.ppx/default/ppx_deriving_yojson+ppx_driver.runner/ppx.exe

manually with -print-transformations

gives empty output, so I am obviously missing something.

The code builds fine with help topkg

, just including ppx_deriving

and ppx_deriving_yojson

as dependencies.

+3


source to share


1 answer


As with later versions of ppx_deriving_yojson, this should be possible.

code:

type t = {x: int; y: int} [@@deriving to_yojson]

let () = print_endline (Yojson.Safe.to_string (to_yojson {x= 1; y= 2}))

      



And an example file jbuild

:

(jbuild_version 1)

(executables
 ((names (main))
  (preprocess (pps (ppx_deriving_yojson)))
  (libraries (ppx_deriving_yojson.runtime))))

(install
 ((section bin)
  (files ((main.exe as main)))))

      

+2


source







All Articles