Warning
This project is on its first release. I'm still trying out the idea. It has not been used in production.
This is a simple but opinionated FFI system for Rust. It allows you to call Rust code from other languages, and vice versa. Some design principles:
- Intended for writing platform-agnostic Rust with platform-specific details in the host language
- FFI support is split into data (structs passed by copy) and code (traits passed by reference)
- Rather than have a separate schema language, the public API in your lib.rs is your schema
- The generated binding code is compact, dependency-free, and straightforward to integrate with
- Primitive types (bool, i32, f64, String, etc.)
- Tuples
- Structs
- Enums
- Top-level constants
- Top-level functions
- Traits (must be either Box<dyn T> or Rc<dyn T>)
- Vec<T>
- Option<T>
- Box<T>
- JavaScript/TypeScript (WASM)
- Swift
- C++
After setting everything up, using miniffi looks something like this. The following example Rust code (in lib.rs) demonstrates passing code and data back and forth between Rust and the host language:
Unlike other FFI systems, there are no annotations required to expose something from lib.rs to the host language other than using pub to mark things public. The miniffi build script parses lib.rs, extracts the supported parts of the public API, and generates FFI binding code both for Rust (the miniffi.rs file referenced above) and for the host language. Calling that example Rust code might look like this:
In JavaScript/TypeScript:
In Swift:
In C++:
More information about how to use miniffi can be found in the documentation.
These projects are much further along, and you may want to use them instead:
.png)

