Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple providers for the same importpath #2206

Closed
qzmfranklin opened this issue Aug 29, 2019 · 3 comments
Closed

Multiple providers for the same importpath #2206

qzmfranklin opened this issue Aug 29, 2019 · 3 comments

Comments

@qzmfranklin
Copy link

What version of rules_go are you using?

0.19.1

What version of gazelle are you using?

0.18.1

What version of Bazel are you using?

0.28.0

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

Not sure, but most probably does.

What operating system and processor architecture are you using?

Ubuntu 18.04.2
amd64

Any other potentially useful information about your toolchain?

N.A.

What did you do?

go_binary(
    name = 'add_person',
    embed = ['add_person_library'],
)

go_library(
    name = 'add_person_library',
    srcs = ['add_person.go'],
    deps = [
        ':addressbook_pb',
        '@com_github_golang_protobuf//proto:go_default_library',
    ],
)

go_library(
    name = 'addressbook_pb',
    srcs = [':addressbook_pb_go'],
    deps = [
        '@com_github_envoyproxy_protoc_gen_validate//validate:go_default_library',
        '@com_github_golang_protobuf//proto:go_default_library',
        '@com_github_golang_protobuf//ptypes/timestamp:go_default_library',
        '@com_github_golang_protobuf//ptypes:go_default_library',
        '@org_golang_google_grpc//:go_default_library',
    ],
    importpath = 'github.com/google/protobuf/examples/tutorial',
)

go_library(
    name = 'addressbook_pb',
    srcs = [':addressbook_pb_go'],
    deps = [
        '@com_github_envoyproxy_protoc_gen_validate//validate:go_default_library',
        '@com_github_golang_protobuf//proto:go_default_library',
        '@com_github_golang_protobuf//ptypes/timestamp:go_default_library',
        '@com_github_golang_protobuf//ptypes:go_default_library',
        '@org_golang_google_grpc//:go_default_library',
    ],
    importpath = 'github.com/google/protobuf/examples/tutorial',
)

# ':addressbook_pb_go' is a filegroup containing two .go files.

Run

bazel build :add_person

What did you expect to see?

The go_binary target add_person builds correctly.

What did you see instead?

The binary does build, but with warnings such as below:

17:25 $ bazel build examples/proto/base/go:add_person
INFO: Invocation ID: e0ce57c1-6a46-4c0a-9bab-2bce87595aea
INFO: Analyzed target //examples/proto/base/go:add_person (0 packages loaded, 0 targets configured).
INFO: Found 1 target...
INFO: Writing explanation of rebuilds to 'build/logs'
INFO: From GoLink examples/proto/base/go/linux_amd64_stripped/add_person:
link: warning: package "github.com/golang/protobuf/ptypes/timestamp" is provided by more than one rule:
    @com_github_golang_protobuf//ptypes/timestamp:go_default_library
    @io_bazel_rules_go//proto/wkt:timestamp_go_proto
Set "importmap" to different paths in each library.
This will be an error in the future.
link: warning: package "github.com/golang/protobuf/ptypes/any" is provided by more than one rule:
    @com_github_golang_protobuf//ptypes/any:go_default_library
    @io_bazel_rules_go//proto/wkt:any_go_proto
Set "importmap" to different paths in each library.
This will be an error in the future.
link: warning: package "github.com/golang/protobuf/ptypes/duration" is provided by more than one rule:
    @com_github_golang_protobuf//ptypes/duration:go_default_library
    @io_bazel_rules_go//proto/wkt:duration_go_proto
Set "importmap" to different paths in each library.
This will be an error in the future.
link: warning: package "github.com/golang/protobuf/ptypes" is provided by more than one rule:
    @com_github_golang_protobuf//ptypes:go_default_library_gen
    @com_github_golang_protobuf//ptypes:go_default_library
Set "importmap" to different paths in each library.
This will be an error in the future.
Target //examples/proto/base/go:add_person up-to-date:
  build/bin/examples/proto/base/go/linux_amd64_stripped/add_person

The dependency graph is:
a.pdf

The @com_github_golang_protobuf repo is specified like the following:

    go_repository(
        name = 'com_github_golang_protobuf',
        sha256 = r'''5d7ac29cd08416a560b33d6040ae1eac4f437c24aeda9218ac64e07b8edc26e2''',
        strip_prefix = r'''protobuf''',
        urls = ['http://github.com/golang/protobuf/archive/6c65a5562fc06764971b7c5d05c76c75e84bdbf7.tar.gz'],
        importpath = r'''github.com/golang/protobuf''',
    )
@qzmfranklin
Copy link
Author

This is not the only incidence of having multiple providers for the same importpath when it comes to wkt protos, which is defined in both @io_bazel_rules_go and @com_github_golang_protobuf.

Making it worse, developers such as me do NOT have full control over the build files generated by gazelle, which has special rules for generating go_proto_library() targets that use rules_go/wkt definitions.

I can understand how this divergence came about. But would like to see more convergence in the future.

At the very least, I do not want such an issue to break my build in the future.

@jayconrod
Copy link
Contributor

This problem is described in Avoiding conflicts.

Since you're using pre-generated .pb.go files here (or at least, not generated with go_proto_library), you can probably resolve this by adding # gazelle:proto disable_global to your root build file and build_proto_mode = "disable_global" to each go_repository rule with protos.

I can understand how this divergence came about. But would like to see more convergence in the future.

Yeah, the current situation is certainly not ideal. It will require a lot of time and careful thought to resolve without breaking builds. For now, the workaround above is all I can recommend.

At the very least, I do not want such an issue to break my build in the future.

I don't expect to make the warning above into an error until there's an easier (more automatic) way to resolve it.

@amitz
Copy link

amitz commented May 5, 2021

I'm having a similar issue, but I'm not sure # gazelle:proto disable_global will help me here, as I'm not using gazelle. I have a couple of protobufs files that depends on Google API protobufs (annotations, HTTP etc). I generate Protobuf code for both Java and Go, and using github.com/googleapi/googleapi - as the BUILD file there handles both Java and Go.

rules_go still use go_googleapis (I saw there's a bug to move into googleapi at some point) and they conflict. Both repositories define the same protobuf (or more specifically - different versions of the same file), and use the same importpath.

I'm getting a warning about that conflict - with a note this will become error in a future release. Anything I can do about besides overwriting go_googleapis locally and reference it to use googleapis repository (so I can use the specific version I need?)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants