An example project using ocaml-rs to link an OCaml library into a Rust program.
If you're looking for an example of calling into Rust from OCaml take a look at ocaml-rust-starter
- Update
README.md - Update the project name in
dune-project - Update the crate name in
Cargo.toml - Update
lib/duneandlib/dunewith the name of your project in place ofrust_ocaml_starter/rust-ocaml-starter - Rename
rust-ocaml-starter.opamto match the name of your project - Remove
lib/rust_ocaml_starter.mladd your own OCaml files - Edit
src/lib.rs
Many of the renaming steps can be automated using init.sh:
$ ./init.sh my_project my-projectinit.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.
Optionally create a local OPAM switch (choose the version you prefer):
opam update
opam switch create . ocaml-base-compiler.4.14.0
eval $(opam env) && opam switch
opam install dune
Then:
cargo build
to run the program:
cargo run