Documentation
¶
Overview ¶
Package toolchain locates the build tools PiG uses for compiled extension cells and Piglet Binaries, and installs a PiG-managed Go toolchain for users who installed only the pig binary.
Index ¶
- Constants
- Variables
- func ConfigRoot() (string, error)
- func ContainerRuntime() (name, path string, ok bool)
- func Go() (string, error)
- func InstallGo(ctx context.Context, client *http.Client, ...) (string, error)
- func ManagedGoRoot(configRoot string) string
- func PythonExecutable(goos string, lookPath func(string) (string, error)) string
- type GoToolchain
Constants ¶
const GoDownloadBase = "https://go.dev/dl/"
GoDownloadBase is the official Go distribution site. Its JSON index publishes the SHA-256 of every archive.
Variables ¶
var ContainerRuntimes = []string{"docker", "podman", "nerdctl"}
ContainerRuntimes lists the container engines PiG can drive, in preference order.
Functions ¶
func ConfigRoot ¶
ConfigRoot is the PiG configuration root: $PIG_HOME, else $XDG_CONFIG_HOME/pig, else ~/.pig, with a leading ~ expanded. It mirrors codingagent.ConfigRoot, which imports this package.
func ContainerRuntime ¶
ContainerRuntime returns the first container engine found on PATH.
func Go ¶
Go returns the go command to run: the one on PATH, else the PiG-managed toolchain. The error names both places it looked and the setup command. A caller that runs the command must also use ResolveGo's Environ, so the command and its GOROOT come from one installation.
func InstallGo ¶
func InstallGo(ctx context.Context, client *http.Client, base, version, goos, goarch, configRoot string) (string, error)
InstallGo downloads the Go archive for version, goos, and goarch from base, verifies its size and the SHA-256 published in the index, and replaces the managed toolchain under configRoot. It returns the installed go command.
func ManagedGoRoot ¶
ManagedGoRoot is the GOROOT of the PiG-managed Go toolchain.
func PythonExecutable ¶
pig additive (D19): PiG runs Python extensions, which Pi does not, and every launch and packed-cell key resolves the interpreter here.
PythonExecutable returns the Python interpreter for goos: the first of python and python3 on Windows, or python3 elsewhere, that lookPath finds. On Windows a clean profile resolves python.exe to the Microsoft Store app-execution alias, a shim that opens the Store instead of running Python, so a real interpreter later in the candidate list wins. The alias is the last resort because, once the Store package is installed, the same path is a working Python. When no candidate is found it returns the bare first candidate name, so the launch reports the missing interpreter.
Types ¶
type GoToolchain ¶
type GoToolchain struct {
// Command is the go executable to run.
Command string
// Root is the GOROOT of the installation Command belongs to. It is empty when
// the command could not report it; the command then finds its own root.
Root string
}
pig additive (D20): PiG compiles extensions, which Pi does not, and resolves one Go toolchain for every build.
GoToolchain is one Go installation: a go command and the GOROOT it belongs to. Every build in a PiG process runs with exactly this pair. The go command compiles with the tools of whichever GOROOT it is given, and refuses tools of another release (`compile: version "go1.26.7" does not match go tool version "go1.26.1"`), so the pair must never come from two different selections.
func ResolveGo ¶
func ResolveGo() (GoToolchain, error)
ResolveGo selects the Go installation for builds: the go command on PATH, else the PiG-managed toolchain. It resolves once per selection and process, so concurrent extension builds cannot pick different installations. Nothing is run when the command lives inside its own installation, which is the case for a release archive, Homebrew and every version manager's real install. A shim or a distribution binary outside its GOROOT is asked where its root is, with the inherited GOROOT removed, so the answer describes that command rather than an environment left by another selection.
func (GoToolchain) Environ ¶
func (t GoToolchain) Environ(environ []string) []string
Environ returns environ with GOROOT set to this installation, replacing any inherited value. An inherited GOROOT that names another installation is the source of the release mismatch above: version managers such as mise export GOROOT for the project directory a shell is in, while the go command found on PATH can belong to another version.
func (GoToolchain) ReleaseMismatch ¶
func (t GoToolchain) ReleaseMismatch(output []byte) (string, bool)
ReleaseMismatch reports a go build that ran the compiler of one Go release under the go command of another. It returns one line naming both releases and the fix.