image:[License,link="https://github.com/hyperpolymath/palimpsest-license"]
ReScript bindings for calling Zig libraries via the C ABI.
This library provides a type-safe way to call Zig code from ReScript. Zig exports C-compatible functions that ReScript can call through its external mechanism.
ReScript → External Declarations → Deno FFI → Zig (C ABI)
ReScript compiles to JavaScript running in Deno, which uses Deno.dlopen
to load Zig shared libraries.
# Add to your deno.json
{
"imports": {
"@hyperpolymath/rescript-zig-ffi": "jsr:@hyperpolymath/rescript-zig-ffi@0.1"
}
}// src/bindings/MyZigLib.res
@module("./ffi.js")
external zigFunction: (int, int) => int = "zigFunction"
@module("./ffi.js")
external zigStringOp: string => string = "zigStringOp"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| ReScript Type | Zig Type | Notes |
|---|---|---|
|
|
32-bit signed integer |
|
|
64-bit float |
|
|
Boolean |
|
|
Null-terminated string |
|
|
Pointer to array |
This library follows the Rhodium Standard Repository guidelines:
-
ReScript for all application code
-
Deno for runtime and package management
-
Zig for FFI implementation
-
No C code required