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

errors when building with bazel #1392

Closed
joesonw opened this issue May 25, 2020 · 10 comments · Fixed by #1487
Closed

errors when building with bazel #1392

joesonw opened this issue May 25, 2020 · 10 comments · Fixed by #1487
Assignees

Comments

@joesonw
Copy link
Contributor

joesonw commented May 25, 2020

Hi, I'm using bazel (3.1.0) to build my project along with grpc-gateway. Followed #1010 , I added 1.14.5 depenpdency, and set go_proto_library as such:

#gazelle:go_grpc_compilers @io_bazel_rules_go//proto:go_grpc,@grpc_ecosystem_grpc_gateway//protoc-gen-grpc-gateway:go_gen_grpc_gateway
go_proto_library(
    name = "api_go_proto",
    compilers = [
        "@io_bazel_rules_go//proto:go_grpc",
        "@grpc_ecosystem_grpc_gateway//protoc-gen-grpc-gateway:go_gen_grpc_gateway",
    ],
    importpath = "xxx",
    proto = ":api_proto",
    visibility = ["//visibility:public"],
    deps = [
        "@go_googleapis//google/api:annotations_go_proto",
    ],
)

However it was unable to compile: in deps attribute of go_proto_library rule //_apiproto:api_go_proto: target '//_apiproto:github.com/golang/protobuf/descriptor' does not exist

Thus I had to add "@com_github_golang_protobuf//descriptor:go_default_library" to either go_proto_library or go_library deps.

It did compile, but it spits more errors when I use it inmain files.

link: warning: package "github.com/golang/protobuf/protoc-gen-go/descriptor" is provided by more than one rule:
    @io_bazel_rules_go//proto/wkt:descriptor_go_proto
    @com_github_golang_protobuf//protoc-gen-go/descriptor:go_default_library
Set "importmap" to different paths in each library.
This will be an error in the future.
link: warning: package "github.com/golang/protobuf/descriptor" is provided by more than one rule:
    @com_github_golang_protobuf//descriptor:go_default_library_gen
    @com_github_golang_protobuf//descriptor:go_default_library
Set "importmap" to different paths in each library.
This will be an error in the future.
link: warning: package "github.com/grpc-ecosystem/grpc-gateway/internal" is provided by more than one rule:
    @com_github_grpc_ecosystem_grpc_gateway//internal:go_default_library
    @grpc_ecosystem_grpc_gateway//internal:go_default_library
Set "importmap" to different paths in each library.
This will be an error in the future.
link: warning: package "github.com/grpc-ecosystem/grpc-gateway/utilities" is provided by more than one rule:
    @com_github_grpc_ecosystem_grpc_gateway//utilities:go_default_library
    @grpc_ecosystem_grpc_gateway//utilities:go_default_library
Set "importmap" to different paths in each library.
This will be an error in the future.
link: warning: package "github.com/grpc-ecosystem/grpc-gateway/runtime" is provided by more than one rule:
    @com_github_grpc_ecosystem_grpc_gateway//runtime:go_default_library
    @grpc_ecosystem_grpc_gateway//runtime:go_default_library
Set "importmap" to different paths in each library.
This will be an error in the future.
go.itab.*github.com/golang/protobuf/protoc-gen-go/descriptor.FieldOptions,google.golang.org/protobuf/runtime/protoiface.MessageV1: relocation target type.*github.com/golang/protobuf/protoc-gen-go/descriptor.FieldOptions not defined
go.itab.*github.com/golang/protobuf/protoc-gen-go/descriptor.FieldOptions,google.golang.org/protobuf/runtime/protoiface.MessageV1: relocation target github.com/golang/protobuf/protoc-gen-go/descriptor.(*FieldOptions).ProtoMessage not defined
go.itab.*github.com/golang/protobuf/protoc-gen-go/descriptor.FieldOptions,google.golang.org/protobuf/runtime/protoiface.MessageV1: relocation target github.com/golang/protobuf/protoc-gen-go/descriptor.(*FieldOptions).Reset not defined
go.itab.*github.com/golang/protobuf/protoc-gen-go/descriptor.FieldOptions,google.golang.org/protobuf/runtime/protoiface.MessageV1: relocation target github.com/golang/protobuf/protoc-gen-go/descriptor.(*FieldOptions).String not defined
go.itab.*github.com/golang/protobuf/protoc-gen-go/descriptor.FileOptions,google.golang.org/protobuf/runtime/protoiface.MessageV1: relocation target type.*github.com/golang/protobuf/protoc-gen-go/descriptor.FileOptions not defined
go.itab.*github.com/golang/protobuf/protoc-gen-go/descriptor.FileOptions,google.golang.org/protobuf/runtime/protoiface.MessageV1: relocation target github.com/golang/protobuf/protoc-gen-go/descriptor.(*FileOptions).ProtoMessage not defined
go.itab.*github.com/golang/protobuf/protoc-gen-go/descriptor.FileOptions,google.golang.org/protobuf/runtime/protoiface.MessageV1: relocation target github.com/golang/protobuf/protoc-gen-go/descriptor.(*FileOptions).Reset not defined
go.itab.*github.com/golang/protobuf/protoc-gen-go/descriptor.FileOptions,google.golang.org/protobuf/runtime/protoiface.MessageV1: relocation target github.com/golang/protobuf/protoc-gen-go/descriptor.(*FileOptions).String not defined
go.itab.*github.com/golang/protobuf/protoc-gen-go/descriptor.MessageOptions,google.golang.org/protobuf/runtime/protoiface.MessageV1: relocation target type.*github.com/golang/protobuf/protoc-gen-go/descriptor.MessageOptions not defined
go.itab.*github.com/golang/protobuf/protoc-gen-go/descriptor.MessageOptions,google.golang.org/protobuf/runtime/protoiface.MessageV1: relocation target github.com/golang/protobuf/protoc-gen-go/descriptor.(*MessageOptions).ProtoMessage not defined
go.itab.*github.com/golang/protobuf/protoc-gen-go/descriptor.MessageOptions,google.golang.org/protobuf/runtime/protoiface.MessageV1: relocation target github.com/golang/protobuf/protoc-gen-go/descriptor.(*MessageOptions).Reset not defined
go.itab.*github.com/golang/protobuf/protoc-gen-go/descriptor.MessageOptions,google.golang.org/protobuf/runtime/protoiface.MessageV1: relocation target github.com/golang/protobuf/protoc-gen-go/descriptor.(*MessageOptions).String not defined
go.itab.*github.com/golang/protobuf/protoc-gen-go/descriptor.MethodOptions,google.golang.org/protobuf/runtime/protoiface.MessageV1: relocation target type.*github.com/golang/protobuf/protoc-gen-go/descriptor.MethodOptions not defined
go.itab.*github.com/golang/protobuf/protoc-gen-go/descriptor.MethodOptions,google.golang.org/protobuf/runtime/protoiface.MessageV1: relocation target github.com/golang/protobuf/protoc-gen-go/descriptor.(*MethodOptions).ProtoMessage not defined
go.itab.*github.com/golang/protobuf/protoc-gen-go/descriptor.MethodOptions,google.golang.org/protobuf/runtime/protoiface.MessageV1: relocation target github.com/golang/protobuf/protoc-gen-go/descriptor.(*MethodOptions).Reset not defined
go.itab.*github.com/golang/protobuf/protoc-gen-go/descriptor.MethodOptions,google.golang.org/protobuf/runtime/protoiface.MessageV1: relocation target github.com/golang/protobuf/protoc-gen-go/descriptor.(*MethodOptions).String not defined
go.itab.*github.com/golang/protobuf/protoc-gen-go/descriptor.ServiceOptions,google.golang.org/protobuf/runtime/protoiface.MessageV1: relocation target type.*github.com/golang/protobuf/protoc-gen-go/descriptor.ServiceOptions not defined
go.itab.*github.com/golang/protobuf/protoc-gen-go/descriptor.ServiceOptions,google.golang.org/protobuf/runtime/protoiface.MessageV1: relocation target github.com/golang/protobuf/protoc-gen-go/descriptor.(*ServiceOptions).ProtoMessage not defined
go.itab.*github.com/golang/protobuf/protoc-gen-go/descriptor.ServiceOptions,google.golang.org/protobuf/runtime/protoiface.MessageV1: relocation target github.com/golang/protobuf/protoc-gen-go/descriptor.(*ServiceOptions).Reset not defined
go.itab.*github.com/golang/protobuf/protoc-gen-go/descriptor.ServiceOptions,google.golang.org/protobuf/runtime/protoiface.MessageV1: relocation target github.com/golang/protobuf/protoc-gen-go/descriptor.(*ServiceOptions).String not defined
google.golang.org/genproto/googleapis/api/annotations..stmp_14: relocation target type.*github.com/golang/protobuf/protoc-gen-go/descriptor.MethodOptions not defined

some WORKSPACE info that might help debugging

Details

http_archive(
    name = "io_bazel_rules_go",
    sha256 = "6a68e269802911fa419abb940c850734086869d7fe9bc8e12aaf60a09641c818",
    urls = [
       "https://mirror.bazel.build/github.com/bazelbuild/rules_go/releases/download/v0.23.0/rules_go-v0.23.0.tar.gz",
        "https://github.com/bazelbuild/rules_go/releases/download/v0.23.0/rules_go-v0.23.0.tar.gz",
    ],
)
load("@io_bazel_rules_go//go:deps.bzl", "go_rules_dependencies", "go_register_toolchains")
go_rules_dependencies()
go_register_toolchains()


http_archive(
    name = "bazel_gazelle",
    sha256 = "bfd86b3cbe855d6c16c6fce60d76bd51f5c8dbc9cfcaef7a2bb5c1aafd0710e8",
    urls = [
        "https://mirror.bazel.build/github.com/bazelbuild/bazel-gazelle/releases/download/v0.21.0/bazel-gazelle-v0.21.0.tar.gz",
        "https://github.com/bazelbuild/bazel-gazelle/releases/download/v0.21.0/bazel-gazelle-v0.21.0.tar.gz",
    ],
)
load("@bazel_gazelle//:deps.bzl", "gazelle_dependencies", "go_repository")
gazelle_dependencies()


http_archive(
    name = "rules_proto",
    sha256 = "602e7161d9195e50246177e7c55b2f39950a9cf7366f74ed5f22fd45750cd208",
    strip_prefix = "rules_proto-97d8af4dc474595af3900dd85cb3a29ad28cc313",
    urls = [
        "https://mirror.bazel.build/github.com/bazelbuild/rules_proto/archive/97d8af4dc474595af3900dd85cb3a29ad28cc313.tar.gz",
       "https://github.com/bazelbuild/rules_proto/archive/97d8af4dc474595af3900dd85cb3a29ad28cc313.tar.gz",
    ],
)
load("@rules_proto//proto:repositories.bzl", "rules_proto_dependencies", "rules_proto_toolchains")
rules_proto_dependencies()
rules_proto_toolchains()


http_archive(
    name = "grpc_ecosystem_grpc_gateway",
    sha256 = "9b6c70ea99b79f3d0ac3259f6bd3ab321a68f6fd21c03b47e1891a1a9efa70c3",
    strip_prefix = "grpc-gateway-1.14.5",
    urls = [
        "https://github.com/grpc-ecosystem/grpc-gateway/archive/v1.14.5.tar.gz",
    ],
)
load("@grpc_ecosystem_grpc_gateway//:repositories.bzl", grpc_gateway_go_repositories = "go_repositories")
grpc_gateway_go_repositories()

@achew22
Copy link
Collaborator

achew22 commented May 26, 2020

I don't believe this is an issue with grpc-gateway, but is instead one with rules_go. I've seen people post issues about this on GitHub like this one bazel-contrib/rules_go#2206. I believe the best advice is to follow the rules_go documentation on the subject.

If this is about the go.itab errors at the bottom, I would be interested in learning more about what a go.itab is. Would it be possible to produce a clone-able repo that exhibits this issue so that we can talk about it more precisely?

@joesonw
Copy link
Contributor Author

joesonw commented May 27, 2020

@achew22 https://github.com/joesonw/grpc-gateway-1392 here.

bazel run //test will fail with error compilepkg: missing strict dependencies: /..../example.com/grpc/api/echo.pb.gw.go: import of "github.com/golang/protobuf/descriptor"

@joesonw
Copy link
Contributor Author

joesonw commented May 27, 2020

I tried using my own go_proto_compiler as following:

go_proto_compiler(
    name = "go_gen_grpc_gateway",
    options = [
        "logtostderr=true",
        "allow_repeated_fields_in_body=true",
    ],
    plugin = "@grpc_ecosystem_grpc_gateway//protoc-gen-grpc-gateway:protoc-gen-grpc-gateway",
    suffix = ".pb.gw.go",
    visibility = ["//visibility:public"],
    deps = [
        "@com_github_golang_protobuf//descriptor:go_default_library",
        "@grpc_ecosystem_grpc_gateway//runtime:go_default_library",
        "@grpc_ecosystem_grpc_gateway//utilities:go_default_library",
        "@com_github_golang_protobuf//proto:go_default_library",
        "@org_golang_google_grpc//:go_default_library",
        "@org_golang_google_grpc//codes:go_default_library",
        "@org_golang_google_grpc//grpclog:go_default_library",
        "@org_golang_google_grpc//status:go_default_library",
        "@org_golang_x_net//context:go_default_library",
    ],
)

It will compile and run, However, It still reports tons of warnings, one like below:

2020/05/27 09:46:14 WARNING: proto: message google.protobuf.GeneratedCodeInfo.Annotation is already registered
	previously from: "github.com/golang/protobuf/protoc-gen-go/descriptor"
	currently from:  "google.golang.org/protobuf/types/descriptorpb"
A future release will panic on registration conflicts. See:
https://developers.google.com/protocol-buffers/docs/reference/go/faq#namespace-conflict

@johanbrandhorst
Copy link
Collaborator

These warnings are a bug in the latest rules_go, it's been fixed on master: bazel-contrib/rules_go#2501

@joesonw
Copy link
Contributor Author

joesonw commented May 27, 2020

@johanbrandhorst What I'm trying to say is that @grpc_ecosystem_grpc_gateway//protoc-gen-grpc-gateway:go_gen_grpc_gateway does not work. The warnings are the result of a workaround, by adding @com_github_golang_protobuf//descriptor:go_default_library to deps

@johanbrandhorst
Copy link
Collaborator

I just checked out the tag v1.14.5 and ran bazel test //... successfully. Is this what you are talking about?

@joesonw
Copy link
Contributor Author

joesonw commented May 27, 2020

I came up with a minimal repo to replicate this error here (https://github.com/joesonw/grpc-gateway-1392)

@johanbrandhorst
Copy link
Collaborator

Thanks for that, I'm not familiar enough with bazel to debug why that is broken, but Andrew can hopefully help when he has the time.

@bartle-stripe
Copy link
Contributor

bartle-stripe commented Jun 24, 2020

I believe the fix is to add @com_github_golang_protobuf//descriptor:go_default_library_gen to deps on the go_gen_grpc_gateway go_proto_compiler rule. This is explained in https://github.com/bazelbuild/rules_go/blob/master/proto/core.rst#go_proto_compiler ("deps: List of Go libraries that Go code generated by this compiler depends on implicitly.").

@johanbrandhorst
Copy link
Collaborator

That seems like a great idea, would you be willing to contribute this fix?

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

Successfully merging a pull request may close this issue.

4 participants