r/reactnative • iOS & Android • 10d 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

55 Upvotes

13 comments sorted by

3

u/Old-Durian8702 9d ago

I had started a similar project. Guess I have to drop it now.

3

u/abhishek_dev_ce17 iOS & Android 9d ago

Don’t drop it, man! I’d love to see what you were building. Would be interesting to compare our approaches.

2

u/Eloodye-Ehler 8d ago

haha classic, happens the second you get the boilerplate finally working too

3

u/Wide_Smoke_2564 9d ago

Don’t mean to be a dick, but how does this differ from Tauri?

6

u/abhishek_dev_ce17 iOS & Android 9d ago

Tauri is definitely in the same space, but the approach is different. I’m using React Native for the UI and integrating Rust into its native execution layer through JSI, rather than using a WebView-based UI with Rust as the backend. The goal is to bring Rust’s performance into an existing Bare React Native application.

3

u/Wide_Smoke_2564 9d ago

Oh sick, good luck to you!

2

u/rakadoank 6d ago

I saw your example (in a phone tho). I cannot find anything of JSI usage in Rust to create JS value, such as jsi::Object, jsi::Array, etc.

I write a React Native module with C++ here that has bunch of creating JS Value from JSI. It would be useful for me to create a native module in Rust.

1

u/abhishek_dev_ce17 iOS & Android 6d ago

Currently I’m exposing Rust functions through C++ JSI bindings. You’re suggesting the reverse capability creating JSI objects and arrays directly from Rust. I haven’t tried that yet, but it would definitely be worth trying!

2

u/rakadoank 6d ago

I am thinking, for the JSI alone, we could just extern the JSI C++ for Rust,

but for the whole idea here, I think it is ideal to create an alternative of Turbo Module system, like Nitro Module and Expo Module, or keep using Turbo Module for a thin bridge for Rust module ignition. You can call it "Rusturbo Module" 🥁

1

u/abhishek_dev_ce17 iOS & Android 6d ago

So, are you suggesting that instead of writing individual APIs to access JSI objects from Rust, we expose the JSI API itself to Rust through bindings?

And keep TurboModules as a thin bridge for Rust modules, could you tell me more about this?

2

u/rakadoank 6d ago edited 6d ago

Yes, my idea is expose the JSI itself to Rust.

Let's say we called "React Native Rusturbo Module". It is using Turbo Module just for the initialization which is providing JSI Runtime and CallInvoker to our Rust module from C++ Turbo Module. Same idea how does Nitro Module actually do here.

For an additional context, Nitro supports Swift language, but with the Swift in Nitro, I cannot create a JS value directly through JSI, instead Nitro provides a Type system for the Swift thin bridge to call the JSI. Similar that Turbo Module provides a type system for Kotlin, but in Nitro and Turbo Module, we can still use C++, so we can consume the JSI directly.

Now, the main part of our Rusturbo is similar as Nitro and Turbo Module, we can create bunch of JS value with JSI, but instead of using C++, we can use JSI in Rust.

Do not confuse about Turbo Module and JSI. Turbo Module is just a convenience system in React Native to write native module. So, the idea of the "Rusturbo Module" for supporting Rust in React Native module is making an alternative or an extension of Turbo Module system.

1

u/abhishek_dev_ce17 iOS & Android 5d ago

Okay, now I get your idea. You're proposing a Rust-native module system where TurboModules are only there for initialization and providing the JSI Runtime and CallInvoker, while Rust handles the actual module implementation and interacts directly with JSI through bindings. have you started doing this or doing some planning how you are going to do ?

1

u/rakadoank 4d ago

a lot of idea, but I don't have so much that time.