bazel-contrib / bazel-contrib/rules_go
If using `cgo`, file paths in build errors contain a path to a random temporary directory
- 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?
v0.50.1
### What version of gazelle are you using?
0.39.1
### What version of Bazel are you using?
7.2.1
### Does this issue reproduce with the latest releases of all the above?
Yes
### What operating system and processor architecture are you using?
Mac ARM64
### Any other potentially useful information about your toolchain?
No
### What did you do?
Perform a build with an error in `.go` code in a `cgo`-enabled package.
### What did you expect to see?
The build error should contain filenames that are meaningful and relative to the workspace root.
### What did you see instead?
```
/var/folders/xl/r959dlf13y968d0d30q1wbr40000gp/T/rules_go_work-2776474039/cgo/github.com/cockroachdb/cockroach/pkg/cli/start.go:283:2: foo declared and not used
/var/folders/xl/r959dlf13y968d0d30q1wbr40000gp/T/rules_go_work-2776474039/cgo/github.com/cockroachdb/cockroach/pkg/cli/start.go:283:9: undefined: bar
```
Internally, `rules_go` creates a temporary directory for these `cgo` files. The long random path (`/var/folders/xl/...`) here seems to be a path to this temporary directory. In this case, the "actual" filename that I care about is `pkg/cli/start.go`. Everything up to that point is unecessary.
In `cockroach`, we use this patch to circumvent this issue: https://github.com/cockroachdb/rules_go/commit/89aeb356adb445f304928769cccf844f20d91c4a This essentially wipes the random temporary directory in the `go tool compile` output. I'm not sure whether you would want a PR with this change or if you would like to apply similar concepts to your own commit.
Contributor guide
Research direction
Reproduce the cgo-enabled build failure using the reported rules_go, Gazelle, Bazel, and macOS ARM64 versions. Inspect the rules_go handling of cgo temporary directories and compare the referenced CockroachDB commit. Done means compiler errors report meaningful paths relative to the workspace instead of random temporary-directory prefixes.
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