Skip to content

Commit d58df3f

Browse files
committed
docs: Add page - "Building of BuildStream Elements"
1 parent e4dcda0 commit d58df3f

File tree

1 file changed

+121
-0
lines changed

1 file changed

+121
-0
lines changed
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
Building of BuildStream Elements
2+
=================================
3+
4+
This page provides an high-level overview of the processes involved in which
5+
Elements are built as part of the build+integration pipeline.
6+
7+
When `bst build` is running on a given Element, it can be - roughly - broken
8+
down into individual steps:
9+
10+
- Sources are fetched
11+
- The sandbox is prepared
12+
- Configure and run commands
13+
These can include:
14+
- `configure-commands`
15+
- `build-commands`
16+
- `install-commands`
17+
- `strip-commands`.
18+
- Caching artifacts
19+
20+
Sources are fetched
21+
-------------------
22+
23+
The hidden first step is actually validating the ``yaml``. This includes
24+
resolving includes, options, appends, which are denoted by ``(@)``,
25+
``(?)`` and ``(>)`` respectively.
26+
27+
The first step once the ``yaml`` has been validated is that BuildStream
28+
will fetch the sources. This is dependent on the source ``kind`` as to
29+
how these are fetched. After the sources are fetched they may need to
30+
checked. For example a ``kind: tar`` would need to check the ``sha256``
31+
matches, and a ``git_repo`` source would need to switch to the specified
32+
commit sha.
33+
34+
The Sandbox is prepared
35+
-----------------------
36+
37+
The Sandbox is prepared as a temporary filesystem, where build
38+
dependencies (``build-depends:``) and general dependencies (``depends``)
39+
are staged, along with their own runtime dependencies. This happens in
40+
an abstract state, which can quickly spot repeated files and overlaps.
41+
42+
When a dependency is being staged, the produced artifact is added from the root
43+
(``/``). This can sometimes be changed using the ``location:`` attribute.
44+
However, this applies to `BuildElements`, and not all `Elements` (where
45+
`BuildElement` is a subclass of `Element`) support the `location` argument.
46+
47+
In most cases dependencies are marked by BuildStream as immutable.
48+
49+
After the dependencies are staged BuildStream stages the sources in the
50+
``build-root`` location. The actual location of this differs slightly
51+
depending on the project file structure, which is why it is common to
52+
see elements use the variable ``%{build-root}`` which resolves to the
53+
correct location.
54+
55+
Configure and Build commands
56+
----------------------------
57+
58+
Now that all dependencies and sources are staged in a temporary filesystem,
59+
this filesystem is mounted inside BuildBox as a sandbox.
60+
61+
The first commands to be run are configure commands and it is
62+
recommended to include things like moving the sources about, generating
63+
config files and other “configure” related actions into this section.
64+
These should be the commands that can only be run once (for example a
65+
folder can only be moved once), this is due to BuildStream
66+
workspaces.
67+
68+
!!! tip “BuildStream Workspaces and Configure Commands”
69+
70+
.. toctree::
71+
:numbered:
72+
:maxdepth: 1
73+
74+
developing/workspaces.rst
75+
76+
::
77+
78+
When a workspace is opened, it stages all the sources for the indicated
79+
element locally, then when doing a build of that element it uses these local
80+
sources instead of pulling in fresh sources. Builds using workspaces only
81+
run configure commands once, and any subsequent builds using the same
82+
workspace will skip the configure commands step, therefore steps of the
83+
build that aren't reproducible (without re-staging sources) should be added
84+
to configure commands.
85+
86+
After Configure commands are run, then Build commands are next. Build
87+
commands are intended to contain the actual build process, for example
88+
if the build uses ``make`` then this stage should run the
89+
``make target`` command.
90+
91+
Install Commands and Caching Artifacts
92+
--------------------------------------
93+
94+
Install commands are the final commands that are run before BuildStream
95+
collects the artifacts and closes the build sandbox. Install commands
96+
should mainly be comprised of moving the built artifacts from the
97+
``${build-root}`` to the ``${install-root}``.
98+
99+
The `install-commands` should not clean up any of the sources, as they can be stored as a _buildtree_, which allows for introspection after the build.
100+
101+
Directories can be created under the install location, for example
102+
``%{install-root}/example/``, and these will be maintained when another
103+
element depends on this one, for example this will become
104+
``example/``.
105+
106+
The contents of the install root are cached. BuildStream caches the
107+
produced artifact to reduce the need to rebuild elements, instead it can
108+
pull from this artifact cache. It will only rebuild an element if the
109+
element file changes, or if the dependencies for an element changes.
110+
111+
!!! tip “Caching Errors”
112+
113+
::
114+
115+
BuildStream will also cache build errors, and if no file has changed
116+
(including the dependencies) then BuildStream will display this cached error,
117+
without attempting a rebuild. This is sometimes not the desired behaviour,
118+
especially if the error was caused by a remote issue, like a source site
119+
being temporarily unavailable. To force an attempted build use the
120+
`-r`/`--retry-failed` option, documented
121+
[here](using_commands.html#cmdoption-bst-build-r)

0 commit comments

Comments
 (0)