-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Support Webassembly #1597
Comments
Sounds very interesting. Could you provide more context around what wasm platform you are targetting? As far as I know, in the browser, there are no TCP sockets. I'm not familiar w/ other wasm platforms. |
@carllerche We need all the network protocols like rpc, tcp, websocket and I/O operations I felt we should first focus on If anyone want to use any Http calls its depends on tokio, hyper, websocket libraries. so we need to make sure all the network protocols can be handled in Rust. |
This is about WASI (https://hacks.mozilla.org/2019/03/standardizing-wasi-a-webassembly-system-interface/) I guess? |
@AchalaSB Support of wasm would require someone to investigate wasm capability. If you're familiar with wasm platforms, it would be good if you could elaborate on availability of IO primitives and event loops there |
Is there a wasm platform today that supports TCP? |
The |
Tokio has the best sync primitive implementation, it would be great if it could be used on wasm. |
Indeed tokio's non-networking primitives would be extremely useful in wasm in the browser: channels, mutexes, (single-threaded) runtime, etc. |
tokio with feature flags |
This is also a dependency for Sentry.io's rust implementation |
I tried these feature flags with wasmtime+WASI and it did not seem to quite work.
Seems I would need to somehow work around the current pending future wait implementation. |
Tokio heavily depends on the epoll mechanism underlayer which is not supported in wasm runtime right now as I know. The wasm runtime(not in the browser) is sandboxed and is wrapped by a WASI layer. The WASI provides simple libc abilities and has some constriains on accessing host resource. |
Yeah, but the same points hold. In the browser, there isn't much for Tokio to do. Tokio already supports what it can for wasm, but it isn't much (sync, and very basic runtime) |
I got the same |
@justinlovinger I had the same error (see discussion #5029). My understanding is that it's not directly caused by WebAssembly and it's probably something in your program. Does the same program work natively? |
It compiles natively, but trying to run it natively would not be trivial. Note, my program is not WASI, it is |
It sounds like your program reached a situation where it would block forever without making any more progress. When this happens, you get that panic. |
You cannot use Tokio runtime in browser. The browser has its own runtime. You can use |
The program ran successfully before tying to use Tokio in place of
It was my understanding this issue is to discuss Tokio support in the browser, I was under the impression this issue was closed, possibly erroneously, due to the belief Tokio supported the browser, hence the statement
Tokio support in the browser is desirable for my project to better support local testing and future native support. |
Can you submit a PR to address this? |
Tokio supports what it possibly could support in the browser without using a completely different implementation for the browser. Admittedly, what it supports is rather limited. |
What is Tokio expected to support in the browser? As far as I can tell, it does not currently support I guess more accurately, it does not seem to support |
Can you perhaps post the program you tried? |
The program is nearly 5000 lines of code, but I found a minimal reproducible example, use futures::{channel::mpsc::unbounded, StreamExt};
use tokio::task;
use wasm_bindgen::prelude::*;
#[tokio::main(flavor = "current_thread")]
#[wasm_bindgen(start)]
pub async fn main() {
let (_tx, rx) = unbounded::<i32>();
task::spawn(rx.for_each(move |_| { async {} })).await.unwrap();
}
|
This program sleeps forever. See my earlier comment:
That you get a panic in this situation is documented here.
I would be happy to accept a PR that improves the error message. |
Note, the full program is currently trying to use Tokio like, task::spawn(optimization_events_fut);
task::spawn(view_fut);
let local = task::LocalSet::new();
local.spawn_local(optimization_fut);
local.spawn_local(controller::run(
Arc::clone(&data_model),
Arc::clone(&optimization_model),
optimization_events_1,
view_events,
));
local.await; It is designed like a series of actors, each sending events and receiving commands in response to events. The main timer is implemented with Edit: would it be accurate to say "Tokio cannot become idle for any length of time"? |
In the browser, yes. Web workers might be able to sleep using |
Is there then no desire to see Tokio work in the browser, at least enough for the runtime to be able to pause? This issue was closed in favor of WASI, but as far as I am aware, WASI support will do no good in the browser. I know libraries exist to generating timing |
I would love to have the same runtime for native and web apps, so I don't have to modify my code when compiling for different targets. Not sure if this is even feasible though with the current state of WebAssembly in the browser? |
You can use the prokio crate, which aims to be a pseudo-runtime which uses tokio and JS Promises as needed. It's also is going to be used in Yew: yewstack/yew#2893 I'm not sure if bringing what wasm-bindgen-futures does (wake futures on the microtask queue tick) to Tokio is a good idea, as tokio is it's own standalone runtime and should stay that way |
It would be very nice to have Tokio work in the browser, but it would require adding a completely separate runtime implementation just for that use-case. Furthermore, our IO types would not work in browser-wasm, so the only new Tokio api this would let you access is timers. It doesn't seem worth it to me. |
I was recently informed WASI can theoretically work with
https://discord.com/channels/442252698964721669/443151097398296587/1032831725761470567 If this is true, WASI support in |
Hey,
Please provide wasm support to this library. Networking is one of the important feature to work on Rust+WASM codes.
Not sure is there any tracker for this. Happy to contribute if any.
Thanks
The text was updated successfully, but these errors were encountered: