bazel__book/rules_go.md

1.4 KiB

rules_go

Ignores the builtin test caching

Command Compilation Caching Test Result Caching
bazel test Cached (re-uses .a files) Cached (won't re-run if inputs match)
bazel run Cached (re-uses .a files) Not Cached (always re-executes the binary)
go test (no args) Cached (re-uses GOCACHE) Not cached: always re-runs the test binary
go test ./... Cached (re-uses GOCACHE) Cached (prints "cached")

Go test caching is disable when using -cpu_profile, -memprofile or -coverprofile flags.

With it, bazel test" on Go, does NOT run go test`. It implements its own test runner

Feature Standard go test Bazel rules_go
Cache Location GOCACHE (usually ~/.cache) Bazel Output Base (_bazel_user/...)
Granularity Package level (mostly) Action level (compile vs link vs test)
Hermeticity Uses host environment Uses isolated sandbox
Sharing Hard to share across machines Easily shared via Remote Cache