rules_go icon indicating copy to clipboard operation
rules_go copied to clipboard

Different proto dependency resolution for libraries and binaries

Open tanyabouman opened this issue 4 years ago • 2 comments

What version of rules_go are you using?

0.27

What version of gazelle are you using?

0.23

What version of Bazel are you using?

4.1.0

Does this issue reproduce with the latest releases of all the above?

Yes

What did you do?

In this example repository, which contains a go_library and a go_test, I built both.

bazel build :mwe
bazel build :mwe_test

What did you expect to see?

I would expect that the dependency resolution would work the same way for the library and the test. Either both would fail or both would build.

What did you see instead?

The library builds, but not the test. The test fails with a proto error:

link: package conflict error: google.golang.org/genproto/protobuf/source_context: multiple copies of package passed to linker:
	@io_bazel_rules_go//proto/wkt:source_context_go_proto
	@org_golang_google_genproto//protobuf/source_context:source_context
Set "importmap" to different paths or use 'bazel cquery' to ensure only one
package with this path is linked.
Target //:mwe_test failed to build

I can make the test build by turning on build generation for grpc_gateway, so I'm not blocked by this problem. Why is there a difference between the dependency resolution for go_library and go_test?

tanyabouman avatar Jun 08 '21 20:06 tanyabouman

This issue is present in 5.0.0 as well. Very annoying.

oakad avatar Feb 23 '22 03:02 oakad

I think this is actually a bug in gazelle's proto plugin not in rules_go. I think the issue is that the known imports for protos are hardcoded to io_bazel_rules_go when they should be hardcoded to org_golang_google_genproto.

I'm sure Gazelle would be interested in a patch if that's something you'd be inclined to do.

achew22 avatar Feb 23 '22 16:02 achew22