Skip to content
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

go.mod: add dependencies for go tooling #5811

Merged
merged 2 commits into from
Mar 19, 2024
Merged

Conversation

sluongng
Copy link
Contributor

@sluongng sluongng commented Feb 3, 2024

This is a change backported from #5792.

Under bzlmod, there will be no deps.bzl file.
The go_repository repos are automatically generated with gazelle's
go_deps extension parsing go.mod and go.sum files.
This let us consolidate go dependency management to a single source of
truth that is consistent with our editor experience.

The downside of this approach is that we should not be adding
go_repository declarations manually, but instead, adding them to
go.mod file by calling go mod tidy -e.
Create a dummy Go source file that imports all the Go tools dependencies
and guard it with a Go build directive that will not be used.

@sluongng sluongng force-pushed the sluongng/tools-go-deps branch 2 times, most recently from 7ef52e2 to ec65e88 Compare February 6, 2024 18:27
@sluongng sluongng marked this pull request as ready for review February 6, 2024 18:28
Comment on lines +3 to +4
// This tools/deps package keep track of Go tooling dependency that we use
// but do not depend directly in code.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what sorts of tool deps need to be included here? i.e. how did you build this list of deps below? (Is there a straightforward way of automating this?)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are 3 groups added here:

  • Go deps we depend on directly in our BUILD files but not our Go files. I.e. gitlab.com/arm-research/smarter/smarter-device-manager

  • Transitive Go deps that our http_archive repo use. For example, in WORKSPACE mode, we used to load some Go deps with

load("@com_github_sluongng_nogo_analyzer//staticcheck:deps.bzl", "staticcheck")

staticcheck()

This is no longer possible because of the new way Gazelle operate in Bzlmod

ERROR: /Users/sluongng/work/buildbuddy/buildbuddy/BUILD:79:5: //:vet_actual depends on @@org_golang_x_tools//go/analysis/passes/unusedresult:unusedresult in repository @@org_golang_x_tools which failed to fetch. no such package '@@org_golang_x_tools//go/analysis/passes/unusedresult': Unable to load package for @@bazel_gazelle_go_repository_cache//:go.env: The repository '@@bazel_gazelle_go_repository_cache' could not be resolved: Repository '@@bazel_gazelle_go_repository_cache' is not defined
  • Our transitive proto/grpc deps that we used to add to server/libmain/libmain.go to help with go mod tidy -e not adding them from proto/** generated code.

These were pretty much manually picked from the errors I encountered #5792.
So maintaining this list would have to be a manual effort for now.

The UX in Bzlmod is documented here https://github.com/bazelbuild/rules_go/blob/master/docs/go/core/bzlmod.md#depending-on-tools.

@sluongng sluongng force-pushed the sluongng/tools-go-deps branch 3 times, most recently from fa4d335 to 3966e92 Compare February 12, 2024 20:22
This is a change backported from #5792.

Under bzlmod, there will be no `deps.bzl` file.
The `go_repository` repos are automatically generated with gazelle's
`go_deps` extension parsing `go.mod` and `go.sum` files.
This let us consolidate go dependency management to a single source of
truth that is consistent with our editor experience.

The downside of this approach is that we should not be adding
`go_repository` declarations manually, but instead, adding them to
`go.mod` file by calling `go mod tidy -e`.
Create a dummy Go source file that imports all the Go tools dependencies
and guard it with a Go build directive that will not be used.
tools/deps/deps.go Show resolved Hide resolved
Co-authored-by: Brandon Duffany <brandon@buildbuddy.io>
@sluongng sluongng merged commit 47e03e1 into master Mar 19, 2024
16 of 18 checks passed
@sluongng sluongng deleted the sluongng/tools-go-deps branch March 19, 2024 14:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants