ocaml-rust-starter
ocaml-rust-starter copied to clipboard
Getting started with ocaml-rs
ocaml-rust-starter
An example project using ocaml-rs to call Rust functions from OCaml.
If you're looking for an example of linking an OCaml library into a Rust program take a look at rust-ocaml-starter
New project checklist
- [ ] Update
README.md - [ ] Update the project name in
dune-project - [ ] Update the crate name in
Cargo.toml - [ ] Update
src/duneandtest/dunewith the name of your project in place ofocaml_rust_example/ocaml-rust-example - [ ] Rename
ocaml-rust-starter.opamto match the name of your project - [ ] Remove
src/ocaml_rust_example.mlandsrc/ocaml_rust_example.mliand add your own OCaml files - [ ] Update
build.rs - [ ] Edit
src/lib.rs - [ ] Add your tests to
test/test.ml - [ ] Use
cargo vendorif you intend to make the project installable using opam
Many of the renaming steps can be automated using init.sh:
$ ./init.sh my_project my-project
init.sh accepts two arguments: the name of the OCaml project and the public_name, if they are the same then one argument is acceptable.
NOTE: init.sh is destructive and can only be executed once (it will remove itself) - make sure you have no modifications that you want to keep before running init.sh.
Building
dune build
to run the tests:
dune runtest
to load your library into an interactive sesssion:
OCAML_INTEROP_NO_CAML_STARTUP=1 dune utop
The OCAML_INTEROP_NO_CAML_STARTUP environment variable should be set to ensure
the library is linked correctly.