Live data from Hacker News

Autogenerating Rust-JS Bindings with UniFFI

hacks.mozilla.org

1–10 of 19 posts

Re: Autogenerating Rust-JS Bindings with UniFFI

#2
I built a proof of concept with UniFFI recently at work. The futures/async support is quite immature and for me meant declaring part of my functions in the UDL file and partly in proc macros, but it's not clear what is supported where. It's still a little early, but is generally a really cool project.

Re: Autogenerating Rust-JS Bindings with UniFFI

#3
I'm not a rust dev, but this language is moving so fast into new territories that I'm more and more interested in picking it up.

Could UniFFI be used to generate native modules to use rust with react native?

The web story with wasm already looks like it could eat away a big chunk of JS's share if WebIDL becomes a thing.

Re: Autogenerating Rust-JS Bindings with UniFFI

#5

I'm not a rust dev, but this language is moving so fast into new territories that I'm more and more interested in picking it up. Could UniFFI be used to generate native modules to use rust with react native? The web story with wasm already looks like it could eat away a big chunk of JS's share if WebIDL becomes a thing.

Yes, you can do that. UniFFI allows you to generate Kotlin and Swift wrappers, which you can wrap in a RN wrapper. We did this at work for a cross-platform mobile app, it's a bit of a headache to create because that are some subtleties with async or these kind of things, and they are handled differently in the UniFFI wrappers and RN wrapper, but for relatively simple libs I find it pretty convenient.

Re: Autogenerating Rust-JS Bindings with UniFFI

#6
post #5

I'm not a rust dev, but this language is moving so fast into new territories that I'm more and more interested in picking it up. Could UniFFI be used to generate native modules to use rust with react native? The web story with wasm already looks like it could eat away a big chunk of JS's share if WebIDL becomes a thing.

Yes, you can do that. UniFFI allows you to generate Kotlin and Swift wrappers, which you can wrap in a RN wrapper. We did this at work for a cross-platform mobile app, it's a bit of a headache to create because that are some subtleties with async or these kind of things, and they are handled differently in the UniFFI wrappers and RN wrapper, but for relatively simple libs I find it pretty convenient.

What would be really awesome would be a tool for generating JSI bindings to Rust code. Then you wouldn't need to go via Kotlin or Swift. I believe there are no technical barriers to such a tool. Someone just needs to implement it.

Re: Autogenerating Rust-JS Bindings with UniFFI

#9
post #5

I'm not a rust dev, but this language is moving so fast into new territories that I'm more and more interested in picking it up. Could UniFFI be used to generate native modules to use rust with react native? The web story with wasm already looks like it could eat away a big chunk of JS's share if WebIDL becomes a thing.

Yes, you can do that. UniFFI allows you to generate Kotlin and Swift wrappers, which you can wrap in a RN wrapper. We did this at work for a cross-platform mobile app, it's a bit of a headache to create because that are some subtleties with async or these kind of things, and they are handled differently in the UniFFI wrappers and RN wrapper, but for relatively simple libs I find it pretty convenient.

Wouldn't this negate the effort of having cross platform Rust Module that now you have to manually create RN wrapper to autogenerated Kotlin and Swift wrappers? Also I think all previous RN bindings from JS to Swift, Java are async in nature end comes with performance penalty (serialization back and forth and async queue)?

Would be great if React Native team extend TurboModules to support generating Rust interop instead of just C++ - there are many truely cross platform rust modules (including support for iOS/android) than c++ and cargo makes much better developer experience than cmake.

Re: Autogenerating Rust-JS Bindings with UniFFI

#10
post #5

Earlier quoted context omitted.

Yes, you can do that. UniFFI allows you to generate Kotlin and Swift wrappers, which you can wrap in a RN wrapper. We did this at work for a cross-platform mobile app, it's a bit of a headache to create because that are some subtleties with async or these kind of things, and they are handled differently in the UniFFI wrappers and RN wrapper, but for relatively simple libs I find it pretty convenient.

What would be really awesome would be a tool for generating JSI bindings to Rust code. Then you wouldn't need to go via Kotlin or Swift. I believe there are no technical barriers to such a tool. Someone just needs to implement it.

maybe some ideas about interop can be taken from flutter module:

https://github.com/fzyzcjy/flutter_rust_bridge

Post reply on HN