bazel-contrib / rules_go

Go rules for Bazel
Apache License 2.0
1.39k stars 664 forks source link

If using `cgo`, file paths in build errors contain a path to a random temporary directory #4160

Open rickystewart opened 4 weeks ago

rickystewart commented 4 weeks ago

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.

fmeum commented 4 weeks ago

Yes, please send that patch as a PR. We might have to add some kind of an escape hatch that shows full paths for debugging purposes.