-
Notifications
You must be signed in to change notification settings - Fork 17.9k
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
proposal: cmd/go, cmd/distpack: build and run tools that are not necessary for builds as needed and don't include in binary distribution #71867
Comments
I agree with the overall goal of this issue, but I wanted to note that currently
Perhaps it is enough to rewrite the |
Does it need to change to |
@seankhliao if the path gets changed to point to a cached binary I guess that would also be fine, but that would be a pretty long and random path, and it wouldn't work if the cache isn't warm - for example if it gets cleaned up manually or after a few days. I would personally prefer the shorter form; it will reproduce the build faithfully as long as none of the inputs like the source code is changed. I don't have a strong opinion here, but @matloob personally, out of all the tools you list, I've only ever run
Could you clarify whether the source for these tools would still be shipped? That is, that the first invocation of e.g. If that's the case, wouldn't changing a tool's source code cause |
@mvdan The |
@mvdan Yes, to preserve the ability to run scripts produced by go build -x, we should list
Yes, the source for the tools would still be shipped in GOROOT. The invocation of the tool wouldn't download anything.
If we default to running a tool that's present in |
Proposal Details
This proposal is to stop including tools that are not needed for builds in the binary distribution. Instead the tools would be built and run as needed by
go tool
using a similar mechanism to that used to build and run tools declared with atool
directive ingo.mod
. The goal of this proposal is to reduce the go binary distribution size.In cmd/distpack, we should be able to discard the following tools before packaging the binary distribution:
addr2line
,buildid
,nm
,objdump
,pprof
,test2json
, andtrace
. These tools do not seem to be invoked by the go command. We could go a little further and also removedoc
andfix
too because they are only invoked bygo doc
andgo fix
respectively.The install target for main packages in cmd will not change, so
go install
will continue to install binaries to$GOROOT/pkg/tool/$GOOS_$GOARCH
.If a tool binary is present in that location, it will be run from there, but if not, the go command will fall back to building (if the tool binary isn't cached) and running the tool, similarly to how
go tool
builds and runs tools declared with thetool
directive.Potential issues we should watch out for and which I would be interested in hearing feedback about:
go tool
to run it may be surprised that the tool that's run doesn't include their changes. So we may want to think a little more about what to do in that case.go test
andgo run
wouldn't work on either.cc @dmitshur
The text was updated successfully, but these errors were encountered: