Building the nRF Connect SDK documentation

The nRF Connect SDK documentation is written using the reStructuredText markup language (.rst file extension) with Sphinx extensions and processed using Sphinx. API documentation is generated from Doxygen comments.

See Documentation overview in the Zephyr developer guide for information about reStructuredText.

Before you start

Before you can build the documentation, you must install the required tools. The following tool versions have been tested to work:

  • Doxygen 1.9.6

  • Mscgen 0.20

  • PlantUML

  • Python dependencies as listed in Building documentation on the Requirements page

Complete the following steps to install the required tools:

  1. If you have not done so already, install the nRF Connect SDK as described in Installing the nRF Connect SDK.

  2. Install or update all required Python dependencies.

  3. Install the additional Python dependencies for building the documentation by entering the following command in a terminal window in the ncs folder. Python virtual environment needs to be active for the command to work:

    pip install -U -r nrf/doc/requirements.txt
    
  4. Install Doxygen.

  5. Install Mscgen and make sure that the mscgen executable is in your PATH.

  6. Install PlantUML. On Windows, you can install PlantUML from chocolatey.

Building documentation output

All documentation build files are located in the ncs/nrf/doc folder. The nrf subfolder in that directory contains all .rst source files that are not directly related to a sample application or a library. Documentation for samples and libraries is provided in a README.rst or another .rst file in the same directory as the code.

Building the documentation output requires building the output for all documentation sets that are part of the Documentation structure. Since there are links from the nRF Connect SDK documentation set into other documentation sets, the documentation is built in a predefined order.

Complete the following steps to build the documentation output:

  1. Start the toolchain environment in a terminal window.

  2. Enter the doc folder ncs/nrf/doc.

  3. Generate the Ninja build files by entering the following command:

    cmake -GNinja -S. -B_build
    
  4. Enter the generated build folder:

    cd _build
    
  5. Run ninja to build the complete documentation by entering the following command:

    ninja
    

The documentation output is written to the doc/_build/html folder. Double-click the index.html file to display the documentation in your browser.

Alternatively, you can work with just a single documentation set, for example, nrf. The build system provides individual targets for such a purpose. If you have not built all documentation sets before, it is recommended to run the following command:

ninja docset-name-all

Here, docset-name is the name of the documentation set, for example, nrf. This target will build the documentation sets that are needed for docset-name.

On subsequent builds, it is recommended to just run the following command:

ninja docset-name

The last couple of targets mentioned in Documentation structure will only invoke the build for the corresponding documentation set (referred by docset-name), assuming that all of its dependencies are available.

Caching and cleaning

To speed up the documentation build, Sphinx processes only those files that have been changed since the last build. This mechanism can sometimes cause issues such as navigation not being updated correctly.

If you experience any of such issues, clean the build folders before you run the documentation build.

To clean all the build files:

ninja clean

To clean the build folders for a particular documentation set:

ninja docset-name-clean

Here, docset-name is the name of the documentation set, for example, nrf.

Testing locally

Documentation sets for different versions of the nRF Connect SDK are defined in the doc/versions.json file. This file is used to display the version drop-down.

To test the version drop-down locally, complete the following steps:

  1. In the documentation build folder (for example, _build), rename the html folder to latest.

  2. Open a command-line window in the documentation build folder and enter the following command to start a Python web server:

    python -m http.server
    
  3. Access http://localhost:8000/latest/index.html with your browser to see the documentation.

To add other versions of the documentation to your local documentation output, build the versions from a tagged release and rename the html folder to the respective version (for example, 2.7.0).

Dealing with warnings

When building the documentation, all warnings are regarded as errors, so they will make the documentation build fail.

However, there are some known issues with Sphinx and Breathe that generate Sphinx warnings even though the input is valid C code. To deal with such unavoidable warnings, Zephyr provides the Sphinx extension zephyr.warnings_filter that filters out warnings based on a set of regular expressions. You can find the extension together with usage details at ncs/zephyr/doc/_extensions/zephyr/warnings_filter.py.

The configuration file that defines the expected warnings for the nrf documentation set is located at ncs/nrf/doc/nrf/known-warnings.txt. It contains regular expressions to filter out warnings related to duplicate C declarations. These warnings are caused by different objects (for example, a struct and a function or nested elements) sharing the same name.