Mozilla Mark Mayo Dec 4, 2024

UniFFI for React Native: Rust-Powered Turbo Modules

Article Summary

Mark Mayo from Mozilla and Tony Haile from Filament just open-sourced a tool that lets React Native developers write their native modules once in Rust instead of twice in platform-specific code. This could change how millions of developers build cross-platform apps.

Mozilla and Filament released UniFFI for React Native, a bindings generator that creates Turbo Modules from Rust code. It builds on Mozilla's UniFFI technology, which already powers critical systems in Firefox used by hundreds of millions of users. The tool generates TypeScript, JSI C++, and the glue code needed to call Rust from React Native seamlessly.

Key Takeaways

Critical Insight

React Native developers can now build faster, memory-safe native modules in Rust with a single codebase instead of maintaining separate iOS and Android implementations.

One developer replaced a slow TypeScript implementation with a Rust crate and had it running the same day with only basic Rust knowledge.

About This Article

Problem

React Native developers have traditionally faced a choice between writing code twice, once for iOS and once for Android, or dealing with complex C++ implementations that are hard to maintain across platforms.

Solution

Mozilla and Filament built UniFFI for React Native, a bindings generator that takes a single Rust codebase and automatically produces TypeScript, JSI C++, and Turbo Modules. This eliminates the need for duplicate platform-specific code.

Impact

Johannes Marbach, with support from Unomed, has already used UniFFI for React Native in production to build a Matrix SDK library. The tool works for real-world React Native applications.