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

Applying fixer for grpc_go_plugin plugin #146

Open
ash2k opened this issue Sep 24, 2021 · 5 comments
Open

Applying fixer for grpc_go_plugin plugin #146

ash2k opened this issue Sep 24, 2021 · 5 comments
Labels
enhancement New feature or request lang-go Go rules specific

Comments

@ash2k
Copy link
Contributor

ash2k commented Sep 24, 2021

Description

I'm getting a lot of such messages with 4.0.0 and new go_validate_compile():

INFO: From Applying fixer for grpc_go_plugin plugin on target //internal/tool/prototool:proto_compile_validate:
Fixing missing plugin output file: internal/tool/prototool/prototool_grpc.pb.go
Warning: failed to find go package for templating go files, falling back to parent dir name
INFO: From Applying fixer for grpc_go_plugin plugin on target //pkg/agentcfg:proto_compile_validate:
Fixing missing plugin output file: pkg/agentcfg/agentcfg_grpc.pb.go
Warning: failed to find go package for templating go files, falling back to parent dir name
INFO: From Applying fixer for grpc_go_plugin plugin on target //internal/module/reverse_tunnel/info:proto_compile_validate:
Fixing missing plugin output file: internal/module/reverse_tunnel/info/info_grpc.pb.go
Warning: failed to find go package for templating go files, falling back to parent dir name
INFO: From Applying fixer for grpc_go_plugin plugin on target //internal/module/reverse_tunnel/tracker:proto_compile_validate:
Fixing missing plugin output file: internal/module/reverse_tunnel/tracker/tracker_grpc.pb.go
Warning: failed to find go package for templating go files, falling back to parent dir name
INFO: From Applying fixer for grpc_go_plugin plugin on target //internal/tool/grpctool:proto_compile_validate:
Fixing missing plugin output file: internal/tool/grpctool/grpctool_grpc.pb.go
Warning: failed to find go package for templating go files, falling back to parent dir name
INFO: From Applying fixer for grpc_go_plugin plugin on target //cmd/kas/kasapp:proto_compile_validate:
Fixing missing plugin output file: cmd/kas/kasapp/kasapp_grpc.pb.go
Warning: failed to find go package for templating go files, falling back to parent dir name
INFO: From Compiling protoc outputs for ruby_plugin plugin on target //pkg/ruby:configuration_project_grpc:
[libprotobuf WARNING ../../src/google/protobuf/compiler/ruby/ruby_generator.cc:517] Omitting proto2 dependency 'validate/validate.proto' from proto3 output file 'internal/module/configuration_project/rpc/rpc_pb.rb' because we don't support proto2 and no proto2 types from that file are being used.
INFO: From Applying fixer for grpc_go_plugin plugin on target //pkg/kascfg:proto_compile_validate:
Fixing missing plugin output file: pkg/kascfg/kascfg_grpc.pb.go
Warning: failed to find go package for templating go files, falling back to parent dir name

Looking at the sources in https://github.com/rules-proto-grpc/rules_proto_grpc/blob/master/go/go_validate_compile.bzl and https://github.com/rules-proto-grpc/rules_proto_grpc/blob/master/go/go_grpc_compile.bzl looks like they both include the gRPC plugin and validate includes all three plugins.

In my project I call each compile rule independently and explicitly, depending on which proto file I'm compiling. So, I didn't expect these rules to try to do this all for me :) Quite a few proto files in my project use the validator plugin but not gRPC and I think that explains why I'm getting those messages.

I'm not sure what to suggest here. I just expected each rule to do one thing only so that they can be composed (via macros) by the end user to do what is necessary. I'm not sure what to do with the existing approach - I was trying to get rid of my custom plugin definition for the validate plugin but looks like I cannot. I prefer to not have those warnings and to not do the compilation work multiple times.

Would it be possible to remove proto and grpc plugins from the validate rule definition? It's probably not too late as 4.0.0 has just been released and not many people use it (it's a breaking change).

@aaliddell
Copy link
Member

That rule is marked as experimental, so we’re free to change it in a breaking way without bumping the major version anyway.

IIRC, the issue is that the validate_library rule needs to bundle at least the protobuf plugin and dep to actually build correctly. So we could split it out to two rules go_proto_validate_library and go_grpc_validate_library, but I don’t think we can have a go_validate_library that has only the validate plugin. Alternatively we could however retain a go_validate_compile that just has the validate plugin, then just add ‘validate’ attrs to the library rules.

Do you have an example of how you expect to use the rules?

@aaliddell aaliddell added the lang-go Go rules specific label Sep 24, 2021
@ash2k
Copy link
Contributor Author

ash2k commented Sep 24, 2021

Do you have an example of how you expect to use the rules?

Here is what I currently do using my own plugin definition. I pretty much swapped my own go_validate_compile with the new one.

So you can see that I have two macros: go_proto_generate and go_grpc_generate. I call them for proto-only and proto+gGRP files. Each macro also calls go_validate_compile if it finds that the proto target depends on the validator proto. (I have also removed double proto generation in that PR that was happening because in go_grpc_generate I also called go_proto_compile in addition to go_grpc_compile).

So I would expect to continue to use the rule this way, but I'm also open to doing something else as long as it makes sense :)

I don't care much about the *_library rules as I don't use them because I check in the generated code.

I think what you are proposing makes sense.

@aaliddell
Copy link
Member

Ok, thanks for the details. Once I have a PR for this, I'll add you as a reviewer to check I'm not doing something too wild 😄

@ash2k
Copy link
Contributor Author

ash2k commented May 18, 2023

This is causing some grief again...

@ash2k
Copy link
Contributor Author

ash2k commented May 18, 2023

Workaround is to define custom rules like so:

load(
    "@rules_proto_grpc//:defs.bzl",
    "ProtoPluginInfo",
    "proto_compile_attrs",
    "proto_compile_impl",
)

go_grpc_compile = rule(
    implementation = proto_compile_impl,
    attrs = dict(
        proto_compile_attrs,
        _plugins = attr.label_list(
            providers = [ProtoPluginInfo],
            default = [
                Label("@rules_proto_grpc//go:grpc_go_plugin"),
            ],
            doc = "List of protoc plugins to apply",
        ),
    ),
    toolchains = [str(Label("@rules_proto_grpc//protobuf:toolchain_type"))],
)

go_validate_compile = rule(
    implementation = proto_compile_impl,
    attrs = dict(
        proto_compile_attrs,
        _plugins = attr.label_list(
            providers = [ProtoPluginInfo],
            default = [
                Label("@rules_proto_grpc//go:validate_go_plugin"),
            ],
            doc = "List of protoc plugins to apply",
        ),
    ),
    toolchains = [str(Label("@rules_proto_grpc//protobuf:toolchain_type"))],
)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request lang-go Go rules specific
Projects
None yet
Development

No branches or pull requests

2 participants