bazel: bazel build is failing on gcc 11

Trying to build bazel on gcc 11:

$ bazel --version
bazel 4.0.0rc6

$ bazel build src:bazel-bin-dev
[...]
ERROR: /home/davido/projects/bazel/third_party/ijar/BUILD:47:11: Compiling third_party/ijar/zlib_client.cc failed: (Exit 1): gcc failed: error executing command /usr/bin/gcc -U_FORTIFY_SOURCE -fstack-protector -Wall -Wunused-but-set-parameter -Wno-free-nonheap-object -fno-omit-frame-pointer '-std=c++0x' -MD -MF ... (remaining 20 argument(s) skipped)

Use --sandbox_debug to see verbose messages from the sandbox gcc failed: error executing command /usr/bin/gcc -U_FORTIFY_SOURCE -fstack-protector -Wall -Wunused-but-set-parameter -Wno-free-nonheap-object -fno-omit-frame-pointer '-std=c++0x' -MD -MF ... (remaining 20 argument(s) skipped)

Use --sandbox_debug to see verbose messages from the sandbox
In file included from third_party/ijar/zlib_client.cc:20:
./third_party/ijar/zlib_client.h:64:46: error: 'numeric_limits' is not a member of 'std'
   64 |   static const size_t MAX_BUFFER_SIZE = std::numeric_limits<int32_t>::max();
      |                                              ^~~~~~~~~~~~~~
./third_party/ijar/zlib_client.h:64:68: error: expected primary-expression before '>' token
   64 |   static const size_t MAX_BUFFER_SIZE = std::numeric_limits<int32_t>::max();
      |                                                                    ^
./third_party/ijar/zlib_client.h:64:71: error: '::max' has not been declared; did you mean 'std::max'?
   64 |   static const size_t MAX_BUFFER_SIZE = std::numeric_limits<int32_t>::max();
      |                                                                       ^~~
      |                                                                       std::max
In file included from /usr/lib/gcc/x86_64-redhat-linux/11/../../../../include/c++/11/algorithm:62,
                 from third_party/ijar/zlib_client.cc:16:
/usr/lib/gcc/x86_64-redhat-linux/11/../../../../include/c++/11/bits/stl_algo.h:3467:5: note: 'std::max' declared here
 3467 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
Target //src:bazel-bin-dev failed to build
Use --verbose_failures to see the command lines of failed build steps.
INFO: Elapsed time: 1.734s, Critical Path: 1.12s
INFO: 21 processes: 19 internal, 2 linux-sandbox.
FAILED: Build did NOT complete successfully

GCC version:

$ g++ --version
g++ (GCC) 11.0.0 20201204 (Red Hat 11.0.0-0)

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 17 (12 by maintainers)

Commits related to this issue

Most upvoted comments

Because it was closed, I opened this issue: #12756.

Should we continue the discussion there?

If you install upcoming Fedora Rawhide 34, then GCC is 11 and Bazel is failing to build.

The issue is outdated abseil that is used by gRPC.

Related: abseil/abseil-cpp#887 and grpc/grpc#25114.

@IleanaAldama,

the path is hardcoded here, in the toolchain

https://github.com/bazelbuild/rules_cc/blob/608c7b605fb844a20e96a3eddc9b49ad2542adab/cc/private/toolchain/cc_toolchain_config.bzl#L1327

There’s --compiler option, but you can’t just specify gcc-10.2.0 there https://docs.bazel.build/versions/master/user-manual.html#flag--compiler, it seems, it is just for selecting one version among versions already defined.

All in all, I believe it is not possible to just override 2 paths values (for cpp and gcc) without defining a custom gcc-10 toolchain https://docs.bazel.build/versions/master/tutorial/cc-toolchain-config.html

Please share if you have something working before I do. Thanks!

// sorry for offtop folks, I’d be happy to move this discussion elsewhere, just let me know

UPDATE: what I ended up doing is simply hardcoding a different path for the cc toolchain in the bazel cache 🤦 It’s a hack, but at least it unblocks the build of my scala + gRPC project after hours of headbanging 😃

To locate the file to edit I simply grepped entire bazel cache by string /usr/bin/gcc

$ cd .cache/bazel
$ grep -r /usr/bin/gcc .
...
./install/129c3d389c2d09bb0ad5b4a301d67a9c/embedded_tools/tools/cpp/cc_toolchain_config.bzl:            tool_path(name = "gcc", path = "/usr/bin/gcc"),
...

sorry if this is not the right place to ask, but is it a way to configure bazel to use an older gcc version? in my system I have gcc10 and gcc11 being the later the default one