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

attribute-based configuration of transport in tonic-build #1941

Open
dakom opened this issue Sep 14, 2024 · 0 comments
Open

attribute-based configuration of transport in tonic-build #1941

dakom opened this issue Sep 14, 2024 · 0 comments

Comments

@dakom
Copy link

dakom commented Sep 14, 2024

Feature Request

Allow the transport functionality of tonic-build to be attribute-based rather than completely included/omitted.

Crates

tonic-build

Motivation

I am using tonic in a Rust crate that targets both regular environments and wasm32. The transport feature needs to be disabled for wasm32, and so I end up having to generate 2 completely different sets of files (i.e. run through the builder once with the feature enabled and a "with-transport" dir, and then a second time with "no-transport" dir.)

It works, but, not without some friction.

Alternatively, parsing the output with a regex replacement and feature-gating, which is smoother for consumers but a bit scary to ensure it's doing the right thing consistently.

Proposal

I'm not familiar with the internals of tonic-build to know if it's possible, but the idea would be to use the client_attribute and server_attribute functionality, or something like, it to generate the transport stuff with the cfg rules there, such that consumer crates can use the same files regardless, i.e. move the determination of "transport" down to the consumer level.

This could, of course, merely be an extension on top of the current functionality (i.e. not having the transport feature won't emit it at all, this would only be an additional configuration on top of the current functionality, and should be fully backwards-compatible)

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

1 participant