Skip to content

Commit cbce641

Browse files
committed
docs: Add 'Execution of BuildStream Elements' page
WIP!
1 parent 1a7651a commit cbce641

File tree

1 file changed

+115
-0
lines changed

1 file changed

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

0 commit comments

Comments
 (0)