-
Notifications
You must be signed in to change notification settings - Fork 113
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
cc_tool builds src for wrong platform #299
Comments
I don't think I quite understand the reasoning in the explanation. Why should a cc_tool() not run on the exec platform? @matts1 fyi |
There were some aspects of the initial design that warranted putting |
I think it should be safe to just replace exec with target. |
My assumption was that your situation would end up with bazel configuring a seperate set of toolchains for each of your remote execution platforms, so you'd get:
I'm hoping someone knowledgable about platforms can educate me more, but is it possible that since the toolchain itself says it's compatible with all execution platforms, it sees macos exec, creates a toolchain for that, then sees linux exec and sees that the toolchain supports linux and attempts to map linux to the existing toolchain instead of creating another one? I wouldn't be surprised if the original authors of the toolchain logic never considered that someone might make one toolchain for all platforms using |
it looks like you're right, so at least 1 way to make it work is to create 3 separate targets for |
I created an example project to demonstrate the effect that @keith is seeing: https://github.com/fmeum/toolchain-exec-example This is caused by the toolchain transition, which forces the execution platform of the Because of that I think that |
Could this be fixed in bazel itself? I imagine a solution would be to just not deduplicate toolchains. Would there be a significant performance implication of this? Or maybe we could simply say that toolchains with no |
I'm not sure what you mean by deduplication, but I don't think anything like that is happening here. It's also not obviously a "bug": If you want to select on the target platform in some places and on the exec platform in other places, there needs to be some way to specify that. Currently As a starter, could you describe which parts of the toolchain config would want to select on the target platform and which ones on the exec platform of the toolchain? |
Hmmm my expectation based on the current implementation is: cc_toolchain(
name = "my_multiplatform_toolchain",
tool_map = ":tool_map_shim", # a select here is under the "target" config.
)
alias(
name = "tool_map_shim",
actual = select({ # Expectation: still selecting on "target" config.
"@platforms//os:macos": ":tool_map_to_target_macos",
"//conditions:default": ":default_:tool_map",
}),
)
cc_tool_map(
name = "tool_map_to_target_macos",
tools = { # select() not possible here for implementation reasons.
"@rules_cc//cc/toolchains/actions:ar_actions": ":llvm-libtool-darwin",
# ...
},
)
cc_tool(
name = ":llvm-libtool-darwin",
src = select({ # Expectation: selecting on "exec" config.
"@platforms//os:linux": "@llvm_linux//:bin/llvm-libtool-darwin",
"@platforms//os:macos": "@llvm_linux//:bin/llvm-libtool-darwin",
"@platforms//os:windows": "@llvm_linux//:bin/llvm-libtool-darwin",
}),
) I know that in this example the This may be a long shot, but try registering the
I'm suspicious that having a single |
This setup can't work correctly with multiple exec platforms since the exec platform of The example I linked above shows how a single |
Quick summary of the current situation with toolchains: when a target (let's say a
Bazel then creates a toolchain dependency from the target ( The toolchain dependency has a few special properties that normal dependencies don't:
However, there is nothing special about the toolchain implemention's own dependencies: these do not keep the forced execution platform, and perform standard toolchain resolution. These properties have the following consequences:
Okay, that was a lot, finishing this comment and starting a new one. |
Back to this specific request: If I understand the setup correctly, we have the following targets in play:
(Is this correct: it looks like some of these are macros, which will confuse the analysis, but the principles are the same) In this case, we have the following configured targets if we run
So, ending the analysis, the initial comment is correct, |
Thanks for the excellent writeup @katre, I'm going to bookmark this! 😁 I spent some time playing @fmeum's example and I think I better understand the nuances of this problem. Long story short: the current design doesn't support cc_toolchain definitions shared by multiple exec platforms. It properly orders exec transitions if and only if all registered execution platforms evaluate the toolchain configuration identically. Problem: no
|
I was able to come up with a pretty reasonable solution for rules_toolchains that would be just as applicable here. It's similar to the approach that @keith got working, except it supports selecting over the exec platform by manually specifying a transition to a specific platform which is the actual exec platform, rather than the one in "exec", which as we've determined, is not the exec platform. To achieve this, we need to manually enumerate all supported exec platforms, but that's something we were doing anyway. I personally think it turned out pretty clean. If we're able to get bazelbuild/bazel#25363 approved, we could even just write |
rules_cc/cc/toolchains/tool.bzl
Line 68 in 8c94e11
I think
cc_tool(src)
should becfg=target
, notcfg=exec
.Explanation: The
cc_tool
rule does not (itself) execute the tool as a build action (no ctx.actions.run). Presumably there will eventually be some other rule that uses the output from cc_tool as an attribute, and (importantly) also invokes the tool. That rule should consume the tool via an attribute with cfg=exec, so the tool transition can evaluate all the constraints correctly for that rule.The text was updated successfully, but these errors were encountered: