1# Zephyr documentation build configuration file. 2# Reference: https://www.sphinx-doc.org/en/master/usage/configuration.html 3 4import sys 5import os 6from pathlib import Path 7import re 8import textwrap 9 10from sphinx.cmd.build import get_parser 11 12args = get_parser().parse_args() 13ZEPHYR_BASE = Path(__file__).resolve().parents[1] 14ZEPHYR_BUILD = Path(args.outputdir).resolve() 15 16# Add the '_extensions' directory to sys.path, to enable finding Sphinx 17# extensions within. 18sys.path.insert(0, str(ZEPHYR_BASE / "doc" / "_extensions")) 19 20# Add the '_scripts' directory to sys.path, to enable finding utility 21# modules. 22sys.path.insert(0, str(ZEPHYR_BASE / "doc" / "_scripts")) 23 24# Add the directory which contains the runners package as well, 25# for autodoc directives on runners.xyz. 26sys.path.insert(0, str(ZEPHYR_BASE / "scripts" / "west_commands")) 27 28# Add the directory which contains the pytest-twister-pytest 29sys.path.insert(0, str(ZEPHYR_BASE / "scripts" / "pylib" / "pytest-twister-harness" / "src")) 30 31import redirects 32 33try: 34 import west as west_found 35except ImportError: 36 west_found = False 37 38# -- Project -------------------------------------------------------------- 39 40project = "Zephyr Project" 41copyright = "2015-2024 Zephyr Project members and individual contributors" 42author = "The Zephyr Project Contributors" 43 44# parse version from 'VERSION' file 45with open(ZEPHYR_BASE / "VERSION") as f: 46 m = re.match( 47 ( 48 r"^VERSION_MAJOR\s*=\s*(\d+)$\n" 49 + r"^VERSION_MINOR\s*=\s*(\d+)$\n" 50 + r"^PATCHLEVEL\s*=\s*(\d+)$\n" 51 + r"^VERSION_TWEAK\s*=\s*\d+$\n" 52 + r"^EXTRAVERSION\s*=\s*(.*)$" 53 ), 54 f.read(), 55 re.MULTILINE, 56 ) 57 58 if not m: 59 sys.stderr.write("Warning: Could not extract kernel version\n") 60 version = "Unknown" 61 else: 62 major, minor, patch, extra = m.groups(1) 63 version = ".".join((major, minor, patch)) 64 if extra: 65 version += "-" + extra 66 67release = version 68 69# parse SDK version from 'SDK_VERSION' file 70with open(ZEPHYR_BASE / "SDK_VERSION") as f: 71 sdk_version = f.read().strip() 72 73# -- General configuration ------------------------------------------------ 74 75extensions = [ 76 "breathe", 77 "sphinx_rtd_theme", 78 "sphinx.ext.todo", 79 "sphinx.ext.extlinks", 80 "sphinx.ext.autodoc", 81 "sphinx.ext.graphviz", 82 "sphinxcontrib.jquery", 83 "zephyr.application", 84 "zephyr.html_redirects", 85 "zephyr.kconfig", 86 "zephyr.dtcompatible-role", 87 "zephyr.link-roles", 88 "sphinx_tabs.tabs", 89 "zephyr.warnings_filter", 90 "zephyr.doxyrunner", 91 "zephyr.gh_utils", 92 "zephyr.manifest_projects_table", 93 "notfound.extension", 94 "sphinx_copybutton", 95 "sphinx_togglebutton", 96 "zephyr.external_content", 97 "zephyr.domain", 98] 99 100# Only use SVG converter when it is really needed, e.g. LaTeX. 101if tags.has("svgconvert"): # pylint: disable=undefined-variable 102 extensions.append("sphinxcontrib.rsvgconverter") 103 104templates_path = ["_templates"] 105 106exclude_patterns = ["_build"] 107 108if not west_found: 109 exclude_patterns.append("**/*west-apis*") 110else: 111 exclude_patterns.append("**/*west-not-found*") 112 113pygments_style = "sphinx" 114highlight_language = "none" 115 116todo_include_todos = False 117 118nitpick_ignore = [ 119 # ignore C standard identifiers (they are not defined in Zephyr docs) 120 ("c:identifier", "FILE"), 121 ("c:identifier", "int8_t"), 122 ("c:identifier", "int16_t"), 123 ("c:identifier", "int32_t"), 124 ("c:identifier", "int64_t"), 125 ("c:identifier", "intptr_t"), 126 ("c:identifier", "off_t"), 127 ("c:identifier", "size_t"), 128 ("c:identifier", "ssize_t"), 129 ("c:identifier", "time_t"), 130 ("c:identifier", "uint8_t"), 131 ("c:identifier", "uint16_t"), 132 ("c:identifier", "uint32_t"), 133 ("c:identifier", "uint64_t"), 134 ("c:identifier", "uintptr_t"), 135 ("c:identifier", "va_list"), 136] 137 138SDK_URL_BASE="https://github.com/zephyrproject-rtos/sdk-ng/releases/download" 139 140rst_epilog = f""" 141.. include:: /substitutions.txt 142 143.. |sdk-version-literal| replace:: ``{sdk_version}`` 144.. |sdk-version-trim| unicode:: {sdk_version} 145 :trim: 146.. |sdk-version-ltrim| unicode:: {sdk_version} 147 :ltrim: 148.. _Zephyr SDK bundle: https://github.com/zephyrproject-rtos/sdk-ng/releases/tag/v{sdk_version} 149.. |sdk-url-linux| replace:: `{SDK_URL_BASE}/v{sdk_version}/zephyr-sdk-{sdk_version}_linux-x86_64.tar.xz` 150.. |sdk-url-linux-sha| replace:: `{SDK_URL_BASE}/v{sdk_version}/sha256.sum` 151.. |sdk-url-macos| replace:: `{SDK_URL_BASE}/v{sdk_version}/zephyr-sdk-{sdk_version}_macos-x86_64.tar.xz` 152.. |sdk-url-macos-sha| replace:: `{SDK_URL_BASE}/v{sdk_version}/sha256.sum` 153.. |sdk-url-windows| replace:: `{SDK_URL_BASE}/v{sdk_version}/zephyr-sdk-{sdk_version}_windows-x86_64.7z` 154""" 155 156# -- Options for HTML output ---------------------------------------------- 157 158html_theme = "sphinx_rtd_theme" 159html_theme_options = { 160 "logo_only": True, 161 "prev_next_buttons_location": None 162} 163html_baseurl = "https://docs.zephyrproject.org/latest/" 164html_title = "Zephyr Project Documentation" 165html_logo = str(ZEPHYR_BASE / "doc" / "_static" / "images" / "logo.svg") 166html_favicon = str(ZEPHYR_BASE / "doc" / "_static" / "images" / "favicon.png") 167html_static_path = [str(ZEPHYR_BASE / "doc" / "_static")] 168html_last_updated_fmt = "%b %d, %Y" 169html_domain_indices = False 170html_split_index = True 171html_show_sourcelink = False 172html_show_sphinx = False 173html_search_scorer = str(ZEPHYR_BASE / "doc" / "_static" / "js" / "scorer.js") 174html_additional_pages = { 175 "gsearch": "gsearch.html" 176} 177 178is_release = tags.has("release") # pylint: disable=undefined-variable 179reference_prefix = "" 180if tags.has("publish"): # pylint: disable=undefined-variable 181 reference_prefix = f"/{version}" if is_release else "/latest" 182docs_title = "Docs / {}".format(version if is_release else "Latest") 183html_context = { 184 "show_license": True, 185 "docs_title": docs_title, 186 "is_release": is_release, 187 "current_version": version, 188 "versions": ( 189 ("latest", "/"), 190 ("3.6.0", "/3.6.0/"), 191 ("3.5.0", "/3.5.0/"), 192 ("2.7.5 (LTS)", "/2.7.5/"), 193 ), 194 "display_gh_links": True, 195 "reference_links": { 196 "API": f"{reference_prefix}/doxygen/html/index.html", 197 "Kconfig Options": f"{reference_prefix}/kconfig.html", 198 "Devicetree Bindings": f"{reference_prefix}/build/dts/api/bindings.html", 199 "West Projects": f"{reference_prefix}/develop/manifest/index.html", 200 }, 201 # Set google_searchengine_id to your Search Engine ID to replace built-in search 202 # engine with Google's Programmable Search Engine. 203 # See https://programmablesearchengine.google.com/ for details. 204 "google_searchengine_id": "746031aa0d56d4912", 205} 206 207# -- Options for LaTeX output --------------------------------------------- 208 209latex_elements = { 210 "papersize": "a4paper", 211 "maketitle": open(ZEPHYR_BASE / "doc" / "_static" / "latex" / "title.tex").read(), 212 "preamble": open(ZEPHYR_BASE / "doc" / "_static" / "latex" / "preamble.tex").read(), 213 "makeindex": r"\usepackage[columns=1]{idxlayout}\makeindex", 214 "fontpkg": textwrap.dedent(r""" 215 \usepackage{noto} 216 \usepackage{inconsolata-nerd-font} 217 \usepackage[T1]{fontenc} 218 """), 219 "sphinxsetup": ",".join( 220 ( 221 # NOTE: colors match those found in light.css stylesheet 222 "verbatimwithframe=false", 223 "VerbatimColor={HTML}{f0f2f4}", 224 "InnerLinkColor={HTML}{2980b9}", 225 "warningBgColor={HTML}{e9a499}", 226 "warningborder=0pt", 227 r"HeaderFamily=\rmfamily\bfseries", 228 ) 229 ), 230} 231latex_logo = str(ZEPHYR_BASE / "doc" / "_static" / "images" / "logo-latex.pdf") 232latex_documents = [ 233 ("index-tex", "zephyr.tex", "Zephyr Project Documentation", author, "manual"), 234] 235latex_engine = "xelatex" 236 237# -- Options for zephyr.doxyrunner plugin --------------------------------- 238 239doxyrunner_doxygen = os.environ.get("DOXYGEN_EXECUTABLE", "doxygen") 240doxyrunner_doxyfile = ZEPHYR_BASE / "doc" / "zephyr.doxyfile.in" 241doxyrunner_outdir = ZEPHYR_BUILD / "doxygen" 242doxyrunner_fmt = True 243doxyrunner_fmt_vars = {"ZEPHYR_BASE": str(ZEPHYR_BASE), "ZEPHYR_VERSION": version} 244doxyrunner_outdir_var = "DOXY_OUT" 245 246# -- Options for Breathe plugin ------------------------------------------- 247 248breathe_projects = {"Zephyr": str(doxyrunner_outdir / "xml")} 249breathe_default_project = "Zephyr" 250breathe_domain_by_extension = { 251 "h": "c", 252 "c": "c", 253} 254breathe_show_enumvalue_initializer = True 255breathe_default_members = ("members", ) 256 257cpp_id_attributes = [ 258 "__syscall", 259 "__syscall_always_inline", 260 "__deprecated", 261 "__may_alias", 262 "__used", 263 "__unused", 264 "__weak", 265 "__attribute_const__", 266 "__DEPRECATED_MACRO", 267 "FUNC_NORETURN", 268 "__subsystem", 269 "ALWAYS_INLINE", 270] 271c_id_attributes = cpp_id_attributes 272 273# -- Options for html_redirect plugin ------------------------------------- 274 275html_redirect_pages = redirects.REDIRECTS 276 277# -- Options for zephyr.warnings_filter ----------------------------------- 278 279warnings_filter_config = str(ZEPHYR_BASE / "doc" / "known-warnings.txt") 280 281# -- Options for zephyr.link-roles ---------------------------------------- 282 283link_roles_manifest_project = "zephyr" 284link_roles_manifest_baseurl = "https://github.com/zephyrproject-rtos/zephyr" 285 286# -- Options for notfound.extension --------------------------------------- 287 288notfound_urls_prefix = f"/{version}/" if is_release else "/latest/" 289 290# -- Options for zephyr.gh_utils ------------------------------------------ 291 292gh_link_version = f"v{version}" if is_release else "main" 293gh_link_base_url = f"https://github.com/zephyrproject-rtos/zephyr" 294gh_link_prefixes = { 295 "samples/.*": "", 296 "boards/.*": "", 297 "snippets/.*": "", 298 ".*": "doc", 299} 300gh_link_exclude = [ 301 "reference/kconfig.*", 302 "build/dts/api/bindings.*", 303 "build/dts/api/compatibles.*", 304] 305 306# -- Options for zephyr.kconfig ------------------------------------------- 307 308kconfig_generate_db = True 309kconfig_ext_paths = [ZEPHYR_BASE] 310 311# -- Options for zephyr.external_content ---------------------------------- 312 313external_content_contents = [ 314 (ZEPHYR_BASE / "doc", "[!_]*"), 315 (ZEPHYR_BASE, "boards/**/*.rst"), 316 (ZEPHYR_BASE, "boards/**/doc"), 317 (ZEPHYR_BASE, "samples/**/*.html"), 318 (ZEPHYR_BASE, "samples/**/*.rst"), 319 (ZEPHYR_BASE, "samples/**/doc"), 320 (ZEPHYR_BASE, "snippets/**/*.rst"), 321 (ZEPHYR_BASE, "snippets/**/doc"), 322] 323external_content_keep = [ 324 "reference/kconfig/*", 325 "develop/manifest/index.rst", 326 "build/dts/api/bindings.rst", 327 "build/dts/api/bindings/**/*", 328 "build/dts/api/compatibles/**/*", 329] 330 331# -- Options for zephyr.domain -------------------------------------------- 332 333zephyr_breathe_insert_related_samples = True 334 335# -- Options for sphinx.ext.graphviz -------------------------------------- 336 337graphviz_dot = os.environ.get("DOT_EXECUTABLE", "dot") 338graphviz_output_format = "svg" 339graphviz_dot_args = [ 340 "-Gbgcolor=transparent", 341 "-Nstyle=filled", 342 "-Nfillcolor=white", 343 "-Ncolor=gray60", 344 "-Nfontcolor=gray25", 345 "-Ecolor=gray60", 346] 347 348# -- Options for sphinx_copybutton ---------------------------------------- 349 350copybutton_prompt_text = r"\$ |uart:~\$ " 351copybutton_prompt_is_regexp = True 352 353# -- Linkcheck options ---------------------------------------------------- 354 355linkcheck_ignore = [ 356 r"https://github.com/zephyrproject-rtos/zephyr/issues/.*" 357] 358 359extlinks = { 360 "github": ("https://github.com/zephyrproject-rtos/zephyr/issues/%s", "GitHub #%s"), 361} 362 363linkcheck_timeout = 30 364linkcheck_workers = 10 365linkcheck_anchors = False 366 367 368def setup(app): 369 # theme customizations 370 app.add_css_file("css/custom.css") 371 app.add_js_file("js/custom.js") 372 app.add_js_file("js/dark-mode-toggle.min.mjs", type="module") 373