Part VI. The build foundation
This part covers 30_foundation, the phase that installs the tools and libraries every later recipe builds with. Read it if you are following the build phase by phase, or if a port fails because a build tool or base library it expected is missing or behaves differently than you assumed.
The phase installs:
- the build systems: make, pkgconf, the autotools, CMake, Meson and Ninja;
- Perl and Python, with the modules their build backends need;
- the documentation tools;
- the base libraries for compression, TLS, networking, XML and text;
- the system’s own foundation: init, the device manager, accounts and login records.
It also rebuilds, as full packages, the rest of the userland the bootstrap installed by hand.
The sections below explain the pinned run that opens the phase’s list and why its order matters, the points at which the build environment changes during the phase, and what the phase provides, grouped by what a later recipe gets from it. The package pages follow, in chapters by shelf (a shelf is the category directory a port lives in, ports/core/<shelf>/<name>/), in the shelves’ own order, and within a shelf in the order kpkgdepends builds them.
One question decides the phase
30_foundation and Part VII’s 31_compilers together install everything needed to rebuild KDOS from KDOS. They are split by one question: does a port need one of the large compilers? A port goes here when nothing in its dependency closure does. The list’s own header says so:
#
# The build systems, interpreters and base libraries every later recipe builds
# with: make, pkgconf, the autotools, cmake, meson and ninja, perl and python3,
# and the archive, TLS and documentation tooling. Nothing here needs a compiler
# from 31_compilers.
#
# This list names every port the phase installs and nothing it does not;
# testing/phaseclosure.py fails when a dependency pulls a port in from outside
# it, or when a shelf section names a port an earlier phase installs.
script/phases/30_foundation/packages.txt, lines 12–20
The check is testing/phaseclosure.py, which preflight runs. It fails when a dependency pulls a port into the phase that the list does not name, and when a shelf heading names a port an earlier phase installs (see Every phase installs exactly its list).
The environment
The phase’s environment is chroot.env with one line added before it, in script/phases/30_foundation/phase.env, after the CHROOT=1 every chroot phase sets:
export CHROOT=1
export LD_LIBRARY_PATH="/usr/lib:/usr/local/lib:/usr/lib64:/usr/local/lib64"${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}
source "${BASH_SOURCE[0]%/*}/../../env/chroot.env"
script/phases/30_foundation/phase.env, lines 23–27
The LD_LIBRARY_PATH line gives the dynamic loader /usr/lib, /usr/local/lib, /usr/lib64 and /usr/local/lib64 to search, followed by whatever the variable already held.
Unlike 20_selfhost, this phase keeps chroot.env’s CC=gcc and CXX=g++. From here on every port is compiled by the gcc package that Part V installed. How the environment reaches each step is in The phase environment.
The pinned run
The list opens with names written ahead of the first shelf heading. They are the phase’s pinned run: ports that must be installed, in this order, before anything else in the phase is built.
# FIRST, AND IN THIS ORDER. These are the build tools recipes reach for without
# naming them in `depends`: a configure script calls pkg-config through
# PKG_CHECK_MODULES, a build.sh runs autoreconf, meson or cmake, and libtool's
# configure runs `file` on a test object to learn its ABI. muon is the
# meson that builds pkgconf: it bootstraps with a C compiler alone, so it is
# installed before any pkg-config exists. Listed ahead
# of every shelf section, they are installed before anything else in the phase,
# in the order kpkgdepends gives this run; bash and GNU coreutils, grep, which
# and musl-utils (getconf, getent, iconv) are the shell and the userland every
# build.sh runs in. fortify-headers, musl, gcc, binutils and m4 are
# 20_selfhost's; naming them here rebuilds one whose recipe changed before
# anything uses it. Under `kdosbuild --port-jobs` this run is the phase's
# serial prefix: it builds one port at a time, and nothing after it starts
# until its last port is installed.
fortify-headers
musl
gcc
binutils
make
file
muon
pkgconf
libtool
autoconf
automake
m4
bison
flex
cmake
meson
ninja
python3
perl
bash
coreutils
grep
which
musl-utils
# 20_selfhost's other ports, so one whose recipe changed rebuilds before the
# shelf sections use it. zlib, ncurses and readline are gcc's and python3's
# dependencies and rebuild ahead of them whatever this list says.
tar
diffutils
gawk
ncurses
readline
zlib
script/phases/30_foundation/packages.txt, lines 22–69
They come first because recipes use them without naming them in depends. A configure script calls pkg-config through PKG_CHECK_MODULES; a build.sh runs autoreconf, meson or cmake; libtool’s configure runs file on a test object to learn its ABI; and every build.sh runs in bash with the GNU userland. A port further down the list that needs one of them finds it installed, whatever its depends line says.
Three properties of the run matter when it is read:
It is serial. Under kdosbuild --port-jobs, the run is the phase’s serial prefix: it builds one port at a time, and nothing after it starts until its last port is installed (see Building a package phase by level).
It brings its dependencies with it. kpkgdepends puts each port’s dependencies ahead of it, so the run’s names install far more than themselves. file depends on zlib, bzip2, xz, zstd and libseccomp; python3 on, among others, libffi, mpdecimal, SQLite, Expat, OpenSSL, gdbm and util-linux; CMake on OpenSSL, nghttp2, libarchive, libuv and python3-sphinx, because its configure is given --sphinx-man and builds its manual pages with Sphinx.
Most of the compression and TLS libraries, the whole Python packaging chain under Sphinx, util-linux and utmps are therefore built inside the run, before any shelf section starts. The package pages follow this order: each page sits where its port is actually built in the resolved order, not where the list names it.
It re-lists earlier ports. fortify-headers, musl, gcc, binutils, m4, tar, diffutils, gawk, ncurses, readline and zlib were installed by 20_selfhost. A name an earlier phase installed from the same recipe is skipped, so on an unchanged tree they cost nothing. When one of their recipes has changed, the port rebuilds at this point, before anything in the phase uses it. A re-list (naming a port an earlier phase already installs) is allowed only in a pinned run; under a shelf heading it fails the closure check.
Two ports of the run need a word of their own:
- pkgconf is configured and built with muon, an implementation of Meson in C whose
bootstrap.shneeds only a C compiler. That lets muon be built before anypkg-configexists. pkgconf’sdependsnames muon, and muon’s names scdoc, so both are installed ahead of pkgconf. - bash is built here as a package for the first time: no phase before this one lists it. The port installs
bashand itsshlink over the copies the bootstrap left in/usr/bin(/binis a link tousr/bin), and from then on owns them.
When the environment changes
Two blocks of script/env/chroot.env check whether a program is installed. Every step sources chroot.env afresh, so the phase’s environment changes part-way through, at the first step after each program is installed:
- Ninja. Once ninja has installed
/usr/bin/ninja, every later step hasscript/binfirst onPATH. That directory holds two wrappers:- its
ninjaadds-j$KDOS_JOBSto a call that names no job count (or, when the build shares a jobserver, hands ninja the jobserver instead), then runs/usr/bin/ninja; - its
mesonadds--wrap-mode=nodownloadto everymeson setupthat chooses no wrap mode, so a subproject the source does not carry fails the configure by name instead of reaching for the network. Until the meson port is installed, it answers as a missing command.
PATH: aninjawrapper with no/usr/bin/ninjabehind it would make a configure probe pick a generator that cannot run. - its
- ccache. Once ccache is installed, every later CMake project is compiled through it, by way of
CMAKE_C_COMPILER_LAUNCHERandCMAKE_CXX_COMPILER_LAUNCHER, with its cache inbuild/ccache. CMake projects built before it, CMake itself among them, are compiled directly. SettingKDOS_CCACHE=0turns the cache off for the whole build. What the cache keys on and why a hit is byte-identical are in The compiler cache.
What the phase provides
After the pinned run, the list is written in sections, one per shelf, each under a heading of the form # <shelf> — <description>. The groups below cut across those shelves by what a later recipe gets from them.
Build systems and build helpers
make, file, muon, pkgconf, libtool, autoconf, automake, m4, bison, flex, CMake, Meson and Ninja, from the pinned run; ccache, intltool and itstool from the buildtools shelf; and from toolchain, the assemblers yasm and nasm, the generators swig and gperf, and the ELF tools elfutils and patchelf.
Perl, Python and Lua
perl and python3 come from the pinned run. The other shelves add:
python: the build backends a Python port’spyproject.tomlnames (setuptools, pip, flit-core, packaging, setuptools-scm, poetry-core, hatchling) and the modules they need.python-libs: Pygments, docutils, MarkupSafe, Jinja2, PyYAML and Sphinx, which documentation builds run. Jinja2 is also here because some C projects generate source from Jinja templates at build time; the list’s own comment names libplacebo’s shaders.perl-cpan: perl-xml-parser, which intltool needs, with the modules it builds on.lang: lua (5.5) and lua54 (5.4), installed side by side with every path of the second one versioned, plus the fourlua54-*modules without which Prosody does not start.
The documentation toolchain
The doctools shelf: texinfo for info manuals, mandoc, which reads the manual pages on the image, help2man, doxygen, asciidoc, xmlto with docbook-xml, docbook-xsl and sgml-common, and scdoc. With libxml2 and libxslt from formats, and Sphinx above, these are the tools a port’s own documentation build calls. Their absence is not always survivable: the list’s comment on help2man notes that a Makefile rule piping $(PROG) --help into it exits 127 when it is missing, and takes the build with it.
Init, devices, accounts and login records
The base and auth shelves hold the system’s foundation:
- sysvinit, PID 1 and the commands that talk to it;
- skalibs and utmps, the utmp and wtmp service over musl; coreutils, sysvinit, util-linux and shadow are built against utmps, which the pinned run installs ahead of all four;
- util-linux, kmod and eudev, the device manager, which depends on both;
- shadow, the account tools, configured
--with-acland linked against utmps; - the libraries they link from
base-libs: attr, acl, libcap, libcap-ng and libffi, and libseccomp fromcontainers; - ca-certificates, the certificate store TLS clients read; cyrus-sasl, the SASL mechanism loader, client side only; and openldap, whose
libldapserves curl’sldap://URLs and dirmngr’s directory lookups.
What these are on a running system is in Boot and init, and why utmps is required of every reader and writer of the login records is in Login records.
The rest of the bootstrap’s userland
The bootstrap installed a minimal userland by hand. 20_selfhost rebuilt part of it (tar, diffutils, gawk, m4 and the toolchain); this phase rebuilds the rest as ports: coreutils, grep, bash and make from the pinned run; patch, findutils, sed and gzip from the base shelf; and xz from the archiver shelf. Each port installs over the bootstrap’s files and adopts them, and several gain what the bootstrap build left out: coreutils is built against ACLs, extended attributes, libcap and utmps, and grep with --enable-perl-regexp against PCRE2. which, less and bc join them as programs the bootstrap did not have. The base userland says which package owns each command-line name and gives the constraints on coreutils’ configure line.
The musl shims
musl leaves out some interfaces that glibc carries and that ports expect, and these ports supply them as libraries of their own:
| Port | What it supplies |
|---|---|
| libintl | The gettext runtime, libintl: musl does not carry it in libc, and the gettext port is built --disable-nls |
| argp-standalone | glibc’s argp argument parser |
| musl-fts | fts(3), the file-tree walk |
| musl-obstack | glibc’s obstack allocator |
| musl-rpmatch | rpmatch(3), the yes/no answer matcher |
| musl-utils | The getconf, getent and iconv programs, from Alpine’s musl package, which musl’s own source does not carry |
elfutils depends on argp-standalone, musl-fts, musl-obstack and musl-rpmatch. musl-utils is in the pinned run, with the rest of the userland every build.sh runs in.
Libraries
The remaining sections install the libraries a large part of the tree links: compression and archives (bzip2, xz, lz4, zstd, LZO, libarchive, Brotli), cryptography (OpenSSL, with openssl3 beside it as a runtime-only second version), networking (nghttp2, ngtcp2, nghttp3, libidn2, libpsl, libssh2, curl, libuv, c-ares), formats and text (Expat, libyaml, libxml2, libxslt, PCRE2), databases (gdbm, SQLite), internationalisation (libunistring, gettext, ICU) and mpdecimal, which Python’s _decimal module links. The vcs shelf adds git, and libgit2, which cargo and cargo-c link in 31_compilers and which every Rust port’s git2 crate would otherwise compile from a bundled copy.
How two versions of one library live side by side, as openssl3 and lua54 do, is in A second version beside the first.
When the phase is over
When the phase finishes:
- Every program a bootstrap step installed has been built again as a port, except kpkg and kinstall, which no phase rebuilds. The Linux API headers wait for the
linuxport of60_kernel. - The tree can configure, compile and document a project in any of the common build systems, with the C, C++ and Fortran compilers of
20_selfhost. - It has no LLVM, no Rust, no Go and no Haskell yet; Part VII adds them.
Snapshots are off by default. In a run that writes them (kdosbuild --snapshot, or S in the startup picker), the phase’s snapshot is the restore point in front of Part VII: a failure among the compilers restores this tree instead of building this phase again (see Snapshots).
See also
- The foundation and the compilers: both phases in the whole journey
- Package lists: pinned runs and shelf headings
- Part V: the ports this phase re-lists
- Reading a package page: how the pages below are laid out
- Part VII: the next phase