bazel-contrib / bazel-contrib/rules_go
nogo with rules_go 0.19.1 breaks exclude rules
- 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.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)
Contributor guide
Research direction
Check out the linked scion commit and run `bazel build //:scion` with rules_go 0.19.1 and Gazelle 0.18.1. Inspect the nogo configuration and the cgo dependency paths shown in the failure, then compare them with the explicit `/tmp/rules_go_work.*` excludes from the second linked commit. Done means the build succeeds while the intended nogo exclusions still apply.
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