codegen/protobuf/scala: wire up protobuf_sources(grpc=True) (feature parity with the Java backend)#23532
Open
robertpi wants to merge 1 commit into
Open
codegen/protobuf/scala: wire up protobuf_sources(grpc=True) (feature parity with the Java backend)#23532robertpi wants to merge 1 commit into
robertpi wants to merge 1 commit into
Conversation
protobuf_sources(grpc=True) currently has no effect when the target is resolved by the Scala codegen backend (pants.backend.codegen.protobuf.scala) -- no *Grpc.scala service stubs are generated and the ScalaPB gRPC runtime is never injected as a dependency. The equivalent Java backend (pants.backend.codegen.protobuf.java) already reads this field correctly; this PR mirrors that existing, accepted pattern for Scala. Two independent pieces, closing the gap end-to-end: 1. rules.py -- generate_scala_from_protobuf now reads ProtobufGrpcToggleField off the protocol target and, when set, passes ScalaPB's grpc: colon- modifier via --scala_out=grpc:<dir> (instead of the always-bare --scala_out=<dir>), enabling ScalaPB's built-in gRPC service-stub codegen -- the same modifier sbt-protoc/ScalaPB passes automatically whenever a .proto declares a service. 2. dependency_inference.py -- ScalaPBRuntimeDependencyInferenceFieldSet now also requires ProtobufGrpcToggleField, and infer_scalapb_runtime_dependency conditionally injects the scalapb-runtime-grpc_<binary_version> artifact plus io.grpc:grpc-stub/grpc-protobuf/grpc-netty-shaded when grpc=True, resolving the correct scala-binary-versioned coordinate the same way the base scalapb-runtime dependency already does. Without this, generated *Grpc.scala files from (1) fail to compile (object grpc is not a member of package scalapb). No behavior change for existing users who don't set grpc=True on a Scala-resolved protobuf_sources/protobuf_source target -- the toggle defaults to False and both code paths are no-ops in that case, exactly as they are today. Fixes pantsbuild#23528
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 join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
protobuf_sources(grpc=True)currently has no effect when the target is resolved by the Scala codegen backend (pants.backend.codegen.protobuf.scala) — no*Grpc.scalaservice stubs are generated and the ScalaPB gRPC runtime is never injected as a dependency. The equivalent Java backend (pants.backend.codegen.protobuf.java) already reads this field correctly; this PR mirrors that existing, accepted pattern for Scala.Two independent pieces, closing the gap end-to-end:
rules.py—generate_scala_from_protobufnow readsProtobufGrpcToggleFieldoff the protocol target and, when set, passes ScalaPB'sgrpc:colon-modifier via--scala_out=grpc:<dir>(instead of the always-bare--scala_out=<dir>), enabling ScalaPB's built-in gRPC service-stub codegen — the same modifier sbt-protoc/ScalaPB passes automatically whenever a.protodeclares aservice.dependency_inference.py—ScalaPBRuntimeDependencyInferenceFieldSetnow also requiresProtobufGrpcToggleField, andinfer_scalapb_runtime_dependencyconditionally injects thescalapb-runtime-grpc_<binary_version>artifact plusio.grpc:grpc-stub/grpc-protobuf/grpc-netty-shadedwhengrpc=True, resolving the correct scala-binary-versioned coordinate the same way the basescalapb-runtimedependency already does. Without this, generated*Grpc.scalafiles from (1) fail to compile (object grpc is not a member of package scalapb).No behavior change for existing users who don't set
grpc=Trueon a Scala-resolvedprotobuf_sources/protobuf_sourcetarget — the toggle defaults toFalseand both code paths are no-ops in that case, exactly as they are today.Provenance: this fix was originally written and verified against a pinned Pants 2.32.0 install in a downstream monorepo (applied as a direct source patch to the installed distribution, since neither touched
@ruleis override-able from a plugin — both are the sole concrete rule bound to their respectiveUnionRule). This PR re-diffs that logic against currentmain.Testing: added
test_generates_grpc_scalatoprotobuf/scala/rules_integration_test.py, mirroring the existingprotobuf/java/rules_integration_test.py::test_generates_grpc_javaand the neighboringtest_generates_fs2_grpc_via_jvm_pluginfor file-naming conventions.Closes #23528