-
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
Using optional C++ toolchains while maintaining compatibility with non-platform builds #16966
Comments
I prototyped a PR that realizes the desired behavior (but isn't polished): #16968 @katre Given that 5.4.0 hasn't been released yet, do you see a way to add no-op parameters to For example, if we added an alias of |
Notes, no particular order:
I can see backporting a small fix to What specific versions do you want to support, and which flags with each version? Part of the appeal of the LTS model for the Bazel team was, honestly, not doing this sort of backporting and incremental rollout of features, because it gets very complicated (and risky) to support the older versions. The optional toolchains API was added a version before the actual implementation in order to allow projects to use the new API, and then get the new features when users upgrade to a Bazel that contained them. Was this the wrong approach? What would have been a better approach, so that we can handle this next time? |
Good point, done.
Yes, this text exists in two places:
The error you see in my example comes from 2., not 1.
I am not proposing to backport #16968 - the change we could backport could be as simple as adding While optional toolchains exist at HEAD, I don't see a way for a ruleset to use them for C++ even at HEAD while remaining compatible with scenarios in which
Summarizing the above, I want to allow a Bazel ruleset to declare an optional C++ toolchain dependency and simultaneously:
The example I gave is meant to demonstrate that this doesn't seem to be possible today, so even if we do not care about backwards compatibility, there is something that needs to be fixed. If we do care about allowing a ruleset to do this and remain compatible with a previous version of Bazel (e.g. 5 or 6), I think that this would require a backport even if bazel-contrib/rules_go#3390 (comment) is used to only request an optional toolchain dependency if the Bazel version supports it. That is because I don't see a way to fix the example without introducing a new
I think that the approach was correct and adding the API a version before the feature is makes it so that rulesets can use it earlier, gracefully falling back to the old behavior but not breaking with versions of Bazel that don't have the feature. In fact, the proposal for a new The only thing that seems to have been missed is compatibility with |
If I understand correctly this is about the old mechanism for toolchain resolution used by C++ rules and the new mechanism not being compatible? If the old one is deprecated, we should focus on removing it instead, no need to support the flag --noincompatible_enable_cc_toolchain_resolution. Every incompatible flag is temporary and not meant for long term support. If the problem is that without fixing the issue described here it becomes impossible to migrate, then that'd be a different story. |
@oquenchil The problem is that Adding a single alias to |
Understood. Thanks for the clarification. |
@katre For the reasons given by Fabian I think we should backport to 6.1 the simple change adding an alias to a BUILD file (not necessary for 5.4, although doing it for 5.4 wouldn't hurt either). #16968 can be checked in at HEAD and that's it, no need to backport that PR. It's only the alias that would be needed to speed up progress by a lot as explained by Fabian. I know that this falls in the domain of C++ rules but you have a lot of expertise in this area. With those clarifications, would you be ok with backporting the alias? |
This looks very reasonable. I took a quick look at the change and it makes sense, but you should do the detailed review. |
By adding an alias and a no-op keyword argument now, rulesets can start using the new optional form of `find_cpp_toolchain` now and benefit from the toolchain actually being optional once that has been implemented in a future version of Bazel. Work towards #16966 Closes #17308. PiperOrigin-RevId: 504501621 Change-Id: I549fea6290195aadad4ccbd045c0aa3c180946d2
By adding an alias and a no-op keyword argument now, rulesets can start using the new optional form of `find_cpp_toolchain` now and benefit from the toolchain actually being optional once that has been implemented in a future version of Bazel. Work towards #16966 Closes #17308. PiperOrigin-RevId: 504501621 Change-Id: I549fea6290195aadad4ccbd045c0aa3c180946d2 Co-authored-by: Fabian Meumertzheim <fabian@meumertzhe.im>
By adding an alias and a no-op keyword argument now, rulesets can start using the new optional form of `find_cpp_toolchain` now and benefit from the toolchain actually being optional once that has been implemented in a future version of Bazel. Work towards #16966 Closes #17308. PiperOrigin-RevId: 504501621 Change-Id: I549fea6290195aadad4ccbd045c0aa3c180946d2
Rules that want to use optional toolchains but still support builds that don't use C++ toolchain resolution should point their `_cc_toolchain` attribute to the new `@bazel_tools//tools/cpp:optional_current_cc_toolchain` target. Fixes #16966 Closes #16968. PiperOrigin-RevId: 505707967 Change-Id: I251749348f982ae063b51f7d9cc0078a1b61a948
Description of the feature request:
It doesn't seem to be possible for a rule to simultaneously:
--noincompatible_enable_cc_toolchain_resolution
(ignoring potential hacks such as selecting between two rule implementations based on a
config_setting
backed byincompatible_enable_cc_toolchain_resolution
or some other signal)Concretely, consider the following example that tries to achieve both:
With
attrs = {"_cc_toolchain": attr.label(default = "@bazel_tools//tools/cpp:current_cc_toolchain")}
, we get:Without the line, we get:
What underlying problem are you trying to solve with this feature?
Allow rules_go to have an optional C++ toolchain dependency (bazel-contrib/rules_go#3390).
Which operating system are you running Bazel on?
any
What is the output of
bazel info release
?0ca7857
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?
No response
Any other information, logs, or outputs that you want to share?
No response
The text was updated successfully, but these errors were encountered: