Go Build Cache: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
Line 6: Line 6:


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>.
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 also specified by the <code>GOCACHE</code> environment variable, which can be printed with:
<span id='GOCACHE'></span>The location is also 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.




The cache can be cleaned with <code>[[Go_Tool#clean|go clean]]</code>.
=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]]?



Revision as of 23:15, 15 September 2023

Internal

Overview

The Go build cache is the filesystem storage 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.

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 also 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.