Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to tell absl's bazel script which compiler (gcc/clang) #1263

Closed
aaron-michaux opened this issue Aug 29, 2022 · 7 comments
Closed

How to tell absl's bazel script which compiler (gcc/clang) #1263

aaron-michaux opened this issue Aug 29, 2022 · 7 comments
Labels

Comments

@aaron-michaux
Copy link

Hi,

I've got an interesting problem, where I've specified my own (gcc based) toolchain, and this is preventing me from using absl's bazel integration. In particular, absl is detecting that I'm using gcc, and starts passing clang-only flags, and... kBOOM!

How does absl figure which compiler I'm using, and how do I tell it to assume gcc?

Thanks

@derekmauro
Copy link
Member

Bazel should default to using gcc flags, so I'm not sure why it isn't. What OS are you using and how is your compiler setup/installed?

But to answer your question, there are environment variables you can use to override these things. Try something like
CC=/path/to/gcc BAZEL_COMPILER=gcc bazel test ...

@aaron-michaux
Copy link
Author

aaron-michaux commented Aug 29, 2022

Using Ubuntu 20.04. We have custom gcc rules, so we use a "gcc toolchain" even though it's the system gcc. It's a large project... it could well be something woolly that we've done.

One curious thing: the error happens when build @com_google_absl//absl/strings:strings. It successfully builds a bunch of files using gcc flags, but then fails to build some random file, which changes each time. This is the generated build command when it fails to build str_cat.cc

/usr/bin/gcc -MD -MF bazel-out/k8-dbg/bin/external/com_google_absl/absl/strings/_objs/strings/str_cat.d \
'-frandom-seed=bazel-out/k8-dbg/bin/external/com_google_absl/absl/strings/_objs/strings/str_cat.o' \
-iquote external/com_google_absl -iquote bazel-out/k8-dbg/bin/external/com_google_absl \
'-std=c++17' -g -Wall -Wextra -Wcast-qual -Wconversion -Wfloat-overflow-conversion -Wfloat-zero-conversion \
-Wfor-loop-analysis -Wformat-security -Wgnu-redeclared-enum -Winfinite-recursion -Wliteral-conversion \
-Wmissing-declarations -Woverlength-strings -Wpointer-arith -Wself-assign -Wshadow -Wstring-conversion \
-Wtautological-overlap-compare -Wundef -Wuninitialized -Wunreachable-code -Wunused-comparison \
-Wunused-local-typedefs -Wunused-result -Wvla -Wwrite-strings -Wno-float-conversion -Wno-implicit-float-conversion \
-Wno-implicit-int-float-conversion -Wno-implicit-int-conversion -Wno-shorten-64-to-32 -Wno-sign-conversion \
-DNOMINMAX -c external/com_google_absl/absl/strings/str_cat.cc \
-o bazel-out/k8-dbg/bin/external/com_google_absl/absl/strings/_objs/strings/str_cat.o

(This doesn't work CC=/path/to/gcc BAZEL_COMPILER=gcc bazel test ...)

@derekmauro
Copy link
Member

When you say you are using a "gcc toolchain", does that mean you are using a toolchain config file? That would explain why the command I gave doesn't work, but unfortunately I can't offer anymore help without a full reproduction that I can try myself.

The start point for how we select compiler flags is here:

ABSL_DEFAULT_COPTS = select({
"//absl:msvc_compiler": ABSL_MSVC_FLAGS,
"//absl:clang-cl_compiler": ABSL_CLANG_CL_FLAGS,
"//absl:clang_compiler": ABSL_LLVM_FLAGS,
"//conditions:default": ABSL_GCC_FLAGS,
})

@aaron-michaux
Copy link
Author

Yes, we have our own cc_common.create_cc_toolchain_config_info, which has special options for various features. Thanks for pointing me to the relevant bzl file. I guess I'll see if I can get the skylark debugger working.

@aaron-michaux
Copy link
Author

If you are curious, this may be the bug: bazelbuild/bazel#12707

@derekmauro
Copy link
Member

If you are curious, this may be the bug: bazelbuild/bazel#12707

If that's actually the issue then I think this can be fixed in a backwards compatible way by adding an additional case to the selectors. I'll give that a try.

@derekmauro
Copy link
Member

@aaron-michaux - Please re-open if this your issue isn't fixed.

netkex pushed a commit to netkex/abseil-cpp that referenced this issue Apr 3, 2024
… to "gcc",

instead of just detecting Bazel's default "compiler" string.

When Bazel auto-configures GCC, it sets the compiler string to
"compiler", probably for backwards compatibility. Some users manually
set the string to "gcc".

This should address the backwards compatibility issues described in
bazelbuild/bazel#12707 and hopefully fix
abseil#1263

PiperOrigin-RevId: 473069817
Change-Id: I8a24721f63f9d61447b22b3b05b06a9dde7d34d8
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants