ppx_deriving icon indicating copy to clipboard operation
ppx_deriving copied to clipboard

README example for running an individual deriver seems not to work in 4.2

Open yomimono opened this issue 8 years ago • 7 comments

I can't seem to run an individual deriver with -deriving-plugin as the README says I should be able to with version 4.2. All output from ocamlfind seems correct and consistent, but I always get Failure("Ast_mapper: OCaml version mismatch or malformed input").

Please let me know what other diagnostic information would be helpful.

4.05.0🐫  user@mirageos:~$ cat test.ml
type foo = A of int | B of float
[@@deriving show]
4.05.0🐫  user@mirageos:~$ ocamlfind ppx_deriving/ppx_deriving     -deriving-plugin `ocamlfind query ppx_deriving`/ppx_deriving_show.cma     test.ml
Failure("Ast_mapper: OCaml version mismatch or malformed input")
4.05.0🐫  user@mirageos:~$ ocamlfind ppx_deriving/ppx_deriving
Usage: /home/user/.opam/4.05.0/lib/ppx_deriving/ppx_deriving [extra_args] <infile> <outfile>
4.05.0🐫  user@mirageos:~$ ocamlfind query ppx_deriving
/home/user/.opam/4.05.0/lib/ppx_deriving
4.05.0🐫  user@mirageos:~$ 

yomimono avatar Sep 25 '17 15:09 yomimono

ppx_deriving is kind of broken right now, but I haven't had time to work properly on it due to FOSS overload. sorry.

whitequark avatar Sep 25 '17 20:09 whitequark

Aw, I'm sorry to hear that. ppx_deriving looked like just the thing for a project I've just started on, and I was looking forward to working with it. Thanks for the quick reply, @whitequark , and I hope you have time and energy to work on the things you find rewarding :)

yomimono avatar Sep 25 '17 22:09 yomimono

I hope we can find the manpower to complement @whitequark here, but I haven't been able to help much myself with the compiler distribution release work. (cc @let-def)

gasche avatar Sep 26 '17 04:09 gasche

The command executed by ocamlfind ppx_deriving/ppx_deriving expects the passed file to contain a marshalled AST, but test.ml is a plain source file.

Here is a temporary workaround:

ocamlfind ocamlopt -ppx '`ocamlfind query ppx_deriving`/ppx_deriving `ocamlfind query ppx_deriving`/ppx_deriving_show.cma' -dsource -c test.ml

xclerc avatar Sep 26 '17 16:09 xclerc

I pushed a tentative fix in a new branch, namely main-omp-driver.

The problem is that is ppx_deriving_main now uses the omp machinery to register a driver. However, to make that happen and be able to set command-line arguments for the driver, we need the registration in ppx_deriving to be explicit (thus breaking other use cases).

My feeling is that moving to omp (and jbuilder for that matter) would make things easier, but I am not sure it can be done in a backward-compatible way.

xclerc avatar Sep 27 '17 10:09 xclerc

@xclerc Can you explain why the registration has to be explicit? (I used to know a few months ago but I completely forgot, sorry)

let-def avatar Oct 02 '17 15:10 let-def

I have quite possibly missed something, but by basing Ppx_deriving_main on the omp registration mechanism I needed to register the driver from there (not. to specify the command-line arguments to be processed).

Is there a way to replace an existing driver (in this case, previously registered by the Ppx_deriving module) with a new one?

xclerc avatar Oct 03 '17 12:10 xclerc