rules_go icon indicating copy to clipboard operation
rules_go copied to clipboard

Advice around git repos that are both go modules and bzlmod modules

Open JonathanPerry651 opened this issue 9 months ago • 5 comments

How should we think about git repos which provide both bazel and go functionality? For example, I have a dependency on rules_go in my go.mod, as well as (of course) a bzlmod dependency. How can I keep them in sync, especially w.r.t. patches?

Thank you!

JonathanPerry651 avatar Mar 16 '25 16:03 JonathanPerry651

Maybe we should add a dedicated go.mod in the go/runfiles Go package.

This has a number of advantages:

  • The version of rules_go can be different than the version of this Go package used in your go.mod. There is no strict dependency between these two versions.
  • We avoid indirect dependency over all Go internal dependencies of rules_go (protobuf / x/tools / grpc / protoc-gen-go-grpc).

lbcjbb avatar Mar 21 '25 22:03 lbcjbb

The whole division between ‘dependencies from a tool used in the build’ vs ‘dependencies from a library we expect client to link’ is fraught with complexity and danger. C.f. the maven repository name difficulties.

JonathanPerry651 avatar Mar 21 '25 22:03 JonathanPerry651

Adding a dedicated go.mod to the runfiles library would be possible.

I'm not sure whether it would greatly improve the situation though since proto and x/tools deps would still need be present. The proto rules link in runtime code, so the version legitimately needs to align with "target configured" deps. x/tools needs to align with "exec configured" targets since users can supply their own nogo analyzers, but I still haven't found a good way to specify different dep versions for target vs. exec configured target. This could also very well lead to more pain than gain.

fmeum avatar Mar 22 '25 09:03 fmeum

Fair. So I guess I’m back to the question of how I should think about them being in sync - it feels like skew between the bazel rules and the go code is a recipe for latent bugs, right?

JonathanPerry651 avatar Mar 22 '25 21:03 JonathanPerry651

Not really as go_deps will still pick the maximum version. It's only a problem for IDEs that aren't fully Bazel aware.

fmeum avatar Mar 28 '25 09:03 fmeum