我正在尝试将jbuilder和ppx_deriving (特别是ppx_deriving_yojson
)一起使用,但是被卡住了一个多小时。我当前的方法是一个jbuild
文件,其中包含以下内容:
(jbuild_version 1)
(executables
((names (my-binary))
(libraries
(ppx_deriving
ppx_deriving_yojson
cohttp
yojson))
(preprocess (pps (ppx_deriving_yojson ppx_driver.runner)))))
但这会导致
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
在_build/.ppx/default/ppx_deriving_yojson+ppx_driver.runner/ppx.exe
中使用-print-transformations
手动运行生成的ppx_driver
会得到空输出,因此我显然遗漏了一些东西。
通过将ppx_deriving
和ppx_deriving_yojson
作为依赖项包括在内,代码可以很好地使用topkg
构建。
发布于 2018-01-17 06:14:30
从较新版本的ppx_deriving_yojson开始,这应该是可能的。
代码:
type t = {x: int; y: int} [@@deriving to_yojson]
let () = print_endline (Yojson.Safe.to_string (to_yojson {x= 1; y= 2}))
和一个示例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)))))
https://stackoverflow.com/questions/43771425
复制相似问题