Go Build Cache: Difference between revisions
(7 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
=Internal= | =Internal= | ||
* [[Go_Language#Build_Cache|Go Language]] | * [[Go_Language#Build_Cache|Go Language]] | ||
* [[Go_Modules#Module_Cache|Module Cache]] | |||
=Overview= | =Overview= | ||
The Go build cache is | The Go build cache is a filesystem storage area used by the Go compiler to store source file hashes and object files produced by builds. This data allows the Go compiler to implement [[Go_Language#Incremental_Builds|incremental builds]]. The build cache is different from the [[Go_Modules#Module_Cache|module cache]], which stores module source code and metadata. | ||
On a Mac, the build cache resides under <code>/Users/<user-name>/Library/Cache/go-build</code>, where <code>/Users/<user-name>/Library/Cache</code> is the standard user cache directory for MacOS. On a Linux system, it is <code>~/.cache/go/go-build</code>. <span id='GOCACHE'></span>The location is specified by the <code>GOCACHE</code> environment variable, which can be printed with: | |||
<font size=-1> | <font size=-1> | ||
go env GOCACHE | go env GOCACHE | ||
</font> | </font> | ||
The cache can be cleaned with <code>[[Go_Tool#clean|go clean]]</code>. | |||
=Structure= | |||
The <code>go-buid</code> folder contains 256 subfolders named after hexadecimal strings from 00 to FF. These subfolders store intermediate files, which allows the compiler to parallelize the compilation process by handling different files in different folders. The Go compiler divides the source code into '''chunks'''. Each chunk is compiled into separated folders. The name of each file is given thy the SHA-256 hash code of the source code of the relative chunk. The hash function takes the source code chunk as input and produces a unique output. The files with an <code>-a</code> suffix are used to store compiled object files. The files with an <code>-d</code> suffix are intended for storage of debugging information. | |||
=Organizatorium= | |||
<font color=darkkhaki>What is the relationship with the [[Go_Modules#Module_Cache|module cache]]? | <font color=darkkhaki>What is the relationship with the [[Go_Modules#Module_Cache|module cache]]? | ||
Latest revision as of 21:32, 8 December 2023
Internal
Overview
The Go build cache is a filesystem storage area used by the Go compiler to store source file hashes and object files produced by builds. This data allows the Go compiler to implement incremental builds. The build cache is different from the module cache, which stores module source code and metadata.
On a Mac, the build cache resides under /Users/<user-name>/Library/Cache/go-build
, where /Users/<user-name>/Library/Cache
is the standard user cache directory for MacOS. On a Linux system, it is ~/.cache/go/go-build
. The location is specified by the GOCACHE
environment variable, which can be printed with:
go env GOCACHE
The cache can be cleaned with go clean
.
Structure
The go-buid
folder contains 256 subfolders named after hexadecimal strings from 00 to FF. These subfolders store intermediate files, which allows the compiler to parallelize the compilation process by handling different files in different folders. The Go compiler divides the source code into chunks. Each chunk is compiled into separated folders. The name of each file is given thy the SHA-256 hash code of the source code of the relative chunk. The hash function takes the source code chunk as input and produces a unique output. The files with an -a
suffix are used to store compiled object files. The files with an -d
suffix are intended for storage of debugging information.
Organizatorium
What is the relationship with the module cache?
Fuzz Cache
Can be cleaned with go clean -fuzzcache
.