-
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
Toolchain resolution problems with multiple platforms and remote execution #8636
Comments
Can you create a plain git repository with this example that I can clone and test? I'd like to be verifying as close as possible to what you are using. The cc toolchain dependency was removed from genrule a few releases ago, and shouldn't still exist, so that's confusing. I'll investigate this as I can. |
In order to reproduce this: * Install docker * Ask me to grant permissions to access projects/rbe-eytankidron-prod-0/instances/default_instance, or just use a different RBE instance. * $ bazel build --config=remote --noremote_accept_cached :echo
Thanks for the sample repo, this made it much easier to debug the problem. I encountered three issues when building your sample:
Here we can see that toolchain resolution is trying the toolchain The fix here was to add constraints to
This tells toolchain resolution to prefer using However, when running the build (and fixing the definition of
This is because Why was the local toolchain selected?
The cc toolchain
It appears that the docker image specified by The build does work if I swap the line in .bazelrc:
This prefers the default RBE platform, which does have clang installed, so that platform is used to compile I've sent PR eytankidron/toolchain-resolution-example#1 to show the changes. |
Just to be clear, I intentionally set up //:plain_platform to not support the cc_toolchain by not having clang in its docker image and by not specifying the constraint_values. I also intentionally put it first in the order of platforms to be considered. This was by design, in order to get different targets to use different platforms. I realize that if I give @rbe_default//config:platform a higher priority the bug does not reproduce. What I expected to happen was that bazel would select @rbe_default//config:platform for the cc_library target and //:plain_platform for the genrule target. I'm still not clear why //:plain_platform could not be used for the genrule target. In other words, why does the genrule target require a cc_toolchain? And a secondary question is this: if bazel does have a valid reason to decide that the genrule target needs the platform to be compatible with the cc_toolchain (presumably due to its tools dependency), the fact that //:plain_platform does not have the appropriate constraint_values, should have ruled out that platform and as a result bazel should have used @rbe_default//config:platform instead. But that did not happen. |
At no point does the genrule require a cc toolchain. The genrule declares a tool dependency, and In your initial example, there is no platform that can build
|
Why? Can't @rbe_default//config:platform be that platform?
I thought the whole point was that different targets in the same invocation can be handled by different platforms. Is that not the case? |
it is entirely possible that different targets have different execution platforms. Every configured target has two platforms it is concerned with: the target platform (where the output will execute) and the execution platform (where build actions will execute). The target |
When playing around with remote execution platform selection, I'm hitting toolchain resolution error with bazel 0.26.1
In .bazelrc, I'm setting:
build:remote --incompatible_enable_cc_toolchain_resolution
build:remote --extra_toolchains=@rbe_default//config:cc-toolchain
build:remote --extra_execution_platforms=//:plain_platform,@rbe_default//config:platform
build:remote --host_platform=//:plain_platform
build:remote --platforms=@rbe_default//config:platform
Where :plain_platform does not implement the appropriate constraint_values to satisfy the cc_toolchain and it also uses a docker image that does not contain clang.
platform(
name = "plain_platform",
remote_execution_properties = """
properties: {
name: "container-image"
value:"docker://gcr.io/gcp-runtimes/ubuntu_16_0_4@sha256:096632d8fb3e78fbd58ae6a2b25ed46020dc70e65d89bca774af6f7b2de6898c"
}
properties {
name: "OSFamily"
value: "Linux"
}
""",
)
My BUILD file defines a cc_library and a genrule which uses that cc_library as a tool.
cc_library(
name = "hello-world-lib",
srcs = ["hello-world-lib.cc"],
hdrs = ["hello-world-lib.h"],
)
genrule($(locations :hello-world-lib) > $ @",
name = "echo",
outs = ["echo.txt"],
cmd = "echo
tools = [
":hello-world-lib",
],
)
Building :hello-world-lib correctly chooses the platform @rbe_default//config:platform, and just works.
However, building :echo fails with the following errors:
$ bazel build --config=remote --noremote_accept_cached :echo
...
ERROR: While resolving toolchains for target //:hello-world-lib: no matching toolchains found for types @bazel_tools//tools/cpp:toolchain_type
ERROR: Analysis of target '//:echo' failed; build aborted: no matching toolchains found for types @bazel_tools//tools/cpp:toolchain_type
...
I don't think :echo should need a cc toolchain. I believe it should be able to choose //:plain_platform. But if I'm wrong and it does need a cc toolchain, it should be able to choose @rbe_default//config:platform as well. Instead it does neither and just fails.
Note that the error does not reproduce if --host_platform=@rbe_default//config:platform.
It also does not reproduce if :echo does not use the cc_library as a tool.
The text was updated successfully, but these errors were encountered: