Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Web support #34

Closed
temeddix opened this issue May 30, 2023 · 11 comments
Closed

Web support #34

temeddix opened this issue May 30, 2023 · 11 comments

Comments

@temeddix
Copy link
Member

temeddix commented May 30, 2023

The web has very many restrictions due to the sandboxed environment. Native threads, atomics, and time are not possible in webassembly and therefore many features are missing from the Rust's std and other crates due to these limitations.

flutter_rust_bridge does provide some way to utilize web workers and streams thanks to its bindings with JavaScript. However, there are still additional support needed from various libraries.

We think that when Threads Proposal for WebAssembly is fully accepted and realized, support from Rust and various libraries will mature. For now, there is a long way to go.

@temeddix
Copy link
Member Author

temeddix commented Jul 10, 2023

Maybe we would need a workaround, such as using async runtime crate for webassembly.

@107295472
Copy link

There is really no need for web, because the pure web is too strong, and the mobile terminal and desktop should be perfect

@temeddix
Copy link
Member Author

Yes, I agree that mobile and desktop support should be perfect, and we should not compromise those features in order to support the web. Maybe supporting a subset or providing a separate main Rust function for wasm can be possible.

I believe that web support should be a separate feature if implemented. The demand for it IS much lower than native platforms, yes :)

@107295472
Copy link

The web can be used, but the performance is very slow. I have experienced the online demo, and it is not as smooth as the native web.

@temeddix
Copy link
Member Author

temeddix commented Jul 14, 2023

Hi @107295472 , thanks for telling us about the web :) Do you mind if I ask you for the link to that web app? Was it something built with Rust backend?

@107295472
Copy link

No, flutter's web is wasm

@temeddix
Copy link
Member Author

temeddix commented Jul 15, 2023

Yes, as far as I know, Flutter uses WASM and JavaScript for the web and it's known to be very slow. Why the web support is being considered though is that Flutter team is trying to make the web part faster and there are some demands from various people that want to use the same Rust code for the web backend. Hope we come up with a reasonable idea someday!

The main drawbacks right now:

  • Most async Rust runtimes like tokio are not available in WASM.
  • Async runtimes do not yield to JavaScript so they cannot receive messages or send them with other Web Workers.

@temeddix temeddix changed the title Support web Web support Jul 19, 2023
@satvikpendem
Copy link

There is really no need for web, because the pure web is too strong, and the mobile terminal and desktop should be perfect

I disagree, many people use Flutter for mainly mobile and web, with desktop usage being much lower (how many desktop apps have you installed recently compared to going to the web version? And most desktop versions like Figma, Slack etc are just Electron wrappers around the web app). There are also a lot of web based Flutter apps like Rive.

So I would definitely like to see web support for this library, I'm using flutter_rust_bridge currently for this.

@lbux
Copy link

lbux commented Jul 26, 2023

There is really no need for web, because the pure web is too strong, and the mobile terminal and desktop should be perfect

I disagree, many people use Flutter for mainly mobile and web, with desktop usage being much lower (how many desktop apps have you installed recently compared to going to the web version? And most desktop versions like Figma, Slack etc are just Electron wrappers around the web app). There are also a lot of web based Flutter apps like Rive.

So I would definitely like to see web support for this library, I'm using flutter_rust_bridge currently for this.

While I agree that Flutter is mainly used for mobile and web as opposed to desktop, the addition of rust makes desktop more appealing. My biggest issue with Rust is UI support, so being able to use Flutter to develop UI desktop applications is welcoming. I don't have an issue with supporting web, but I do like that desktop support is one of the the main focuses of this project.

@temeddix
Copy link
Member Author

temeddix commented Jul 27, 2023

Finally, support for the web seems to be successful and the new version will be released in a few days! This huge commit 7410bfa contains all the core changes.

Now you can target all 6 platforms with a single codebase using Flutter and Rust. The way to use this framework remains almost the same, only with some slight changes to the exposed Rust template. Version 2.0 will be published once the minor tasks below are done 😊

  • Modify the bridge code
  • Apply worker-single and zero-copy
  • Remove unneeded crates such as parking_lot
  • Remove unnecessary comments
  • Remove print( and println!( used for debugging
  • Update code snippets
  • Add guides about threads and concurrency of wasm and non-wasm
  • Add a guide about switching Rust-analyzer to wasm mode
  • Add guides about running and building in wasm(also in native)
  • Make sure web support appears on pub.dev
  • Check API visibility on pub.dev
  • Fix a problem of unmatched parameter count in Dart bridge
  • Add web_alias Rust module

For version 2.1:

  • Fix a problem with sleep not working on the web
  • Create or modify .cargo/config.toml when applying the template
  • Make cargo target installation print and ask to wait
  • Add a guide about browser policy headers
  • Remove unneeded worker pools
  • Merge bridge_engine crate into hub, as well as updatingREADME.md files
  • Remove unnecessary crate-type fields in Cargo.toml

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants