-
Notifications
You must be signed in to change notification settings - Fork 380
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
#gazelle:proto file” directive isn’t usable unless option go_package is explicitly set in each proto_library #1724
Comments
It's sounds like a bug if gazelle generates unbuildable targets. @wolfd, @pcj, @danny-skydio, @Michaelhobo, @jvolkman, @ggirelli did you run into this issue? |
I tend to be using https://github.com/stackb/rules_proto for gazelle proto support, which does use the I'm not saying the OP should switch to that, but I did encounter this issue when designing that alternative rule for golang: https://github.com/stackb/rules_proto/blob/9fffedbc7cd8a01ecbf7bf7d00a4d573f085bca7/pkg/rule/rules_go/go_library.go#L201. In that solution, if you have a package with In some ways this defeats the purpose of |
That's exactly the situation that we find ourselves in -- we would like the individual I think ideally the gazelle go language extension would bundle the But I recognize that, pragmatically, this probably has to exist as a separate mode, at least initially, to avoid breaking folks. (Let me know if I'm wrong or missing obvious things here -- totally possible, we're relatively new to gazelle & go codegen.) |
That sounds about right to me. I'm not an ex-googler so I don't know how things are inside G, but I think I saw some hint somewhere from @adonovan that golang within google can use bazel labels for If that were true generally, |
I agree that compiling multiple proto_library targets into one go_proto_library or go_library target defeats the purpose of So example.com/foo/bar.proto will produce a go_proto_library with |
What I do is typically one
BUT I am indeed specifying the
Which is OK, imho. |
The other approach is to have gazelle generate what @jayconrod suggested here |
@ggirelli I've tried this, but it typically fails to build if foo.proto imports bar.proto |
@jeromep-stripe gotcha. I generally avoid importing between proto files in the same package so I have not hit that issue. |
Actually, if |
@ggirelli So I just set up a foo.proto and bar.proto in a directory, where foo.proto imports bar.proto. I used
It's a bit weird that
I get the same outcome when I change |
Interesting. Are you using
in your proto files? Also, what is the Can you try
(in the above I changed and then run
? But, generally, I would really advise against imports between proto files in the same package. If you are importing they should either be in different packages or in the same proto file. If you are splitting them in two files because you reuse some of the messages, you should really move them somewhere else instead. |
@ggirelli
I tried using your BUILD file contents, and What does work and build successfully is having a single
|
@jeromep-stripe I guess what you suggested is the best solution. Can you make the following changes?
|
@linzhp, for 1, |
@linzhp Question about requirements: On these lines, gazelle ensures that in
But this might create many changes in repos that currently use gazelle (with file mode). Should we continue generating the |
I think we should not generate |
@linzhp I was discussing with @ouguoc2-stripe whether generating a |
What version of gazelle are you using?
0.29.0
What version of rules_go are you using?
0.40.1
What version of Bazel are you using?
7.0.0
Does this issue reproduce with the latest releases of all the above?
yes
What operating system and processor architecture are you using?
macOS Sonoma 14.0, arm64
Context: We maintain a large golang repository with gazelle, and often have multiple .proto files in a single directory. Due to some tooling requirements, we want each .proto file to have its own proto_library rule.
I tried using the “#gazelle:proto file” directive, but this also caused separate go_proto_library targets to be generated, with the same importpaths, which seems to cause build failures (similar issue here). It’s not really an option for us to enforce specification of unique “option go_package” lines in the .proto files. Ideally, we’d have some directive that works with “#gazelle:proto file” – maybe something like “#gazelle:go_proto importpath” so that we can generate a proto_library target for each .proto file, but only have one go_proto_library target per “inferred importpath” BUILD file. This would mean setting the “protos” attribute of the go_proto_library, which currently doesn’t seem to be supported. We’re thinking of creating a patch for our purposes, but was curious if there’s a better way to accomplish what we want, or if something like this could be an upstream change.
The text was updated successfully, but these errors were encountered: