Building cross-platform Rust for Web, Android and iOS – a minimal example
artificialworlds.net
artificialworlds.net
The reason for this is because iOS has a multitude of device specific optimizations built into the native networking stack to my knowledge is opted out of with the usage of cross platform networking. This includes features coalescence of calls across apps to occur when the antenna is already awake (to save power) and transparent management of multi-connection situations (e.g. when the phone has both wifi and cell available). The result is more power used and less fluidity in some situations.
I don't think this is as much of an issue on Android where third party networking libs like OkHTTP are the norm anyway.
With this in mind I believe the best functionality to put in a shared core is generic common logic which does not have platform optimizations.
Features like this one are certainly not available when using an alternative networking stack.
It’s just nice to see Rust and WebAssembly mature little by little.
Can you detail, say, why curl as a backend isn't necessarily sufficient here?
On the other hand your shared code can parse or generate data and pass it to/obtain it from a platform specific networking layer.
That said, people should look to Spotify’s wrapper as a target to clone, as I believe they managed to work around this.
- Add an NSURLSession backend to reqwest. The abstractions match well, and Obective-C interop is pretty solid
- A Tokio API compatible networking implementation using the Network framework’s C API. Not quite sure how well this would work, but I think it’s possible.
I will try to build these at some point
ktor.io successfully does the first thing for Kotlin Multiplatform, multiplexing all of OkHttp, NSURLSession, fetch and others
You do have to write an export header spec in 'UDL' (a Mozilla authored interface definition language with a JetBrains plug-in to make it easier to write) - but in exchange, you get proper (idiomatic) Kotlin, Swift, Ruby and Python bindings for your Rust modules. It's nice that for instance the Swift bindings are actually 'native' instead of implemented via Objective-C interop (which would have arguably been simpler).
[edit] I should note that the Kotlin bindings are a little wonky for non-scalar types because they're exported as AutoCloseable resources, and care must be taken to use them correctly. [1]
[1] https://mozilla.github.io/application-services/book/howtos/u...
I personally like it and use it because it clicks with how I think, so there isn't much extra additional learning to be done.
Not sure how it compares but it looks interesting.