【问题标题】:How to make bazel pick up right version of com_google_protobuf_cc repository for loaded gRPC repository?如何让 bazel 为加载的 gRPC 存储库选择正确版本的 com_google_protobuf_cc 存储库?
【发布时间】:2018-01-05 05:54:17
【问题描述】:

我正在使用 bazel 构建一个带有 gRPC 库的程序。我的工作空间文件:

http_archive(
    name = "com_github_grpc_grpc",
    urls = ["https://github.com/grpc/grpc/archive/v1.8.3.zip"],
    sha256 = "57a2c67abe789ce9e80d49f473515c7479ae494e87dba84463b10bbd0990ad62",
    strip_prefix = "grpc-1.8.3",
)

load("@com_github_grpc_grpc//bazel:grpc_deps.bzl", "grpc_deps")
grpc_deps()

构建文件:

proto_library(
    name = "test_proto",
    srcs = ["test.proto"],
)

cc_proto_library(
    name = "test_cc_proto",
    deps = [":test_proto"],
)

cc_binary(
    name = "hello",
    srcs = ["hello.cc"],
    deps = [ 
        ":test_cc_proto",
        "@com_github_grpc_grpc//:grpc++",
    ],  
)

编译这个会抛出错误:

every rule of type proto_library implicitly depends upon the target '@com_google_protobuf_cc//:cc_toolchain', but this target could not be found because of: no such package '@com_google_protobuf_cc//': The repository could not be resolved.

如果我手动包含 com_google_protobuf_cc 存储库,则版本不匹配,并且我收到错误消息说 test.pb.h 是使用较新版本的 protoc 生成的。

如何让 gRPC 加载正确版本的 com_google_protobuf_cc?

【问题讨论】:

    标签: c++ protocol-buffers grpc bazel


    【解决方案1】:

    您如何手动包含 Protobuf,您在 BUILD 和/或 WORKSPACE 文件中添加了什么来实现这一点?如果不确切知道您尝试了什么,就很难评论可能出了什么问题。

    据我所知,您可以通过下载所需的版本来包含它,然后将以下内容添加到您的 WORKSPACE 文件中:

    local_repository(
        name = "com_google_protobuf",
        path = "../protobuf-3.4.1",
    )
    
    local_repository(
        name = "com_google_protobuf_cc",
        path = "../protobuf-3.4.1",
    )
    

    当然要更改路径以匹配您下载的 Protobuf 副本的版本和位置。或者,您可以使用 http_archive 将其直接指向应下载的位置,就像您为 gRPC 所做的那样。

    【讨论】:

    • /home/chakradarraju/.cache/bazel/_bazel_chakradarraju/0549007034a1e84cfecc4d5dd5eb47c0/external/com_google_protobuf_cc/WORKSPACE (@com_google_protobuf) 中的工作区名称与存储库定义 (@com_google_protobuf_cc) 中给出的名称不匹配;这将在未来的版本中导致构建错误。
    • 这似乎只是一个警告,而不是一个错误,究竟发生了什么?
    猜你喜欢
    • 2023-04-10
    • 2023-03-28
    • 1970-01-01
    • 1970-01-01
    • 2019-12-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-03-09
    相关资源
    最近更新 更多