-
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
Transitions can inspect configurable attributes, but don't see a value for them #15157
Comments
/cc @gregestren |
Just skimming this (apologies!), but I think this is an intentional design restriction described at https://bazel.build/rules/config#defining. Specifically:
https://docs.google.com/document/d/1VIRx06cZB4wLU-ASq1XKFHmx67yfHtNOCbCempaPeaA/ gets into the ugly details:
I agree that silent failure is no good. It looks like the original intention was for Bazel to communicate the problem? Also, I think the main conclusion from then was that supporting your use case is technically hard. That doesn't necessarily mean it's impossible - there may be some innovative thinking we didn't think of. The current state is largely a desire to get the functionality working and aiming for just not supporting certain use cases vs. blocking the functionality on a more complete solution. I'm open to creative ideas beside better error messaging if you can think of any. |
As per bazelbuild/bazel#15157 currently we can't configure any transition-relevant attributes using select. This is because we use self-transitions on targets, and when this happens, configurable attributes aren't passed to the transition, so we make incorrect transition decisions. Instead, insert a dummy rule which exists only to transition its dependencies using an edge transition, which means the appropriate attributes are resolved before the transition is called. To achieve this, we symlink the actual built binaries into our transitioning wrapper rules, and forward any providers needed. Fixes bazel-contrib#3103.
As per bazelbuild/bazel#15157 currently we can't configure any transition-relevant attributes using select. This is because we use self-transitions on targets, and when this happens, configurable attributes aren't passed to the transition, so we make incorrect transition decisions. We only actually consult configuration data in `_go_context_data`, so we only actually need to transition on the edges which (transitively) reach a `_go_context_data`, which is `_go_context_data` itself and `deps`.
As per bazelbuild/bazel#15157 currently we can't configure any transition-relevant attributes using select. This is because we use self-transitions on targets, and when this happens, configurable attributes aren't passed to the transition, so we make incorrect transition decisions. We only actually consult configuration data in `_go_context_data`, so we only actually need to transition on the edges which (transitively) reach a `_go_context_data`, which is `_go_context_data` itself and `deps`.
As per bazelbuild/bazel#15157 currently we can't configure any transition-relevant attributes using select. This is because we use self-transitions on targets, and when this happens, configurable attributes aren't passed to the transition, so we make incorrect transition decisions. Instead, insert a dummy rule which exists only to transition its dependencies using an edge transition, which means the appropriate attributes are resolved before the transition is called. To achieve this, we symlink the actual built binaries into our transitioning wrapper rules, and forward any providers needed. Fixes bazel-contrib#3103.
@gregestren I'm not sure how difficult this would be to implement, but how about the following: Populate the configured value for all attributes for which the select keys are disjoint from the set of output settings declared by the transition. This should get around all the difficult situations, but still allow for the common, non-pathological use cases. |
I think that's possible. I think the logic would be:
It sounds tricky but doable. Mostly tricky in not spreading the logic across too many classes or overly-complicating method signatures. I'm also not sure about manually parsing the |
Re: |
Yes, I ran into this issue when I started trying to conditionally make static binaries depending on the target platform. bazel-contrib/rules_go#3103 was my issue report there, and bazel-contrib/rules_go#3130 a proposed (but somewhat hacky) fix. |
Got it, thanks. Principally I support narrowing down which attributes we can't access as much as we reasonably can. I don't have time at the moment to tackle this but I'm open to contributions. With the caveat that there is a balance of utility vs. code complexity, so any code I'd want to be very careful doesn't overly complicate Bazel's code in one of the more nuance parts of its code base. That's where I'd focus review attention. |
As per bazelbuild/bazel#15157 currently we can't configure any transition-relevant attributes using select. This is because we use self-transitions on targets, and when this happens, configurable attributes aren't passed to the transition, so we make incorrect transition decisions. Instead, insert a dummy rule which exists only to transition its dependencies using an edge transition, which means the appropriate attributes are resolved before the transition is called. To achieve this, we symlink the actual built binaries into our transitioning wrapper rules, and forward any providers needed. Fixes bazel-contrib#3103.
As per bazelbuild/bazel#15157 currently we can't configure any transition-relevant attributes using select. This is because we use self-transitions on targets, and when this happens, configurable attributes aren't passed to the transition, so we make incorrect transition decisions. Instead, insert a dummy rule which exists only to transition its dependencies using an edge transition, which means the appropriate attributes are resolved before the transition is called. To achieve this, we symlink the actual built binaries into our transitioning wrapper rules, and forward any providers needed. Fixes bazel-contrib#3103.
As per bazelbuild/bazel#15157 currently we can't configure any transition-relevant attributes using select. This is because we use self-transitions on targets, and when this happens, configurable attributes aren't passed to the transition, so we make incorrect transition decisions. Instead, insert a dummy rule which exists only to transition its dependencies using an edge transition, which means the appropriate attributes are resolved before the transition is called. To achieve this, we symlink the actual built binaries into our transitioning wrapper rules, and forward any providers needed. Fixes bazel-contrib#3103.
As per bazelbuild/bazel#15157 currently we can't configure any transition-relevant attributes using select. This is because we use self-transitions on targets, and when this happens, configurable attributes aren't passed to the transition, so we make incorrect transition decisions. Instead, insert a dummy rule which exists only to transition its dependencies using an edge transition, which means the appropriate attributes are resolved before the transition is called. To achieve this, we symlink the actual built binaries into our transitioning wrapper rules, and forward any providers needed. Fixes bazel-contrib#3103.
As per bazelbuild/bazel#15157 currently we can't configure any transition-relevant attributes using select. This is because we use self-transitions on targets, and when this happens, configurable attributes aren't passed to the transition, so we make incorrect transition decisions. We only actually consult configuration data in `_go_context_data`, so we only actually need to transition on the edges which (transitively) reach a `_go_context_data`, which is `_go_context_data` itself and `deps`.
As per bazelbuild/bazel#15157 currently we can't configure any transition-relevant attributes using select. This is because we use self-transitions on targets, and when this happens, configurable attributes aren't passed to the transition, so we make incorrect transition decisions. We only actually consult configuration data in `_go_context_data`, so we only actually need to transition on the edges which (transitively) reach a `_go_context_data`, which is `_go_context_data` itself and `deps`.
As per bazelbuild/bazel#15157 currently we can't configure any transition-relevant attributes using select. This is because we use self-transitions on targets, and when this happens, configurable attributes aren't passed to the transition, so we make incorrect transition decisions. We only actually consult configuration data in `_go_context_data`, so we only actually need to transition on the edges which (transitively) reach a `_go_context_data`, which is `_go_context_data` itself and `deps`.
I've heard another request from https://github.com/lizkammer. |
Not really assigning myself, but github does not have a CC capability |
We do intend to prioritize this shortly. Stay tuned. |
Update: @aranguyen has been working on this with good success. Main remaining technical complications:
We intend to either have this done by end-of-June or a have a clear update of the final work remaining by then. |
Reviewing at https://bazel-review.googlesource.com/c/bazel/+/224533. |
Any updates? |
You can see the latest patch set from https://bazel-review.googlesource.com/c/bazel/+/224533 is from Aug 15. We're doing an internal review on this, which looks close to ready to me. |
Description of the problem / feature request:
When a rule has a configurable attribute, a transition which operates on the rule gets an
attr
map which doesn't contain the attr name or value at all.This can cause buggy behaviour. e.g. this transition in rules_go looks at what the value of
getattr(attr, "static", "auto")
to decide whether to statically link a binary, but if thestatic
attribute is a configurable attribute, the transition will always seeNone
as the value of the attribute, so will fall back to its default behaviour.Ideally the transition would get the current configuration's value of the attribute.
If that's not feasible, trying to read one of these attributes in a configuration should be an error (conceptually, we'd be declaring any attribute used in a transition as non-configurable, but by doing this detection on the fly and raising a runtime error; alternatively, we could introduce a "non-configurable" marker on attrs, and require it to be set for any attributes read by transitions).
In the case we decide to forbid this acces, it would be great to work out how rules_go's transition should be determining whether a target should be compiled as static.
Either way, silently hiding the attribute is error-prone.
Bugs: what's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.
Expect to see printed "Attr: Default condition in BUILD"
Actually see printed: "Attr: NOT PRESENT"
If you switch over the commented
explicit_config
values in the BUILD.bazel file and re-run, you'll see "Attr: String in BUILD" as expected.What operating system are you running Bazel on?
macOS
What's the output of
bazel info release
?release 6.0.0-pre.20220324.1
The text was updated successfully, but these errors were encountered: