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 included from Doxygen comments.

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

Before you start

Before you can build the documentation, install the nRF Connect SDK as described in Installing the nRF Connect SDK manually. Make sure that you have installed the required Python dependencies.

See Installing the documentation processors in the Zephyr developer guide for information about installing the required tools to build the documentation and their supported versions. In addition to these tools, you must install mscgen and make sure the mscgen executable is in your PATH.

Note

On Windows, the Sphinx executable sphinx-build.exe is placed in the Scripts folder of your Python installation path. Depending on how you have installed Python, you might need to add this folder to your PATH environment variable. Follow the instructions in Windows Python Path if needed.

Documentation structure

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 are provided in a README.rst or .rst file in the same directory as the code.

Building the documentation output requires building output for all documentation sets. Currently, there are four sets: nrf, nrfxlib, zephyr, and mcuboot (covering the contents of bootloader/mcuboot). Since there are links from the ncs documentation set into other documentation sets, the other documentation sets must be built first.

Building documentation output

Complete the following steps to build the documentation output:

  1. Open a shell and enter the doc folder ncs/nrf/doc.

    • On Windows:

      1. Navigate to ncs/nrf.

      2. Hold shift and right-click on the doc folder. Select Open command window here.

    • On Linux or macOS:

      1. Open a shell window.

      2. Navigate to ncs/nrf/doc. If the ncs folder is in your home directory, enter:

        cd ~/ncs/nrf/doc
        
  2. Generate the Ninja build files:

    cmake -GNinja -B_build .
    
  3. Enter the generated build folder:

    cd _build
    
  4. Run ninja to build the documentation:

    ninja build-all
    

    This command will build all documentation sets. Note that this process can take quite some time.

    Alternatively, if you want to build each documentation set separately, complete the following steps:

    1. Run ninja to build the Kconfig documentation:

      ninja kconfig-html
      
    2. Run ninja to build the Zephyr documentation:

      ninja zephyr
      

      This step can take up to 15 minutes.

    3. Run ninja to build the mcuboot documentation:

      ninja mcuboot
      
    4. Run ninja to build the nrfxlib inventory file (used by nrf):

      ninja nrfxlib-inventory
      
    5. Run ninja to build the nRF Connect SDK documentation:

      ninja nrf
      
    6. Run ninja to build the nrfxlib documentation:

      ninja nrfxlib
      

The documentation output is written to _buildhtml. Double-click the index.html file to display the documentation in your browser.

Tip

If you modify or add RST files, you do not need to rerun the full documentation build. For simple changes, it is sufficient to run the substep that builds the respective documentation (for example, only ninja nrf for changes to the nRF Connect SDK documentation). If this results in unexpected build errors, follow Caching and cleaning and rerun ninja build-all.

Caching and cleaning

To speed up the documentation build, Sphinx processes only those files that have been changed since the last build. In addition, RST files are copied to a different location during the build process. This mechanism can cause outdated or deleted files to be used in the build, or the navigation to not be updated as expected.

If you experience any such problems, clean the build folders before you run the documentation build. Note that this will cause the documentation to be built from scratch, which takes a considerable time.

To clean the build folders for the Zephyr documentation:

ninja clean-zephyr

To clean the build folders for the nrfxlib documentation:

ninja clean-nrfxlib

To clean the build folders for the MCUboot documentation:

ninja clean-mcuboot

To clean the build folders for the nRF Connect SDK documentation:

ninja clean-nrf

Out-of-tree builds

Out-of-tree builds are also supported, so you can actually build from outside the source tree:

# On Linux/macOS
cd ~
source ncs/zephyr/zephyr-env.sh
cd ~
mkdir build
# On Windows
cd %userprofile%
ncs\zephyr\zephyr-env.cmd
mkdir build

# Use cmake to configure a Ninja-based build system:
cmake -GNinja -Bbuild/ -Hncs/nrf/doc
# Now run ninja on the generated build system:
ninja -C build/ zephyr
ninja -C build/ mcuboot
ninja -C build/ nrfxlib-inventory
ninja -C build/ nrf
ninja -C build/ nrfxlib
# If you modify or add .rst files in the nRF repository, run ninja again:
ninja -C build/ nrf

If you want to build the documentation from scratch, delete the contents of the build folder and run cmake and then ninja again.

Different versions

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 in the top-left corner of the documentation.

The version drop-down is displayed only if the documentation files are organized in the required folder structure and the documentation is hosted on a web server. 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 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, 1.4.0).