-
-
Notifications
You must be signed in to change notification settings - Fork 277
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
Panics in browser environment #511
Comments
I will let @seanmonstar weigh-in more definitively. I am not sure how h2 is used in wasm. My gut would be to only depend on |
Is there a reason that |
WASM (and especially wasm32-unknown-unknown) doesn't mean you are running inside a browser. WASM is a portable bytecode. Unfortunately they designed wasm-bindgen without introducing a browser specific target. (And honestly wasm32-unknown-unknown should've never had std in the first place). |
Yes, the unspecified environment in Just to give you a motivation for my patch of More technical details: How about following the |
@seanmonstar: Any update on this? It would be great to come up with a solution that makes everybody happy. :) Then we could move forward with |
I've poked the I see you mention adding a cargo feature, that's one possibility... I'm not sure if it's purest usage of features, since ideally features would work anywhere. But I dunno... |
Isn't there a WASM working group for Rust? Do they have any guidance on how to support browsers without assuming the target? Or any advice at all? |
@seanmonstar Thank you for coming back to this. I asked the wasm wg. They recommend to use https://crates.io/crates/instant. I will prepare a PR if it is fine with you. |
Thanks for checking in with them! Btw, how did you find where to do that? I tried looking but wasn't sure... As for the suggestion of the But! I've thought of two other possibilities. The first one is the easiest:
|
I understand the problem with implicit public dependency on About the two alternatives: I checked the source of |
That's likely fine! |
Here are the patches of @seanmonstar, if you think this the right direction, I'll create the corresponding PRs. It still feels to be slightly too implicit. However, I tried out this approach with tonic, and it works quite well. About the second approach: this, unfortunately, does not seem to work, since there is no |
Yea, it's a little implicit... But at the same time, it's not really doing anything crazy extra. It's just exposing a configuration that might otherwise be useful. 🤷♂️ |
Panic happens due to usage of
Instant::now()
which is not implemented in the stdlib for thewasm32-unknown-unknown
target.A solution would be to use a more general
wasm-timer
crate, which re-exportsstd::time::Instant
for native targets and usesweb_sys
to implement it for wasm32.Here is a patch which I am using for a while in production: boxdot@a14c89c.
Please let me know if it is acceptable, then I will create a PR.
The text was updated successfully, but these errors were encountered: