bazelbuild / rules_go

Go rules for Bazel
Apache License 2.0
1.35k stars 635 forks source link

link: package conflict error #3957

Closed ZhengXinwei-F closed 1 week ago

ZhengXinwei-F commented 2 weeks ago

What version of rules_go are you using?

What version of gazelle are you using?

What version of Bazel are you using?

bazel: 6.3.2
rules_go: v0.47.0
rules_docker: 6db7c12fbe4b49682f5dcbc193e4c467011a9fb6
gazelle: v0.35.0

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

I haven't had the chance to give it a try yet.

What operating system and processor architecture are you using?

devContainer: Linux 30eedc3eab42 5.15.146.1-microsoft-standard-WSL2 #1 SMP Thu Jan 11 04:09:03 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux

Any other potentially useful information about your toolchain?

What did you do?

I encountered the following error:

link: package conflict error: localpath/core/validator/typed/v1alpha1: package imports 
localpath/core/compute/common/v1
          was compiled with: @//localpath/core/compute/common/v1:common
        but was linked with: @//localpath/core/compute/common/v1:common_go_proto

I referred to issue #1877 but didn't find a solution. Eventually, I discovered that the issue stemmed from localpath/core/compute/acp/v1 referencing localpath/core/compute/common/v1, and localpath/core/validator/typed/v1alpha1 also referencing both localpath/core/compute/acp/v1 and localpath/core/compute/common/v1.

In localpath/core/compute/acp/v1, the reference is as follows:

go_proto_library(
    name = "acp_go_proto",
    importpath = "localpath/core/compute/acp/v1",
    proto = ":acp_proto",
    visibility = ["//visibility:public"],
    deps = [
        "//localpath/core/compute/common/v1:common_go_proto",

Therefore, I manually updated the reference in localpath/core/validator/typed/v1alpha1 from @//localpath/core/compute/common/v1:common to @//localpath/core/compute/common/v1:common_go_proto, resolving the issue.

I would like to inquire if such modification is reasonable, and whether the community should address such problems caused by indirect dependencies. Alternatively, if a fix already exists, I may have overlooked it.

Awaiting and appreciating your response.

ZhengXinwei-F commented 1 week ago

I've caused the issue by using 'embed,' resulting in duplicated objects. This was my mistake. This issue will be closed. /close

ZhengXinwei-F commented 1 week ago

/close