build/docs/build-overview.rst

Tue, 06 Jan 2015 21:39:09 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 06 Jan 2015 21:39:09 +0100
branch
TOR_BUG_9701
changeset 8
97036ab72558
permissions
-rw-r--r--

Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

michael@0 1 .. _build_overview:
michael@0 2
michael@0 3 =====================
michael@0 4 Build System Overview
michael@0 5 =====================
michael@0 6
michael@0 7 This document provides an overview on how the build system works. It is
michael@0 8 targeted at people wanting to learn about internals of the build system.
michael@0 9 It is not meant for persons who casually interact with the build system.
michael@0 10 That being said, knowledge empowers, so consider reading on.
michael@0 11
michael@0 12 The build system is composed of many different components working in
michael@0 13 harmony to build the source tree. We begin with a graphic overview.
michael@0 14
michael@0 15 .. graphviz::
michael@0 16
michael@0 17 digraph build_components {
michael@0 18 rankdir="LR";
michael@0 19 "configure" -> "config.status" -> "build backend" -> "build output"
michael@0 20 }
michael@0 21
michael@0 22 Phase 1: Configuration
michael@0 23 ======================
michael@0 24
michael@0 25 Phase 1 centers around the ``configure`` script, which is a bash shell script.
michael@0 26 The file is generated from a file called ``configure.in`` which is written in M4
michael@0 27 and processed using Autoconf 2.13 to create the final configure script.
michael@0 28 You don't have to worry about how you obtain a ``configure`` file: the build
michael@0 29 system does this for you.
michael@0 30
michael@0 31 The primary job of ``configure`` is to determine characteristics of the system
michael@0 32 and compiler, apply options passed into it, and validate everything looks OK to
michael@0 33 build. The primary output of the ``configure`` script is an executable file
michael@0 34 in the object directory called ``config.status``. ``configure`` also produces
michael@0 35 some additional files (like ``autoconf.mk``). However, the most important file
michael@0 36 in terms of architecture is ``config.status``.
michael@0 37
michael@0 38 The existence of a ``config.status`` file may be familiar to those who have worked
michael@0 39 with Autoconf before. However, Mozilla's ``config.status`` is different from almost
michael@0 40 any other ``config.status`` you've ever seen: it's written in Python! Instead of
michael@0 41 having our ``configure`` script produce a shell script, we have it generating
michael@0 42 Python.
michael@0 43
michael@0 44 Now is as good a time as any to mention that Python is prevalent in our build
michael@0 45 system. If we need to write code for the build system, we do it in Python.
michael@0 46 That's just how we roll. For more, see :ref:`python`.
michael@0 47
michael@0 48 ``config.status`` contains 2 parts: data structures representing the output of
michael@0 49 ``configure`` and a command-line interface for preparing/configuring/generating
michael@0 50 an appropriate build backend. (A build backend is merely a tool used to build
michael@0 51 the tree - like GNU Make or Tup). These data structures essentially describe
michael@0 52 the current state of the system and what the existing build configuration looks
michael@0 53 like. For example, it defines which compiler to use, how to invoke it, which
michael@0 54 application features are enabled, etc. You are encouraged to open up
michael@0 55 ``config.status`` to have a look for yourself!
michael@0 56
michael@0 57 Once we have emitted a ``config.status`` file, we pass into the realm of
michael@0 58 phase 2.
michael@0 59
michael@0 60 Phase 2: Build Backend Preparation and the Build Definition
michael@0 61 ===========================================================
michael@0 62
michael@0 63 Once ``configure`` has determined what the current build configuration is,
michael@0 64 we need to apply this to the source tree so we can actually build.
michael@0 65
michael@0 66 What essentially happens is the automatically-produced ``config.status`` Python
michael@0 67 script is executed as soon as ``configure`` has generated it. ``config.status``
michael@0 68 is charged with the task of tell a tool how to build the tree. To do this,
michael@0 69 ``config.status`` must first scan the build system definition.
michael@0 70
michael@0 71 The build system definition consists of various ``moz.build`` files in the tree.
michael@0 72 There is roughly one ``moz.build`` file per directory or per set of related directories.
michael@0 73 Each ``moz.build`` files defines how its part of the build config works. For
michael@0 74 example it says *I want these C++ files compiled* or *look for additional
michael@0 75 information in these directories.* config.status starts with the ``moz.build``
michael@0 76 file from the root directory and then descends into referenced ``moz.build``
michael@0 77 files by following ``DIRS`` variables or similar.
michael@0 78
michael@0 79 As the ``moz.build`` files are read, data structures describing the overall
michael@0 80 build system definition are emitted. These data structures are then fed into a
michael@0 81 build backend, which then performs actions, such as writing out files to
michael@0 82 be read by a build tool. e.g. a ``make`` backend will write a
michael@0 83 ``Makefile``.
michael@0 84
michael@0 85 When ``config.status`` runs, you'll see the following output::
michael@0 86
michael@0 87 Reticulating splines...
michael@0 88 Finished reading 1096 moz.build files into 1276 descriptors in 2.40s
michael@0 89 Backend executed in 2.39s
michael@0 90 2188 total backend files. 0 created; 1 updated; 2187 unchanged
michael@0 91 Total wall time: 5.03s; CPU time: 3.79s; Efficiency: 75%
michael@0 92
michael@0 93 What this is saying is that a total of *1096* ``moz.build`` files were read.
michael@0 94 Altogether, *1276* data structures describing the build configuration were
michael@0 95 derived from them. It took *2.40s* wall time to just read these files and
michael@0 96 produce the data structures. The *1276* data structures were fed into the
michael@0 97 build backend which then determined it had to manage *2188* files derived
michael@0 98 from those data structures. Most of them already existed and didn't need
michael@0 99 changed. However, *1* was updated as a result of the new configuration.
michael@0 100 The whole process took *5.03s*. Although, only *3.79s* was in
michael@0 101 CPU time. That likely means we spent roughly *25%* of the time waiting on
michael@0 102 I/O.
michael@0 103
michael@0 104 For more on how ``moz.build`` files work, see :ref:`mozbuild-files`.
michael@0 105
michael@0 106 Phase 3: Invokation of the Build Backend
michael@0 107 ========================================
michael@0 108
michael@0 109 When most people think of the build system, they think of phase 3. This is
michael@0 110 where we take all the code in the tree and produce Firefox or whatever
michael@0 111 application you are creating. Phase 3 effectively takes whatever was
michael@0 112 generated by phase 2 and runs it. Since the dawn of Mozilla, this has been
michael@0 113 make consuming Makefiles. However, with the transition to moz.build files,
michael@0 114 you may soon see non-Make build backends, such as Tup or Visual Studio.
michael@0 115
michael@0 116 When building the tree, most of the time is spent in phase 3. This is when
michael@0 117 header files are installed, C++ files are compiled, files are preprocessed, etc.

mercurial