This wiki page is intended to describe the issues of, and mechanisms for, bootstrapping Debian from zero to a full archive. Otherwise known as profile builds (and previously staged builds). It has developed somewhat over several years as practical experience has grown, and is now technically useable, and making its way into the archive.
The detailed spec is at BuildProfileSpec
- Packaging/Design principles
- Available Patches
- Automated Bootstrapping
- Circular dependencies/staged builds
- Specifying profiles/stages
- Changed binary packages
- Heuristics to detect bootstrapping problems
- Related documents
There is a real need to bootstrap Debian from sources when doing new ports or flavours (sub-arch builds). Every new architecture or optimisation flavour needs to do this at least once, and making it easier than the current 'really very hard' would be great. It is also very useful for cross-compiling to new or non-self-hosted architectures, and for a genuinely new arch at least part of the system (toolchains+build-essential) has to be cross-built until there is enough to become self-hosting.
New bootstraps are done every year. At the time of writing sh4, armhf, uclibc and avr32, and x32 have been done, and arm64 and mips64el are in progress. Subarch flavoured rebuilds (e.g. to optimise for a particular CPU) are particularly useful on ARM and MIPS architectures (Raspberry Pi is most popular recent example).
This is also helpful when bringing a lagged architecture up to date, especially considering documentation tools (that may be too old), optional dependencies (that may be too old or not exist) like php5, which depends on everything and the kitchen sink, etc. I wish this had been implemented when starting to work on m68k…
It can also help to solve problems like libc ABI changes by rebuilding everything. Example: http://lists.debian.org/20140714203645.GA23576@hall.aurel32.net (But this was solved by upstream reverting the change in the end)
Currently people tend to use non-debian tools (such as Yocto/Gentoo/OpenEmbedded) to get a basic rootfs image of the target arch/ABI then do native building within that. This works but needs a great deal of manual loop-breaking and we really ought to be able to bootstrap our own OS.
Putting the necessary bootstrapping metadata and build rules into the packages themselves in an orderly fashion enables the info to be maintained easily. QA tests to report on breakage will help enormously here. It also makes for a repeatable and deterministic process.
This work needs build-system and policy changes, which are detailed on this page.
The goal is to be able to run regular automated bootstrap builds of the archive to check that it works, and allow porters to concentrate on actual porting work, rather than a lot of associated aggravation.
The current (Jan 2014) status is:
- build profiles are supported in dpkg 1.17.2 onwards, and apt 0.9.16
- Support in the buildd infrastructure is still needed
Suite bootstrappability is tracked at https://bootstrap.debian.net/
An important principle in the design is that the packaging changes necessary for this to work are reasonably clear and transparent. A Debian packager should not have to understand this stuff (staged builds and cross-building) in loving detail to avoid breaking things whilst making maintenance changes.
All the metadata needed should be part of the packages, so it can be maintained over time. Any solution with external patches/metadata is doomed to bitrot.
These principles informed the design when deciding between different technically-satisfactory ways of achieving things.
The concept is simple: add support for minimal/reduced/staged builds to packages involved in build-dependency loops, so that build loops are broken. Also ensure packages cross-build properly so that an initial minimal native-building system can be produced.
Working out which packages to modify, and how, is fundamentally a manual process, done by manually examining build-dep loops and choosing which packages are most easily and cleanly modified. Since the "Port bootstrap build-ordering tool" project in the GSoC 2012, the process of finding source packages which make sense to modify can be semi-automated. Once that is done, building bootstrap-able packages can be a fully automated process.
This spec caters for multiple stages of staged/bootstrap build, so that if necessary a package can have stage1, stage2, etc. before the final, normal, build. Almost all packages only need one stage other than the standard build. Only toolchain packages are known to have more than one stage at this time.
The reduced dependencies are specified in the control file, using a concept which is called build profiles. The build profile format was proposed by Guillem Jover together with other solutions he presented in bug#661538. Build profiles extend the Build-Depends format with a syntax similar to architecture restrictions but using < and > instead. The current Spec is detailed in BuildProfileSpec. Previous revisions were discussed on debian-devel and debian-dpkg.
Build-Depends: huge (>= 1.0) [i386 arm] <!cross !stage1>, tiny
The build dependency "huge" would not be required by the source package if it is built in the "cross" or "stage1" profile. This mechanism neatly allows for removed build-deps, replaced build-deps and added build-deps, and an arbitrary number of possible 'profiles'.
Besides bootstrapping, these build profiles can also be used for embedded builds, to allow for changed build-deps when cross-building, and build-dependencies only needed for running tests.
This scheme supersedes an earlier version, (referred-to as 'staged' builds), which used repeated Build-depends-StageN: lines. See the dpkg bug#661538 for the evolution of this. The profile labels are arbitrary but agreement on label usage is necessary. For bootstrap automation we have been using 'stage1', 'stage2', etc which fits with existing custom in packages which already have such internal mechanisms using DEB_STAGE (currently gcc, eglibc, libselinux, gcj, gnat, gdc, linux ) These seem like sensible names so we propose to stick with them. Other useful profiles are 'cross' and 'notest'.
An environment variable (DEB_BUILD_PROFILES) is used to control when packages are built in reduced staged/bootstrap mode, and at what stage.. debian/rules can check this variable and miss out some optional features to reduce the dependency tree (e.g. building kerberos without LDAP support, avahi without gtk and qt, etc). dpkg-buildpackage/dpkg-checkbuilddeps also checks the reduced/changed build-dependencies instead of the normal ones.
DEB_BUILD_PROFILES is used because it is preserved and passed on by all build tools, and this is a build option like other things it is used to control.
So setting DEB_BUILD_PROFILES=stage1 will cause dpkg-buildpackage to call dpkg-checkbuilddeps with -Pstage1 so that Stage1 dependencies are checked, rather than the normal set. Similarly other tools like apt and xdeb will use the stage1 dependencies for the top-level package.
Bootstrapped/Staged packages are marked as such (in the control file) with a new field called Built-for-profiles:. They are not uploaded to normal repositories. It is important to avoid accidentally mistaking a bootstrap/staged package for a 'real' (normally-built) package. As soon as possible a bootstrap package should be rebuilt as a full package, to avoid having to rebuild many packages against the full version once it is available. A version suffix is useful too, mostly to help humans, but is not enforced by the tools.
This process is usually called 'profile' builds, but the terms 'staged' builds and 'bootstrap' builds have also been used as it developed.
Patches are tracked on BuildProfileSpec
The dpkg bug gives a useful idea of how this spec has developed.
Here are various older patches for packages, adding support for profiled builds of packages: http://people.debian.org/~wookey/bootstrap/patches/profiles/packages/
Bootstrapping is closely related to support for cross-building Debian packages because at least part of the process must be done cross. Enough packages to make a bootable image need to be cross-buildable, because you cannot magic a system out of thin air. To move from cross to native building you need build-essential to be cross-buildable.
The number of build-loops that must be broken for cross-building is much smaller than the number that need to be broken for native building. This spec proposes that we start by fixing the loops that mean you can't even cross-build a base Debian image before going on to fix all the packages which have native build-dep loops.
Debian/Ubuntu cross-building is documented here: https://wiki.linaro.org/Platform/DevPlatform/CrossCompile/CrossBuilding
Patched sources with build-profile patches applied and extra multiarch and profile build support in package metadata are in http://people.debian.org/~wookey/bootstrap.html
For cross-building to be reliable cross-dependency metadata needs to be in packages, so that it is clear whether a build dependency should be satisfied by the build architecture or the host architecture. Multiarch information can be used to provide this information along with build-dependency decoration for the farily rare exceptions. Details are specified here: MultiarchCross
The current state of buildability using this technology is recorded here: http://people.linaro.org/~wookey/buildd/ and http://people.canonical.com/~cjwatson/cross/armhf/raring/
Prior to useful amounts of multiarch metadata is in packages, heurisitics must be used, as implemented in xdeb (and the now-deprecated apt-cross), or all dependencies must be installed for both host and native, as implemented in xapt. These are all ugly and horrid, but better than nothing. xdeb or xapt are better than multiarch-cross in wheezy and precise, but multiarch-cross is where all the current work is, and as of end 2012 it works for much of the base system in Debian unstable and Ubuntu raring. From Maverick and Jessie onwards multiarch cross-building is the recommended method.
The full automated bootstrapping process needs to keep track of staged builds and rebuilding things as needed so that they don't hang around any longer than necessary. However any such tool could get out of sync with the current status, unless it is always determinable from the current package-set state. This spec attempts to define things such that it is always intrinsically stateful.
Packages do need to be uploaded to a bootstrap repository in order to satisfy build-dependecies (that's the whole point). However because packages of the same version get built, and thus uploaded, more than once we need a way to deal with this. One proposal is to append ~stageN+M to the package version automatically, where N is the stage number and M a continuously incremented (by the buildd) number. Or do binNMUs, which are already recognised by the tools and package management system very well, and almost all packages are (supposedly) binNMU safe. This was awkward when combined with multiarch until the separate binNMU changelog feature was implemented.
See 'Changed binary packages' below for a discussion of how profiles causing a binary package normally built to be omitted should be dealt with. The meta-data in package Build-Deps allows static analysis tools to determine in advance if the package set has a fully linearisable build-order or not. The botch tool can do this analysis.
The toolchain has a complex 3-stage bootstrapping process involving binutils, gcc, glibc and kernel-headers. It uses the DEB_STAGE variable name internally to control the build stages. The multiple stage sequencing is currently managed by external packages in Debian (buildcross) and Ubuntu (<arch>-cross-toolchain-base and gcc-cross-defaults), using binary -source packages.
Using multiarch to supply cross-libc actually removes most of the complexity of cross-toolchain building, and was the subject of a 2012 GSOC project. That was successful and cross-toolchains can now be built that way. Work is ongoing to get this in a state suitable for the archive, so allowing cross-toolchains to be built by buildds. This work is tracked on the MultiarchCrossToolchains page
Circular dependencies/staged builds
The main issue is circular build-dependencies. These fall into three main areas:
- Most languages depend on themselves to build (gcc, openjdk, mono, haskell, python, ada(gnat)).
Libraries sometimes circularly depend:
kerberos → ldap → kerberos
- qt → poppler → cups → qt
- pulseaudio → bluez → gst-plugins-base0.10 → libtheora → libsdl1.2 → pulseaudio
- Documentation packages. Many packages need documentation tools (sgmltools, jade, tex, doxygen) which cannot be built until many other packages are built. This is largely only a problem for native-builds, as the doc-tools are generally available when cross-building. A 'nodocs' profile is very useful here, and also when build hardware is slow or emulated.
The generic way to deal with all of these is 'profile builds', where a version of the package is built with lesser functionality and thus a smaller dependency tree. This allows the depending package to then be built, then for the 'stageN' package to be built normally.
Encoding the build-profile dependencies in the control file makes it simple for automatic build-ordering and analysis tools.
CircularBuildDependencies is a list of loops found in the initial (2011) analysis.
'Profile' builds are invoked by setting DEB_BUILD_PROFILES to specify which profile(s) to build to dpkg-buildpackage. When no profile option is set then a normal build occurs. Some packages may need more than one staged build. We do not know what the maximum number of stages needed is: it is proably two, but to assume so would be foolish. We count up from Stage1, Stage2 to 'normal'. Hopefully this is reasonably clear to the average packager.
Any profile-built package must be identified as such in the metadata so it is not accidentally uploaded as a 'real' package. The mechanism is an extra header inserted by dpkg-genchanges, to indicate which profiles it was built with. dpkg sets Built-with-Profiles=<profiles>, i.e in the case of a bootstrap builds, Built-with-Profiles: stage1
It must be possible for the build-tools to identify what build-stages are available. By reading the profiles specified in the Build-Depends. The existence of that defines such a stage as being available.
Let's consider kerberos as a typical example of a library package involved in a circular dependency. krb5 needs libldap2-dev to build (from openldap). openldap need libkrb5-dev (from krb5) to build. To fix this we add a staged build to krb5 to miss out the generation of the krb5-ldap package. This is easy to do with a debhelper-based package by simply setting DH_OPTIONS="--no-package=krb5-ldap", and running configure with --without-ldap (when DEB_BUILD_PROFILES=stage1).
Dealing with changed build dependencies
The DEB_BUILD_PROFILES syntax is:
Build-Depends: foo , bar <!profile.stage1>, libfoo2 <!profile.stage1 !profile.stage2>, wibble <profile.stage2>
Which is an implausibly complicated example which normally build-depnds on foo, bar, libfoo2. For a stage1 build it doesn't need bar or libfoo2. For stage2 it needs foo, bar and also needs wibble, but does not need libfoo2
This syntax allows the usual case of missing out a build-dep but also supports substitutions. dpkg 1.17.2 onwards (i.e Jessie or later) understands this syntax. Its major disadvantage is that packages using this syntax cannot be uploaded until the dpkg on the buildds understands this syntax. And the Wheezy dpkg does not understand this syntax.
So for krb5 we'd have:
Build-Depends:debhelper (>= 7), byacc | bison, comerr-dev, docbook-to-man, libkeyutils-dev [!kfreebsd-i386 !kfreebsd-amd64 !hurd-i386] libncurses5-dev, libssl-dev, ss-dev, ldap2-dev <!profile.stage1>, texinfo
Setting DEB_BUILD_PROFILES=stage1 and building this package causes it to build without ldap support, and without needed ldap2-dev available.
For packages which depend on themselves (usually languages), the Build-dependencies should be changed to depend on lang | lang-bootstrap. In a normal repository the (native version) lang-bootstrap will not be available so a lang will be used. In a bootstraping environment lang may well not be available in which case lang-bootstrap needs to be built. The bootstraping tool knows to do a staged build in this case.
Setting DEB_BUILD_PROFILES=stage1 and building this package causes it to produce lang-bootstrap (which is normally not emitted). This is implemented by adding a new control stanza for lang-bootstrap and specifying --no-package=lang-bootstrap in debian/rules for normal builds, but not for the stage1 build (which will probably exclude a load of other stuff).
For documentation issues some packages already implement DEB_BUILD_OPTIONS=nodocs. Building without docs usually affects the build-dependencies, so it is not quite like other DEB_BUILD_OPTIONS, and using DEB_BUILD_PROFILES instead now makes more sense.
Documentation loops are primarily an issue for native building, although they do cause issues for cross-building too (gobject introspection, perl module docs).
Changed binary packages
Often a profile/staged build will omit a binary package that is normally produced. e.g. if there is a foo-gui binary that brings in a lot of gtk build-deps, but foo is also a low-level package needed by other things (avahi is a good example of this).
If these changed binary outputs are not recording in package metadata then a tool analysing the build-order cannot determine in advance whether a build-order will complete, because although it knows that a package has a build profile which needs reduced build-deps, it does not know if any of the package binaries will not be produced for this particular profile, and thus what could be built afterwards. For an iterative process where stuff that can be built next is built, then the new state examined for more things to build, this does not really matter, but it would be good if analysis tools like dose3 could determine from package files alone whether or not a bootstrap order exists and which order would be the most optimal in terms of least number of source packages which are profile built.
A suggested mechanism to allow this is to add a field to affected binary packages in debian/control saying X-Builds-With-Profile: !stage1 (for packages not built in stage1) X-Builds-With-Profile: stage2 (for packages built only in stage2)
Nearly all packages would not have any such notation and would thus always be produced by all profiles, as now. Current analysis suggests that there will not be more than 83 source packages which have to have this new field.
This feature may be deemed unnecessary complexity that is only actually needed by external analysis tools. Maintaining this data means that a bootstrap analysis can be known to be correct and if it says there is a build order then that order will actually work. Without this info the tool may produce a build order but it may not actually work in practice because some binary-package will not be built, but will actually be needed.
Implementing this is a minor change to dpkg-gencontrol
Heuristics to detect bootstrapping problems
Ideally the following would be converted into a tool that detects and reports this problems, so that maintainers can fix them. These would be shown on a site such as the PTS or tracker.debian.org.
- Packages that cointain perl .so (XS modules, but the same could be done for python or other language modules), and are Build-Depended on by another package, implies it needs to be a build tool or used by one, because the program should not be linking against those. Those Build-Depends need to be marked :native (reliable).
- Packages that once excluding irrelevant stuff like /usr/share/doc and similar only contain *.so* files, implies they need to be tagged M-A:same (reliable).
Packages that are Arch:any once excluding irrelevant stuff only contain scripts in bin/*, and those match digests on different architectures then it means it's probably M-A:foreign safe (they might still be calling arch specific interfaces) (guess).
- A hard-coded list of interpreters could be maintained, those would need to be marked M-A:allowed (reliable).
This section collects some information about how this concept has developed over time in order to make the above page clearer.
The initial proposal was written down in 2010 as a result of a UDS (ubuntu Developer Summit) discussion: Specs/M/ARMAutomatedBootstrap Back then the concept was called 'Staged Builds', and used a simple extra line in the control file repeating and modifying the normal build-dependencies: Build-Depends-StageN and builds controlled with DEB_BUILD_OPTIONS=profile=stage1
This made it very easy to implement as existing tools will not barf as no new syntax is used. However it is an ugly implementation inside dpkg with many extra fields defined and a limit (of 2) on how many stages could be supported. No other profiles types are possible without hard-defining more fields inside dpkg. See 661538 for how that developed.
3 successive years of GSOC projects by Gustavo Alkmim, P. J McDermott, Johannes Schauer, and Thibaut Girka, progressed the practical and theoretical work, as well as heavy sponsorship of this work by Linaro and Canonical which enabled a lot of the supporting cross-building and multiarch work to get done.
It became clear from actually doing staged builds that it made more sense if cross-building, test-skipping, doc-skipping and language/tool extra dependencies (bootstrapping) changes were described independently rather than arbitrarily lumped together in the way a bootstrap on a particular arch might like it. So the newer profile modifier syntax was developed and implemented, whilst being tested on actual cross-builds and bootstraps.
Over 2013 an actual spec and implementation in dpkg was pinned down, agreed and implemented, leading to a profile-supporting dpkg upload at the end of 2013.
These are some related activities and documents which have generated input for this one.
- GSOC 2011 project