Skip to the text
KDOS
Menu
kdos.dev KDOS from Scratch KDOS 0.2 · 4dd4a10 · 2026-11-30 Contents Index

62.4. go-1.27.2

The Go programming language toolchain (with bootstrap)

Version 1.27.2, release 2
Shelf lang — Language implementations, plus the modules of any language that has no module shelf of its own
Phase 31_compilers (Compilers), 18 of 22 in build order
Licence BSD-3-Clause
Homepage https://go.dev/
Build time 2.2 SBU
Installed size 226.6 MiB in 7843 files
Recipe ports/core/lang/go/kpkgbuild

About

This port is the Go toolchain: the go command, gofmt, the compiler, linker and assembler under pkg/tool, and the standard library as source. Many ports are Go programs built with it, among them podman, buildah and skopeo, syncthing, restic, rclone, gh, git-lfs, fzf, caddy, esbuild and the language server gopls, and chromium needs it to build. How a Go port is written, and which flags every Go build in the tree gets, is in go.

Go’s compiler is written in Go, so the build starts from upstream’s prebuilt linux-amd64 release, the second source = line, which unpacks beside the source as $SRC_ROOT/go. That release is a bootstrap seed: make.bash compiles the new toolchain with it, and nothing of the seed is installed. The tree’s list of seeds is in Bootstrap seeds.

The toolchain is installed whole into /usr/lib/go, which is its GOROOT, with go and gofmt linked into /usr/bin. The go command finds its GOROOT from the path of its own executable, so the links in /usr/bin reach the tree under /usr/lib/go.

Sources

Dependencies

Depends on: bash, gcc.

Required by (43): aerc, age, buildah, caddy, chezmoi, chromium, croc, direnv, doggo, duf, esbuild, fx, fzf, gh, git-lfs, glow, go-md2man, go-pmtiles, gocryptfs, gopls, ipp-usb, lazydocker, lazygit, lf, maddy, micro, miller, pat, podman, podman-tui, rclone, restic, seqkit, shfmt, skopeo, step-ca, step-cli, syncthing, termshark, typescript-go, uosc, usql, yq.

Patches

build.sh applies these; kpkg applies nothing by itself.

Installation

From the repository root, inside the build container, this is the line kdosbuild runs for the port:

script/chroot/exec.sh bash -c 'source script/phases/31_compilers/phase.env && kpkg install go'

What kpkg does

kpkg runs these steps, in this order, as root inside the chroot. The port directory is /ports/core/lang/go.

1. Verify every declared source. Each file a sha256 = line names, found in the port directory or in /var/cache/kpkg/sources, must hash to its line; a mismatch stops the build before anything is unpacked.

cd /ports/core/lang/go
echo '03495da2ba64894d40f5c4992e49454fa78b50690604ff92b6afff5081b76e62  go-1.27.2.tar.gz' | sha256sum -c -
echo '00859d7bd6defe8bf84d9db9e57b9a4467b2887c18cd93ae7460e713db774bc1  go1.25.9.linux-amd64.tar.gz' | sha256sum -c -

2. Unpack. The work directory is emptied and the first source is unpacked into $SRC with its top directory stripped; any later tarball lands unstripped beside it in $SRC_ROOT, and a file that is not a tarball is copied into $SRC.

SRC_ROOT=/var/cache/kpkg/work/go
SRC=$SRC_ROOT/go-1.27.2
PKG=$SRC_ROOT/pkg
rm -rf "$SRC_ROOT"
mkdir -p "$SRC" "$PKG"
tar --no-same-permissions --warning=no-unknown-keyword -xf go-1.27.2.tar.gz -C "$SRC" --strip-components=1
tar --no-same-permissions --warning=no-unknown-keyword -xf go1.25.9.linux-amd64.tar.gz -C "$SRC_ROOT"

Every config.guess and config.sub older than automake’s is then replaced with automake’s, so a configure script recognises the musl target.

3. Build. build.sh is sourced in a subshell under set -e, from $SRC, with name, version, release and the recipe’s helpers _bootstrap, _arch and the five paths PKGNAME, PORT_SRC, SRC_ROOT, SRC and PKG set as shell variables. Its body, verbatim:

patch -p1 --no-backup-if-mismatch -i "$PORT_SRC/go-env-toolchain-local.patch"

cd src
export GOROOT_BOOTSTRAP="$SRC_ROOT/go"
export GOROOT_FINAL=/usr/lib/go
export GOOS=linux GOARCH=amd64
export CGO_ENABLED=1
export GO_LDFLAGS=-buildmode=pie

./make.bash

cd ..
install -d $PKG/usr/lib/go
cp -a bin pkg src lib api $PKG/usr/lib/go/
install -m644 go.env VERSION -t $PKG/usr/lib/go/
[ -d misc ] && cp -a misc $PKG/usr/lib/go/

find $PKG/usr/lib/go/src/runtime/race $PKG/usr/lib/go/src/crypto/internal/boring/syso \
	-name '*.syso' -delete
rm -rf $PKG/usr/lib/go/pkg/obj
find $PKG/usr/lib/go/src -type d -name testdata -prune -exec rm -rf {} +
rm -f $PKG/usr/lib/go/src/*.rc
install -d $PKG/usr/bin
ln -s /usr/lib/go/bin/go $PKG/usr/bin/go
ln -s /usr/lib/go/bin/gofmt $PKG/usr/bin/gofmt

The switches, and why each is set:

The common switches of each build system are explained in the Flag glossary.

4. Package. kpkg removes libtool archives, the info directory index, mimeinfo.cache and every fonts.dir from $PKG, copies the source’s licence files into /usr/share/licenses/go, prunes what the image does not ship, lints the tree and rolls it reproducibly:

tar --sort=name --format=gnu --numeric-owner --owner=0 --group=0 \
    --mtime=@$SOURCE_DATE_EPOCH \
    --use-compress-program='xz -9 -T0 --block-size=32MiB --no-adjust' \
    -cf go-1.27.2-2.tar.xz -C "$PKG" .

5. Adopt. kpkgadd installs the package’s files over the root, refusing a path another package owns, records the file list in /var/lib/kpkg/db/go, and runs the triggers its paths call for.

Contents

Installed programs: go, gofmt.

Installed directories: /usr/lib/go, /usr/share/licenses/go.

Notes

cp -a bin pkg src lib api does not copy the files at the top of the source tree, so go.env and VERSION are installed by name after it. Without go.env in GOROOT, the patch above would not reach the installed system.

The source archive carries object files that upstream compiled and that no step here rebuilds: the race detector’s runtime under src/runtime/race and the BoringCrypto module under src/crypto/internal/boring/syso. The find ... -delete removes them from the package, so go build -race and GOEXPERIMENT=boringcrypto fail to link on KDOS; the rule this follows is in What is built from source. pkg/obj is make.bash’s scratch directory and is removed as well, and so is every testdata directory under src, which only go test std reads, and the Plan 9 build scripts src/*.rc.