Skip to content

jhugman/uniffi-bindgen-react-native

Repository files navigation

CI Compatibility (Android) Compatibility (iOS) Compatibility (Android, latest) Compatibility (iOS, latest)

🦀 uniffi-bindgen-react-native

uniffi-bindgen-react-native is a tool that generates TypeScript bindings for Rust code, making it usable in React Native apps and web pages. It builds on UniFFI, Mozilla's bindings generator ecosystem.

With this tool, you can write your business logic once in Rust and access it seamlessly from TypeScript, whether you're developing for mobile platforms or the web.

UniFFI provides procedural macros to describe your API, prioritizing expressivity and memory safety. This makes it ideal for portability.

✨ Features

It provides tooling to generate safe and performant TypeScript to access Rust from:

  • 📱 React Native
    • with JSI C++ to call Rust from TypeScript and back again, and
    • a Turbo-Module that installs the bindings into a running React Native library.
  • 🌐 Web pages
    • with a WASM binding crate

All using the same proc macros: you annotate your Rust once, and build for Android, iOS and the Web.

Javascript hosts the Rust library, and uniffi-bindgen-react-native and uniffi facilitate the communication between the two:

  • Same thread calling across the FFI from Javascript to Rust.
  • Async calls from Javascript to Rust
  • Same thread callbacks from Rust to Javascript
  • Async callbacks from Rust to Javascript
  • Pass by Reference (for "Objects")
  • Pass by Value (for "Records")
  • Enums and tagged unions

Why use uniffi-bindgen-react-native instead of wasm-bindgen?

  • uniffi-bindgen-react-native generates a wasm-bindgen crate, from uniffi annotations.
  • when you come to use your Rust crate in another context (say, from Python, or Kotlin, or React Native), then you can generate FFIs for those platforms, all with the same uniffi annotations.

🚀 Getting Started

If you're ready to start, then begin with a step-by-step tutorial to make a Rust turbo-module and then run it in web page with WASM.

If you're new to UniFFI, then the UniFFI user guide or the UniFFI examples are interesting places to start.

🤔 Why uniffi-bindgen-react-native?

  • 🧩 Spend more time writing TypeScript and Rust, less time hand-writing FFIs
  • 🌍 Your Rust SDK is portable across multiple languages

Who is using uniffi-bindgen-react-native?

Prior art and related projects

Notice

Now uniffi-bindgen-react-native supports WASM, the React Native no longer seems appropriate. In the near future, we'll change the name to uniffi-bindgen-javascript. Backwards compatibility will be ensured.

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.

Funding

uniffi-bindgen-react-native is led by James Hugman, with deep collaboration from the Filament engineering team, funded by Filament and Mozilla.

License

MPL-2.0