Can Rust compile to mobile and web platforms?

Hi guys,

I want to write a project in Rust, and with minimal modification have it run in the browser, and Android/iOS.

I want to build a puzzle game, with pieces on a board. Pieces will be images (SVGs likely) that get dragged and dropped onto a board.

I already built the backend in Rust because I assumed I was going to hook it into WebAssembly, but the front-end, I got no idea where to begin. It doesn't have to be WASM. But I'm not really familiar with my choices.

I'm quite confused at the moment, having looked into many options:

And now my head is spinning and I need some guidance! Do I build everything (GUI included) as a rust library? Should WASM just draw it all to the HTML canvas? Do I separate front-end and back-end? etc.

Any help gratefully received. Thank you

I haven't done anything in that direction myself, so take the following with a grain of salt :slight_smile:

As far as I know there is no simple way of creating native apps on ios and android. At least on android you could try going through a java native interface, but I don't think that's a "beautiful" solution.

What I would probably try is taking one of the GUI frameworks (as far as I know they are all still in progress), see here.
At least iced and druid can somehow be compiled to webasembly and used in the browser (there are examples to test in the browser, so its possible), but I don't know how complicated these are to do.

After this step you could try using a webview on android to show your application, I'm not sure if something similar exists in iOS though.

Hope that helps :slight_smile:

Edit:
The relevant example from the iced repository link.

Thank you very much your clear response, and good understanding of my problem!

I'm pretty sure yeah webview is a thing on iOS to.

web-view is a crate in Rust, You supply it a string containing HTML code, and then, I believe, it asks the OS to generate a webview from the HTML. It can ask, Linux, Windows, and MacOS for a webview. If this crate had implementations for android and iOS wouldn't this crate at least theoretically be the all-in-one solution? (Asking to make sure even I understand my own problem correctly!)

Also, could you please talk a little bit about why JNI is not a beautiful solution? (Is it related to FFI?, a whole new concept to me also!)

From a quick look web-view does not seem to have a android target (it probably could but that's another story), but this would only solve 1/3 of you problem (in this case):

  1. Backend (which you already have)
  2. Backend to web stuff (missing)
  3. Draw web stuff (webview could do this, at least for its available targets)

Disclaimer: I have used jni only very briefly.
That being said jni is mostly used to interact with C code, and should also be usable to interact with rust ffi.
There are crates out there that seem to provide this functionality, but I haven't tried them (searched for jni on crates.io). There are also some android specific results.

I would try going the simplest route, which for me looks like getting some GUI library to output some webpage (which could be tested on your Dev machine) and then get that running on mobile platforms and their respective webview widgets.
This would obviously require wrapper applications for the mobile platforms, but I guess you would need them either way (considering app icons, permissions, etc).

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.