-
-
Notifications
You must be signed in to change notification settings - Fork 736
Can't configure static differently for different platforms #3103
Description
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:
go_binary(
...
static = select({
"@io_bazel_rules_go//go/platform:linux": "on",
"//conditions:default": "auto",
}),
)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...