Skip to main content
Version: 0.17.0

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

Stay where you are. Every command of this path runs from ~/yoke-yocto, the build's directory, beside the layer and never inside it: kas is given the layer's files by their path from here, meta-yoke/kas/…, and checks the other layers out next to it.

The layer has one branch, main, for the Yocto Project's newest long-term series, and no versions of its own: the clone takes its newest revision, which is the one to build. To take a newer one later, pull it — Upgrading is that step:

git -C meta-yoke pull

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.

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.

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, the build's directory named after the machine you build for.

First name the machine. machine=… is no command, and prints nothing: it gives a variable of the shell a value, which the commands after it read as $machine. Like the exports below, it lasts as long as the shell; in a new one, type it again. The next page names the form and its image the same way.

machine=qemux86-64

QEMU's 64-bit x86 machine; qemuarm64 is the 64-bit Arm one, and builds the same way.

export KAS_BUILD_DIR="$HOME/yoke-yocto/build-$machine"
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 file of the machine you will build for — a board's file adds the board's support layer to the ones every build needs:

kas checkout meta-yoke/kas/$machine.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 /tmp on many distributions.

  • Trim the shared state to what your builds use, when it grows too large. Not now: there is nothing to trim before a build, and this is a habit for later. The core layer carries the script that keeps what the named build directories used last, and removes the rest; name only build directories that have built, since the script stops on one with no tmp/stamps/ yet. With the two machines below built, run it with -n first, 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" -n

    and again with -y in place of -n to remove them. A build directory not named loses what only it used.