-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
cpp toolchain: stop passing -std=c++0x per default #18181
Comments
Closes bazelbuild#18167. abseil is missing stdint.h include, that broke recent compiler versions. This problem was fixed in this commit upstream: abseil/abseil-cpp@36a4b07 Note, that we cannot update to the latst abseil-cpp version, because this breaking change: "Abseil now requires at least C++14" starting from LTS release 20230125 and Bazel is passing per default -std=c++0x option, see: bazelbuild#18181
It might be viable to bump this to C++ 17 instead of 14, as most non-ancient compilers support C++17 apart from a few exceptions that likely aren't relevant to Bazel's dependencies. The Google style guide also encourages this. |
Let's do it in two steps and bump C++ standard to C++14 per default first. Bazel CI still depends on outdated toolchains, see bazelbuild/continuous-integration#1593. |
Fixes: bazelbuild#18181. Closes: bazelbuild#18280.
Can we instead make the standard a feature on the toolchain so that the user has control over which c++ standard they want to use? |
Fixes: bazelbuild#18181. Closes: bazelbuild#18280. Closes bazelbuild#18280. PiperOrigin-RevId: 530246609 Change-Id: I6b49d1bd827e98ca65db87c34c1bb13106ffc232
Fixes: bazelbuild#18181. Closes: bazelbuild#18280. Closes bazelbuild#18280. PiperOrigin-RevId: 530246609 Change-Id: I6b49d1bd827e98ca65db87c34c1bb13106ffc232 (cherry picked from commit 978cd23)
Fixes: bazelbuild#18181. Closes: bazelbuild#18280. Closes bazelbuild#18280. PiperOrigin-RevId: 530246609 Change-Id: I6b49d1bd827e98ca65db87c34c1bb13106ffc232 (cherry picked from commit 978cd23)
A fix for this issue has been included in Bazel 6.4.0 RC4. Please test out the release candidate and report any issues as soon as possible. Thanks! |
The MacOS c++ toolchain config for released bazel 6.4.0 still has c++11 as the version (better than c++0x, but still incompatible with abseil acquired with recent protobuf), if the goal was to standardize on c++14 as the global bazel default for supplied toolchains. |
I'm hitting this as well trying to build absl on MacOS. Are there any workarounds? |
Recent bazels have d56dc18, which no longer tries to use xcode if it is available (regardless of the USE_XCODE... env var), and defers entirely to the unix toolchain. I might see about getting it in for a 6.5. 7 should have this as well when it is cut. |
Happy to hear a quick and optimistic response. So is it expected that I'll hit this issue on 6.3.2? What should I update to? I mostly care about stability, I believe I have all the features I need from bazel otherwise. |
All I want to do is build the google standard libraries using the google standard build tool on a major operating system using a c++ standard that is less than 12 years old. It is not reasonable that I've been stuck on this for days. Please help. Here's what I've tried. I downloaded that and am trying to use it to download bazel 7.0.0, which according to your mailing list can be done using something like this: USE_BAZEL_VERSION=last_rc However, I get this error message, indicating that that syntax does not work. My .bazelrc is specifying c++17 as follows: Bazel is ignoring my bazelrc file's specification for these external builds and I don't know why unless absl or bazel is specifically choosing to use a flag that is not longer supported. I've tried several other ways of specifying the build version including the workarounds in the original post above, but it's still using c++11. If you look through the subcommands, it seems like it's trying to use both the c++11 flag AND the c++17 flag.
|
This is not how you pass Lines 52 to 57 in cc2fa9a
|
Thank you for the tip. If that method is no longer supported, there's a lot of stack overflow to update. I don't think you were suggesting that the build flag change would fix the issue, so here's more debugging. .bazelversion containing last_rc gives me this: In other news, I downloaded 7.0.0-pre.20231018.3 and built it myself and now I hit this error. It's different, so while it seems like perhaps the issue in this bug is indeed fixed closer to HEAD, it looks like the fix described by werkt@ above: "Recent bazels have d56dc18, which no longer tries to use xcode if it is available (regardless of the USE_XCODE... env var), and defers entirely to the unix toolchain." So if we're using the unix toolchain, it can't build apple targets? I get this is a prerelease, but if that's true that's a huge issue. I can't be stuck between a build system that doesn't support absl and a build system that doesn't support Apple. It took me ages to migrate everything to bazel. I need bazel to work. I guess I should try some old version of absl that still supports c++11? |
If nobody can give me a workaround, can we reopen this? |
cc: @keith I think I'm missing something--if you use the Apple CC Toolchain (per the instructions), and then build with Can you provide explicit instructions for reproing with 7.0.0.something? Assume I have a mac and have not yet run a bazelisk install or checked out Absl. What I am ideally looking for is: What version of macOS I need to run. |
I'll start by trying to clarify that where I started being stuck and where I became stuck are different, and that where I became stuck wasn't relevant to the original bug. Now that I'm reading your post I've realized this got a bit derailed, and I'm sorry for that, but I guess this is as good of a place as any to try and clarify. Where I started:Problem: absl wasn't building with bazel 6.4.0 on Sonoma 14.1.1 mac. I believe it should as this is a major bazel release and absl is a major google lib. You can reproduce this problem using the following repo It produces the error.
Up until that point, this is relevant to the opened bug. In trying to fix that issue that I started uncovering different problems, and confusingly posted about them here as it was a continuance of the same conversation. Where I am now:Because it was suggested to me that this problem was fixed in prereleased versions of bazel, I tried updating. As far as I can tell, bazelisk doesn't support these versions, so I downloaded bazel-7.0.0-pre.20231018, built it using bazel 6.4.0, The error above is fixed if I use that same repo from above, noting that the .bazeliskrc file is now ignored by my self-built version of bazel. In this adventure to clarify my problem, I believe that I've resolved my issue, as I can now build the new (empty) target in this updated repo using I guess the problem I'm having is that bazel is just evolving faster than I can keep up with as an independent developer. It was my expectation that common libs like absl would work as long as I'm using one of the LTS bazel releases. When that didn't work, I got pushed into a prerelease because I was simply stuck in a hard place by my build system. I don't know what a MODULE file is, if or when So now that I understand things, I believe we can close this bug again. |
Although all that said, I think I'm still having a relevant issue to this bug. I'm clearly specifying to use c++ 17 in my build. Over specifying, probably... but I'm still seeing libs that are being built with c++14-- however BOTH c++14 and c++17 flags are making it into the command. This for a non-absl target, one that isn't external to my repo. .bazelrc
Using the --subcommands flag.
|
The reason your original repro fails is because these
Are not being used because you also have to set:
Because it's not enabled by default, once I do that it works. The reason it's fixed in 7.x is because the C++ default was bumped to 14 (it was meant to be bumped everywhere in 6.4.x in #19794 but it looks like this one missed the macOS specific toolchain used when you have Xcode installed). The reason your IMO the real solution for absl is to encode this in their BUILD files somewhere, although then I suppose they'd have to worry about allowing overrides of that version for folks who intentionally build absl with a newer C++ standard. |
I extrapolated that commenting out that --enable_platform_specific_config line would fix my current problem as well, but it seems to still use both c++14 and c++17 flags (in that order), presumably ignoring the later one. Here's an excerpt from my bazelrc file if you have suggestions for me in my new non-absl-related problem.
|
The later one wins, you can see this with clang by passing
It's still possible that some libs are setting |
Libs that require c++17 symbols are not building for me, even though I'm specifying to use c++17 in the build rule. The actual error I get is: |
Is that error in the case of the subcommands you posted above? Maybe it's worth passing |
I get different specific errors every time because it's compiling different files on different threads. All of them seem to point to not using c++17, some explicitly check for that and produce an error. Are you just testing if the flag gets passed, or are you hoping the log is more verbose?
|
With |
OK, thanks. So what are my options? |
can you provide a repro with that case? |
Somewhat to my own surprise, I actually can! This includes a pull of the JUCE repo, which by anyone's standards makes this not a minimum example, but I think you don't have to understand anything about JUCE except for ThirdParty/Juce/JUCE/modules/juce_core/system/juce_CompilerSupport.h in the lines surrounding 91. It relies on the __cplusplus macro, which I think comes from the compiler directly (I don't really know) If you do |
juce.bzl defines an |
I see. That does seem to fix that issue. So is it correct that I should have all three of these, and not the BAZEL_CXXOPTS line? Is there a way to use a variable in a bazelrc file so that I only need to specify c++17 once?
|
yes that looks good (if you end up needing the host_ version of objccopt you'd have to use host_per_file_copt) There's no flag that implies all of them, theoretically we could make that env var work in the Xcode specific toolchain, I doubt there was a good reason it didn't, but even so I don't think that would cover the objc case unless the issue i linked above was fixed |
Thanks so much for all the help! |
Last note, I have to do this to get around #5318, which seems a little jank, but at least I'm not blocked on it.
|
For such a basic requirement, why can't we specify, as a feature, to use a particular standard C++ version. I have come across a number of things in trying to get C++20 into my builds. I am using Bazel version 7.0.0 executing in Linux - WSL with a very minimal C++ program #include <iostream>
int main() {} My .bazelrc file is this
However, despite the example @meteorcloudy gave, I don't get C++20 Result of /usr/bin/gcc -U_FORTIFY_SOURCE -fstack-protector -Wall -Wunused-but-set-parameter -Wno-free-nonheap-object -fno-omit-frame-pointer '-std=c++14' -MD -MF bazel-out/k8-fastbuild/bin/projects/minexample/_objs/minexample/main.pic.d '-frandom-seed=bazel-out/k8-fastbuild/bin/projects/minexample/_objs/minexample/main.pic.o' -fPIC -iquote . -iquote bazel-out/k8-fastbuild/bin -iquote external/bazel_tools -iquote bazel-out/k8-fastbuild/bin/external/bazel_tools -fno-canonical-system-headers -Wno-builtin-macro-redefined '-D__DATE__="redacted"' '-D__TIMESTAMP__="redacted"' '-D__TIME__="redacted"' -c projects/minexample/main.cpp -o bazel-out/k8-fastbuild/bin/projects/minexample/_objs/minexample/main.pic.o
However, if I modify the .bazelrc file to now
I now get If I use the So a few questions:
Thanks |
|
Description of the bug:
After upgrading gcc version to 13 there are issues with different Bazel projects.
Consider this output:
However, without passing -std=c++0x option, the default is c++17:
Now, trying to build abseil-cpp, this breakge is reported:
Where the Bazel command produced by Bazel@HEAD is:
Removing '-std=c++0x' makes this command work.
The code in ./absl/base/policy_checks.h:79:
What's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.
Bump gcc version to 13 and build abseil-cpp@HEAD (https://github.com/abseil/abseil-cpp) with Bazel@HEAD.
My environment:
Which operating system are you running Bazel on?
Linux
What is the output of
bazel info release
?All released Bazel versions are affected including Bazel@HEAD.
If
bazel info release
returnsdevelopment version
or(@non-git)
, tell us how you built Bazel.No response
What's the output of
git remote get-url origin; git rev-parse master; git rev-parse HEAD
?No response
Have you found anything relevant by searching the web?
There are a number of reports:
abseil/abseil-cpp#1431
protocolbuffers/protobuf#12393
https://stackoverflow.com/questions/75850778/error-c-versions-less-than-c14-are-not-supported-in-bazel-how-to-resolve
Any other information, logs, or outputs that you want to share?
There is a workaround, bump -std-option in .bazelrc:
The text was updated successfully, but these errors were encountered: