从源代码构建 gRPC C++

Building gRPC C++ from source

本文关键字:C++ gRPC 构建 源代码      更新时间:2023-10-16

我正在尝试从构建 gRPC C++的源代码构建gRPC c++我已经安装了 bazel。 虽然当我尝试构建时,我看到以下错误。

$ bazel build :all
Starting local Bazel server and connecting to it...
ERROR: /home/bigz/.cache/bazel/_bazel_bigz/a68d37101a3d172c639dd67a1941f719/external/io_bazel_rules_python/python/pip.bzl:39:25: Traceback (most recent 
call last):
File "/home/bigz/.cache/bazel/_bazel_bigz/a68d37101a3d172c639dd67a1941f719/external/io_bazel_rules_python/python/pip.bzl", line 37
repository_rule(<2 more arguments>)
File "/home/bigz/.cache/bazel/_bazel_bigz/a68d37101a3d172c639dd67a1941f719/external/io_bazel_rules_python/python/pip.bzl", line 39, in repositor
y_rule
attr.label(allow_files = True, <2 more arguments>)
'single_file' is no longer supported. use allow_single_file instead. You can use --incompatible_disable_deprecated_attr_params=false to temporarily disable th
is check.
ERROR: error loading package '': Extension file 'python/pip.bzl' has errors
ERROR: error loading package '': Extension file 'python/pip.bzl' has errors
INFO: Elapsed time: 7.505s
INFO: 0 processes.
FAILED: Build did NOT complete successfully (0 packages loaded)

有人可以指出我在这里缺少什么。

当我尝试运行bazel info时,我收到以下错误。

$ bazel info --incompatible_disable_deprecated_attr_params=false
ERROR: /home/bigz/.cache/bazel/_bazel_bigz/a68d37101a3d172c639dd67a1941f719/external/org_pubref_rules_protobuf/protobuf/internal/proto_compile.bzl:771:21: name 'FileType' is not defined
ERROR: error loading package '': in /home/bigz/.cache/bazel/_bazel_bigz/a68d37101a3d172c639dd67a1941f719/external/org_pubref_rules_protobuf/python/rules.bzl: in /home/bigz/.cache/bazel/_bazel_bigz/a68d37101a3d172c639dd67a1941f719/external/org_pubref_rules_protobuf/cpp/rules.bzl: in /home/bigz/.cache/bazel/_bazel_bigz/a68d37101a3d172c639dd67a1941f719/external/org_pubref_rules_protobuf/protobuf/rules.bzl: Extension 'protobuf/internal/proto_compile.bzl' has errors

虽然bazel --version显示为bazel 2.0.0.

$ bazel --version
bazel 2.0.0

gRPC 的最新提交是9dfbd34f5c0b20bd77658c73c59b9a3e4e8f4e14

$ git log -1
commit 9dfbd34f5c0b20bd77658c73c59b9a3e4e8f4e14 (HEAD, tag: v1.20.0)
Merge: 1b488f8361 ae72bf76b3
Author: Lidi Zheng <scallopsky@gmail.com>
Date:   Mon Apr 15 15:38:24 2019 -0700
Merge pull request #18760 from lidizheng/v1.20.x
Bump version to v1.20.0

您尝试构建的 grpc 提交与您已安装的 bazel 版本(2.0.0( 不兼容。

提交9dfbd34f5c0b20bd77658c73c59b9a3e4e8f4e14很旧(19 年 4 月 15 日(,该存储库的 HEAD(在撰写本文时(位于eba60d8dbe4099c34b8097b2c89998d4484740ac,现在在 BUILDING.md 中表明您至少需要版本 1.0.0(tools/bazel有一个 bazel 包装器,无论如何都会拦截并使用 1.0.0(

但是,对于您的特定提交,尝试不同的版本,我能够使用 bazel 版本 0.20.0 构建:all标签

我建议尝试巴兹利斯克。您可以将其添加到您的 PATH 中,将.bazelversion文件添加到存储库,bazelisk 将负责下载所需的 bazel 版本。