Gleam bindings for calling Zig libraries via FFI.
This library provides a type-safe way to call Zig code from Gleam. Zig exports C-compatible functions that Gleam can call through its FFI mechanism.
// src/my_zig_lib.gleam
@external(erlang, "my_zig_nif", "add")
pub fn add(a: Int, b: Int) -> Int
@external(erlang, "my_zig_nif", "multiply")
pub fn multiply(a: Int, b: Int) -> IntYour Zig code must export C-compatible functions:
// mylib.zig
export fn add(a: i32, b: i32) callconv(.C) i32 {
return a + b;
}For BEAM, use Zigler to create NIFs directly. For JavaScript, build as shared library.
| Gleam Type | Zig Type | Notes |
|---|---|---|
|
|
Platform dependent |
|
|
64-bit float |
|
|
Boolean |
|
|
Null-terminated |
|
|
Pointer + length |
This library follows the Rhodium Standard Repository guidelines:
-
Gleam for backend services
-
Zig for performance-critical FFI
-
No C wrapper code required