Make generated client feature gate configurable#194
Merged
iainmcgin merged 3 commits intoJun 28, 2026
Conversation
|
All contributors have signed the CLA ✍️ ✅ |
- Reject client feature names that aren't valid Cargo feature names (e.g. "grpc client", "foo/bar"): an invalid name emits a cfg gate Cargo can never enable, silently suppressing every generated client item. Validation is inlined for now; switch to buffa_codegen::FeatureGateNames::is_valid_name once the buffa-codegen dependency moves to 0.8. - Config::client_feature_name(..) now also enables gate_client_feature, matching the plugin's gate_client_feature=<name> form so build.rs consumers don't need two calls. - Update gate_client_feature rustdoc to cross-link the name setter instead of hard-coding "client".
iainmcgin
approved these changes
Jun 28, 2026
iainmcgin
left a comment
Collaborator
There was a problem hiding this comment.
[claude code] Thanks — this is a clean implementation of #181 and the default behaviour is fully backward-compatible (task generate:all produces zero diff in the checked-in *.__connect.rs files).
I pushed two maintainer commits:
- 92d384b — merged
mainand resolved theCHANGELOG.mdconflict (keep-both; also added the missing[#181]link reference). - 3390690 — three small tightenings:
- Validate the feature name against Cargo's grammar. A name like
"grpc client"or"foo/bar"would emit#[cfg(feature = "...")]that Cargo can never enable, silently suppressing every generated client item with no diagnostic. The check is inlined for now; once the workspace moves tobuffa-codegen0.8 it can defer tobuffa_codegen::FeatureGateNames::is_valid_name. Config::client_feature_name(..)now also enablesgate_client_feature, mirroring the plugin'sgate_client_feature=<name>form. Previously calling only.client_feature_name("x")was a silent no-op (gating stayed off). The order-dependence with an explicit.gate_client_feature(false)is documented on both setters.- Updated
gate_client_feature's rustdoc to cross-link the new setter instead of hard-coding"client".
- Validate the feature name against Cargo's grammar. A name like
LGTM with those applied.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
protoc-gen-connect-rustcan already gate generated client items behind a Cargo feature, but the feature name is fixed toclient. Crates that expose their generated client surface under a different feature name cannot use the existing gate directly.Change
Options::client_feature_name, defaulting toclient, and thread it into generated client cfg attributes.gate_client_feature=<name>in the protoc plugin while preserving the existing baregate_client_featurebehavior.connectrpc_build::Config::client_feature_name(...)as the build wrapper companion API.grpc-clientwork.This keeps the existing opt-in shape intact:
gate_client_featurestill enables gating, and the default gate remainsclient.Validation
Using
protocv33.5:cargo test -p connectrpc-codegen gate_client_featurecargo test -p connectrpc-build gate_client_featurecargo check -p connectrpc-codegencargo check -p connectrpc-buildcargo check --workspace --all-features --all-targetscargo test --workspace --all-featurescargo clippy --workspace --all-features --all-targets -- -D warningscargo +nightly-2026-02-27 fmt --all -- --checkRUSTDOCFLAGS="-Dwarnings" cargo doc --workspace --all-features --no-depsgit diff --checkRisk
Low. This is additive, the default remains
client, and the existing bare plugin flag continues to work. The main compatibility risk is rejecting an empty explicitly configured feature name; that is covered by a focused parser test.Out of scope
gate_client_feature(bool)API.Issue linkage
Closes #181