githubEdit

Compile Reason With An OCaml Package Using Dune

In Compile Reason To Native With Dunearrow-up-right, I showed how to compile a basic ReasonML file as a native executable using Dune.

Any non-trivial program will likely involve pulling in an OCaml dependency. For example, you may want to pull in Lwtarrow-up-right. Assuming this package is available, whether you've manually downloaded it via opamarrow-up-right or used something like esyarrow-up-right, you'll want to let Dune know that Lwt is an available library.

;; dune
(executable
 (name hello_reason)
 (libraries lwt lwt.unix))

The modules in the Lwt package will now be globally available to your Reason code.

let () = {
  Lwt_main.run(
    Lwt_io.printf("Hello, Reason!\n")
  );
};

When Dune builds your code, it will include and compile Lwt.

See a full example herearrow-up-right.

Last updated