[HN Gopher] Building cross-platform Rust for Web, Android and iO... ___________________________________________________________________ Building cross-platform Rust for Web, Android and iOS - a minimal example Author : andsoitis Score : 67 points Date : 2023-07-09 16:54 UTC (6 hours ago) (HTM) web link (www.artificialworlds.net) (TXT) w3m dump (www.artificialworlds.net) | dylanowen wrote: | I found https://github.com/antoniusnaumann/cargo-swift pretty | nice for iOS. It uses UniFFI under the hood but automates the | other pieces with building an xcode project. | LoveMortuus wrote: | Macroquads can also nicely build cross-platform. For Web, | Android, Windows, Linux and from what I understand there also | work being done for iOS. | | 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. | jwells89 wrote: | This is cool, but it's worth noting that depending on how | network-heavy the app in question is it may not be advisable to | build the networking portion of an app as part of the shared | core. | | 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. | manmal wrote: | A handy feature of NSURLSession comes to mind: You can | configure requests to enqueue ,,forever" (eg when offline) | until they are finally successful. No retry mechanism | necessary, or exponential backoff which can add nontrivial idle | time. | | Features like this one are certainly not available when using | an alternative networking stack. | j45 wrote: | It's early and it will get figured out. | | It's just nice to see Rust and WebAssembly mature little by | little. | jamil7 wrote: | UniFFI is pretty amazing productivity-wise for sharing common | components across clients and teams. I haven't really figured out | the WASM side yet though or if it's even really feasible. | arcticbull wrote: | I spent some time doing exactly this a couple of months ago, and | I agree, Mozilla's UniFFI is really cool. It's also what I'd | probably recommend at this time if you're trying do Rust code | sharing across higher-level platforms like iOS and Android. | | 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... ___________________________________________________________________ (page generated 2023-07-09 23:00 UTC)