3 ms·
I've worked on some projects (private and commercial) where embedding Rust into one of those targets was required: iOS, Android, Flutter, macOS, Web. I've playe
by terhechte 4y ago
I've worked on some projects (private and commercial) where embedding Rust into one of those targets was required: iOS, Android, Flutter, macOS, Web. I've played around with a variety of approaches because there exist multiple solutions depending on the platform. Apart from Web/Wasm, where Rust really shines, the next best solution is uniffi by Mozilla, which has quite solid iOS/Android support:
https://github.com/mozilla/uniffi-rs https://github.com/mozilla/uniffi-rs
While this works, the bigger pain (at least on iOS) is that the Rust-Compiler LLVM and Xcode LLVM are not always in sync leading to strange bugs. Also, packaging Rust libraries into a nice XCFramework (or even SPM Module) works, but usually involves hacky shell scripts.
The reason why you'd still want to do this is if there's a Rust library that has no equivalent on the Kotlin or Swift side. There're a lot of good crates / libraries for Rust would require an expensive re-implementation in Swift or Kotlin. Also, because Rust doesn't have a garbage collector, it is easier to embed in garbage collected languages like Kotlin without running into situations where the two garbage collectors don't agree.
- pc2g4d 4y agoSo even using uniffi you are getting weird bugs on iOS? I've long been interested in sharing Rust code between iOS and Android but found the integration to be pretty daunting. Could it be compiled into a React Native app, I wonder?
- terhechte 4y agoNo, sorry, that was phrased wrongly. Uniffi works fine, but you might have compile-time issues whenever the Rust & Swift LLVM versions are out of sync. When Rust is ahead, it is easy to resolve by going to an earlier Rust release. When Swift is ahead, this means staying with an older Xcode version until Rust also upgrades LLVM. However, this means sometimes you can't upgrade to new features on one of the two platforms.