fzyzcjy / flutter_rust_bridge

Flutter/Dart <-> Rust binding generator, feature-rich, but seamless and simple.
https://fzyzcjy.github.io/flutter_rust_bridge/
MIT License
3.61k stars 254 forks source link

Question about Targeting Web with Crates having Tokio / Mio as Dependencies #1893

Closed CupOfOwls closed 3 days ago

CupOfOwls commented 4 weeks ago

Is your feature request related to a problem? Please describe. It seems infeasible to use Rust's tokio when targeting web apps / WASM. flutter_rust_bridge_codegen build-web fails for any crates that include tokio and/or mio as a dependency, as far as I can tell. Here is an example of crates I cannot seem to get to work when targeting web:

[dependencies]
aws-config = "0.54.1"
aws-sdk-cognitoidentity = "0.24.0"
aws-sdk-dynamodb = "0.24.0"

This seems to be known (acknowledged here) and is not an issue with flutter rust bridge itself.

Describe the solution you'd like In the case that a crate uses tokio or mio as a dependency, is there any recommended work around to target web? The above packages, for example, seem pretty standard for web development (though I am no expert). I just feel like I am missing something, is it really the case that a wide array of crates simply cannot be used in WASM because of tokio as a dependency?

Describe alternatives you've considered I know that spawn, spawn_local, and spawn_blocking_with (provided by flutter rust bridge) could be used in code that I write myself, but can they be plugged into crates that would otherwise be incompatible with building to wasm / web due to their tokio / mio dependencies?

Additional context I guess technically the 'feature' I am asking for is some way to use crates when targeting web apps, that are blocked by their dependency on tokio / mio. I am pretty new to both Rust and Flutter so please forgive me if this is something obvious!

welcome[bot] commented 4 weeks ago

Hi! Thanks for opening your first issue here! :smile:

fzyzcjy commented 4 weeks ago

is there any recommended work around to target web? is it really the case that a wide array of crates simply cannot be used in WASM because of tokio as a dependency? but can they be plugged into crates that would otherwise be incompatible with building to wasm / web due to their tokio / mio dependencies?

My two cents: For crates today, one way may be to make tokio conditional dependency, i.e. depend on in when on non-web, and do not depend on in when web. For 3rd party crates, I guess one way is to fork it and modify it, if Rust does not provide mechanisms about this; another way is to create an issue and maybe they will fix it. In addition, waiting for tokio to support web in the future may also be possible. Or, another standard practice is to add an abstraction layer (e.g. the spawn you mentioned in flutter_rust_bridge) that calls tokio on non-web and other async runtimes on web. I guess this is a general Rust + WASM question, thus it would be great to ask in Rust forum/github, as well as in the packages you use as well.

EDIT: It seems that tokio can compile with some flags, e.g. rt (without rt-multi-thread). If that mode is supported in the aws crates you use, then that seems to also be a solution.

fzyzcjy commented 3 days ago

Close since no replies. Feel free to reopen and discuss more when needed!