Ppx_deriving, ppx_type_conv and jbuilder: things should be better now

Hi,

You might have exeperienced issues recently related to bad
interactions between ppx_type_conv and ppx_deriving. Work was done
to improve the situation, and since
this last PR yesterday
I expected that all remaining issues are gone.

In particular, if you have been using both ppx_deriving plugins such
as ppx_deriving_yojson and ppx_type_conv plugins such as
ppx_sexp_conv on the same files, then everything should work
properly again. You should also be able to upgrade to OCaml 4.06
without additional issues.

I did some work earlier this year in order to satisfy a growing demand
of being able to use ppx_deriving plugins with jbuilder. This work
spanned across multiple repositories and not all parts were released
at the same time in opam. I was away for the past few months so I
couldn’t finish all this properly, and I didn’t leave a detailed plan
of the whole work so that other could finish it. Sorry for the
troubles caused.

At this point, the complex part of the work for being able to use
ppx_deriving plugins with jbuilder has been done and is released.
There are just a few things that every ppx_deriving plugin must do
to ensure it is compatible with jbuilder. Note that plugins that are
developped with jbuilder are automatically compatible with jbuilder
and other build systems. This is only for plugins that are developped
and packaged using other systems (oasis, ocamlbuild, makefiles,
etc…).

Here are what such plugins must ensure:

  1. the plugin and in particular the META file must support static
    linking. ppx_deriving itself supports both dynamic linking and
    static linking of custom ppx drivers, so there should normally be
    nothing to change for most plugins

  2. jbuilder uses a slightly different model for dealing with ppx
    rewriters that the original model. The main difference for
    ppx_deriving plugins is that runtime dependencies of the rewriter
    must be specified explicitely in the META file as follow:

    ppx_runtime_deps = "foo.runtime ..."
    
  3. because jbuilder always statically links plugins inside custom ppx
    drivers, you must make sure that the .cma and .cmxa archives of
    plugins are linked with the -linkall flag of the OCaml compiler,
    otherwise they’ll be ignored by the compiler when linking the
    custom ppx driver. For instance if you are using ocamlbuild, you
    can add a line like this to your _tags file:

    <src/foo.{cma,cmxa}>: linkall
    
13 Likes

Thank you for the update, and for y’alls work getting this worked out as quickly as possible. The effort and attention is much appreciated!

1 Like