bazel-contrib / bazel-contrib/rules_go
Attribute linkmode in go_binary doesn't support select
- Dominant language
- Go
- Stars
- 1.5k
- Forks
- 760
- Avg merge
- 1d 11h
- Merged PRs (30d)
- 12
Description
When trying to create a cross-platform `go_binary` target that works for Linux/Android and 32/64 bits, the standard approach would be to use a `select` (unless #4478 is fixed):
```
config_setting(
name = "armv7_linux",
constraint_values = [
"@platforms//cpu:armv7",
"@platforms//os:linux",
],
)
go_binary(
name = "run",
srcs = ["run.go"],
linkmode = select({
":armv7_linux": "normal",
"//conditions:default": "pie",
}),
pure = "on",
)
```
However, this fails with:
> ERROR: (...): in go_non_executable_binary rule //:run: Returning RunEnvironmentInfo from a non-executable, non-test target has no effect
It looks like the issue is that you're not handling a `select` in `go_binary_macro`:
https://github.com/bazel-contrib/rules_go/blob/74199c92e20399b6ef46684b2c6fdd94b50a7892/go/private/rules/wrappers.bzl#L42-L45
Contributor guide
Research direction
Reproduce the cross-platform go_binary example with linkmode set through select, then inspect go/private/rules/wrappers.bzl around lines 42-45 and the go_binary_macro entry point. Confirm that the selected linkmode is handled without the erroneous RunEnvironmentInfo warning, and verify the target builds for the stated configurations.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- build-system
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100