无法使用 gRPC 构建 go_proto_library
Cannot build go_proto_library with gRPC
我开始使用 bazel 并尝试为 golang 生成 RPC 服务的 protobuf 代码。
当我尝试构建它时出现以下错误:
bazel-out/k8-fastbuild/bin/examples/grpc/protos/helloworld_go_proto_/examples/grpc/protos/helloworld.pb.go:229:7: undefined: grpc.ClientConnInterface
bazel-out/k8-fastbuild/bin/examples/grpc/protos/helloworld_go_proto_/examples/grpc/protos/helloworld.pb.go:233:11: undefined: grpc.SupportPackageIsVersion6
bazel-out/k8-fastbuild/bin/examples/grpc/protos/helloworld_go_proto_/examples/grpc/protos/helloworld.pb.go:243:5: undefined: grpc.ClientConnInterface
bazel-out/k8-fastbuild/bin/examples/grpc/protos/helloworld_go_proto_/examples/grpc/protos/helloworld.pb.go:246:26: undefined: grpc.ClientConnInterface
完整构建日志:https://app.buildbuddy.io/invocation/c3773978-22dd-44c8-b977-13967a1953b7
代码如下:https://github.com/juanique/example-go-grpc。我正在尝试包含尽可能少的代码以使该目标正常工作。
由于 BUILD
文件是由 gazelle
生成的,我怀疑问题出在 WORKSPACE
文件中:https://raw.githubusercontent.com/juanique/example-go-grpc/main/WORKSPACE. I'm just doing what I found in https://github.com/bazelbuild/rules_go
更新:看起来肯定是版本问题:https://github.com/grpc/grpc-go#compiling-error-undefined-grpcsupportpackageisversion
不是 bazel 用户,但经过几个小时的测试,我发现你的 rpc 版本应该更高:
go_repository(
name = "org_golang_google_grpc",
- build_file_proto_mode = "disable",
importpath = "google.golang.org/grpc",
- sum = "h1:J0UbZOIrCAl+fpTOf8YLs4dJo8L/owV4LYVtAXQoPkw=",
- version = "v1.22.0",
+ sum = "h1:f+PlOh7QV4iIJkPrx5NQ7qaNGFQ3OTse67yaDHfju4E=",
+ version = "v1.41.0",
)
然后你就可以构建它了:
~/code/example-go-grpc (main*) [09:45:55]
p1gd0g$ bazel build //examples/grpc/protos:helloworld_go_proto
INFO: Analyzed target //examples/grpc/protos:helloworld_go_proto (49 packages loaded, 306 targets configured).
INFO: Found 1 target...
Target //examples/grpc/protos:helloworld_go_proto up-to-date:
bazel-bin/examples/grpc/protos/helloworld_go_proto.a
INFO: Elapsed time: 41.180s, Critical Path: 1.20s
INFO: 29 processes: 1 internal, 28 linux-sandbox.
INFO: Build completed successfully, 29 total actions
并且我建议使用 gazelle 和 go.mod 来生成 WORKSPACE。演示:https://github.com/p1gd0g/helloworld
我开始使用 bazel 并尝试为 golang 生成 RPC 服务的 protobuf 代码。
当我尝试构建它时出现以下错误:
bazel-out/k8-fastbuild/bin/examples/grpc/protos/helloworld_go_proto_/examples/grpc/protos/helloworld.pb.go:229:7: undefined: grpc.ClientConnInterface
bazel-out/k8-fastbuild/bin/examples/grpc/protos/helloworld_go_proto_/examples/grpc/protos/helloworld.pb.go:233:11: undefined: grpc.SupportPackageIsVersion6
bazel-out/k8-fastbuild/bin/examples/grpc/protos/helloworld_go_proto_/examples/grpc/protos/helloworld.pb.go:243:5: undefined: grpc.ClientConnInterface
bazel-out/k8-fastbuild/bin/examples/grpc/protos/helloworld_go_proto_/examples/grpc/protos/helloworld.pb.go:246:26: undefined: grpc.ClientConnInterface
完整构建日志:https://app.buildbuddy.io/invocation/c3773978-22dd-44c8-b977-13967a1953b7
代码如下:https://github.com/juanique/example-go-grpc。我正在尝试包含尽可能少的代码以使该目标正常工作。
由于 BUILD
文件是由 gazelle
生成的,我怀疑问题出在 WORKSPACE
文件中:https://raw.githubusercontent.com/juanique/example-go-grpc/main/WORKSPACE. I'm just doing what I found in https://github.com/bazelbuild/rules_go
更新:看起来肯定是版本问题:https://github.com/grpc/grpc-go#compiling-error-undefined-grpcsupportpackageisversion
不是 bazel 用户,但经过几个小时的测试,我发现你的 rpc 版本应该更高:
go_repository(
name = "org_golang_google_grpc",
- build_file_proto_mode = "disable",
importpath = "google.golang.org/grpc",
- sum = "h1:J0UbZOIrCAl+fpTOf8YLs4dJo8L/owV4LYVtAXQoPkw=",
- version = "v1.22.0",
+ sum = "h1:f+PlOh7QV4iIJkPrx5NQ7qaNGFQ3OTse67yaDHfju4E=",
+ version = "v1.41.0",
)
然后你就可以构建它了:
~/code/example-go-grpc (main*) [09:45:55]
p1gd0g$ bazel build //examples/grpc/protos:helloworld_go_proto
INFO: Analyzed target //examples/grpc/protos:helloworld_go_proto (49 packages loaded, 306 targets configured).
INFO: Found 1 target...
Target //examples/grpc/protos:helloworld_go_proto up-to-date:
bazel-bin/examples/grpc/protos/helloworld_go_proto.a
INFO: Elapsed time: 41.180s, Critical Path: 1.20s
INFO: 29 processes: 1 internal, 28 linux-sandbox.
INFO: Build completed successfully, 29 total actions
并且我建议使用 gazelle 和 go.mod 来生成 WORKSPACE。演示:https://github.com/p1gd0g/helloworld