#ffi #bindgen

uniffi_build

a multi-language bindings generator for rust (build script helpers)

22 releases (14 breaking)

new 0.15.2 Nov 24, 2021
0.14.1 Oct 27, 2021
0.12.0 Jun 14, 2021
0.8.0 Mar 5, 2021
0.5.0 Nov 9, 2020

#58 in FFI

Download history 458/week @ 2021-08-10 732/week @ 2021-08-17 794/week @ 2021-08-24 709/week @ 2021-08-31 1420/week @ 2021-09-07 902/week @ 2021-09-14 953/week @ 2021-09-21 1429/week @ 2021-09-28 899/week @ 2021-10-05 949/week @ 2021-10-12 1224/week @ 2021-10-19 1166/week @ 2021-10-26 1270/week @ 2021-11-02 1287/week @ 2021-11-09 1680/week @ 2021-11-16 1262/week @ 2021-11-23

5,588 downloads per month
Used in 2 crates

MPL-2.0 license

145KB
3K SLoC

Rust 2K SLoC // 0.1% comments Kotlin 259 SLoC // 0.2% comments Swift 244 SLoC // 0.1% comments Python 199 SLoC // 0.1% comments Ruby 197 SLoC // 0.1% comments

UniFFI - a multi-language bindings generator for Rust

UniFFI is a toolkit for building cross-platform software components in Rust.

By writing your core business logic in Rust and describing its interface in a special interface definition file, you can use UniFFI to help you:

  • Compile your Rust code into a shared library for use on different target platforms.
  • Generate bindings to load and use the library from different target languages.

For example, UniFFI is currently used in the mozilla/application-services project to build browser storage and syncing functionality for Firefox mobile browsers. Core functionality is written once in Rust, and auto-generated bindings allow that functionality to be called from both Kotlin (for Android apps) and Swift (for iOS apps).

User Guide

You can read more about using the tool in the UniFFI user guide.

Please be aware that UniFFI is being developed concurrently with its initial consumers, so it is changing rapidly and there are a number of sharp edges to the user experience. Still, we consider is developed enough for production use in Mozilla products and we welcome any feedback you may have about making it more broadly useful.

Etymology and Pronunciation

ˈjuːnɪfaɪ. Pronounced to rhyme with "unify".

A portmanteau word that also puns with "unify", to signify the joining of one codebase accessed from many languages.

uni - [Latin ūni-, from ūnus, one] FFI - [Abbreviation, Foreign Function Interface]

Contributing

If this tool sounds interesting to you, please help us develop it! You can:

Code of Conduct

This project is governed by Mozilla's Community Participation Guidelines.


(Versions v0.9.0 though v0.11.0 include a deprecation notice that links to this README. Once those versions have sufficiently aged out, this section can be removed from the top-level README.)

Thread Safety

It is your responsibility to ensure the structs you expose via UniFFI are all Send+Sync. This will be enforced by the Rust compiler, likely with an inscrutable error from somewhere in UniFFI's generated Rust code.

Early versions of this crate automatically wrapped rust structs in a mutex, thus implicitly making the interfaces thread-safe and safe to be called over the FFI by any thread. However, in practice we found this to be a mis-feature, so version 0.7 first introduced the ability for the component author to opt-out of this implicit wrapping and take care of thread-safety themselves by adding a [Threadsafe] attribute to the interface.

Version 0.9.0 took this further, and interfaces not marked as [Threadsafe] started issuing a deprecation warning. If you are seeing these deprecation warnings, you should upgrade your component as soon as possible. For an example of what kind of effort is required to make your interfaces thread-safe, you might like to see this commit where we made one the examples thread-safe.

As of version 0.11.0, all interfaces will be required to be Send+Sync, and the [Threadsafe] attribute will be deprecated and ignored.

See also adr-0004 which outlines the reasoning behind this decision.

Dependencies

~0.1–1MB
~21K SLoC