Provide a transition for switching the target platform to the exec platform?
Nobody has claimed this yet.
Assessment
- Difficulty
- 5/5
- Estimated time
- Over a week
- Newbie friendliness
- 25/100
- Issue type
- Feature
- Clarity
- Needs clarification
- Activity status
- Stale
- Domain
- build-system
Research direction
Start with the proposed transition_to_target implementation in the issue, then review rules_oci#590, rules_rust#2684, and Bazel#19645 for the existing use cases and API constraints. Determine whether rules_platform should provide the transition or whether Bazel needs a Starlark API change; done requires a decided scope and an agreed implementation direction.
Written by the indexing model from the issue text.
Description
In https://github.com/bazel-contrib/rules_oci/pull/590 and https://github.com/bazelbuild/rules_rust/issues/2684 we noticed that a common mistake in rulesets is that they use executables provided by toolchains outside the scope of ctx.actions.run(). Namely, they get embedded into runfiles directories of binaries and tests.
One approach to work around this issue is to declare "run" toolchains, where you essentially leave exec_compatible_with cleared, but set target_compatible_with instead. This is what rules_python uses, which it can do because the toolchain is never directly invoked as part of ctx.actions.run(). It's only embedded into runfiles directories, so that a subsequent py_binary() can run it. In other cases this is impractical, because there is a desire to use tools both within ctx.actions.run() AND runfiles directories. In those cases you need to declare all toolchains in twofold, which is highly inconvenient.
In the PRs linked above we managed to prevent the duplication by adding a special transition like this:
def _transition_to_target_impl(settings, attr):
return {
# String conversion is needed to prevent a crash with Bazel 6.x.
"//command_line_option:extra_execution_platforms": [
str(platform)
for platform in settings["//command_line_option:platforms"]
],
}
transition_to_target = transition(
implementation = _transition_to_target_impl,
inputs = ["//command_line_option:platforms"],
outputs = ["//command_line_option:extra_execution_platforms"],
)
This can be combined with a helper rule that depends on a toolchain and returns its configuration through one or more providers. By setting the execution platforms to the target platform, the toolchain resolution is performed in such a way that the exec and target platforms are identical.
Considering that we already needed a transition like this in multiple places, would it make sense to provide it as part of rules_platform? Or would it instead be desirable to extend Bazel's Starlark API for supporting more flexible resolution of toolchains? See https://github.com/bazelbuild/bazel/issues/19645.
- Dominant language
- Starlark
- Stars
- 12
- Forks
- 7
- Avg merge
- 1h 35m
- Merged PRs (30d)
- 1
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from bazelbuild/rules_platform
-
Difficulty 3/5 1-2 days Newbie friendliness 45/100
bazelbuild/rules_platform#11 · 4 comments ·
-
Difficulty 3/5 1-2 days Newbie friendliness 38/100
bazelbuild/rules_platform#10 · 4 comments ·
-
Tag 0.1.2 Open
Difficulty 5/5 Over a week Newbie friendliness 20/100
All issues in bazelbuild/rules_platform
Similar issues
-
type/automation type/tech-debt
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
priority: p3
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
googleapis/librarian#7636 ·
-
package-update
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
oSoWoSo/vOid_Community_repOsitory#147 · 1 comment ·
-
Builders
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 88/100