【问题标题】:Cannot build go_proto_library with gRPC无法使用 gRPC 构建 go_proto_library
【发布时间】:2021-11-19 03:33:28
【问题描述】:

我开始使用 bazel,并尝试为 RPC 服务生成 golang 的 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。我只是在做我在https://github.com/bazelbuild/rules_go中找到的东西

【问题讨论】:

    标签: go protocol-buffers grpc bazel


    【解决方案1】:

    更新:看起来肯定是版本问题: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
    

    而且我建议使用 go.mod 和 go.mod 来生成 WORKSPACE。一个演示:https://github.com/p1gd0g/helloworld

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-10-09
      • 2018-08-26
      • 2023-02-10
      • 1970-01-01
      • 2018-11-14
      • 1970-01-01
      相关资源
      最近更新 更多