OCaml bindings for calling Zig libraries via FFI.
This library provides type-safe OCaml bindings to Zig libraries.
Zig exports C-compatible functions that OCaml can call through
its C FFI mechanism using ctypes or external declarations.
opam install ocaml-zig-ffiOr add to your dune-project:
(depends
(ocaml-zig-ffi (>= 0.1)))Your Zig code must export C-compatible functions:
// mylib.zig
export fn add(a: i32, b: i32) callconv(.C) i32 {
return a + b;
}Build as shared library:
zig build-lib -dynamic -O ReleaseFast mylib.zig| OCaml Type | Zig Type | Ctypes Type |
|---|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
This library follows the Rhodium Standard Repository guidelines:
-
OCaml for AffineScript compiler
-
Zig for performance-critical FFI
-
No C wrapper code required