Preparing the build
The build is described by files the layer carries, under meta-yoke/kas/: one naming the layers the
build needs, each at the commit the layer is tested with, and what every image of it needs; one per
machine; and one per form. kas reads them, checks out the other layers beside the layer, writes the
build's configuration, and runs BitBake.
kas works in the directory it is run from, so the build gets a directory of its own, with the layer cloned into it:
mkdir ~/yoke-yocto
cd ~/yoke-yocto
git clone https://github.com/yoke-project/meta-yoke.git
The layer has one branch, main, for the Yocto Project's newest long-term series. A revision that
built once keeps building; to build one again later, check it out:
git -C meta-yoke checkout <revision>
Get kas 5.5, the version the files are written for.
- Locally
- In a container
This machine needs Python 3 and the packages the Yocto Project asks of a build host, listed for each distribution in its system requirements. On Debian or Ubuntu:
sudo apt install build-essential chrpath cpio debianutils diffstat file gawk gcc git iputils-ping \
libacl1 lz4 locales python3 python3-git python3-jinja2 python3-pexpect python3-pip python3-subunit \
python3-venv socat texinfo unzip wget xz-utils zstd
kas goes into an environment of its own, so that nothing else on the machine changes its version:
python3 -m venv ~/yoke-yocto/.kas
~/yoke-yocto/.kas/bin/pip install kas==5.5
export PATH="$HOME/yoke-yocto/.kas/bin:$PATH"
kas --version
kas 5.5 (configuration format version 23, earliest compatible version 1)
The export lasts as long as the shell; in a new one, type it again.
kas-container runs kas in the image its authors publish, with every package a build host needs, so
this machine needs Podman or Docker and nothing else. It is one script, taken at its version:
curl -fsSLo kas-container https://raw.githubusercontent.com/siemens/kas/5.5/kas-container
chmod +x kas-container
./kas-container --version
kas-container 5.5
It uses Docker when it finds it and Podman otherwise; KAS_CONTAINER_ENGINE=podman chooses Podman
where both are installed. Every kas command on the pages that follow is ./kas-container in this tab.
Where the build goes
kas builds in build/, beside the layers, unless KAS_BUILD_DIR names another directory. Naming it
lets one checkout of the layers serve several builds, each in a directory of its own — one per machine,
say. Two more variables say where a build keeps what it downloads, DL_DIR, and what it has built
and can take again instead of building it, the shared state, SSTATE_DIR; left unset, both go inside
the build's directory, and a second build starts from nothing. Set all three in the shell, before kas
runs, as absolute paths:
export KAS_BUILD_DIR="$HOME/yoke-yocto/build-qemux86-64"
export DL_DIR="$HOME/yoke-yocto/downloads"
export SSTATE_DIR="$HOME/yoke-yocto/sstate-cache"
The exports last as long as the shell, and every kas command on the pages that follow reads them; in a
new shell, type them again, with the build directory of the build you are working on. kas-container
reads the same three, creates the directories if they do not exist, and makes them visible in its
container.
Check the other layers out, at their commits, with the machine you will build for — QEMU's 64-bit x86 machine here; the machine changes nothing of what is checked out:
- Locally
- In a container
kas checkout meta-yoke/kas/qemux86-64.yml
./kas-container checkout meta-yoke/kas/qemux86-64.yml
~/yoke-yocto/
├── meta-yoke/ the layer
├── bitbake/ BitBake, at its commit
├── openembedded-core/ the core layer, at its commit
├── meta-openembedded/ meta-oe and meta-python, at their commit
├── build-qemux86-64/ the build: its configuration, and what it builds
├── downloads/ what every build downloads
└── sstate-cache/ what every build has built
When you expect more than one build
The shared state is what makes a second build short. BitBake signs every task with what goes into
it — the recipe, its sources, the configuration that reaches it — and takes the task's output from
SSTATE_DIR when a task with the same signature was built before, by any build that shares the
directory. A few habits keep it working for you:
-
One build directory per machine, one download and one shared-state directory for all of them. The two forms of a machine share its build directory: they are two images of the same packages. A build directory can then be deleted whenever it is in the way; the next build in it takes back from the shared state everything that has not changed.
-
What a machine of another architecture shares is the tools. The compilers and the other programs that run on this machine are built once and taken by every build; the packages for the device are built again for each architecture, and shared between machines of the same one.
-
One build at a time. Two builds that share the directories may run together, but each takes all the processors and a great deal of memory; side by side, they finish later than one after the other.
-
Keep the directories on a disk, with room. A first build of a machine takes tens of gigabytes, most of them in the shared state, which only grows; never on a file system kept in memory, such as
/tmpon many distributions. -
Trim the shared state to what your builds use, when it grows too large: the core layer carries the script that keeps what the named build directories used last, and removes the rest. Run it with
-nfirst, which only says what it would remove:python3 openembedded-core/scripts/sstate-cache-management.py --cache-dir "$SSTATE_DIR" \--stamps-dir "$HOME/yoke-yocto/build-qemux86-64/tmp/stamps" \--stamps-dir "$HOME/yoke-yocto/build-raspberrypi5/tmp/stamps" -nand again with
-yin place of-nto remove them. A build directory not named loses what only it used.