Closed sAlexander closed 10 months ago
As a workaround, using toolchain = ctx.toolchains["@rules_cc//cc:toolchain_type"]
directly in _foo_impl works fine. But that won't work if incompatible_enable_cc_toolchain_resolution
is omitted. And it's obviously not a proper fix.
It looks like this may have been fixed by https://github.com/bazelbuild/rules_cc/commit/88ef31b429631b787ceb5e4556d773b20ad797c8.
Tried out latest HEAD (https://github.com/bazelbuild/rules_cc/commit/c612c9581b9e740a49ed4c006edb93912c8ab205) locally, and I was able to getfind_cc_toolchain
working with and without --incompatible_enable_cc_toolchain_resolution
.
Stale
Description of the problem / feature request:
Summary:
find_cc_toolchain
fails with--incompatible_enable_cc_toolchain_resolution
The
find_cc_toolchain
documentation indicates that if you're using--incompatible_enable_cc_toolchain_resolution
, you must declare a dependency on the cc toolchain. It even provides a nice code snippet example (thank you!):However, the provided code does not appear to actually work when using
incompatible_enable_cc_toolchain_resolution
. Instead, we receive the errorIn order to use find_cc_toolchain, your rule has to depend on C++ toolchain. See find_cc_toolchain.bzl docs for details.
Bugs: what's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.
The simplest example is following the exact instructions in the documentation:
WORKSPACE
#Empty file
foo.bzl
BUILD
To reproduce the failure, you can use:
bazel build --incompatible_enable_cc_toolchain_resolution :fails
Instead of the expected print output, you get an error with
In order to use find_cc_toolchain, your rule has to depend on C++ toolchain. See find_cc_toolchain.bzl docs for details.
You can confirm that thing work as expected when not using the incompatible_enable_cc_toolchain_resolution flag.
What operating system are you running Bazel on?
Linux, Ubuntu
What's the output of
bazel info release
?release 3.1.0
What version of rules_cc do you use? Can you paste the workspace rule used to fetch rules_cc? What other relevant dependencies does your project have?
I have not depended on rules_cc in any special way; it appears to be unnecessary to include a dependency in my WORKSPACE files in order to use rules_cc.
Out of curiosity, I also imported the master branch as of this morning with the following in my WORKSPACE files, and the failure with the simple repro above still occurred:
What Bazel options do you use to trigger the issue? What C++ toolchain do you use?
bazel build --incompatible_enable_cc_toolchain_resolution :fails
Have you found anything relevant by searching the web?
I was not able to find any relevant info from the web. The issue for toolchain resolution (https://github.com/bazelbuild/bazel/issues/7260) mentions find_cc_toolchain as though it works, and the find_cc_toolchain even provides a nice code example. Looking at the code for find_cc_toolchain, everything looks normal, though there is "do not use" appended to "is_cc_toolchain_resolution_enabled_do_not_use", which is a bit suspicious.