DeveloperWiki:Building in a clean chroot

Why

Building in a clean chroot prevents missing dependencies in packages, whether due to unwanted linking or packages missing in the depends array in the PKGBUILD. It also allows users to build a package for the stable repositories (core, extra, community) while having packages from [testing] installed.

Convenience way

To quickly build a package in a clean chroot without any further tinkering, one can use the helper scripts from the devtools package.

These helper scripts should be called in the same directory where the PKGBUILD is, just like with makepkg. For instance, extra-x86_64-build automatically sets up a chroot from a clean chroot matrix in /var/lib/archbuild, updates it, and builds a package for the extra repository. For multilib builds there is just multilib-build without an architecture. Consult the table below for information on which script to use when building for a specific repository and architecture.

The -c parameter resets the chroot matrix, which can be useful in case of breakage. It is not needed for building in a clean chroot.

Note: [core] is omitted because those packages are required to go through [testing] first before landing in [core].
Note: If the objective is to build a [core] package for your own local usage, it may be desirable to use the stable repositories instead of the testing. In this case you may simply use the extra build scripts.
Target repositoryArchitectureBuild script to usePacman configuration file used
extra / communityx86_64extra-x86_64-build/usr/share/devtools/pacman-extra.conf
testing / community-testingx86_64testing-x86_64-build/usr/share/devtools/pacman-testing.conf
staging / community-stagingx86_64staging-x86_64-build/usr/share/devtools/pacman-staging.conf
multilibx86_64multilib-build/usr/share/devtools/pacman-multilib.conf
multilib-testingx86_64multilib-testing-build/usr/share/devtools/pacman-multilib-testing.conf
multilib-stagingx86_64multilib-staging-build/usr/share/devtools/pacman-multilib-staging.conf

Classic way

Setting up a chroot

The devtools package provides tools for creating and building within clean chroots. Install it if not done already.

To make a clean chroot, create a directory in which the chroot will reside. For example, $HOME/chroot.

$ mkdir ~/chroot

Define the CHROOT variable:

$ CHROOT=$HOME/chroot

Now create the chroot (the sub directory root is required because the directory will get other sub directories for clean working copies):

$ mkarchroot $CHROOT/root base-devel

Edit to set the packager name and any makeflags. Also adjust the mirrorlist in and enable the testing repository in , if desired.

Note: The ~ and $HOME variable are resolved to /root/ by the makechrootpkg script (described below).

Custom pacman.conf

Alternatively, provide a custom and with the following:

$ mkarchroot -C <pacman.conf> -M <makepkg.conf> $CHROOT/root base-devel

Building in the chroot

Firstly, make sure the base chroot ($CHROOT/root) is up to date:

$ arch-nspawn $CHROOT/root pacman -Syu

Then, build a package by calling in the directory containing its PKGBUILD:

$ makechrootpkg -c -r $CHROOT

Pre-install required packages

To build a package with dependencies unavailable from the repositories enabled in , pre-install them to the working chroot with :

$ makechrootpkg -c -r $CHROOT -I build-dependency-1.0-1-x86_64.pkg.tar.xz -I required-package-2.0-2-x86_64.pkg.tar.xz

Passing arguments to makepkg

To pass arguments to makepkg, list them after an end-of-options marker; e.g., to force a check():

$ makechrootpkg -c -r $CHROOT -- --check

Handling major rebuilds

The cleanest way to handle a major rebuild is to use the [staging] repositories. Build the first package against [extra] and push it to [staging]. Then rebuild all following packages against [staging] and push them there.

If you cannot use [staging], you can build against custom packages using a command like this:

# extra-x86_64-build -- -I ~/packages/foobar/foobar-2-1-any.pkg.tar.xz

You can specify more than one package to be installed using multiple -I arguments.

A simpler, but dirtier way to handle a major rebuild is to install all built packages in the chroot, never cleaning it. Build the first package using:

# extra-x86_64-build

And build all following packages using:

# makechrootpkg -n -r /var/lib/archbuild/extra-x86_64

Running namcap (the -n argument) implies installing the package in the chroot. *-build also does this by default.

Tips and tricks

Build in tmpfs

If the system has enough RAM, it is possible to specify a tmpfs for the devtools build scripts.

# mount --mkdir -t tmpfs -o defaults,size=20G tmpfs /mnt/chroots/arch
# extra-x86_64-build -c -r /mnt/chroots/arch
gollark: * decimal time
gollark: They also had metric time for a bit.
gollark: It was made by Frænce.
gollark: Or, well, measured in that.
gollark: Arbitrary but it's based on lightspeed now.
This article is issued from Archlinux. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.