这里我的目标很简单:我想要一个定制的c++工具链,在这里我可以指定自己的编译器和编译器选项。我已经将当前的问题简化为一个人为的示例回购:工具链
我按照在https://docs.bazel.build/versions/main/tutorial/cc-toolchain-config.html上描述的教程使用我定制的gcc版本。在我添加cc_proto_library之前,这似乎还不错。Bazel似乎使用我的自定义工具链来构建protoc/zlib和错误,因为我在我的自定义工具链中有警告标志。我的印象是,--host_crosstool_top=@bazel_tools//tools/cpp:toolchain会告诉Bazel忽略我的自定义工具链,但是情况似乎并非如此。我希望它使用/bin/gcc,而不是我的习惯gcc或警告。如能提供任何帮助,将不胜感激。
以下是当前构建失败的地方:
$ bazel build --config=gcc_config //main:hello-world --verbose_failures
INFO: Analyzed target //main:hello-world (0 packages loaded, 0 targets configured).
INFO: Found 1 target... ERROR: /home/brian/.cache/bazel/_bazel_brian/2fc228b5a7b1bf0ef87f3ee9353aa72d/external/com_google_protobuf/BUILD:155:11: Compiling src/google/protobuf/extension_set.cc failed: (Exit 1): gcc failed: error executing command
(cd /home/brian/.cache/bazel/_bazel_brian/2fc228b5a7b1bf0ef87f3ee9353aa72d/sandbox/linux-sandbox/404/execroot/__main__ && \
exec env - \
LD_LIBRARY_PATH=/home/brian/.local/lib64:/home/brian/.local/lib \
PATH=/home/brian/.local/tools/bazel/4.2.2/bin:/home/brian/.local/bin:/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/bin:/sbin:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl \
PWD=/proc/self/cwd \
/opt/custom/gcc/11.2.0/bin/gcc -MD -MF bazel-out/k8-fastbuild/bin/external/com_google_protobuf/_objs/protobuf_lite/extension_set.d '-frandom-seed=bazel-out/k8-fastbuild/bin/external/com_google_protobuf/_objs/protobuf_lite/extension_set.o' -iquote external/com_google_protobuf -iquote bazel-out/k8-fastbuild/bin/external/com_google_protobuf -isystem external/com_google_protobuf/src -isystem bazel-out/k8-fastbuild/bin/external/com_google_protobuf/src -xc++ -Werror -Wswitch-default -DHAVE_ZLIB -Wmissing-field-initializers -Woverloaded-virtual -Wno-sign-compare -c external/com_google_protobuf/src/google/protobuf/extension_set.cc -o bazel-out/k8-fastbuild/bin/external/com_google_protobuf/_objs/protobuf_lite/extension_set.o)
Execution platform: @local_config_platform//:host
Use --sandbox_debug to see verbose messages from the sandbox
external/com_google_protobuf/src/google/protobuf/extension_set.cc: In function 'bool google::protobuf::internal::{anonymous}::is_packable(google::protobuf::internal::WireFormatLite::WireType)':
external/com_google_protobuf/src/google/protobuf/extension_set.cc:72:10: error: switch missing default case [-Werror=switch-default]
72 | switch (type) {
| ^
external/com_google_protobuf/src/google/protobuf/extension_set.cc: In member function 'void* google::protobuf::internal::ExtensionSet::MutableRawRepeatedField(int, google::protobuf::internal::FieldType, bool, const google::protobuf::FieldDescriptor*)':
external/com_google_protobuf/src/google/protobuf/extension_set.cc:419:12: error: switch missing default case [-Werror=switch-default]
419 | switch (WireFormatLite::FieldTypeToCppType(
| ^
external/com_google_protobuf/src/google/protobuf/extension_set.cc: In member function 'void google::protobuf::internal::ExtensionSet::RemoveLast(int)':
external/com_google_protobuf/src/google/protobuf/extension_set.cc:855:10: error: switch missing default case [-Werror=switch-default]
855 | switch (cpp_type(extension->type)) {
| ^
external/com_google_protobuf/src/google/protobuf/extension_set.cc: In member function 'void google::protobuf::internal::ExtensionSet::SwapElements(int, int, int)':
external/com_google_protobuf/src/google/protobuf/extension_set.cc:910:10: error: switch missing default case [-Werror=switch-default]
910 | switch (cpp_type(extension->type)) {
| ^
external/com_google_protobuf/src/google/protobuf/extension_set.cc: In member function 'void google::protobuf::internal::ExtensionSet::InternalExtensionMergeFrom(const google::protobuf::MessageLite*, int, const google::protobuf::internal::ExtensionSet::Extension&, google::protobuf::Arena*)':
external/com_google_protobuf/src/google/protobuf/extension_set.cc:1008:12: error: switch missing default case [-Werror=switch-default]
1008 | switch (cpp_type(other_extension.type)) {
| ^
external/com_google_protobuf/src/google/protobuf/extension_set.cc:1055:14: error: switch missing default case [-Werror=switch-default]
1055 | switch (cpp_type(other_extension.type)) {
| ^
external/com_google_protobuf/src/google/protobuf/extension_set.cc: In member function 'bool google::protobuf::internal::ExtensionSet::ParseFieldWithExtensionInfo(int, bool, const google::protobuf::internal::ExtensionInfo&, google::protobuf::io::CodedInputStream*, google::protobuf::internal::FieldSkipper*)':
external/com_google_protobuf/src/google/protobuf/extension_set.cc:1322:12: error: switch missing default case [-Werror=switch-default]
1322 | switch (extension.type) {
| ^
external/com_google_protobuf/src/google/protobuf/extension_set.cc:1378:12: error: switch missing default case [-Werror=switch-default]
1378 | switch (extension.type) {
| ^
external/com_google_protobuf/src/google/protobuf/extension_set.cc: In member function 'void google::protobuf::internal::ExtensionSet::Extension::Clear()':
external/com_google_protobuf/src/google/protobuf/extension_set.cc:1612:12: error: switch missing default case [-Werror=switch-default]
1612 | switch (cpp_type(type)) {
| ^
external/com_google_protobuf/src/google/protobuf/extension_set.cc: In member function 'size_t google::protobuf::internal::ExtensionSet::Extension::ByteSize(int) const':
external/com_google_protobuf/src/google/protobuf/extension_set.cc:1660:14: error: switch missing default case [-Werror=switch-default]
1660 | switch (real_type(type)) {
| ^
external/com_google_protobuf/src/google/protobuf/extension_set.cc:1710:14: error: switch missing default case [-Werror=switch-default]
1710 | switch (real_type(type)) {
| ^
external/com_google_protobuf/src/google/protobuf/extension_set.cc:1751:12: error: switch missing default case [-Werror=switch-default]
1751 | switch (real_type(type)) {
| ^
external/com_google_protobuf/src/google/protobuf/extension_set.cc: In member function 'int google::protobuf::internal::ExtensionSet::Extension::GetSize() const':
external/com_google_protobuf/src/google/protobuf/extension_set.cc:1799:10: error: switch missing default case [-Werror=switch-default]
1799 | switch (cpp_type(type)) { | ^
external/com_google_protobuf/src/google/protobuf/extension_set.cc: In member function 'void google::protobuf::internal::ExtensionSet::Extension::Free()':
external/com_google_protobuf/src/google/protobuf/extension_set.cc:1825:12: error: switch missing default case [-Werror=switch-default]
1825 | switch (cpp_type(type)) {
| ^
external/com_google_protobuf/src/google/protobuf/extension_set.cc: In member function 'uint8_t* google::protobuf::internal::ExtensionSet::Extension::InternalSerializeFieldWithCachedSizesToArray(const google::protobuf::MessageLite*, const google::protobuf::internal::ExtensionSet*, int, uint8_t*, google::protobuf::io::EpsCopyOutputStream*) const':
external/com_google_protobuf/src/google/protobuf/extension_set.cc:2026:14: error: switch missing default case [-Werror=switch-default]
2026 | switch (real_type(type)) {
| ^
external/com_google_protobuf/src/google/protobuf/extension_set.cc:2060:14: error: switch missing default case [-Werror=switch-default]
2060 | switch (real_type(type)) {
| ^
external/com_google_protobuf/src/google/protobuf/extension_set.cc:2111:12: error: switch missing default case [-Werror=switch-default]
2111 | switch (real_type(type)) {
| ^
cc1plus: all warnings being treated as errors
Target //main:hello-world failed to build
INFO: Elapsed time: 3.122s, Critical Path: 3.00s
INFO: 18 processes: 9 internal, 9 linux-sandbox.
FAILED: Build did NOT complete successfully发布于 2022-01-14 19:57:41
巴泽尔将两次构建部分原型机,一次给主机,一次给目标。extension_set.cc就是其中之一。--host_crosstool_top将在编译主机以生成protoc以便稍后在构建中运行时使用。在为目标构建相同的文件时,将使用自定义工具链作为最终二进制文件的一部分。
当使用自定义工具链为目标构建时,生成失败。你得想办法让它发挥作用。最后,我经常修改构建文件以添加-Wno-* copts,这样它们就可以使用我的工具链。可以用科普特代替。
如果您想在设置时只构建主机版本,请编写如下简单的泛型规则:
genrule(
name = "abc",
tools = [ "@com_google_protobuf//:protoc" ],
outs = [ "dummy" ],
cmd = "touch $@",
)如果您使用bazel build abc,那么bazel将为主机构建protoc,即使它实际上并不为cmd所用。
https://stackoverflow.com/questions/70714768
复制相似问题