5318
Comment: Changing "Setup" section for simpler instructions
|
5337
Hide old Setup information
|
Deletions are marked like this. | Additions are marked like this. |
Line 59: | Line 59: |
{{{#!wiki comment |
sbuild
sbuild is used on the official buildd network to build binary packages for all supported architectures. It can also be used by individuals to prepare packages. Alternatives to sbuild are cowbuilder and pbuilder.
This page is intended as a short guide to sbuild. It documents how to set up sbuild and build packages with it, but intentionally does not document all possible options to keep it short and simple.
Setup
To get started so you may build packages for Debian sid, run the following.
sudo apt-get install sbuild sudo sbuild-createchroot --make-sbuild-tarball=/var/lib/sbuild/sbuild.tar.gz sid `mktemp -d` http://ftp.debian.org/debian sudo sbuild-adduser $LOGNAME sudo sbuild-update --keygen
Now for a brief explanation on what these commands do.
The first line installs sbuild onto the system.
The second line uses sbuild-createchroot to create a chroot used by sbuild meant for building packages targeting Debian sid main. The chroot is saved as a tarball in /var/lib/sbuild/sbuild.tar.gz. The apt repository used is http://ftp.debian.org/debian. This can be changed to use a URL for a local mirror of the Debian archive.
The third line will add your username so that it may use the sbuild command. Additional users may be added by running sudo sbuild-adduser USER1 USER2 ....
Finally, the fourth line generates apt keys used internally by sbuild.
Setup, with using btrfs snapshots
Using snapshots for the chroot environment allows to skip removing installed build dependencies and cleaning the build directory. One filesystem supporting this is btrfs, but it is also possible to use LVM snapshots or aufs/unionfs (see schroot.conf(5) for these).
To use btrfs snapshots with the above setup, make sure /srv/chroot is located on a btrfs filesystem and run
btrfs subvolume create /srv/chroot/$distribution-$architecture-sbuild
before sbuild-createchroot. After sbuild-createchroot run
mkdir -p /srv/chroot/snapshots sed -i "s,type=directory,type=btrfs-snapshot,; /directory=/ d" /etc/schroot/chroot.d/$distribution-$architecture-sbuild* cat >>/etc/schroot/chroot.d/$distribution-$architecture-sbuild* <<EOT btrfs-source-subvolume=/srv/chroot/$distribution-$architecture-sbuild btrfs-snapshot-directory=/srv/chroot/snapshots EOT
Usage
To build a package just run
sbuild -A -d sid
in the source directory. You can also specify a different architecture with --arch=$architecture or pass a .dsc file.
The chroot environment should be updated from time to time. Just run
sbuild-update -ugd sid
Again, use --arch=$architecture for a chroot environment for a architecture that differs from the host architecture.
Using ccache with sbuild
Sometimes you are building a big package and after building (and waiting for too long) you realize that there was a problem in a install file. Using ccache one can avoid to have to wait for that long again for a simple fix.
Installing ccache in the chroot
cd /; schroot -c $distribution-$architecture-sbuild apt-get install ccache
Create a script to setup ccache on each build
This script was modified from the original from Modestas Vainius. Put it in /srv/chroot/$distribution-$architecture-sbuild/usr/local/bin/build-env.sh
if [ -z "$CCACHE_DISABLE" ]; then export CCACHE_DIR=/var/cache/ccache-`dpkg-architecture -qDEB_HOST_ARCH` export CCACHE_UMASK=002 export CCACHE_BASEDIR=`pwd` export CCACHE_COMPRESS=1 export PATH="/usr/lib/ccache:$PATH" # Set ccache's cache size to 4G, special for big builds. # Use an appropiate value here. ccache --max-size 4G fi
Don't forget to chmod it at least to 744.
Then edit ~/.sbuildrc and add/uncomment the following line:
$build_env_cmnd = "build-env.sh";