-
-
Notifications
You must be signed in to change notification settings - Fork 661
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
bzlmod: offer "go install" like capabilities #3646
Comments
I really like this idea, it could provide a clean solution to bazel-contrib/bazel-gazelle#1585. I will happily offer support to anyone who wants to work on this, but we first need to discuss the design. Whether this should live in rules_go or gazelle ultimately depends on how we want to implement it. For example, we probably need to answer these questions:
|
Is it possible to have a shared bazel cache for the tools if we go with the
I also think we should.
I'm afraid I don't understand the internals of bzlmod / Bazel well enough to make a statement on this. I think that being able to share go tools caches / binaries between workspaces would be great if possible. |
We should probably wait for the repository cache design doc. Since different tools would use different repos for their deps anyway (due to isolation), we may not be able to cache anything but the final build output anyway. |
I thought about this more and can offer a design proposal: Instead of introducing a new module extension or even new API at all, how about making the existing
By default, the tool would share its transitive dependencies with all other Go deps, resulting in cache sharing for common dependencies, both during load and build time. If you need specific dependency version to build a tool, you can rely on a separate Let me know what you think about this approach. If someone is interested in working on this, please let me know and I can offer support. |
Sounds like a good solution. I can't promise to work on this anytime soon, but may pick this up if I have time. |
@fmeum So, instead of trying to shoehorn all of the Go deps into When I have tackled this for my own repos, I thought the shortcoming was with how I could tell |
I just came across the semi-official recommendation in golang/go#25922 (comment). The |
I'm not sure if I fully understand your proposal. Would I, as a user still have one set of go dependencies for tools and my own go code with the If the end result is still minimal version selection on all deps of my code and the deps of my Go tools (such as gazelle and rules_go binaries), I don't gain a lot from this. |
Ideally you could do both. Here is what I envision the |
The tricky part is making |
I fixed the linker issues. Could you give bazel-contrib/bazel-gazelle#1678 a try? |
Prevent linker errors by sharing go_proto_library dependencies across isolated dependency closures, which allows the standard tools.go approach to be used to manage Go tools with go_deps with fully separate version resolution. Fixes bazel-contrib/rules_go#3646
Thank you so much @fmeum! That looks very nice. Was not able to give it a try yet but I’m pretty sure this fits my use case well. |
Prevent linker errors by sharing go_proto_library dependencies across isolated dependency closures, which allows the standard tools.go approach to be used to manage Go tools with go_deps with fully separate version resolution. Fixes bazel-contrib/rules_go#3646
What version of rules_go are you using?
v0.41.0
What version of gazelle are you using?
v0.32.0
What version of Bazel are you using?
6.3.1
Does this issue reproduce with the latest releases of all the above?
yes
What operating system and processor architecture are you using?
Ubuntu 22.04 / amd64
Any other potentially useful information about your toolchain?
n/a
What did you do?
A lot of developer tools are written in go. Often, those are installed like this on a developers laptop:
go install example.com/module@v1.2.3
.With bzlmod, I think rules_go could allow users to specify a dependency on a go tool from a third party module in the MODULE.bazel file.
Consider the following (imaginary) syntax:
The tool could then be used in genrules, to build custom rules (things like gazelle) or can be executed via
bazel run
.Most importantly, I would want this to use the
isolated
dependency mechanism discussed in #3458, so you can depend on a tool written in go that uses one set of dependencies (and dep versions) that is disconnected from your own code.This is a feature request / idea. I would potentially like to work on this but first want to know if this is actually something rules_go wants to offer.
Also note that I am not sure if this belongs in rules_go or gazelle.
What did you expect to see?
The ability to easily use third party go tools in bazel.
What did you see instead?
Currently, you have to jump through some hoops. One possibility is to depend on the main package of a tool in your monorepo and create your own binary. This has downsides, like introducing the tools dependencies into your own source code.
The text was updated successfully, but these errors were encountered: