rules_go icon indicating copy to clipboard operation
rules_go copied to clipboard

Uber's gomock 0.5.0 is incompatible with rules_go's gomock.bzl

Open TvdW opened this issue 1 year ago • 9 comments

What version of rules_go/gazelle/bazel/gomock are you using?

  • rules_go 0.50.1 (latest)
  • gazelle 0.39.1 (latest)
  • bazel 7.3.1 (latest)
  • Uber's gomock 0.5.0 (latest)

What happened?

reflect mode got dropped, and so the latest release no longer generates a source file that then gets compiled into a binary, which rules_go expects it to do. Instead, a new package mode was added, which calls the go binary, which is unavailable in the Bazel sandbox.

I tried to modify rules_go to support the new mode but my bazel-fu isn't quite at the level needed for that 😄

Error

ERROR: xxx/BUILD.bazel:15:7: GoMockReflectProgOnlyGen xxx.go failed: (Exit 1): sandbox-exec failed: error executing GoMockReflectProgOnlyGen command
  (cd xxx/execroot/_main && \
  exec env - \
    TMPDIR=xxx/T/ \
  /usr/bin/sandbox-exec -f xxx/sandbox.sb xxx/process-wrapper '--timeout=0' '--kill_delay=15' '--stats=xxx/stats.out' /bin/bash -c '
           $(pwd)/xxx/mockgen -prog_only xxx xxx > xxx.go
        ')
2024/10/23 13:49:53 Loading input failed: load package: load packages: err: go command required, not found: exec: "go": executable file not found in $PATH: stderr:

TvdW avatar Oct 23 '24 17:10 TvdW

@linzhp

fmeum avatar Oct 23 '24 19:10 fmeum

We are not planning to support Uber's gomock in rules_go. The plan is to move it to the same repo as Uber's gomock so they can co-evolve easily. The maintainers of Uber's gomock agreed with the plan. It's in my backlog, but any helping hand will be welcomed.

linzhp avatar Oct 24 '24 03:10 linzhp

@linzhp, to clarify, is the plan to move gomock.bzl to the Uber gomock repo? Is this just as simple as creating a PR in the Uber gomock repo copying it over?

SpencerC avatar Nov 18 '24 20:11 SpencerC

Yes, the first PR would be just that and maybe update the mockgen tool used by the rule to be Uber's mockgen. As followups, we should also

  • set up some tests to make sure gomock rule work as expected
  • publish the gomock rule to Bazel Central Registry

linzhp avatar Nov 19 '24 02:11 linzhp

FYI: https://github.com/uber-go/mock/pull/231

linzhp avatar Jan 05 '25 17:01 linzhp

Is there any timeline for this? We are using uber gomock 0.5.0 in our codebase and this feature is really helpful. Also, uber-go is not part of bazel central registry. Do I need to vendor to use gomock.bzl from v0.4.0?

jatin-scifin avatar Jun 25 '25 06:06 jatin-scifin

[email protected] is compatible with Uber's gomock v0.5.3-0.20250612195617-359202c7b2fe. Please migrate your gomock rule to that one. We are planning to remove the one in rules_go.

linzhp avatar Jun 25 '25 15:06 linzhp

[email protected] is compatible with Uber's gomock v0.5.3-0.20250612195617-359202c7b2fe. Please migrate your gomock rule to that one. We are planning to remove the one in rules_go.

Great I'm assuming you'll do the needful to add this to MODULE.bazel. Please let me know if you need help.

mohitaron avatar Jun 25 '25 15:06 mohitaron

Which MODULE.bazel?

linzhp avatar Jun 25 '25 16:06 linzhp