Actual behavior
Any Bazel gomock(...) target that mocks a compiled library (i.e. uses the _gomock_archive rule rather than _gomock_source) fails at analysis time when built with rules_go 0.61.x:
ERROR: .../BUILD.bazel:48:7: in _gomock_archive rule //go/svc/fe:mock_sess:
Traceback (most recent call last):
File ".../bazel_gomock+/rules/gomock.bzl", line 251, column 24, in _gomock_archive_impl
go = go_ctx.go.path,
Error: 'struct' value has no field or method 'go'
Available attributes: _ctx, actions, archive, binary, ..., sdk, stdlib, tool_args, toolchain
rules_go 0.61 removed the deprecated .go shortcut field from the go_context struct, but _gomock_archive_impl still reads go_ctx.go.path (bazel/rules/gomock.bzl, line 256 on main / line 251 in the v0.2.0 release):
https://github.com/uber-go/mock/blob/main/bazel/rules/gomock.bzl#L256
""".format(
go = go_ctx.go.path, # <-- removed in rules_go 0.61
goroot = go_ctx.sdk.root_file.dirname,
cmd = ctx.executable.mockgen_tool.path,
),
Expected behavior
The _gomock_archive rule should build successfully against rules_go 0.61.x and generate the mock, the same as it does with rules_go 0.60.x.
To Reproduce Steps to reproduce the behavior
-
In a Bazel module using bazel_dep(name = "bazel_gomock", version = "0.2.0") and bazel_dep(name = "rules_go", version = "0.61.1"), declare a gomock target whose library is a compiled Go library (not source):
load("@bazel_gomock//rules:gomock.bzl", "gomock")
gomock(
name = "mock_sess",
out = "mock_sess_test.go",
interfaces = ["SessionsClient"],
library = "//proto/sessions/sessproto",
package = "main",
)
-
Build it: bazel build //path/to:mock_sess
-
Analysis fails with Error: 'struct' value has no field or method 'go'.
Additional Information
- gomock mode (reflect or source): reflect (the
_gomock_archive code path)
- gomock version or git ref:
bazel_gomock v0.2.0 (latest on the Bazel Central Registry); also reproduces on main
- golang version: Go 1.26.3 (via rules_go go_sdk)
Triage Notes for the Maintainers
The Go binary is already reachable via the SDK, and go_ctx.sdk.go is used two lines above in the same rule's tools list. Routing the path lookup through the SDK fixes it and is valid on both rules_go 0.60 and 0.61:
- go = go_ctx.go.path,
+ go = go_ctx.sdk.go.path,
Note that _gomock_source_impl already calls go_context(ctx, include_deprecated_properties = False) and uses sdk.go, so only the archive path needs this change.
Actual behavior
Any Bazel
gomock(...)target that mocks a compiledlibrary(i.e. uses the_gomock_archiverule rather than_gomock_source) fails at analysis time when built with rules_go 0.61.x:rules_go 0.61 removed the deprecated
.goshortcut field from thego_contextstruct, but_gomock_archive_implstill readsgo_ctx.go.path(bazel/rules/gomock.bzl, line 256 onmain/ line 251 in the v0.2.0 release):https://github.com/uber-go/mock/blob/main/bazel/rules/gomock.bzl#L256
Expected behavior
The
_gomock_archiverule should build successfully against rules_go 0.61.x and generate the mock, the same as it does with rules_go 0.60.x.To Reproduce Steps to reproduce the behavior
In a Bazel module using
bazel_dep(name = "bazel_gomock", version = "0.2.0")andbazel_dep(name = "rules_go", version = "0.61.1"), declare agomocktarget whoselibraryis a compiled Go library (not source):Build it:
bazel build //path/to:mock_sessAnalysis fails with
Error: 'struct' value has no field or method 'go'.Additional Information
_gomock_archivecode path)bazel_gomockv0.2.0 (latest on the Bazel Central Registry); also reproduces onmainTriage Notes for the Maintainers
The Go binary is already reachable via the SDK, and
go_ctx.sdk.gois used two lines above in the same rule'stoolslist. Routing the path lookup through the SDK fixes it and is valid on both rules_go 0.60 and 0.61:Note that
_gomock_source_implalready callsgo_context(ctx, include_deprecated_properties = False)and usessdk.go, so only the archive path needs this change.