rules_go: Can't build a project that depends on gocloud.dev v0.24.0 and some other packages
What version of rules_go are you using?
Tried with both v0.28.0 and v0.29.0
What version of gazelle are you using?
Tried with both v0.23.0 and Master
What version of Bazel are you using?
v4.2.1
Does this issue reproduce with the latest releases of all the above?
Yes
What operating system and processor architecture are you using?
Tried both Mac and Linux (amd64 on both)
Any other potentially useful information about your toolchain?
Nothing special.
What did you do?
- Create an empty project with a Go file depending on both
gocloud.dev v0.24.0
andfirebase.google.com/go/v4 v4.6.0
(it happens withgocloud.dev v0.24.0
and other packages as well. firebase is just a simple example). - Run
go mod tidy
and thenbazel run //:gazelle -- update-repos -to_macro=repositories.bzl%go_repositories -from_file=./go.mod
(I also tried running with-build_file_proto_mode=disable
, same problem) - Try to build
(Example can be found here: https://github.com/mishas/bazel-cross-compile-rebuild/tree/example/gocloud.dev_v0.24.0) (Run output can be found here: https://github.com/mishas/bazel-cross-compile-rebuild/runs/3830586153?check_suite_focus=true)
What did you expect to see?
Successful build
What did you see instead?
INFO: Analyzed target //pkg/demo:demo (210 packages loaded, 2136 targets configured).
INFO: Found 1 target...
ERROR: /.../pkg/demo/BUILD.bazel:14:10: GoLink pkg/demo/demo_/demo failed: (Exit 1): builder failed: error executing command bazel-out/host/bin/external/go_sdk/builder '-param=bazel-out/darwin-fastbuild/bin/pkg/demo/demo_/demo-0.params' -- -extld external/local_config_cc/cc_wrapper.sh '-buildid=redacted' -extldflags ... (remaining 1 argument(s) skipped)
Use --sandbox_debug to see verbose messages from the sandbox
link: package conflict error: google.golang.org/genproto/googleapis/api/annotations: multiple copies of package passed to linker:
@org_golang_google_genproto//googleapis/api/annotations:annotations
@go_googleapis//google/api:annotations_go_proto
Set "importmap" to different paths or use 'bazel cquery' to ensure only one
package with this path is linked.
Target //pkg/demo:demo failed to build
Use --verbose_failures to see the command lines of failed build steps.
INFO: Elapsed time: 8.852s, Critical Path: 0.14s
INFO: 2 processes: 2 internal.
FAILED: Build did NOT complete successfully
Additional information
- Everything works just fine with
gocloud.dev v0.23.0
, but I believe it’s because v0.24.0 added a bunch of new dependencies… - I’ve added
build_file_proto_mode = "disable_global"
to a bunch ofgo_repository
targets, and made it work (specifically tocom_github_googleapis_gax_go_v2
,com_google_cloud_go
,com_google_cloud_go_firestore
,com_google_cloud_go_storage
,org_golang_google_grpc
). But in my real code it wasn’t enough: I have .proto files that hasimport "google/rpc/status.proto"
, which still created the problem 😦.
About this issue
- Original URL
- State: open
- Created 3 years ago
- Comments: 20 (6 by maintainers)
Commits related to this issue
- Fix beam build due to gazelle/@com_google_cloud_go_storage issue. See https://github.com/bazelbuild/rules_go/issues/2981. — committed to gonzojive/beam by gonzojive 2 years ago
- Fix beam build due to gazelle/@com_google_cloud_go_storage issue. See https://github.com/bazelbuild/rules_go/issues/2981. — committed to gonzojive/beam by gonzojive 2 years ago
Looks like https://github.com/googleapis/google-cloud-go/pull/6266 fixed the issue for google storage, verified that the issue is present before this PR and vanishes after this PR.
This fix is not released yet, but 1.24 release is being prepared from what I see: https://github.com/googleapis/google-cloud-go/pull/6336. You can try the pre 1.24 release to see whether it works:
We had the same issue at one point. The issue is basically version drift between the
go_googleapis
workspace, and thegoogle.golang.org/genproto/googleapis
module. When a target uses both as a dependency, for the protobufs Gazelle prefers to resolve togo_googleapis
, but that may or may not contain code that would be ingoogle.golang.org/genproto/googleapis
.When something like this comes up, Gazelle can be taught to always resolve to
go_googleapis
with something likeI ran into this problem again recently, using the latest version of Gazelle, rules_go, etc, and the only solution that worked for me was to downgrade
com_google_cloud_go_storage
tov1.15.0
.As that version is getting increasingly old, I imagine it will eventually cause compatibility problems, are there any other workarounds that have worked for folks?
Does anyone else find this error message could be more explicit about the suggested corrections and diagnostic commands?
Ran into this issue too and downgrading google storage to v1.15.0 really does the magic… ❤️