-
-
Notifications
You must be signed in to change notification settings - Fork 673
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
Can't configure static differently for different platforms #3103
Comments
As bazelbuild/bazel#15157 only applies to incoming edge transitions, maybe the solution is to move rules_go's transitions to the relevant outgoing edges (e.g. deps)? |
To make sure I understand, that means that rather than using |
I'm not intimately familiar with the internal rules_go setup, but I would have thought of the following: In |
As per bazel-contrib#3103 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.
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.
Thinking a bit more about this: What would you expect to happen if the |
I don't think it makes sense to have As a concrete example, I don't think it makes sense to write: go_binary(
name = "bin",
goos = "linux",
goarch = "amd64",
static = select({
"@io_bazel_rules_go//go/platform:linux": "on",
"//conditions:default": "off",
}),
) If you're hard-coding Stepping back into the bigger picture, the |
Fully agree here. I was just asking a "provocative" question so that we can pin down the intended semantics. |
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.
What version of rules_go are you using?
0.31.0
What version of Bazel are you using?
5.1.0
Does this issue reproduce with the latest releases of all the above?
Yes
What operating system and processor architecture are you using?
macOS x86-64
Any other potentially useful information about your toolchain?
Using musl to cross-compile to Linux x86-64.
What did you do?
Trying to ensure that binaries built for Linux are statically linked, and for Darwin are not.
Writing code along the lines of:
What did you expect to see?
Expect this to lead to a static binary on Linux and a dynamic one on macOS.
What did you see instead?
A dynamic binary is produced on both platforms. This appears to be because of bazelbuild/bazel#15157 - this transition inspects
attr.static
to determine whether to statically link, but because the attribute is a configurable one, the transition doesn't see the value for the attribute at all, so defaults to "auto". It's explicitly not supported to consult configurable attributes in a transition (and should probably become an error), but it feels like being able to have platform-configurable static-ness is a pretty reasonable feature request.It feels like there should be a way to do this attribute resolution which doesn't involve a transition, but I'm not familiar enough with the internals of rules_go to know what that would look like. Do folks have ideas for how we could make this static attribute stickier?
I'm happy to put in the work if folks have ideas for what this may look like...
The text was updated successfully, but these errors were encountered: