• Stars
    star
    212
  • Rank 186,122 (Top 4 %)
  • Language
    Rust
  • License
    ISC License
  • Created almost 7 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

OCaml extensions in Rust

ocaml-rs - OCaml extensions in Rust

ocaml-rs allows for OCaml extensions to be written directly in Rust with no C stubs. It was originally forked from raml, but has been almost entirely re-written thanks to support from the OCaml Software Foundation.

Works with OCaml versions 4.08.0 and up

Please report any issues on github

NOTE: While ocaml-rs can be used safely, it does not prevent a wide range of potential errors or mistakes. It should be thought of as a Rust implementation of the existing C API. ocaml-interop can be used to perform safe OCaml/Rust interop. ocaml-rs uses ocaml-interop behind the scenes to interact with the garbage collector. ocaml-rs also exports an interop module, which is an alias for ocaml_interop and the two interfaces can be combined if desired.

Documentation

Getting started

ocaml-rust-starter is a basic example to help get started with ocaml-rs.

On the Rust side, you will need to add the following to your Cargo.toml:

ocaml = "*"

or

ocaml = {git = "https://github.com/zshipko/ocaml-rs"}

For macOS you will need also to add the following to your project's .cargo/config file:

[build]
rustflags = ["-C", "link-args=-Wl,-undefined,dynamic_lookup"]

This is because macOS doesn't allow undefined symbols in dynamic libraries by default.

Additionally, if you plan on releasing to opam, you will need to vendor your Rust dependencies to avoid making network requests during the build phase, since reaching out to crates.io/github will be blocked by the opam sandbox. To do this you should run:

cargo vendor

then follow the instructions for editing .cargo/config

Build options

By default, building ocaml-sys will invoke the ocamlopt command to figure out the version and location of the OCaml compiler. There are a few environment variables to control this.

  • OCAMLOPT (default: ocamlopt) is the command that will invoke ocamlopt
  • OCAML_VERSION (default: result of $OCAMLOPT -version) is the target runtime OCaml version.
  • OCAML_WHERE_PATH (default: result of $OCAMLOPT -where) is the path of the OCaml standard library.
  • OCAML_INTEROP_NO_CAML_STARTUP (default: unset) can be set when loading an ocaml-rs library into an OCaml bytecode runtime (such as utop) to avoid linking issues with caml_startup

If both OCAML_VERSION and OCAML_WHERE_PATH are present, their values are used without invoking ocamlopt. If any of those two env variables is undefined, then ocamlopt will be invoked to obtain both values.

Defining the OCAML_VERSION and OCAML_WHERE_PATH variables is useful for saving time in CI environments where an OCaml install is not really required (to run clippy for example).

Features

  • derive
    • enabled by default, adds #[ocaml::func] and friends and derive implementations for FromValue and ToValue
  • link
    • link the native OCaml runtime, this should only be used when no OCaml code will be linked statically
  • no-std
    • Allows ocaml to be used in #![no_std] environments like MirageOS

More Repositories

1

rust-kv

An embedded key/value store for Rust
Rust
122
star
2

ocaml-py

Python 3.5+ bindings for OCaml
OCaml
54
star
3

image2-rs

Image processing library for Rust
Rust
51
star
4

ocaml-bimage

Composable image processing library for OCaml
C
35
star
5

llama

Rust LLVM bindings
Rust
29
star
6

yurt

OCaml HTTP Microframework
OCaml
25
star
7

ocaml-rust-starter

Getting started with ocaml-rs
Shell
23
star
8

futhark-bindgen

A Futhark binding generator for Rust and OCaml
Rust
17
star
9

ocaml-vec

Example OCaml library written using Rust and ocaml-rs
OCaml
15
star
10

halide-runtime

Rust bindings to the Halide runtime
C++
14
star
11

resp

OCaml library for building clients and servers that communicate using the Redis Serialization Protocol
OCaml
12
star
12

irmin-redis

Redis backend for Irmin
OCaml
10
star
13

irmin-remote

OCaml
9
star
14

irmin-ipfs

OCaml
9
star
15

irmin-web

A tool for building web applications using Irmin
OCaml
8
star
16

irmin-graphql-js

Irmin GraphQL bindings for Javascript
JavaScript
8
star
17

ocaml-hiredis

Hiredis bindings for OCaml
C
7
star
18

qq

A message queue for MirageOS
OCaml
7
star
19

libirmin

C bindings for Irmin
OCaml
7
star
20

irmin-resp

A RESP server for Irmin
OCaml
6
star
21

halide-build

Rust
6
star
22

irmin-unikernels

OCaml
6
star
23

ocaml-ezsqlite

Simple SQLite3 bindings for OCaml
C
5
star
24

resp-server

An OCaml library for building servers that speak RESP
OCaml
5
star
25

ocaml-b2

Backblaze API for OCaml
OCaml
5
star
26

irmin-graphql-go

Go bindings to the Irmin GraphQL API
Go
5
star
27

castor

An embedded content addressable store for Rust
Rust
4
star
28

libtwombly

Vector graphics library based on Antigrain
C++
4
star
29

ocaml-fusion

Lazy streams for OCaml
OCaml
4
star
30

irmin-fuse

OCaml
3
star
31

memtrace-filters

OCaml
3
star
32

rust-ocaml-starter

Shell
3
star
33

ocaml-openbsd

OCaml
3
star
34

ezimage

bare-bones image I/O library
C++
3
star
35

ocaml-rusage

C
2
star
36

seqdir

OCaml
2
star
37

worm-rs

Rust
1
star
38

ocaml-rs-tuple-of-vectors

Rust
1
star
39

worm

Reflection-based RESP3 server framework
Go
1
star
40

ocaml-crc64

OCaml
1
star
41

fileproxy-rs

Rust
1
star
42

ocaml-warc

OCaml
1
star
43

rust-sexplib

Rust
1
star
44

redis-tls

A secure proxy for Redis
OCaml
1
star
45

irmin-rpc-rust

Rust
1
star
46

ocamlformat-auto

Automatic ocamlformat version selection
OCaml
1
star
47

c-header-to-json

Python
1
star
48

repr-rs

Rust
1
star