MCPcopy Index your code
hub / github.com/boltffi/boltffi

github.com/boltffi/boltffi @v0.27.2

Chat with this repo
repository ↗ · DeepWiki ↗ · release v0.27.2 ↗ · + Follow
16,462 symbols 53,372 edges 1,141 files 1,380 documented · 8%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

BoltFFI

A high-performance multi-language bindings generator for Rust. Up to 1,000x faster than UniFFI. Up to 450x faster than wasm-bindgen.

Join our Discord

Quick links: User Guide | Tutorial | Getting Started

Performance

vs UniFFI (Swift/Kotlin)

Benchmark BoltFFI UniFFI Speedup
noop <1 ns 1,416 ns >1000x
echo_i32 <1 ns 1,416 ns >1000x
counter_increment (1k calls) 1,083 ns 1,388,895 ns 1,282x
generate_locations (1k structs) 4,167 ns 1,276,333 ns 306x
generate_locations (10k structs) 62,542 ns 12,817,000 ns 205x

vs wasm-bindgen (WASM)

Benchmark BoltFFI wasm-bindgen Speedup
1k particles 29,886 ns 13,532,530 ns 453x
100 particles 3,117 ns 748,287 ns 240x
1k locations 21,931 ns 4,037,879 ns 184x
1k trades 42,015 ns 5,781,767 ns 138x
100 locations 2,199 ns 283,753 ns 129x

Full benchmark code: benchmarks

Why BoltFFI?

Serialization-based FFI is slow. UniFFI serializes every value to a byte buffer. wasm-bindgen materializes every struct as a JavaScript object. That overhead shows up even when you're making tens or hundreds of FFI calls per second.

BoltFFI uses zero-copy where possible. Primitives pass as raw values. Structs with primitive fields pass as pointers to memory both sides can read directly. WASM uses a wire buffer format that avoids per-field allocation. Only strings and collections go through encoding.

What it does

Mark your Rust types with #[data] and functions with #[export]:

use boltffi::*;

#[data]
pub struct Point {
    pub x: f64,
    pub y: f64,
}

#[export]
pub fn distance(a: Point, b: Point) -> f64 {
    let dx = b.x - a.x;
    let dy = b.y - a.y;
    (dx * dx + dy * dy).sqrt()
}

Run BoltFFI for the targets you need:

boltffi pack all
# Produces: ./dist/apple/YourCrate.xcframework + Package.swift
# Produces: ./dist/android/jniLibs/<abi>/libyour_crate.so + Kotlin bindings
# Produces: ./dist/java/native/<host-target>/libyour_crate_jni.* + Java bindings
# Produces: ./dist/wasm/pkg/*.wasm + TypeScript bindings + npm package
# Produces: ./dist/csharp/packages/*.nupkg with RID native assets
# Produces: ./dist/python/wheelhouse/*.whl with Python package sources

Use it from Swift, Kotlin, Java, C#, TypeScript, or Python.

let d = distance(a: Point(x: 0, y: 0), b: Point(x: 3, y: 4)) // 5.0
val d = distance(a = Point(x = 0.0, y = 0.0), b = Point(x = 3.0, y = 4.0)) // 5.0
double d = MyLib.distance(new Point(0.0, 0.0), new Point(3.0, 4.0)); // 5.0
double d = MyLib.Distance(new Point(0.0, 0.0), new Point(3.0, 4.0)); // 5.0
import { distance } from 'your-crate';
const d = distance({ x: 0, y: 0 }, { x: 3, y: 4 }); // 5.0
import your_crate
d = your_crate.distance(your_crate.Point(0, 0), your_crate.Point(3, 4))  # 5.0

The generated bindings use each language's idioms. Swift gets async/await. Kotlin gets coroutines. Java gets CompletableFuture and functional interfaces. C# gets Tasks and async enumerables. TypeScript gets Promises. Errors become native exceptions.

Supported languages

Language Status
Swift Full support
Kotlin Full support
Java Full support
C# Full support
WASM/TypeScript Full support
C Partial
Python Full support
C++ Planned
Ruby Planned
Dart In progress
Scala Planned
Go Planned
Lua Potential
R Potential

Want another language? Open an issue.

Installation

cargo install boltffi_cli

Add BoltFFI to your library crate:

cargo add boltffi

Configure the crate type in Cargo.toml:

[lib]
crate-type = ["cdylib", "staticlib"]

Documentation

Alternative tools

Other tools that solve similar problems:

  • UniFFI - Mozilla's binding generator, uses serialization-based approach
  • Diplomat - Focused on C/C++ interop
  • cxx - Safe C++/Rust interop

Contributing

If this tool sounds interesting to you, please help us develop it. You can:

License

BOLTFFI is released under the MIT license. See LICENSE for more information.

Extension points exported contracts — how you extend this code

Render (Interface)
A render rule for one typed expansion input. The `(S, Input)` pair selects the implementation. Generic `S: RenderSurfac [61 …
boltffi_macros/src/experimental/wrapper/mod.rs
ReturnPlanRender (Interface)
Target-language rendering for return plans. The shared walker owns the `ReturnPlan` variant traversal. Backends impleme [5 …
boltffi_binding/src/ir/callable.rs
WireEncode (Interface)
(no doc) [17 implementers]
boltffi_core/src/wire/encode.rs
LanguageGenerator (Interface)
(no doc) [6 implementers]
boltffi_cli/src/commands/generate/generator.rs
SyntaxFragment (Interface)
(no doc) [8 implementers]
boltffi_backend/src/core/syntax.rs
Rule (Interface)
(no doc) [8 implementers]
boltffi_verify/src/rules/mod.rs
CSharpCallablePlan (Interface)
Common template-facing view of a generated C# callable. Top-level functions and methods live in different plan structs [2 …
boltffi_bindgen/src/render/csharp/plan/callable/callable_plan.rs
SyncValueCallback (Interface)
(no doc) [4 implementers]
boltffi_tests/src/callbacks.rs

Core symbols most depended-on inside this repo

clone
called by 1964
boltffi_binding/src/ir/op.rs
iter
called by 1306
boltffi_bindgen/src/metadata.rs
map
called by 983
boltffi_binding/src/ir/codec.rs
collect
called by 797
boltffi_scan/src/marked.rs
join
called by 683
boltffi_cli/src/pack/scratch.rs
as_str
called by 584
boltffi_bindgen/src/render/jni/plan.rs
push
called by 530
boltffi_core/src/ringbuffer.rs
push
called by 523
boltffi_bindgen/src/render/csharp/ast/argument_list.rs

Shape

Method 7,705
Function 6,236
Class 1,827
Enum 529
Interface 165

Languages

Rust84%
Kotlin6%
C#2%
Python2%
TypeScript2%
C2%

Modules by API surface

benchmarks/harnesses/kotlin-jvm-bench/app/src/main/java/com/example/bench_riff/BenchRiff.kt486 symbols
boltffi_macros/src/experimental/expansion/mod.rs345 symbols
boltffi_bindgen/src/render/java/lower.rs276 symbols
boltffi_bindgen/src/render/kotlin/lower.rs232 symbols
benchmarks/harnesses/dotnet-bench/SharedSurfaceBenchmarks.cs227 symbols
boltffi_cli/src/config/mod.rs205 symbols
boltffi_bindgen/src/render/jni/lower.rs168 symbols
benchmarks/harnesses/kotlin-jvm-bench/app/src/main/kotlin/com/example/bench_riff/BenchRiff.kt167 symbols
boltffi_bindgen/src/scan/mod.rs163 symbols
benchmarks/harnesses/kotlin-jvm-bench/app/src/main/java/jni/jni_glue.c159 symbols
boltffi_macros/src/experimental/wrapper/callback.rs154 symbols
boltffi_ffi_rules/src/lib.rs154 symbols

For agents

$ claude mcp add boltffi \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact