1 .. _mozilla_projects_nss_building:
6 `Introduction <#introduction>`__
7 --------------------------------
11 This page has detailed information on how to build NSS. Because NSS is a
12 cross-platform library that builds on many different platforms and has many
13 options, it may be complex to build._ Two build systems are maintained
14 concurrently: a ``Make`` based and a ``gyp`` based system.
16 .. _build_environment:
18 `Prerequisites <#build_environment>`__
19 ------------------------------------------
23 NSS needs a C and C++ compiler. It has minimal dependencies, including only
24 standard C and C++ libraries, plus `zlib <https://www.zlib.net/>`__.
25 For building, you also need `make <https://www.gnu.org/software/make/>`__.
26 Ideally, also install `gyp-next <https://github.com/nodejs/gyp-next>`__ and `ninja
27 <https://ninja-build.org/>`__ and put them on your path. This is
28 recommended, as the build is faster and more reliable.
29 Please, note that we ``gyp`` is currently unmaintained and that our support for
30 ``gyp-next`` is experimental and might be unstable.
32 To install prerequisites on different platforms, one can run the following
39 sudo apt install mercurial git ninja-build python3-pip
40 python3 -m pip install gyp-next
46 brew install mercurial git ninja python3-pip
47 python3 -m pip install gyp-next
49 It is also necessary to make sure that a `python` (not just `python3`)
50 executable is in the path.
51 The Homebrew Python installation has the necessary symlink but may require
52 explicit adding to the PATH variable, for example like this:
56 export PATH="/opt/homebrew/opt/python/libexec/bin:$PATH"
65 To retrieve the source code from the project repositories, users will need to
66 download a release or pull the source code with their favourite Version
67 Control System (git or Mercurial). Installing a VCS is not necessary to build
68 an NSS release when downloaded as a compressed archive.
70 By default Mozilla uses a Mercurial repository for NSS. If you whish to
71 contribute to NSS and use ``git`` instead of Mercurial, we encourage you to
72 install `git-cinnabar <https://github.com/glandium/git-cinnabar>`__.
75 `Windows <#windows>`__
76 ~~~~~~~~~~~~~~~~~~~~~~
80 NSS compilation on Windows uses the same shared build system as Mozilla
81 Firefox. You must first install the `Windows Prerequisites
82 <https://firefox-source-docs.mozilla.org/setup/windows_build.html>`__,
83 including **MozillaBuild**.
85 You can also build NSS on the Windows Subsystem for Linux, but the resulting binaries aren't
86 usable by other Windows applications.
90 `Source code <#get_the_source>`__
91 ---------------------------------
95 NSS and NSPR use Mercurial for source control like other Mozilla projects. To
96 check out the latest sources for NSS and NSPR--which may not be part of a
97 stable release--use the following commands:
101 hg clone https://hg.mozilla.org/projects/nspr
102 hg clone https://hg.mozilla.org/projects/nss
105 **To get the source of a specific release, see:**
106 ref:`mozilla_projects_nss_releases` **.**
108 To download the source using ``git-cinnabar`` instead:
112 git clone hg::https://hg.mozilla.org/projects/nspr
113 git clone hg::https://hg.mozilla.org/projects/nss
116 `Build with gyp and ninja <#build>`__
117 -------------------------------------
121 Build NSS and NSPR using our build script from the ``nss`` directory:
128 This builds both NSPR and NSS in a parent directory called ``dist``.
130 Build options are available for this script: ``-o`` will build in **Release**
131 mode instead of the **Debug** mode and ``-c`` will **clean** the ``dist``
132 directory before the build.
134 Other build options can be displayed by running ``./build.sh --help``
138 `Build with make <#build_with_make>`__
139 --------------------------------------
143 Alternatively, there is a ``make`` target, which produces a similar
144 result. This supports some alternative options, but can be a lot slower.
150 The make-based build system for NSS uses a variety of variables to control
151 the build. Below are some of the variables, along with possible values they
155 :header: "BUILD_OPT", ""
158 "0", "Build a debug (non-optimized) version of NSS. **This is the default.**"
159 "1", "Build an optimized (non-debug) version of NSS."
162 :header: "USE_64", ""
165 "0", "Build for a 32-bit environment/ABI. **This is the default.**"
166 "1", "Build for a 64-bit environment/ABI. *This is recommended.*"
169 :header: "USE_ASAN", ""
172 "0", "Do not create an `AddressSanitizer
173 <http://clang.llvm.org/docs/AddressSanitizer.html>`__ build. **This is the default.**"
174 "1", "Create an AddressSanitizer build."
179 `Unit testing <#unit_testing>`__
180 --------------------------------
184 NSS contains extensive unit tests. Scripts to run these are found in the ``tests`` directory.
185 Run the standard suite by:
189 HOST=localhost DOMSUF=localdomain USE_64=1 ./tests/all.sh
191 .. _unit_test_configuration:
193 `Unit test configuration <#unit_test_configuration>`__
194 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
198 NSS tests are configured using environment variables.
199 The scripts will attempt to infer values for ``HOST`` and ``DOMSUF``, but
200 can fail. Replace ``localhost`` and ``localdomain`` with the hostname and
201 domain suffix for your host. You need to be able to connect to
204 If you don't have a domain suffix you can add an entry to ``/etc/hosts`` (on
205 Windows,\ ``c:\Windows\System32\drivers\etc\hosts``) as follows:
209 127.0.0.1 localhost.localdomain
211 Validate this opening a command shell and typing: ``ping localhost.localdomain``.
213 Remove the ``USE_64=1`` override if using a 32-bit build.
217 `Test results <#test_results>`__
218 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
222 Running all tests can take a considerable amount of time.
224 Test output is stored in ``tests_results/security/$HOST.$NUMBER/``. The file
225 ``results.html`` summarizes the results, ``output.log`` captures all the test
228 Other subdirectories of ``nss/tests`` contain scripts that run a subset of
229 the full suite. Those can be run directly instead of ``all.sh``, which might
230 save some time at the cost of coverage.