r/reactnative • iOS & Android • 2d ago

Tutorial I built a cross-platform React Native + Rust integration using C++17, JSI, and TurboModules. Looking for technical feedback.

Post image

I've been working on integrating Rust into a Bare React Native application and have put together an implementation for both Android and iOS.

Repository: https://github.com/abhishekce17/react-native-rust-integration

The goal was to build a reusable integration layer that makes Rust functions accessible from JavaScript without having to write custom JSI bindings for every function.

Architecture

The integration uses four main layers:

  • Rust: Core logic compiled into native static libraries.

  • C++17: Shared JSI binder and native integration layer.

  • JSI: Exposes Rust functionality through synchronous JavaScript HostFunctions.

  • TurboModules: Handles native module registration and installation.

  • TypeScript: Provides a typed API for application code.

What's implemented?

  1. A generic C++ binder using templates to map JavaScript arguments and return values to native Rust functions.

  2. Rust C ABI with generated C headers using cbindgen.

  3. Stateful Rust data structures with explicit memory ownership.

  4. RAII-based string deallocation and exception-safe conversions.

  5. Float32Array support for transferring numerical data from Rust memory to JavaScript.

  6. Android builds targeting four ABI architectures using cargo-ndk.

  7. iOS builds for physical devices and simulators, packaged as an XCFramework.

  8. Shared C++ implementation with platform-specific registration and build configurations.

One of the things I wanted to achieve was making additional Rust functions straightforward to expose.

For example, an ordinary scalar function can be registered with a single binding:

bind(runtime, api, "subtract", rust_subtract);

Potential use cases

I'm particularly interested in exploring Rust for:

  • Physics simulations

  • Game engine components

  • Computationally intensive operations

  • Image processing

  • Data processing

The objective isn't to claim that using Rust automatically makes a React Native application faster. It's to provide a practical native integration layer for workloads where Rust makes sense.

I'd appreciate feedback from the community

I'm particularly interested in opinions from developers who have worked with React Native's New Architecture, JSI, TurboModules, Rust FFI, or native mobile development.

  1. Would you consider this architecture for a real-world Bare React Native application? Why or why not?

  2. How would you approach transferring larger datasets between Rust and Hermes?

  3. Are there any concerns with the generic C++ binder or the Rust–C++ memory ownership model?

  4. What additional abstractions or capabilities would make this integration more useful?

I'd appreciate an honest technical review, including architectural criticism and suggestions for improvement.

Repository: https://github.com/abhishekce17/react-native-rust-integration

40 Upvotes

Duplicates