#ifdef / conditional compilation in *.ml files

I’m wondering if there is something like C’s #ifdef, so we can do something like:

#ifdef ReScript
... code for ReScript compiler ...
... code for ocaml compiler ...

This is for situations where I need to define a function; in the ReScript case, using the JS./ API, and in the OCaml case, using Base/Core; so I’d like some type of conditional flag to include/exclude code in *.ml files, based on whether it is ReScript or OCaml doing the compiling.

See Any documentation on Conditional Compilation?

EDIT: this is specific to ReScript though, it won’t work in upstream OCaml.

1 Like


#if ...

work in OCaml as well? From the docs / trying stuff, it appears it is for doing conditional compilation based on different versions of bucklescript.

However, I want conditional compilation based on whether it’s rescript/bsc or if its OCaml.