-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Add client feature flag to support wasm32 targets. #693
Conversation
When protobuf is generated without the transport feature, the generated client can be compiled to wasm32 targets and used in browser environment. To be able to run the client in browser, a `h2` version including the commit 5c72713 has to be used.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for opening this, I am not 100% sure if this is the right approach but I need to spend sometime digging into the wasm stuff a bit. So I am not going to include this in 0.5
but will try to get it in for 0.6. Thanks for all the hard work on this!
@@ -39,6 +41,13 @@ tls-roots-common = ["tls"] | |||
tls-roots = ["tls-roots-common", "rustls-native-certs"] | |||
tls-webpki-roots = ["tls-roots-common", "webpki-roots"] | |||
prost = ["prost1", "prost-derive"] | |||
client = [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should this feature be called wasm
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Technically, this is not about wasm
but about having a client without relying on any OS features e.g. like sockets. But naming is hard and I agree client
is somehow misleading.
@@ -241,6 +241,7 @@ impl Endpoint { | |||
} | |||
|
|||
/// Create a channel from this config. | |||
#[cfg(feature = "transport")] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hm this feels a bit funky to me
I'm curious if there's been any progress on this front. I'm also quite in favor of tonic clients working in wasm. |
Bump. I'd like to use a client in WASM, and this seems like exactly what I need. Can we get this merged? |
It got stale. I will rebase this PR on branch 0.6. |
I had done this merge locally and mostly got it working for my own purposes, but it seems like there might be a missing #[cfg in the generated Client code for XyzClient::connect, which prevents the same generated code from being used for both wasm and non-wasm builds. For reference, I haven't been using the tonic::include_proto macro but instead generating code into my crate which I check in, partially so it's easier to see what code is actually produced. |
Further notes:
|
Bump. I would like to use tonic over WebSockets in webasm for my project |
Hi, gRPC tunneled over WebSocket seems perfect solution for my project. Couldn't we create a server that can be tunneled by any kind of stream? |
Tarpc already lets you use any transport that implements AsyncRead + AsyncWrite, it's just a matter of supporting the wasm32 target |
I'd like to warm this up, as this is vastly superior to the @LucioFranco what's your opinion on this PR? Which are the open issues to get this going again? |
I've created an updated version based on current tonic over here: https://github.com/lucasmerlin/tonic/tree/wasm-client-feature Trying this in my project it works flawlessly! I'm happy to create a new PR with my changes if @boxdot is not interested in working on this anymore |
@lucasmerlin Feel free to push to this branch, or open a new PR. Whatever works better for you. Since you did already all the necessary work, I would not wait for me and try to bring it in. |
Hi there, wondering if there's any plans to merge this one in ? Thanks |
I think this has moved to a new PR at #1594 |
When protobuf is generated without the transport feature, the generated client can be compiled to wasm32 targets and used in browser environment.
To be able to run the client in browser, a
h2
version including the commit 5c72713 has to be used.Motivation
This enables tonic clients to compile to
wasm32-unknown-unknown
target and run in a Browser environment. For more information, please see #491.Solution
For this to work, we
spawn
function which either usestokio::spawn
orwasm_bindgen_futures::spawn_local
dependening on the compilation target,http2_max_concurrent_reset_streams
to 0 for wasm, to disable theInstant::now
usage in h2 which is not available in Browser.