Quick Start

Build your first BoltFFI project in 5 minutes.

1. Create a new library

cargo new --lib mylib
cd mylib

2. Configure Cargo.toml

[package]
name = "mylib"
version = "0.1.0"
edition = "2021"

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

[dependencies]
boltffi = "0.1"

[build-dependencies]
boltffi = "0.1"

3. Create build.rs

fn main() {
    boltffi::build::generate();
}

4. Write your Rust code

Replace src/lib.rs:

use boltffi::{data, export};

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

#[export]
pub fn add(a: i32, b: i32) -> i32 {
    a + b
}

#[export]
pub fn greet(name: &str) -> String {
    format!("Hello, {}!", name)
}

#[export]
pub fn distance(a: Point, b: Point) -> f64 {
    ((b.x - a.x).powi(2) + (b.y - a.y).powi(2)).sqrt()
}

5. Build and generate bindings

# Initialize config
boltffi init

# Build for iOS
boltffi build ios --release

# Generate Swift bindings
boltffi generate swift

# Package as XCFramework
boltffi pack ios

6. Use from Swift

let sum = add(a: 2, b: 3)
print("2 + 3 = \(sum)")  // "2 + 3 = 5"

let message = greet(name: "World")
print(message)  // "Hello, World!"

let p1 = Point(x: 0, y: 0)
let p2 = Point(x: 3, y: 4)
print("Distance: \(distance(a: p1, b: p2))")  // "Distance: 5.0"