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

Add client feature flag to support connect_with_connector in wasm32 targets #1594

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

lucasmerlin
Copy link

This is an updated version of @boxdot's PR #693. The main purpose is to allow compiling tonic for wasm32-unknown-unknown with the connect_with_connector function, so you could use custom connectors in wasm.

Motivation

The main motivation is to allow using something like https://github.com/boxdot/tonic-ws-transport to use tonic in browsers over websockets. grpc-web has a limit on concurrent conections that are open and doesn't allow for client streaming. There is also a related issue for this, #491.

Solution

The connect_with_connector function, as well as the Endpoint and Channel structs, are gated behind the transport feature. Enabling this feature also enables things that are impossible to compile for wasm. This PR introduces a client feature that that enables everything necessary to make connect_with_connector work in wasm and disables anything that fails to compile for wasm.

An alternative to adding a new client feature could also be to gate everything that doesn't compile for wasm behind a #[cfg()] attribute that is disabled for wasm.

I could also add a test that checks whether compilation to wasm works with the client feature, so this won't break in the future.

…r in wasm32 targets

This adds a new feature that enables compilation of connect_with_connector and the Endpoint and Channel struct for wasm.

Related: hyperium#491
@flokli
Copy link

flokli commented Jun 14, 2024

@lucasmerlin I'm also interested in this. Any chance you can address the conflicts?

@pbower
Copy link

pbower commented Jun 14, 2024

Second this, would love to see it come to fruition.

@lucasmerlin
Copy link
Author

Hi, I gave it a shot and got the native version of tonic-ws-transport working natively, but I'm struggling to get tonic to compile for wasm again.
hyper-utils e.g. depends on tower/make which in turn depends on tokio features which aren't available on wasm. So I think there will need to be some patches to other crates to get this working again, which I unfortunately don't have the time for right now.

If someone else wants to give it a try, these are the branches with my rebased changes:
https://github.com/lucasmerlin/tonic/tree/wasm-client-feature-hyper-1.0
https://github.com/lucasmerlin/tonic-ws-transport/tree/hyper-1.0

That said, I'm still using tonic-ws-transport with tonic 0.10.x in my project and it's working really well for me.

@flokli
Copy link

flokli commented Jun 18, 2024

IIRC there's some work ongoing in hyper-utils to make some dependencies optional, though tower still seems to be required after hyperium/hyper-util#105. cc @tottoto for visibility.

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

Successfully merging this pull request may close these issues.

3 participants