bazel-contrib / bazel-contrib/rules_go
Bazel produces different paths for binary output with gotags attr
- Dominant language
- Go
- Stars
- 1.5k
- Forks
- 760
- Avg merge
- 1d 11h
- Merged PRs (30d)
- 12
Description
### What version of rules_go are you using?
0.29.0
### What version of gazelle are you using?
0.24.0
### What version of Bazel are you using?
4.2.0
### Does this issue reproduce with the latest releases of all the above?
Yes, I tried with bazel 4.2.2 and rules_go 0.31.0
### What operating system and processor architecture are you using?
Debian Linux, amd64
### Any other potentially useful information about your toolchain?
N/A
### What did you do?
Wrote a simple helloworld go file and build it with bazel. Used go_binary.gotags attr
```
load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library")
go_library(
name = "helloworld_lib",
srcs = ["main.go"],
importpath = "cmd/helloworld",
visibility = ["//visibility:private"],
)
go_binary(
name = "helloworld",
embed = [":helloworld_lib"],
gotags = ["test"],
visibility = ["//visibility:public"],
)
```
And run `bazel build //cmd/helloworld` to build the binary.
### What did you expect to see?
Generated binary in `bazel-bin`. Like the output below without `gotags`.
```
% bazel build //cmd/helloworld
INFO: Analyzed target //cmd/helloworld:helloworld (1 packages loaded, 263 targets configured).
INFO: Found 1 target...
Target //cmd/helloworld:helloworld up-to-date:
bazel-bin/cmd/helloworld/helloworld_/helloworld
INFO: Elapsed time: 1.354s, Critical Path: 0.91s
INFO: 2 processes: 2 internal.
INFO: Build completed successfully, 2 total actions
```
### What did you see instead?
The binary was put into `bazel-out/k8-fastbuild-ST-d99531819a79` path, with the digest changes often so I don't have a stable path to get the binary.
```
% bazel build //cmd/helloworld
Starting local Bazel server and connecting to it...
INFO: Analyzed target //cmd/helloworld:helloworld (77 packages loaded, 8149 targets configured).
INFO: Found 1 target...
Target //cmd/helloworld:helloworld up-to-date:
bazel-out/k8-fastbuild-ST-d99531819a79/bin/cmd/helloworld/helloworld_/helloworld
INFO: Elapsed time: 5.020s, Critical Path: 0.91s
INFO: 1 process: 1 internal.
INFO: Build completed successfully, 1 total action
```
Is this the expected behavior? Anything I can do to have the `bazel-bin` path with gotags?
Thanks.
Contributor guide
Research direction
Reproduce the issue with the shown go_library and go_binary targets, including gotags = ["test"], then run bazel build //cmd/helloworld and compare the reported output paths. Start by tracing how the go_binary gotags attribute affects Bazel output handling in rules_go. Done means the built binary is reported through a stable bazel-bin path as expected.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- build-system
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100