-
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
Enable setting C/C++ standards as a toolchain feature #16552
base: master
Are you sure you want to change the base?
Enable setting C/C++ standards as a toolchain feature #16552
Conversation
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
44261bb
to
3cbda3a
Compare
tools/cpp/unix_cc_configure.bzl
Outdated
@@ -528,6 +521,12 @@ def configure_unix_toolchain(repository_ctx, cpu_value, overriden_tools): | |||
cpu_value, | |||
False, | |||
)), | |||
"%{cxx_standard}": escape_string(get_env_var( | |||
repository_ctx, | |||
"BAZEL_CXXOPTS", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this is a safe change as previously this env var could have contained much more than just this. I think to keep compatibility you'll have to move this back up to where it was, just default it to nothing, and hardcode the C++ default here (although I guess it also could have affected the CXX include directories output? I'm not sure if that's good or bad)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, of course 🤦🏼 .
So since that's the case I've left everything in unix_cc_configure.bzl
alone and only added the new features that set the standard. No more default_cxx_standard
enabled by default either.
If the features are activated then they take precedent over the -std=c++0x
opt defined in cxx_opts
(since they come later on the cmd line).
If one really doesn't want duplicate options then I guess they could set BAZEL_CXXOPTS=""
.
Does that sound better? Certainly simpler implementation wise.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yea sg
5a332fc
to
43daa1f
Compare
If one really doesn't want duplicate options then I guess they could set BAZEL_CXXOPTS="". |
Hey, is this ready for a review? |
Whoops. Sorry for letting this go stale. See the issue I linked for the background on why I initially proposed this. Internally we ended up just settling on splitting up building c and c++ code because we also need to set things like However I still think this is a good and useful change for Bazel in general. I'll rebase and test this weekend and get it ready for review. Are there any tests I should be adding for this stuff someone can point me to? |
Adds a handful of new features to the default toolchain that enables setting the c++ standard. This enables setting the standard on a target by target basis.
6073e36
to
0896d3c
Compare
Hi @isaactorz, Lets us know once it is ready for review. Thanks! |
Will do. Been very busy lately. Only thing left I want to do is add support for this feature to the mingw toolchain. |
RTYI, @jsharpe. :) |
Why not adding C++ 23 and C++ 26 ? they have already landed in CMake and it will take months (years?) to have bazel 7.0 widely available so....
ref: https://cmake.org/cmake/help/latest/prop_tgt/CXX_STANDARD.html Also you have C 23
see: https://cmake.org/cmake/help/latest/prop_tgt/C_STANDARD.html ps: |
I was going for a consistent set of features to expose across the "big 3" (gcc/clang/msvc) with gcc and clang this would probably be fine since they have explicit codenames for the newer standards (i.e. Side note: maybe we even should consider using |
FYI CMake adapt what it would pass to the command line according to the compiler version... |
Hi @jungleraptor what is the status of this, it is a sorely missed feature! |
Hello! At work we ended up forking @sgowroji @buildbreaker2021 @Mizux Is this something we could land in mostly it's current shape ? |
@buildbreaker2021 @sgowroji @Mizux friendly ping Recently came across another case in Also tagging @keith since you did the initial review. |
Adds a handful of new features to the default toolchain that enables setting the C/C++ standards, with or without gnu extensions (
-std=gnu
) at the target level.The issue associated with the PR is linked, and goes into further detail about the motivation for introducing this feature.
#16551
This is an initial implementation. I'd like to get feedback on whether it's possible to accept this change before I add tests/documentation etc..Usage
Testing
Testing was done using this project: https://github.com/isaactorz/bazel-features-test
Let me know if there's an appropriate place in this repo to add these tests.
Testing done w/
-mmacos-version-min
flag to get the c++17 tests to build as the default was to low to useoptional
api.)TODO
Assuming this can be merged I'd think the next steps would be: