I'm having an issue building my code base with Bazel, Go and Protobuf. The Protobuf files aren't mapped right by Bazel Gezelle when generated. I think it's a known bug. I've opened up my own ticket. If this is the problem, I don't expect it to be resolved anytime soon. It was tagged as a P2 and has been open since October. I'm looking for a solution to the problem in the mean time.
We use a custom Protobuf plugin when buliding our protobuf files. My thought process is to generate the protobuf files by hand and have Bazel ignore the protobuf files, just using the already generated code.
Does this sound like something that would work? How would I do this? Can I have Gezelle ignore the Protobuf files for me?
Thank you for your time
Copying my reply on bazelbuild/bazel-gazelle#209 for anyone running into the same issue.
Yep, bazelbuild/bazel#3867 is the issue.
Whenever you build a proto_library
with Bazel (for in any language, not just Go), Bazel thinks the imports are relative to a repository root (either in your local repository or in any of your external repositories). I'm guessing brand.proto
is importing github.com/xxx/jscode/jsge/pkg/paging/proto/page.proto
. Since the file you want to import is actually jsge/pkg/paging/proto/page.proto
, protoc won't find it when invoked by Bazel.
Since this is an issue with proto_library
, there's not much Gazelle or rules_go can do about it. If bazelbuild/bazel#3867 is implemented, you'll be able to adjust proto_library
import paths. Until then, you won't be able to build proto_library
rules without modifying them.
Unfortunately, the best advice I can offer at the moment is to check in pre-generated .pb.go files and include those in your go_library
rules. If you add a comment # gazelle:proto disable
in your root build file, it will ignore .proto files and will include .pb.go files.