You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Bazel: source mode mocks fail analysis with the race detector on rules_go 0.63 #322
Actual behavior With rules_go 0.63.0, every gomock target in source mode fails analysis when the race detector is enabled:
Error in fail: race instrumentation can't be enabled when cgo is disabled. Check that pure is not set to "off" and a C/C++ toolchain is configured.
The traceback goes from _gomock_source_impl through go_context(ctx, include_deprecated_properties = False) to validate_mode. Archive mode is not affected.
Expected behavior Builds and tests with --@io_bazel_rules_go//go/config:race work for targets that depend on source mode mocks.
To Reproduce Steps to reproduce the behavior
In bazel/MODULE.bazel, raise rules_go to 0.63.0. This resolves gazelle 0.51.3, whose tools need go 1.25.0 in bazel/go.mod.
In bazel/, run bazel test --@io_bazel_rules_go//go/config:race //....
All _gomock_source targets in tests/source and tests/source_with_importpath fail with the error above.
Additional Information
gomock mode (reflect or source): source, through the Bazel gomock rule
golang version: 1.25.0, with rules_go 0.63.0 and Bazel 9.2.0 on Linux amd64
Cause
Since rules_go 0.62, go_context forces pure mode for rules that do not declare a C/C++ toolchain, and pure mode cannot be combined with race. _gomock_source reads the target Go configuration through _go_context_data, so it sees race enabled, but it declares only the Go toolchain. rules_go 0.63 added an opt-out and documents it for this kind of rule: "Rules that only use the Go SDK or generate Go sources can use rule, declare only the @io_bazel_rules_go//go:toolchain toolchain, and call go_context(ctx, maybe_needs_cc_toolchain = False)." From the rules_go sources, 0.62 forces pure mode the same way, while 0.61 and older do not.
Proposed fix
Call go_context(ctx, include_deprecated_properties = False, maybe_needs_cc_toolchain = False) in _gomock_source_impl. The parameter exists since rules_go 0.61 and takes effect from 0.63, so bazel/MODULE.bazel would require rules_go 0.63.0. A CI step that runs the Bazel tests with --@io_bazel_rules_go//go/config:race catches regressions. A PR with this change follows; locally the Bazel tests pass with and without the race flag.
Activity