OCaml scripting and ppx support

I know we can simply use #!/usr/bin/env ocaml to write OCaml scripts,
and we can even use #load “topfind” and then have access to ocaml libraries
easily via #require.

But what about getting good support for ppx in the script itself?
How can I use some deriving annotation in my OCaml script?

Let’s say I would like to use the ppx_cmdliner extensions from my script, so it’s also
super easy to define the cmdline interface. How can I invoke #!/usr/bin/env ocaml …
to get access to this ppx extension?

You can #require ppx libraries too:

#require "ppx_deriving_cmdliner";;
6 Likes

My god, it actually works! I was sure we had to pass some flag to ocaml like we do
in the dune file with those pps or ppx.