tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

configuring_build_options.rst (14485B)


      1 Configuring Build Options
      2 =========================
      3 
      4 This document details how to configure Firefox builds.
      5 Most of the time a ``mozconfig`` file is not required. The default
      6 options are the most well-supported, so it is preferable to add as few
      7 options as possible. Please read the following directions carefully
      8 before building, and follow them in order. Skipping any step may cause
      9 the build to fail, or the built software to be unusable. Build options,
     10 including options not usable from the command-line, may appear in
     11 "``confvars.sh``" files in the source tree.
     12 
     13 
     14 Using a ``mozconfig`` configuration file
     15 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     16 
     17 The choice of which Mozilla project to build and other configuration
     18 options can be configured in a ``mozconfig`` file. (It is possible to
     19 manually call ``configure`` with command-line options, but this is not
     20 recommended). The ``mozconfig`` file should be in your source directory
     21 (that is, ``/mozilla-central/mozconfig``).
     22 
     23 Create a blank ``mozconfig`` file:
     24 
     25 .. code:: bash
     26 
     27    echo "# My first mozilla config" > mozconfig
     28 
     29 If your mozconfig isn't in your source directory, you can also use the
     30 ``MOZCONFIG`` environment variable to specify the path to your
     31 ``mozconfig``. The path you specify **must** be an **absolute** path or
     32 else ``client.mk`` will not find it. This is useful if you choose to
     33 have multiple ``mozconfig`` files for different projects or
     34 configurations (see below for a full example). Note that in the
     35 ``export`` example below the filename was not ``mozconfig``. Regardless
     36 of the name of the actual file you use, we refer to this file as the
     37 ``mozconfig`` file in the examples below.
     38 
     39 Setting the ``mozconfig`` path:
     40 
     41 .. code:: bash
     42 
     43   export MOZCONFIG=$HOME/mozilla/mozconfig-firefox
     44 
     45 .. note::
     46 
     47   Calling the file ``.mozconfig`` (with a leading dot) is also
     48   supported, but this is not recommended because it may make the file
     49   harder to find. This will also help when troubleshooting because
     50   people will want to know which build options you have selected and
     51   will assume that you have put them in your ``mozconfig`` file.
     52 
     53 
     54 ``mozconfig`` contains two types of options:
     55 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     56 
     57 -  Options prefixed with ``mk_add_options`` are passed to
     58   ``client.mk``. The most important of these is ``MOZ_OBJDIR``, which
     59   controls where your project gets built (also known as the object
     60   directory).
     61 -  Options prefixed with ``ac_add_options`` are passed to ``configure``,
     62   and affect the build process.
     63 
     64 
     65 Building with an objdir
     66 ~~~~~~~~~~~~~~~~~~~~~~~
     67 
     68 This means that the source code and object files are not intermingled in
     69 your directory system and you can build multiple projects (e.g.,
     70 Firefox and Thunderbird) from the same source tree. If you do not
     71 specify a ``MOZ_OBJDIR``, it will be automatically set to
     72 ``@TOPSRCDIR@/obj-@CONFIG_GUESS@``.
     73 
     74 If you need to re-run ``configure``, the easiest way to do it is using
     75 ``./mach configure``; running ``configure`` manually is strongly
     76 discouraged.
     77 
     78 Adding the following line to your ``mozconfig`` allows you to change the
     79 objdir:
     80 
     81 .. code:: bash
     82 
     83   mk_add_options MOZ_OBJDIR=@TOPSRCDIR@/obj-@CONFIG_GUESS@
     84 
     85 It is a good idea to have your objdir name start with ``obj`` so that
     86 the VCS ignores it.
     87 
     88 Sometimes it can be useful to build multiple versions of the source
     89 (such as with and without diagnostic asserts). To avoid the time it
     90 takes to do a full rebuild, you can create multiple ``mozconfig`` files
     91 which specify different objdirs. For example, a ``mozconfig-dbg``:
     92 
     93 .. code:: bash
     94 
     95   mk_add_options MOZ_OBJDIR=@TOPSRCDIR@/obj-ff-dbg
     96   ac_add_options --enable-debug
     97 
     98 and a ``mozconfig-rel-opt``:
     99 
    100 .. code:: bash
    101 
    102   mk_add_options MOZ_OBJDIR=@TOPSRCDIR@/obj-ff-rel-opt
    103   ac_add_options --disable-debug
    104   ac_add_options --enable-optimize
    105 
    106 allow for building both versions by specifying the configuration via
    107 the ``MOZCONFIG`` environment variable:
    108 
    109 .. code:: bash
    110 
    111   $ env MOZCONFIG=/path/to/mozconfig-dbg ./mach build
    112   $ env MOZCONFIG=/path/to/mozconfig-rel-opt ./mach build
    113 
    114 Don't forget to set the ``MOZCONFIG`` environment variable for the
    115 ``mach run`` command as well.
    116 
    117 Be aware that changing your ``mozconfig`` will require the configure
    118 process to be rerun and therefore the build will take considerably
    119 longer, so if you find yourself changing the same options regularly, it
    120 may be worth having a separate ``mozconfig`` for each. The main downside
    121 of this is that each objdir will take up a significant amount of space
    122 on disk.
    123 
    124 
    125 Parallel compilation
    126 ~~~~~~~~~~~~~~~~~~~~
    127 
    128 .. note::
    129 
    130   The build system automatically makes an intelligent guess
    131   for how many CPU cores to use when building. The option below is
    132   typically not needed.
    133 
    134 Most modern systems have multiple cores or CPUs, and they can be
    135 optionally used concurrently to make the build faster. The ``-j`` flag
    136 controls how many parallel builds will run concurrently. You will see
    137 (diminishing) returns up to a value approximately 1.5× to 2.0× the
    138 number of cores on your system.
    139 
    140 .. code:: bash
    141 
    142   mk_add_options MOZ_PARALLEL_BUILD=4
    143 
    144 If your machine is overheating, you might want to try a lower value.
    145 
    146 
    147 Choose a project
    148 ~~~~~~~~~~~~~~~~
    149 
    150 The ``--enable-project=project`` flag is used to select a project to
    151 build. Firefox is the default.
    152 
    153 Choose one of the following options to add to your ``mozconfig`` file:
    154 
    155 Browser (Firefox)
    156   .. code::
    157 
    158      ac_add_options --enable-project=browser
    159 
    160   .. note::
    161 
    162      This is the default
    163 
    164 Mail (Thunderbird)
    165   .. code::
    166 
    167      ac_add_options --enable-project=comm/mail
    168 
    169 Mozilla Suite (SeaMonkey)
    170   .. code::
    171 
    172      ac_add_options --enable-project=suite
    173 
    174 Calendar (Lightning Extension, uses Thunderbird)
    175   .. code::
    176 
    177      ac_add_options --enable-project=comm/mail
    178      ac_add_options --enable-calendar
    179 
    180 
    181 Selecting build options
    182 ~~~~~~~~~~~~~~~~~~~~~~~
    183 
    184 The build options you choose depends on what project you are
    185 building and what you will be using the build for. If you want to use
    186 the build regularly, you will want a release build without extra
    187 debugging information; if you are a developer who wants to hack the
    188 source code, you probably want a non-optimized build with extra
    189 debugging macros.
    190 
    191 There are many options recognized by the configure script which are
    192 special-purpose options intended for embedders or other special
    193 situations, and should not be used to build the full suite/XUL
    194 projects. The full list of options can be obtained by running
    195 ``./mach configure -- --help``.
    196 
    197 .. warning::
    198 
    199   Do not use a configure option unless you know what it does.
    200   The default values are usually the right ones. Each additional option
    201   you add to your ``mozconfig`` file reduces the chance that your build
    202   will compile and run correctly.
    203 
    204 The following build options are very common:
    205 
    206 sccache
    207 ^^^^^^^
    208 
    209 `SCCache <https://github.com/mozilla/sccache>`__ allows speeding up subsequent
    210 C / C++ builds by caching compilation results. Unlike
    211 `ccache <https://ccache.dev>`__, it also allows caching Rust artifacts, and
    212 supports `distributed compilation
    213 <https://github.com/mozilla/sccache/blob/master/docs/DistributedQuickstart.md>`__.
    214 
    215 In order to enable ``sccache`` for Firefox builds, you can use
    216 ``ac_add_options --with-ccache=sccache``.
    217 
    218 From version 0.7.4, sccache local builds are using the ``preprocessor cache mode``
    219 by default. With a hot cache, it decreases the build time by a factor of 2 to 3
    220 compared the previous method. This feature works like the `direct mode in ccache
    221 <https://ccache.dev/manual/3.7.9.html#_the_direct_mode>`__,
    222 using a similar way to handle caching and dependencies.
    223 
    224   .. note::
    225 
    226      When using sccache, because of the operation on the files and storage,
    227      the initial build of Firefox will be slower.
    228 
    229 Optimization
    230 ^^^^^^^^^^^^
    231 
    232 ``ac_add_options --enable-optimize``
    233   Enables the default compiler optimization options
    234 
    235   .. note::
    236 
    237      This is enabled by default
    238 
    239 ``ac_add_options --enable-optimize=-O2``
    240   Chooses particular compiler optimization options. In most cases, this
    241   will not give the desired results, unless you know the Mozilla
    242   codebase very well; note, however, that if you are building with the
    243   Microsoft compilers, you probably **do** want this as ``-O1`` will
    244   optimize for size, unlike GCC.
    245 ``ac_add_options --enable-debug``
    246   Enables assertions in C++ and JavaScript, plus other debug-only code.
    247   This can significantly slow a build, but it is invaluable when
    248   writing patches. **People developing patches (especially in C++)
    249   should generally use this option.**
    250 ``ac_add_options --disable-optimize``
    251   Disables compiler optimization. This makes it much easier to step
    252   through code in a debugger.
    253 ``ac_add_options --enable-release``
    254   Enables more conservative, release engineering-oriented options. This may
    255   slow down builds. This also turns on full optimizations for Rust. Note this
    256   is the default when building release/beta/esr.
    257 ``ac_add_options --enable-debug-js-modules``
    258   Enable only JavaScript assertions. This is useful when working
    259   locally on JavaScript-powered components like the DevTools. This will
    260   help catch any errors introduced into the JS code, with less of a
    261   performance impact compared to the ``--enable-debug`` option.
    262 ``export RUSTC_OPT_LEVEL=2``
    263   Enable full optimizations for Rust code.
    264 
    265 You can make an optimized build with debugging symbols. See :ref:`Building
    266 with Debug Symbols <Building with Debug Symbols>`.
    267 
    268 Building as Beta or Release
    269 ^^^^^^^^^^^^^^^^^^^^^^^^^^^
    270 
    271 ``ac_add_options --as-milestone=release``
    272   This makes it easy to build nightly with a release or beta configuration to
    273   test the different ifdef behaviors. To do a full beta simulation see
    274   `Sheriffing/How To/Beta simulations <https://wiki.mozilla.org/Sheriffing/How_To/Beta_simulations>`__.
    275 
    276   - ``early-beta``
    277   - ``late-beta``
    278   - ``release``
    279 
    280 Tests
    281 ^^^^^
    282 
    283 ``ac_add_options --disable-tests``
    284   By default, many auxiliary test programs are built, which can
    285   help debug and patch the mozilla source. Disabling these tests can
    286   speed build time and reduce disk space considerably. Developers
    287   should generally not use this option.
    288 
    289 Localization
    290 ^^^^^^^^^^^^
    291 
    292 ``mk_add_options MOZ_CO_LOCALES=ISOcode``
    293   TBD.
    294 ``ac_add_options --enable-ui-locale=ISOcode``
    295   TBD.
    296 ``ac_add_options --with-l10n-base=/path/to/base/dir``
    297   TBD.
    298 
    299 Other Options
    300 ^^^^^^^^^^^^^
    301 
    302 ``mk_add_options AUTOCLOBBER=1``
    303   If a clobber would be required before a build, this will cause mach
    304   to clobber and continue with the build instead of asking the user to
    305   manually clobber and exiting.
    306 
    307 ``ac_add_options --enable-warnings-as-errors``
    308   This makes compiler warnings into errors which fail the build. This
    309   can be useful since certain warnings coincide with reviewbot lints
    310   which must be fixed before merging.
    311 
    312 .. _Example_.mozconfig_Files:
    313 
    314 Example ``mozconfig`` Files
    315 ~~~~~~~~~~~~~~~~~~~~~~~~~~~
    316 
    317 Mozilla's official builds use mozconfig files from the appropriate
    318 directory within each repository.
    319 
    320 .. warning::
    321 
    322   These ``mozconfig`` files are taken from production builds
    323   and are provided as examples only. It is recommended to use the default
    324   build options, and only change the properties from the list above as
    325   needed. The production builds aren't really appropriate for local
    326   builds."
    327 
    328 -  .. rubric:: Firefox, `Debugging Build (macOS
    329      64bits) <https://github.com/mozilla-firefox/firefox/blob/main/browser/config/mozconfigs/macosx64/debug>`__
    330      :name: Firefox.2C_Default_Release_Configuration
    331 
    332 Building multiple projects from the same source tree
    333 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    334 
    335 It is possible to build multiple projects from the same source tree,
    336 as long as you `use a different objdir <#Building_with_an_Objdir>`__ for
    337 each project.
    338 
    339 You need to create multiple ``mozconfig`` files.
    340 
    341 As an example, the following steps can be used to build Firefox and
    342 Thunderbird. You should first create three ``mozconfig`` files.
    343 
    344 ``mozconfig-common``:
    345 
    346 .. code::
    347 
    348   # add common options here, such as making an optimized release build
    349   mk_add_options MOZ_PARALLEL_BUILD=4
    350   ac_add_options --enable-optimize --disable-debug
    351 
    352 ``mozconfig-firefox``:
    353 
    354 .. code::
    355 
    356   # include the common mozconfig
    357   . ./mozconfig-common
    358 
    359   # Build Firefox
    360   mk_add_options MOZ_OBJDIR=@TOPSRCDIR@/obj-firefox
    361   ac_add_options --enable-project=browser
    362 
    363 ``mozconfig-thunderbird``:
    364 
    365 .. code::
    366 
    367   # include the common mozconfig
    368   . ./mozconfig-common
    369 
    370   # Build Thunderbird
    371   mk_add_options MOZ_OBJDIR=@TOPSRCDIR@/obj-thunderbird
    372   ac_add_options --enable-project=comm/mail
    373 
    374 To build Firefox, run the following commands:
    375 
    376 .. code::
    377 
    378   export MOZCONFIG=/path/to/mozilla/mozconfig-firefox
    379   ./mach build
    380 
    381 To build Thunderbird, run the following commands:
    382 
    383 .. code::
    384 
    385   export MOZCONFIG=/path/to/mozilla/mozconfig-thunderbird
    386   ./mach build
    387 
    388 Using mozconfigwrapper
    389 ^^^^^^^^^^^^^^^^^^^^^^
    390 
    391 Mozconfigwrapper is similar to using multiple mozconfig files except
    392 that it abstracts and hides them so you don't have to worry about where
    393 they live or which ones you've created. It also saves you from having to
    394 export the MOZCONFIG variable each time. For information on installing
    395 and configuring mozconfigwrapper, see
    396 https://github.com/ahal/mozconfigwrapper.
    397 
    398 Changing build options per directory -- the moz.build hook
    399 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    400 
    401 Adding a statement like the following to a ``mozconfig`` file:
    402 
    403 .. code::
    404 
    405    ac_add_options MOZ_BUILD_HOOK=/absolute/path/to/file/buildhook.py
    406 
    407 will cause this file to be appended to each ``moz.build`` file of the tree. It
    408 is recommended to place this file outside of the tree, so that it is not wiped
    409 when cleaning up the tree via ``git clean``.
    410 
    411 This hook file is written in the same subset of Python as ``moz.build`` files.
    412 
    413 Possibilities are endless, but this is particularly useful to tweak compiler
    414 options for selected directories, such as disabling optimizations to have a
    415 better debugging experience without having the entire browser being very slow:
    416 
    417 .. code:: python
    418 
    419    nonopt = (
    420        "dom/media/",
    421        "media/ffvpx/",
    422        "media/libcubeb/",
    423    )
    424    if RELATIVEDIR.startswith(nonopt):
    425        COMPILE_FLAGS["OPTIMIZE"] = []
    426 
    427 will make all compilation units at or under those three paths have no
    428 optimization.
    429 
    430 Another useful thing to set per directory is ``FILES_PER_UNIFIED_FILE=1`` to
    431 disable :ref:`unified builds<unified_builds>`.