bazel-contrib / bazel-contrib/rules_go

Different proto dependency resolution for libraries and binaries

Open
#2,891 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
Go
Stars
1.5k
Forks
760
Avg merge
1d 11h
Merged PRs (30d)
12

Description

### 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](https://github.com/tanyabouman/mwe-grpc_gateway-import), 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`?

Contributor guide

Open the contributing guide

Research direction

Reproduce the issue in the linked example repository with `bazel build :mwe` and `bazel build :mwe_test`. Compare dependency resolution for the `go_library` and `go_test`, including the effect of enabling grpc_gateway build generation; done means both targets resolve the proto dependency consistently and the test no longer reports duplicate `source_context` packages.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
build-system
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.