-
-
Notifications
You must be signed in to change notification settings - Fork 665
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
Use edge transitions not self transitions #3112
Use edge transitions not self transitions #3112
Conversation
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.
|
||
providers.append( | ||
DefaultInfo( | ||
files = default_info.files, | ||
data_runfiles = default_info.data_runfiles, | ||
default_runfiles = default_runfiles, | ||
data_runfiles = runfiles_wrapper.data_runfiles, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that previously we didn't add the new executable to data_runfiles
and now we do - this felt like a positive change, assuming not doing so before was simply oversight, but if there was an important reason for not doing this before, I can revert and add a comment.
@illicitonion I may be missing something, but I think that this PR can be simplified: Instead of using a wrapper to transition the entire |
As far as I can tell, that can't change how the binary is actually linked? My use-case is using a musl toolchain to cross-compile Linux binaries to put in docker images from a macOS host. We want to statically link, and so want to set
I tried patching in your linked change instead of mine, and didn't end up with the static binary I'd expect. I think this makes sense, because something needs to be able to apply a transition to the |
To clarify what I think may be a misunderstanding: The commit 089f13e, which is part of #3108, is not meant to fix the issue you reported as #3103. Rather, it is meant to fix bazelbuild/bazel#14626, which at its root is caused by rules_go applying transitions on Go settings to all its attributes, even those that do not reference Go targets (e.g. What I suggested - if it turns out to work - is a way to simultaneously 1) simplify the current PR and 2) reduce, but not completely remove the need for transitions resetting Go settings on non-Go dependency edges such as
I think that this part is not necessarily true: If I understand the code correctly, the only way in which rules_go accesses the values of the settings set in the transition is through Sorry for the confusion I caused by bringing up the other PR. I hope that the above managed to clarify the situation and my proposal. Please let me know if I should elaborate on something. |
Aha, that makes a lot more sense, apologies for the confusion! That sounds great, and definitely a lot cleaner - I gave it a try and it seemed to work for my test-cases. Would you have any interest in pulling those |
Glad to hear it worked! Since my PR becomes simpler due to yours and yours should be easier to review, I would suggest that we should aim for getting yours merged first. Since I already have two PRs based on each other (#3005 and #3108) and blocked on a third one (#3113), I would just wait until it got merged and rebase. |
What type of PR is this?
Bug fix
What does this PR do? Why is it needed?
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.
Which issues(s) does this PR fix?
Fixes #3103
Other notes for review
The first commit just extracts variables for attr dicts without modifying them, the second contains the meat of the change.