merman-ffi
C ABI bindings for embedding merman in non-Rust hosts.
merman is a headless Rust implementation of Mermaid diagram parsing, layout, and rendering. It is
intended for servers, CLIs, mobile apps, desktop apps, and other environments that need Mermaid
output without launching a browser. The main library can produce semantic JSON, layout JSON, SVG,
terminal text, and raster formats depending on enabled features.
Start with the main project README for product scope and diagram coverage:
- Repository: https://github.com/Latias94/merman
- Project README: https://github.com/Latias94/merman
- Rust library: https://crates.io/crates/merman
- CLI: https://crates.io/crates/merman-cli
- Coverage status: https://github.com/Latias94/merman/blob/main/docs/alignment/STATUS.md
This crate exposes the low-level stable boundary described by
docs/bindings/FFI_PROTOCOL.md.
Higher-level generated bindings such as UniFFI should sit above the same behavior, not replace this
C ABI.
Build
From the workspace:
The crate builds cdylib, staticlib, and rlib artifacts. Include
include/merman.h
from C or C-compatible hosts.
Optional features:
The first C ABI release candidate exposes SVG, ASCII text, semantic JSON, layout JSON, validation JSON, and binding metadata. Native raster byte outputs are intentionally split into a later ABI lane.
Minimal C Usage
static const uint8_t source = "flowchart TD\nA[Hello] --> B[World]";
MermanResult result = ;
if
;
Every non-empty MermanResult.data buffer must be freed exactly once with merman_buffer_free.
Do not use free, delete, or a host runtime allocator for buffers returned by Rust.
For repeated calls with the same options, create a reusable engine:
MermanEngineResult engine = ;
if
MermanResult result = ;
;
;
Example
examples/render_svg.c
is a small C consumer that renders a flowchart to SVG through the C ABI.
examples/render_svg_engine.c
shows the reusable engine/context API for repeated calls with shared options.
On macOS or Linux:
To compile the reusable-engine example, replace render_svg.c with render_svg_engine.c in the
same command.
Entry Points
merman_abi_versionmerman_package_versionmerman_buffer_struct_sizemerman_result_struct_sizemerman_engine_result_struct_sizemerman_engine_newmerman_engine_freemerman_engine_render_svgmerman_engine_render_asciimerman_engine_parse_jsonmerman_engine_layout_jsonmerman_engine_validate_jsonmerman_render_svgmerman_render_asciimerman_parse_jsonmerman_layout_jsonmerman_validate_jsonmerman_supported_diagrams_jsonmerman_ascii_supported_diagrams_jsonmerman_supported_themes_jsonmerman_supported_host_theme_presets_jsonmerman_buffer_free
See
include/merman.h
for declarations and
docs/bindings/FFI_PROTOCOL.md
for result codes, options JSON, threading, and compatibility rules.
Higher-level platform wrappers:
- Apple SwiftPM:
docs/bindings/APPLE_SWIFT.md - Android JNI/Kotlin:
docs/bindings/ANDROID_JNI.md - Flutter/Dart FFI:
docs/bindings/FLUTTER_DART_FFI.md - Python UniFFI:
docs/bindings/PYTHON_UNIFFI.md