[Feature] Support for Rust language in nitrogen
FWIW, came across this repo: https://github.com/getditto/rn-jsi-rust-bridging and accompanying article: https://ditto.live/blog/bridging-react-native-and-rust-via-jsi and some other of their related repos: https://github.com/getditto/react-ditto https://github.com/getditto/react-native-sample-app
where they are bridging react native to rust (for both old and new architecture). I know almost nothing about rust (so cannot help) but curious if nitro could simplify the process for such react native - rust bindings?
It would probably open a new world of possibilities since there is plenty of truely multiplatoform (mobile include) libraries in rust land and rust cargo is a godsend comparing to cmake - there is a lot of c++ libraries that officially don't support mobile but mostly because of build issues.
In rust there is plenty of nice gems that have functionality missing in react native (or are not as good):
opencv-rust - [autogenerated opencv + opencv_contrib bindings] https://github.com/twistedfall/opencv-rust Cv-convert - [conversion between cv and different image libs ndarray] https://crates.io/crates/cv-convert cpal - [realtime audio i/o processing] https://github.com/RustAudio/cpal midir - [midi i/o] https://github.com/Boddlnagg/midir wmidi or rimd - [midi encoding / decoding] Peertalk-rst [ios - usb communication] https://github.com/AstroHQ/peertalk-rs rust-sdl2 - [gamecontrollers, IMU sensors, audio, etc] https://github.com/Rust-SDL2/rust-sdl2 rodio - [audio player] https://github.com/RustAudio/rodio
Maybe worth to contact those guys from ditto.live to invite for collaboration? (they might not know about Nitro), they seem have big clients in Aviation industry so they probably know what they are doing.
Ha, it's funny how much of my code is in that repo/article. From the JSI integration, to even the error messages.
Anyways - yea this article isn't very relevant as of right now because it mostly showcases the JSI integration part, and then exposing a simple Rust function as an external C function. We use C++, and classes and inheritance, this would not be supported by Rust.
So if you know how to use Rust, it'd be quite easy to just expose your Rust functions to C++, and then call them in Nitro.
This also goes for all of the libraries you shared - you can expose them as C decls and call them from C++.
@pzoltowski this is not exactly what you're asking, but you might find this interesting: https://hacks.mozilla.org/2024/12/introducing-uniffi-for-react-native-rust-powered-turbo-modules/
Xactly. bump for this - wanna hear about uniffi x nitro - a dream, or nightmare ?
https://github.com/niteshbalusu11/react-native-nitro-tor
https://github.com/niteshbalusu11/tor-rust-sdk
Here's my nitro modules library where most of the code that runs the Tor daemon is written in Rust, and the methods are exposed and called from C++ in nitro modules.
Cool stuff @niteshbalusu11 !
Any progress on this?
Any progress on this?
Just write all core logic in rust and expose to C++ via FFI. It's really easy.
But is anybody working on something to automate the process?
Also, a guide added to the docs would be helpful.
By automated I mean not needing to write anything FFI related.
As to keep the code clean and more towards the core code of the lib.
Just write all core logic in rust and expose to C++ via FFI. It's really easy.
Agreed - this could be super easy.
My stance on this is; we/I can add Rust support to Nitro if one of the following applies;
- A company sponsors us/pays us to implement and maintain it (❌)
- We use it for one of our own projects (❌)
- A popular and actively maintained open-source project uses Nitro + Rust (❌)
Until none of those apply, there is zero reason for us to implement Rust support for Nitro, since I wouldn't have feedback, no testers, no one interested in backporting fixes or helping maintain it, and no one that will be worth the countless of hours of effort this would be (as a plugin for the nitrogen). Only issues and feature requests would and will not help here.
As to keep the code clean and more towards the core code of the lib.
The bigger the codebase of Nitro gets, the harder it is to maintain. Right now it's super simple and minimal, anything we add now cannot simply be removed (it'd be breaking) and harder to maintain.
Keep in mind this is a huge effort - bridging every type over to Rust is pretty hard and requires a ton of testing and feedback.
So, this is happening https://www.callstack.com/blog/announcing-node-api-support-for-react-native
Apparently will be possible to use https://napi.rs
https://www.callstack.com/blog/build-and-run-node-api-modules-in-react-native
Waiting for confirmation, but It seems to be already possible with their ferric-cli https://github.com/callstackincubator/react-native-node-api/discussions/198
There are plenty offtopic urls (non-nitro) above.
I edited the hidden post with a possible way that they already have in their repo, as a Rust option. If works, it's as clean or even more than nitro with c++.
Looks like a new thing is out where we can use Rust.
https://github.com/leegeunhyeok/craby