Description
Today, a coworker and myself noticed how doing a go get -u
downloaded a large number of modules which were completely uninteresting to us, mostly from @dmitshur:
go: finding github.com/shurcooL/go-goon latest
go: finding github.com/shurcooL/github_flavored_markdown v0.0.0-20181002035957-2122de532470
go: finding github.com/shurcooL/component latest
go: finding github.com/shurcooL/htmlg v0.0.0-20170918183704-d01228ac9e50
go: finding honnef.co/go/tools latest
go: finding github.com/shurcooL/events latest
go: finding github.com/shurcooL/highlight_diff v0.0.0-20170515013008-09bb4053de1b
go: finding github.com/shurcooL/issues v0.0.0-20181008053335-6292fdc1e191
go: finding github.com/gregjones/httpcache latest
go: finding sourcegraph.com/sqs/pbtypes v0.0.0-20180604144634-d3ebe8f20ae4
go: finding github.com/neelance/sourcemap latest
go: finding github.com/shurcooL/httperror v0.0.0-20170206035902-86b7830d14cc
go: finding github.com/jellevandenhooff/dkim latest
go: finding github.com/shurcooL/htmlg latest
go: finding github.com/shurcooL/highlight_diff latest
go: finding github.com/shurcooL/github_flavored_markdown latest
go: finding golang.org/x/exp v0.0.0-20190121172915-509febef88a4
go: finding github.com/shurcooL/go latest
go: finding github.com/russross/blackfriday v1.5.2
go: finding github.com/shurcooL/issues latest
go: finding sourcegraph.com/sqs/pbtypes v1.0.0
go: finding github.com/shurcooL/httperror latest
go: finding github.com/prometheus/procfs latest
You can reproduce this by running go get -u
on https://github.com/xo/usql. What's more worrying, commands like go mod why github.com/shurcooL/httpgzip
report that the main module doesn't need all those packages.
After some manual digging, we ended up tracing this to the cloud.google.com/go
module: https://github.com/googleapis/google-cloud-go/blob/52299f000fab02ff521d180fd9f101ceb44d0f38/go.mod
And in particular, its requirement on the golang.org/x/build
module: https://github.com/golang/build/blob/ad59fb13d31575de611cdf1252fa3fbfd8f07794/go.mod
It's in that last go.mod
file where one can see over fifty third-party module requirements, counting // indirect
lines.
Now, I would understand that the module which sets up golang.org's CI infrastructure needs to have lots of dependencies. After all, it needs to do lots of work. And that would be fine, as long as extremely few packages required the x/build
module.
However, cloud.google.com/go
, and by extension many other popular modules like google.golang.org/grpc
and google.golang.org/api
, require x/build
. So any developer wishing to use Google Cloud with Go is forced to download dozens of third-party Go modules for no apparent reason. This can add up quickly even on a warm cache, as go get -u
needs to do much more work.
I do understand that, once module mirrors are widespread, we'll only have to download go.mod
files for these unnecessary modules, and not clone their entire git repositories. Still, I think it's bad design that cloud.google.com/go
is pulling so many module requirements, some of which are exclusively for frontend/JS coding.
I can imagine multiple solutions, besides leaving the situation as it is now:
- Actively discourage "library" modules from requiring
x/build
(thoughcloud.google.com/go
imports non-trivial chunks ofx/build
) - Split up the library-useful bits of
x/build
into a separate module - Gradually remove the third party dependencies of
x/build
, bringing it more in line with othergolang.org/x/...
repos
I realise I could have raised this issue against the google-cloud-go repository, but I think it's best to open it here first. Developers also tend to trust golang.org/x
repos, so I personally think it's reasonable of them to default to trusting x/build
.