| 1 |
# UniFFI - a multi-language bindings generator for Rust |
| 2 |
|
| 3 |
UniFFI is a toolkit for building cross-platform software components in Rust. |
| 4 |
|
| 5 |
For the impatient, see [**the UniFFI user guide**](https://mozilla.github.io/uniffi-rs/) |
| 6 |
or [**the UniFFI examples**](https://github.com/mozilla/uniffi-rs/tree/main/examples#example-uniffi-components). |
| 7 |
|
| 8 |
By writing your core business logic in Rust and describing its interface in an "object model", |
| 9 |
you can use UniFFI to help you: |
| 10 |
|
| 11 |
* Compile your Rust code into a shared library for use on different target platforms. |
| 12 |
* Generate bindings to load and use the library from different target languages. |
| 13 |
|
| 14 |
You can describe your object model in an [interface definition file](https://mozilla.github.io/uniffi-rs/udl_file_spec.html) |
| 15 |
or [by using proc-macros](https://mozilla.github.io/uniffi-rs/proc_macro/index.html). |
| 16 |
|
| 17 |
UniFFI is currently used extensively by Mozilla in Firefox mobile and desktop browsers; |
| 18 |
written once in Rust, auto-generated bindings allow that functionality to be called |
| 19 |
from both Kotlin (for Android apps) and Swift (for iOS apps). |
| 20 |
It also has a growing community of users shipping various cool things to many users. |
| 21 |
|
| 22 |
UniFFI comes with support for **Kotlin**, **Swift**, **Python** and **Ruby** with 3rd party bindings available for **C#** and **Golang**. |
| 23 |
Additional foreign language bindings can be developed externally and we welcome contributions to list them here. |
| 24 |
See [Third-party foreign language bindings](#third-party-foreign-language-bindings). |
| 25 |
|
| 26 |
## User Guide |
| 27 |
|
| 28 |
You can read more about using the tool in [**the UniFFI user guide**](https://mozilla.github.io/uniffi-rs/). |
| 29 |
|
| 30 |
We consider it ready for production use, but UniFFI is a long way from a 1.0 release with lots of internal work still going on. |
| 31 |
We try hard to avoid breaking simple consumers, but more advanced things might break as you upgrade over time. |
| 32 |
|
| 33 |
### Etymology and Pronunciation |
| 34 |
|
| 35 |
ˈjuːnɪfaɪ. Pronounced to rhyme with "unify". |
| 36 |
|
| 37 |
A portmanteau word that also puns with "unify", to signify the joining of one codebase accessed from many languages. |
| 38 |
|
| 39 |
uni - [Latin ūni-, from ūnus, one] |
| 40 |
FFI - [Abbreviation, Foreign Function Interface] |
| 41 |
|
| 42 |
## Alternative tools |
| 43 |
|
| 44 |
Other tools we know of which try and solve a similarly shaped problem are: |
| 45 |
|
| 46 |
* [Diplomat](https://github.com/rust-diplomat/diplomat/), which is focused more on C/C++ interop. |
| 47 |
* [Interoptopus](https://github.com/ralfbiedert/interoptopus/) |
| 48 |
|
| 49 |
(Please open a PR if you think other tools should be listed!) |
| 50 |
|
| 51 |
## Third-party foreign language bindings |
| 52 |
|
| 53 |
* [React Native bindings](https://github.com/jhugman/uniffi-bindgen-react-native). The repository contains tooling to generate bindings for [Hermes](https://github.com/facebook/hermes) and for [creating Turbo Modules](https://reactnative.dev/blog/2024/10/23/the-new-architecture-is-here#new-native-modules). |
| 54 |
* [Kotlin Multiplatform support (Gobley)](https://github.com/gobley/gobley). The repository contains Kotlin Multiplatform bindings generation for UniFFI, letting you target both JVM and Native. |
| 55 |
* [Go bindings](https://github.com/NordSecurity/uniffi-bindgen-go) |
| 56 |
* [C# bindings](https://github.com/NordSecurity/uniffi-bindgen-cs) |
| 57 |
* [Dart bindings](https://github.com/NiallBunting/uniffi-rs-dart) |
| 58 |
* [Java bindings](https://github.com/IronCoreLabs/uniffi-bindgen-java) |
| 59 |
|
| 60 |
### External resources |
| 61 |
|
| 62 |
There are a few third-party resources that make it easier to work with UniFFI: |
| 63 |
|
| 64 |
* [Plugin support for `.udl` files](https://github.com/Lonami/uniffi-dl) for the IDEA platform ([*uniffi-dl* in the JetBrains marketplace](https://plugins.jetbrains.com/plugin/20527-uniffi-dl)). It provides syntax highlighting, code folding, code completion, reference resolution and navigation (among others features) for the [UniFFI Definition Language (UDL)](https://mozilla.github.io/uniffi-rs/). |
| 65 |
* [cargo swift](https://github.com/antoniusnaumann/cargo-swift), a cargo plugin to build a Swift Package from Rust code. It provides an init command for setting up a UniFFI crate and a package command for building a Swift package from Rust code - without the need for additional configuration or build scripts. |
| 66 |
* [Cargo NDK Gradle Plugin](https://github.com/willir/cargo-ndk-android-gradle) allows you to build Rust code using [`cargo-ndk`](https://github.com/bbqsrc/cargo-ndk), which generally makes Android library builds less painful. |
| 67 |
* [`uniffi-starter`](https://github.com/ianthetechie/uniffi-starter) is a minimal project demonstrates a wide range of UniFFI in a complete project in a compact manner. It includes a full Android library build process, an XCFramework generation script, and example Swift package structure. |
| 68 |
|
| 69 |
(Please open a PR if you think other resources should be listed!) |
| 70 |
|
| 71 |
## Contributing |
| 72 |
|
| 73 |
If this tool sounds interesting to you, please help us develop it! You can: |
| 74 |
|
| 75 |
* View the [contributor guidelines](./docs/contributing.md). |
| 76 |
* File or work on [issues](https://github.com/mozilla/uniffi-rs/issues) here in GitHub. |
| 77 |
* Join discussions in the [#uniffi:mozilla.org](https://matrix.to/#/#uniffi:mozilla.org) |
| 78 |
room on Matrix. |
| 79 |
|
| 80 |
## Code of Conduct |
| 81 |
|
| 82 |
This project is governed by Mozilla's [Community Participation Guidelines](./CODE_OF_CONDUCT.md). |