golang / go

The Go programming language
https://go.dev
BSD 3-Clause "New" or "Revised" License
124.1k stars 17.68k forks source link

proposal: cmd/go: allow disabling build cache trimming #69565

Open rittneje opened 1 month ago

rittneje commented 1 month ago

Proposal Details

We have our own docker image containing our Go toolchain. As an optimization, we also pre-compile the standard library (go build std) so that it is in the gocache.

Evidently, the various Go tools will trim the cache upon exit. In particular, they will delete any files in the cache that have not been modified in the last five days. While this may be reasonable for a cache on someone's host machine, it does not make sense for a short-lived container using a cache from its image, since the mtimes will all reflect when the image was built. At best, it trimming the cache is pointless because the container will be destroyed shortly, and at worst is actively counterproductive as those cached files may be used by subsequent commands.

Please add an environment variable to disable trimming the gocache upon command exit. The specific name is immaterial, but something like GOCACHE_AUTO_TRIM=0 would be fine.

gabyhelp commented 1 month ago

Related Issues and Documentation

(Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.)

ianlancetaylor commented 1 month ago

CC @matloob

matloob commented 1 month ago

I don't know if this justifies its own environment variable (that would show up in go env, etc.) but maybe we can make it an undocumented # godebug setting?

rittneje commented 1 month ago

@matloob If you mean something we can set via the GODEBUG environment variable, that would also be acceptable. We just need something we can easily configure globally in the base image.

matloob commented 1 month ago

Yes. That is what I mean.