bazel-contrib / bazel-gazelle

Gazelle is a Bazel build file generator for Bazel projects. It natively supports Go and protobuf, and it may be extended to support new languages and custom rule sets.
Apache License 2.0
1.2k stars 380 forks source link

gRPC-Go 1.30.0 breaks the build #819

Open johanbrandhorst opened 4 years ago

johanbrandhorst commented 4 years ago

What version of rules_go are you using?

v0.23.3

What version of gazelle are you using?

v0.21.1

What version of Bazel are you using?

v3.3.0

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

Yes

What operating system and processor architecture are you using?

Linux amd64

What did you do?

Upgraded to grpc-go 1.30.0, ran the bazelisk go_repository macro and tried rebuilding.

What did you expect to see?

A successful build.

What did you see instead?

A build failure:

ERROR: /tmp/build_output/external/org_golang_google_grpc/reflection/grpc_reflection_v1alpha/BUILD.bazel:19:11: GoCompilePkg external/org_golang_google_grpc/reflection/grpc_reflection_v1alpha/go_default_library.a failed (Exit 1) builder failed: error executing command bazel-out/host/bin/external/go_sdk/builder compilepkg -sdk external/go_sdk -installsuffix linux_amd64 -src ... (remaining 55 argument(s) skipped)

Use --sandbox_debug to see verbose messages from the sandbox

compilepkg: error running subcommand: exit status 2

/tmp/build_output/sandbox/processwrapper-sandbox/89/execroot/bazel_monorepo/external/org_golang_google_grpc/reflection/grpc_reflection_v1alpha/reflection_grpc.pb.go:19:6: ServerReflectionClient redeclared in this block
    previous declaration at /tmp/build_output/sandbox/processwrapper-sandbox/89/execroot/bazel_monorepo/bazel-out/k8-fastbuild/bin/external/org_golang_google_grpc/reflection/grpc_reflection_v1alpha/grpc_reflection_v1alpha_go_proto_/google.golang.org/grpc/reflection/grpc_reflection_v1alpha/reflection.pb.go:898:6
/tmp/build_output/sandbox/processwrapper-sandbox/89/execroot/bazel_monorepo/external/org_golang_google_grpc/reflection/grpc_reflection_v1alpha/reflection_grpc.pb.go:25:6: serverReflectionClient redeclared in this block
    previous declaration at /tmp/build_output/sandbox/processwrapper-sandbox/89/execroot/bazel_monorepo/bazel-out/k8-fastbuild/bin/external/org_golang_google_grpc/reflection/grpc_reflection_v1alpha/grpc_reflection_v1alpha_go_proto_/google.golang.org/grpc/reflection/grpc_reflection_v1alpha/reflection.pb.go:902:6
/tmp/build_output/sandbox/processwrapper-sandbox/89/execroot/bazel_monorepo/external/org_golang_google_grpc/reflection/grpc_reflection_v1alpha/reflection_grpc.pb.go:29:6: NewServerReflectionClient redeclared in this block
    previous declaration at /tmp/build_output/sandbox/processwrapper-sandbox/89/execroot/bazel_monorepo/bazel-out/k8-fastbuild/bin/external/org_golang_google_grpc/reflection/grpc_reflection_v1alpha/grpc_reflection_v1alpha_go_proto_/google.golang.org/grpc/reflection/grpc_reflection_v1alpha/reflection.pb.go:906:61
/tmp/build_output/sandbox/processwrapper-sandbox/89/execroot/bazel_monorepo/external/org_golang_google_grpc/reflection/grpc_reflection_v1alpha/reflection_grpc.pb.go:42:6: ServerReflection_ServerReflectionInfoClient redeclared in this block
    previous declaration at /tmp/build_output/sandbox/processwrapper-sandbox/89/execroot/bazel_monorepo/bazel-out/k8-fastbuild/bin/external/org_golang_google_grpc/reflection/grpc_reflection_v1alpha/grpc_reflection_v1alpha_go_proto_/google.golang.org/grpc/reflection/grpc_reflection_v1alpha/reflection.pb.go:919:6
/tmp/build_output/sandbox/processwrapper-sandbox/89/execroot/bazel_monorepo/external/org_golang_google_grpc/reflection/grpc_reflection_v1alpha/reflection_grpc.pb.go:48:6: serverReflectionServerReflectionInfoClient redeclared in this block
    previous declaration at /tmp/build_output/sandbox/processwrapper-sandbox/89/execroot/bazel_monorepo/bazel-out/k8-fastbuild/bin/external/org_golang_google_grpc/reflection/grpc_reflection_v1alpha/grpc_reflection_v1alpha_go_proto_/google.golang.org/grpc/reflection/grpc_reflection_v1alpha/reflection.pb.go:925:6
/tmp/build_output/sandbox/processwrapper-sandbox/89/execroot/bazel_monorepo/external/org_golang_google_grpc/reflection/grpc_reflection_v1alpha/reflection_grpc.pb.go:67:6: ServerReflectionServer redeclared in this block
    previous declaration at /tmp/build_output/sandbox/processwrapper-sandbox/89/execroot/bazel_monorepo/bazel-out/k8-fastbuild/bin/external/org_golang_google_grpc/reflection/grpc_reflection_v1alpha/grpc_reflection_v1alpha_go_proto_/google.golang.org/grpc/reflection/grpc_reflection_v1alpha/reflection.pb.go:942:6
/tmp/build_output/sandbox/processwrapper-sandbox/89/execroot/bazel_monorepo/external/org_golang_google_grpc/reflection/grpc_reflection_v1alpha/reflection_grpc.pb.go:74:6: UnimplementedServerReflectionServer redeclared in this block
    previous declaration at /tmp/build_output/sandbox/processwrapper-sandbox/89/execroot/bazel_monorepo/bazel-out/k8-fastbuild/bin/external/org_golang_google_grpc/reflection/grpc_reflection_v1alpha/grpc_reflection_v1alpha_go_proto_/google.golang.org/grpc/reflection/grpc_reflection_v1alpha/reflection.pb.go:947:6
/tmp/build_output/sandbox/processwrapper-sandbox/89/execroot/bazel_monorepo/external/org_golang_google_grpc/reflection/grpc_reflection_v1alpha/reflection_grpc.pb.go:81:6: RegisterServerReflectionServer redeclared in this block
    previous declaration at /tmp/build_output/sandbox/processwrapper-sandbox/89/execroot/bazel_monorepo/bazel-out/k8-fastbuild/bin/external/org_golang_google_grpc/reflection/grpc_reflection_v1alpha/grpc_reflection_v1alpha_go_proto_/google.golang.org/grpc/reflection/grpc_reflection_v1alpha/reflection.pb.go:954:57
/tmp/build_output/sandbox/processwrapper-sandbox/89/execroot/bazel_monorepo/external/org_golang_google_grpc/reflection/grpc_reflection_v1alpha/reflection_grpc.pb.go:85:6: _ServerReflection_ServerReflectionInfo_Handler redeclared in this block
    previous declaration at /tmp/build_output/sandbox/processwrapper-sandbox/89/execroot/bazel_monorepo/bazel-out/k8-fastbuild/bin/external/org_golang_google_grpc/reflection/grpc_reflection_v1alpha/grpc_reflection_v1alpha_go_proto_/google.golang.org/grpc/reflection/grpc_reflection_v1alpha/reflection.pb.go:958:96
/tmp/build_output/sandbox/processwrapper-sandbox/89/execroot/bazel_monorepo/external/org_golang_google_grpc/reflection/grpc_reflection_v1alpha/reflection_grpc.pb.go:89:6: ServerReflection_ServerReflectionInfoServer redeclared in this block
    previous declaration at /tmp/build_output/sandbox/processwrapper-sandbox/89/execroot/bazel_monorepo/bazel-out/k8-fastbuild/bin/external/org_golang_google_grpc/reflection/grpc_reflection_v1alpha/grpc_reflection_v1alpha_go_proto_/google.golang.org/grpc/reflection/grpc_reflection_v1alpha/reflection.pb.go:962:6
/tmp/build_output/sandbox/processwrapper-sandbox/89/execroot/bazel_monorepo/external/org_golang_google_grpc/reflection/grpc_reflection_v1alpha/reflection_grpc.pb.go:89:6: too many errors

See https://app.circleci.com/pipelines/github/johanbrandhorst/bazel-mono/185/workflows/8cfdad13-0197-431e-9fab-17514bd4cba1/jobs/1564/steps for the full log.

jayconrod commented 4 years ago

The library with the error looks like this:

go_library(
    name = "go_default_library",
    srcs = ["reflection_grpc.pb.go"],
    embed = [":grpc_reflection_v1alpha_go_proto"],
    importpath = "google.golang.org/grpc/reflection/grpc_reflection_v1alpha",
    visibility = ["//visibility:public"],
    deps = [
        "//codes:go_default_library",
        "//status:go_default_library",
        "@org_golang_google_grpc//:go_default_library",
    ],
)

This builds a pre-generated file, reflection_grpc.pb.go, together with build-time generated files. I think reflection_grpc.pb.go is generated with google.golang.org/grpc/cmd/protoc-gen-go-grpc, so it includes services but not messages. go_proto_library uses github.com/golang/protobuf/cmd/protoc-gen-go, so it includes both services and messages. So the services get declared twice.

Some special incantation to Gazelle may be needed here. If the intent is to use protoc-gen-go-grpc, perhaps Gazelle should declare a go_proto_compiler for that and use it automatically. If the intent is to use the pre-generated sources, then there should be an easier way to set build_file_proto_mode = "disable_global" on repos that need it.

zhangqiulu commented 4 years ago

Same problem, I build with go build and it's ok, but with bazel... redeclared

adieu commented 4 years ago

798 is also related to this issue. The reflection_grpc.pb.go file in google.golang.org/grpc/reflection/grpc_reflection_v1alpha caused the problem. We could revert back to google.golang.org/grpc@v1.29.1 or inject a custom BUILD.bazel file removing reflection_grpc.pb.go from srcs as a workaround.

scorsi commented 4 years ago

@adieu using 1.29.1 allows to temporarily serve as a work-around waiting for the issue to be solved.

Bogdan-Catalin commented 3 years ago

@adieu For me it's not an option to switch to 1.29.1. How did you inject a custom build file ? I managed to do it only by using vendored version, but it's not a great solution because I have to make sure to copy over the patched build file every time I run go mod vendor.