【发布时间】:2021-08-25 07:10:53
【问题描述】:
我有一些使用 Bazel、C++ 和 protobuf 的项目。我还使用 gitlab CI/CD 来构建、测试、检查覆盖率等。
问题是项目第一次编译的时候还要编译一个protobuf编译器,每一步增加了大约15分钟(这个步骤本身需要1-5分钟)。
我使用的是本文档中的设置示例: https://blog.bazel.build/2017/02/27/protocol-buffers.html
在这里我创建了a simple hello world example with protobuf。
当我使用protoc 生成*.pb.cc、*.pb.h 文件大约需要5 秒。
当我使用bazel build ... 时,它需要15 minutes,因为它构建了protobuf 编译器。
构建日志:https://gitlab.com/mvfwd/issue-bazel-protobuf-compile/-/jobs/1532045913
主要问题
有没有其他方法可以设置 Bazel 使用已经预编译的 protoc 并在每一步跳过 15 分钟?
2021 年 8 月 27 日更新
添加了覆盖proto_compiler 和proto_toolchain_for_cc,如Implicit Dependencies and Proto Toolchains 中所述
建筑 :person_proto 现在可以正常工作了
$ bazel build :person_proto
WARNING: Ignoring JAVA_HOME, because it must point to a JDK, not a JRE.
INFO: Analyzed target //:person_proto (19 packages loaded, 61 targets configured).
INFO: Found 1 target...
Target //:person_proto up-to-date:
bazel-bin/person_proto-descriptor-set.proto.bin
INFO: Elapsed time: 0.428s, Critical Path: 0.08s
INFO: 5 processes: 4 internal, 1 linux-sandbox.
INFO: Build completed successfully, 5 total actions
但构建 :person_cc_proto 失败
$ bazel build :person_cc_proto
WARNING: Ignoring JAVA_HOME, because it must point to a JDK, not a JRE.
ERROR: /home/m/Synology/drive/prog/2021/b/issue-bazel-protobuf-compile/BUILD:2:14: in :aspect_cc_proto_toolchain attribute of BazelCcProtoAspect aspect on proto_library rule //:person_proto: '@local_config_cc//:toolchain' does not have mandatory providers: ProtoLangToolchainProvider
ERROR: Analysis of target '//:person_cc_proto' failed; build aborted: Analysis of target '//:person_proto' failed
INFO: Elapsed time: 0.124s
INFO: 0 processes.
FAILED: Build did NOT complete successfully (0 packages loaded, 25 targets configured)
【问题讨论】:
-
从dependencies 的列表中,在我看来
protobuf_rule在主机架构可用时使用了预编译的二进制文件。 -
在任何情况下,您都应该设置一个 blaze 远程缓存,以便在 CI 调用之间重用构建工件。
标签: protocol-buffers gitlab-ci bazel protoc bazel-rules