rules_go icon indicating copy to clipboard operation
rules_go copied to clipboard

go_grpc_v2 fails when one or more of the proto files in the package has no service statement

Open oakad opened this issue 7 months ago • 5 comments

rules_go v0.54.0

I have a bunch of GRPC services which used to compile just fine with "go_grpc". I'm trying to use "go_grpc_v2" to compile the same packages, and it fails with the following uninspiring errors:

file "bazel-out/k8-fastbuild/bin/schema/protobuf/fancysvc/go_proto_/schema/protobuf/fancysvc/somefile_grpc.pb.go" expected from plugin "bazel-out/k8-opt-exec-ST-d57f47055a04/bin/external/rules_go+/proto/go_grpc_v2_reset_plugin_/protoc-gen-go-grpc" but not created

It so happens, that my package has a bunch of proto files, and some of those files have no service directive in them (because they contain definitions of various sort). For those files, only "somefile.pb.go" artifacts are produced. This causes the build to fail.

I understand, that go_grpc_library rule simply assumes, that each proto file will produce both ".pb.go" file and "_grpc.pb.go" file. However, it seems that grpc plugin simply skips files which have no service block in them, producing no output.

Can this be fixed? Even relatively simple GRPC services may require great many messages and enums defined across multiple proto files.

oakad avatar May 15 '25 17:05 oakad

https://github.com/grpc/grpc-go/blob/f2d3e11f3057cc8b4935fc342446ae8372de33d3/cmd/protoc-gen-go-grpc/grpc.go#L136

Seems like the actual plugin was always working like described, but packages were still compiling.

oakad avatar May 15 '25 17:05 oakad

Could you check whether https://github.com/bazel-contrib/rules_go/commit/66cd5f5ea009cfe349de526772a7e877cdd76d34 fixes this?

fmeum avatar May 16 '25 12:05 fmeum

@fmeum I just tried out that commit, and it resolved this error for me. Thanks!

archive_override(
    module_name = "rules_go",
    integrity = "sha256-MM08acUc2iw4L3zoGQwaf5+ACZ6EOdwioRy5TaWsaRE=",
    strip_prefix = "rules_go-66cd5f5ea009cfe349de526772a7e877cdd76d34",
    urls = ["https://github.com/bazel-contrib/rules_go/archive/66cd5f5ea009cfe349de526772a7e877cdd76d34.zip"],
)

turmanticant avatar May 17 '25 15:05 turmanticant

The fix compiles for me as well.

oakad avatar May 19 '25 08:05 oakad

I had to switch back to go_grpc because it says "undefined: [thing that is defined]" in the generated *_grpc.pb.go file, even though the thing is defined in the neighboring file without the _grpc.pb part. this is for a proto with a service statement, but this is the only go_grpc_v2 compatibility issue so it seems reasonable to report this here while the issue is open.

dkrieger avatar Aug 20 '25 14:08 dkrieger