# Directly compiling and using ppx\_deriving

**URL:** <https://discuss.ocaml.org/t/directly-compiling-and-using-ppx-deriving/2295>\
**Category:** Ecosystem\
**Tags:** ppx\
**Created:** [July 14, 2018, 6:51pm UTC](https://discuss.ocaml.org/t/directly-compiling-and-using-ppx-deriving/2295 "2018-07-14T18:51:44Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ELLIOTTCABLE](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/elliottcable/32/799_2.png) [@ELLIOTTCABLE](https://discuss.ocaml.org/u/ELLIOTTCABLE)\
**Post date:** [July 14, 2018, 6:51pm UTC](https://discuss.ocaml.org/t/directly-compiling-and-using-ppx-deriving/2295/1 "2018-07-14T18:51:44Z")

</div>

I’ve grown used to tools like `ppx_inline_test` and `ppx_show` in my OCaml code built by Dune; and I’m currently headed down the road of integrating them into my BuckleScript-to-JavaScript pipeline. (Lord, how I miss Dune!)

However, at the moment, I can’t even get a simple hand-built ppx driver working! Can anybody walk this newbie thru what he’s doing wrong?

```
$ cat test.ml
type foo = A of int | B of float
[@@deriving show]

$ ocamlfind opt -predicates ppx_driver -linkpkg -linkall -o ppx_driver \
    -package ppx_deriving.show -package ppx_deriving
findlib: [WARNING] Interface topdirs.cmi occurs in several directories: /Users/ec/Documents/Code/Source/ppx_deriving/_opam/lib/ocaml/compiler-libs, /Users/ec/Documents/Code/Source/ppx_deriving/_opam/lib/ocaml

$ ocamlc -c -ppx "./ppx_driver -as-ppx" test.ml
File "test.ml", line 1:
Error: External preprocessor does not produce a valid file
Command line: ./ppx_driver -as-ppx '/var/folders/xt/wm01x2h50nv993t_csb1t5qm0000gn/T/camlppx7ee45a' '/var/folders/xt/wm01x2h50nv993t_csb1t5qm0000gn/T/camlppx3eb5cb'

```

Trying `./ppx_driver -help` produces no output, nor any errors … in fact, no input, files, or stdin seems to cause it to do anything whatsoever.

Please help me learn how ppx-drivers work! `D:`

---

<div class="post-metadata">

**Author:** ![dariusf](https://avatars.discourse-cdn.com/v4/letter/d/f07891/32.png) [@dariusf](https://discuss.ocaml.org/u/dariusf)\
**Post date:** [July 16, 2018, 4:34am UTC](https://discuss.ocaml.org/t/directly-compiling-and-using-ppx-deriving/2295/2 "2018-07-16T04:34:33Z")

</div>

Check [this](https://github.com/ocaml-ppx/ppxlib#building-a-custom-driver-using-ocamlfind) out. That lets you do `./ppx file.ml` to view the preprocessed version of a source file.

To actually integrate it into a build, if you’re using BuckleScript and bsb, this is one way:

1. Compile ppx\_deriving with BS. You can do this by forking it, [adding a `bsconfig.json`](https://github.com/dariusf/ppx_deriving/commit/e1ac92d1b464411acd61847415945bc919d44830), then doing `bsb -make-world`.
2. In your project, `npm install` your repository and add its `name` (check its `package.json`) to `bsconfig.json` under `bs-dependencies`. This makes ppx\_deriving’s runtime library available.
3. `opam install ppx_deriving` on a BS-compatible switch (4.02.3 last time I tried this).
4. [Tell BS to call the opam-installed driver](https://github.com/BuckleScript/bucklescript/issues/2407#issuecomment-367212852). Alternatively, you can try to get the driver into `node_modules` somehow.

This worked for me a few months ago. I don’t know if the Reason community has since come up with a better way to use ppx preprocessors.
