gitmyhub

uniffi-rs

Rust ★ 4.7k updated 1d ago

a multi-language bindings generator for rust

UniFFI is a tool built by Mozilla that solves a specific cross-platform development problem: you write your core logic once in Rust, and UniFFI automatically generates the glue code needed to call that logic from other programming languages like Kotlin, Swift, Python, or Ruby.

The practical use case at Mozilla is Firefox for mobile devices. The core browser functionality is written in Rust, and UniFFI generates the bindings that let Android apps call that code through Kotlin and iOS apps call it through Swift. Without a tool like this, developers would have to write and maintain that bridging code by hand for each language, which is tedious and error-prone.

The way it works is that you describe your Rust code's public interface in either a dedicated definition file (using a language UniFFI calls UDL) or by adding special annotations directly to your Rust code. UniFFI then reads that description and generates the appropriate bindings files for whichever target languages you need. It also compiles your Rust code into a shared library that the generated bindings can load.

Beyond the officially supported languages, the community has built additional bindings for Go, C#, Dart, Java, JavaScript, and Node.js. There are also third-party plugins and helper tools for workflows like building Swift packages or integrating with Android's build system.

Mozilla considers UniFFI ready for production use, though it has not reached a 1.0 release and may make breaking changes in more advanced usage over time. The project is open-source, welcomes contributions, and has a community chat room on Matrix. The name is pronounced to rhyme with "unify" and stands for Uniform Foreign Function Interface.