toolchain

package
v0.7.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 5, 2026 License: MIT Imports: 23 Imported by: 0

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

View Source
const GoDownloadBase = "https://go.dev/dl/"

GoDownloadBase is the official Go distribution site. Its JSON index publishes the SHA-256 of every archive.

View Source
const MinGoVersion = "1.26"

MinGoVersion is the oldest Go release that builds extensions: the go directive of extensions/sdk/go.mod. Builds run with GOTOOLCHAIN=local semantics, so an older go cannot switch to a newer release by itself.

Variables

View Source
var ContainerRuntimes = []string{"docker", "podman", "nerdctl"}

ContainerRuntimes lists the container engines PiG can drive, in preference order.

Functions

func ContainerRuntime

func ContainerRuntime() (name, path string, ok bool)

ContainerRuntime returns the first container engine found on PATH.

func Go

func Go() (string, error)

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

func ManagedGoRoot(configRoot string) string

ManagedGoRoot is the GOROOT of the PiG-managed Go toolchain.

func PythonExecutable

func PythonExecutable(goos string, lookPath func(string) (string, error)) string

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.

func SBCLExecutable

func SBCLExecutable(goos string, lookPath func(string) (string, error)) string

pig additive (D19): PiG runs Common Lisp extensions, which Pi does not, and every image build and launch resolves SBCL here.

SBCLExecutable returns the Steel Bank Common Lisp executable: PIG_SBCL when set, else the first of sbcl and sbcl.exe that lookPath finds. When none is found it returns the bare name, so the launch reports the missing toolchain.

func WorkDirEnv

func WorkDirEnv(dir string, environ []string) []string

WorkDirEnv returns environ with PWD naming dir, the working directory of a command started with an explicit environment. os/exec sets PWD for a command's Dir only when its Env is nil, so the command would otherwise inherit this process's PWD, which names another directory. The go command then takes the physical working directory, and a dir reached through a symbolic link (/tmp or /var on macOS) no longer matches the paths it was given, such as GOWORK and the go.work `use .` it names. Windows and Plan 9 do not use PWD.

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. A go on PATH older than MinGoVersion gives way to a PiG-managed toolchain that meets it. 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) BelowFloor

func (t GoToolchain) BelowFloor() bool

BelowFloor reports whether the installation is a known release older than MinGoVersion.

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) FloorRemedy

func (t GoToolchain) FloorRemedy() string

FloorRemedy is the one line that tells the user the go found is too old to build extensions and how to fix it.

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.

func (GoToolchain) Version

func (t GoToolchain) Version() string

Version is the release of the installation, read from its VERSION file, such as "go1.26.1". It is empty when the release cannot be read.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL