bazelbuild / rules_go

Go rules for Bazel
Apache License 2.0
1.36k stars 645 forks source link

nogo with rules_go 0.19.1 breaks exclude rules #2172

Open lukedirtwalker opened 5 years ago

lukedirtwalker commented 5 years ago

What version of rules_go are you using?

0.19.1

What version of gazelle are you using?

0.18.1

What version of Bazel are you using?

0.26.1

Does this issue reproduce with the latest releases of all the above?

Yes (tried with bazel 0.28.1 as well)

What operating system and processor architecture are you using?

Ubuntu Linux 16.04. Kernel 4.15. X86_64 (Intel)

Any other potentially useful information about your toolchain?

What did you do?

We updated to rules_go to 0.19.1 and gazelle to 0.18.1 and then ran a normal build (bazel build //:scion). (see https://github.com/lukedirtwalker/scion/commit/635859ef3472213579106f28386f8677b93201cd)

What did you expect to see?

The build works.

What did you see instead?

The build failed because of nogo exclude rules no longer matching.

ERROR: /home/luke/.cache/bazel/_bazel_luke/dd6535e009b1b20856ab42d41796880c/external/com_github_google_gopacket/afpacket/BUILD.bazel:3:1: GoCompilePkg external/com_github_google_gopacket/afpacket/linux_amd64_stripped/go_default_library%/github.com/google/gopacket/afpacket.a failed (Exit 1) builder failed: error executing command bazel-out/host/bin/external/go_sdk/builder compilepkg -sdk external/go_sdk -installsuffix linux_amd64 -src external/com_github_google_gopacket/afpacket/afpacket.go -src ... (remaining 39 argument(s) skipped)

Use --sandbox_debug to see verbose messages from the sandbox
compilepkg: nogo: errors found by nogo during build-time code analysis:
/tmp/rules_go_work-055855368/afpacket.go:437:22: possible misuse of unsafe.Pointer
/tmp/rules_go_work-055855368/afpacket.go:443:22: possible misuse of unsafe.Pointer
/tmp/rules_go_work-055855368/afpacket.go:450:24: possible misuse of unsafe.Pointer
/tmp/rules_go_work-055855368/header.go:189:43: possible misuse of unsafe.Pointer

It seems like bazel uses a custom tmp path for building files and with that it no longer matches the exclude rules in the nogo configuration. To verify this I added explicit excludes for /tmp/rules_go_work.* (see https://github.com/lukedirtwalker/scion/commit/a04f4dbe73011ca1bf0fccdb4aee2b2d2b7d6a17) and then the build works again.

I have a strong suspicion that this is only a problem for dependencies which use cgo since other excludes still seemed to have worked as expected.

If you prefer I can also create a toy project to help you reproduce. (but if you check out the commit linked above and run bazel build //:scion you should already be able to reproduce it)

rmohr commented 3 years ago

We experience the same after updating to 0.27 with a cgo dependency and nogo. Adding rules_go_work-.*/ to the excludes fixes it, but something seems to have changed.