Derive-ocaml: a rust crate to help with ocaml FFI

i’m pleased to announce the first release of derive-ocaml` a set of rust macros 1.1/2.0 (similar to ppx) to generate boilerplate of writing rust stubs for ocaml external calls.

The crate has no runtime and relies on the ocaml crate for all the ocaml runtime bindings.

The macros are still a bit experimental but should make ocaml/rust ffi much easier to create.
Also while here i’d like to thank @zshipko for maintaining and improve the ocaml crate !!

13 Likes

So this is to allow calling Rust from OCaml?

yes,but mostly it’s helper to derive conversion from and to ocaml types to rust structures/enums. This is the main feature, it generates boilerplate code to call store_field()/field ‘macros’ like in C.
On top of that it has some glue to make rust functions “nice” looking by hiding CAMLparams and co macros.

You can see a very basic example here :

4 Likes

This is very exciting. Hopefully, it will become stable and safe to use in production.

I’m already using this in prod, but at a small scale (~5 functions, 3 structs/enums). I don’t want to remove the “experimental” warning before writing a good testsuite, but i need to find the time to do that

5 Likes