kuniffi-generator

Crates.iokuniffi-generator
lib.rskuniffi-generator
version0.2.0
created_at2026-01-10 21:49:30.728892+00
updated_at2026-01-10 23:47:09.240917+00
descriptionGenerate iOS (.a, .dylib) and Android (.so) libraries from Rust projects with UniFFI
homepagehttps://github.com/KevalPatel94/KUniffi-Generator
repositoryhttps://github.com/KevalPatel94/KUniffi-Generator
max_upload_size
id2034747
size33,537
Keval T Patel (KevalPatel94)

documentation

README

kuniffi-generator

A tool to generate iOS (.a, .dylib) and Android (.so) libraries from Rust projects with UniFFI

Generate native libraries for iOS and Android from your Rust project with a simple command.

Installation

From crates.io (when published)

cargo install kuniffi-generator

From Local Path (for development)

git clone https://github.com/KevalPatel94/KUniffi-Generator.git
cd KUniffi-Generator
cargo install --path .

Make sure ~/.cargo/bin is in your PATH:

export PATH="$HOME/.cargo/bin:$PATH"

Quick Start

1. Install the Tool

cargo install kuniffi-generator

2. Navigate to Your Rust Project

cd /path/to/your/rust/project

3. Ensure Your Project Has UniFFI Setup

Your Cargo.toml should have:

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

[dependencies]
uniffi = "0.30.0"

[[bin]]
name = "uniffi-bindgen"
path = "uniffi-bindgen.rs"
required-features = ["bindgen-cli"]

[features]
bindgen-cli = ["uniffi/cli"]

Create uniffi-bindgen.rs:

fn main() {
    uniffi::uniffi_bindgen_main();
}

In your src/lib.rs, use UniFFI procedural macros:

uniffi::setup_scaffolding!();

#[uniffi::export]
pub fn my_function(x: i32) -> i32 {
    x * 2
}

4. Build Libraries

# Build for iOS (generates .a and .dylib files)
kuniffi-build ios

# Build for Android (generates .so files)
kuniffi-build android

# Build for both platforms
kuniffi-build both

# Specify package name explicitly (if auto-detection fails)
kuniffi-build ios mylib

The tool will automatically detect your package name from Cargo.toml if not specified.

Usage

kuniffi-build <ios|android|both> [package-name]
  • ios - Build iOS libraries (.a and .dylib files)
  • android - Build Android libraries (.so files)
  • both - Build for both iOS and Android
  • package-name - Optional Rust package name (auto-detected from Cargo.toml if not provided)

Output Structure

After building, libraries are generated in:

iOS:

bindings/ios/
├── aarch64-apple-ios/
│   ├── libmylib.a
│   └── libmylib.dylib
├── aarch64-apple-ios-sim/
│   ├── libmylib.a
│   └── libmylib.dylib
└── x86_64-apple-ios/
    ├── libmylib.a
    └── libmylib.dylib

Android:

bindings/android/jniLibs/
├── arm64-v8a/
│   └── libmylib.so
├── armeabi-v7a/
│   └── libmylib.so
├── x86/
│   └── libmylib.so
└── x86_64/
    └── libmylib.so

Requirements

  • Rust toolchain - Install from rustup.rs
  • For iOS builds: Xcode Command Line Tools and iOS targets
  • For Android builds: cargo-ndk and Android NDK

Installing iOS Targets

rustup target add aarch64-apple-ios
rustup target add aarch64-apple-ios-sim
rustup target add x86_64-apple-ios

Installing Android Requirements

cargo install cargo-ndk
rustup target add aarch64-linux-android
rustup target add armv7-linux-androideabi
rustup target add i686-linux-android
rustup target add x86_64-linux-android

The tool will automatically install missing Rust targets during the build process.

Example

See the examples/calculator directory for a complete working example:

cd examples/calculator
kuniffi-build ios
kuniffi-build android

How It Works

  1. Detects your Rust package name from Cargo.toml
  2. Builds release libraries for the specified platform(s)
  3. Copies generated libraries to bindings/ directory
  4. Scripts are automatically embedded and extracted as needed

All builds use release mode for optimized, production-ready libraries.

Troubleshooting

"command not found: kuniffi-build"

Make sure ~/.cargo/bin is in your PATH:

export PATH="$HOME/.cargo/bin:$PATH"
# Add to ~/.bashrc or ~/.zshrc for persistence

"cargo-ndk not found" (Android builds)

cargo install cargo-ndk

Build fails with "Could not determine package name"

Either specify the package name explicitly:

kuniffi-build ios mylib

Or ensure Cargo.toml exists in the current directory with a valid [package] section.

Build fails for specific target

Make sure the Rust target is installed:

rustup target list --installed
rustup target add <target-name>

The tool will attempt to auto-install missing targets, but manual installation may be needed in some cases.

License

MIT

Commit count: 8

cargo fmt