[libc-commits] [libc] 62e03e7 - [libc][docs] Migrate docgen output to MyST Markdown (#239413)

via libc-commits libc-commits at lists.llvm.org
Fri Nov 6 08:04:52 PST 2026


Author: Jeff Bailey
Date: 2026-11-06T16:04:46Z
New Revision: 62e03e74713841958502debab55ad2fa295f940f

URL: https://github.com/llvm/llvm-project/commit/62e03e74713841958502debab55ad2fa295f940f
DIFF: https://github.com/llvm/llvm-project/commit/62e03e74713841958502debab55ad2fa295f940f.diff

LOG: [libc][docs] Migrate docgen output to MyST Markdown (#239413)

The rest of libc/docs/ has migrated to MyST Markdown, leaving docgen as
the last generator emitting reStructuredText list-tables with plain
checkmark substitutions.

Switch docgen to emit MyST Markdown with styled HTML status tables that
adapt to Furo's light and dark colour themes and include screen-reader
labels for symbol status badges.

Assisted-by: Automated tooling, human reviewed.

Added: 
    libc/docs/_static/status.css

Modified: 
    libc/docs/CMakeLists.txt
    libc/docs/conf.py
    libc/docs/dev/building_docs.md
    libc/utils/docgen/docgen.py
    libc/utils/docgen/docgen_test.py

Removed: 
    


################################################################################
diff  --git a/libc/docs/CMakeLists.txt b/libc/docs/CMakeLists.txt
index 305e1ad5ec6fdd..9f338e1c339782 100644
--- a/libc/docs/CMakeLists.txt
+++ b/libc/docs/CMakeLists.txt
@@ -4,8 +4,8 @@ if(LLVM_ENABLE_SPHINX)
     if(${SPHINX_OUTPUT_HTML})
       # Similar to clang, we copy our static documentation files from libc/docs/
       # to the $build_dir/libc/docs/. That way, we can have a mix of both static
-      # committed files and dynamically generated .rst files. We don't want the
-      # dynamically generated .rst files to pollute the source tree.
+      # committed files and dynamically generated .md files. We don't want the
+      # dynamically generated .md files to pollute the source tree.
       # Maintain a list of headers for which we dynamically generate html docs
       # for via docgen. For more complex docs (such as per arch support, a la
       # math.h), those should be omitted and exist statically in
@@ -67,7 +67,7 @@ if(LLVM_ENABLE_SPHINX)
         wctype
       )
       foreach(stem IN LISTS docgen_list)
-        list(APPEND libc_generated_docs "headers/${stem}.rst")
+        list(APPEND libc_generated_docs "headers/${stem}.md")
       endforeach()
       list(APPEND libc_generated_docs configure.rst)
       add_sphinx_source_sync_target(copy-libc-rst-docs
@@ -102,13 +102,13 @@ if(LLVM_ENABLE_SPHINX)
         # docgen relies on the "/" to find headers nested under directories.
         # Replace with underscore and namespace the target to avoid collisions
         # with other runtime targets in combined builds.
-        string(REPLACE "/" "_" stem_rst ${stem})
-        set(docgen_target_name libc-docgen-${stem_rst})
+        string(REPLACE "/" "_" stem_target ${stem})
+        set(docgen_target_name libc-docgen-${stem_target})
 
         # docgen invocation.
         add_custom_target(${docgen_target_name}
           COMMAND ${Python3_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/../utils/docgen/docgen.py ${stem}.h >
-            ${CMAKE_CURRENT_BINARY_DIR}/headers/${stem}.rst)
+            ${CMAKE_CURRENT_BINARY_DIR}/headers/${stem}.md)
         add_dependencies(${docgen_target_name} copy-libc-rst-docs)
         # depend on the docgen invocation.
         add_dependencies(docs-libc-html ${docgen_target_name})

diff  --git a/libc/docs/_static/status.css b/libc/docs/_static/status.css
new file mode 100644
index 00000000000000..f1828153559c8d
--- /dev/null
+++ b/libc/docs/_static/status.css
@@ -0,0 +1,152 @@
+:root {
+  --hc-green-bg: rgba(31, 136, 61, 0.1);
+  --hc-green-border: rgba(26, 127, 55, 0.4);
+  --hc-green-text: #166534;
+  --hc-blue-bg: rgba(9, 105, 218, 0.09);
+  --hc-blue-border: rgba(9, 105, 218, 0.3);
+  --hc-blue-text: #0969da;
+}
+
+body[data-theme="dark"] {
+  --hc-green-bg: rgba(46, 160, 67, 0.15);
+  --hc-green-border: rgba(63, 185, 80, 0.45);
+  --hc-green-text: #3fb950;
+  --hc-blue-bg: rgba(56, 139, 253, 0.15);
+  --hc-blue-border: rgba(88, 166, 255, 0.4);
+  --hc-blue-text: #58a6ff;
+}
+
+ at media (prefers-color-scheme: dark) {
+  body:not([data-theme="light"]) {
+    --hc-green-bg: rgba(46, 160, 67, 0.15);
+    --hc-green-border: rgba(63, 185, 80, 0.45);
+    --hc-green-text: #3fb950;
+    --hc-blue-bg: rgba(56, 139, 253, 0.15);
+    --hc-blue-border: rgba(88, 166, 255, 0.4);
+    --hc-blue-text: #58a6ff;
+  }
+}
+
+.hc-sr-only {
+  position: absolute;
+  width: 1px;
+  height: 1px;
+  padding: 0;
+  margin: -1px;
+  overflow: hidden;
+  clip: rect(0, 0, 0, 0);
+  white-space: nowrap;
+  border: 0;
+}
+
+.hc-table-wrap {
+  border: 1px solid var(--color-background-border, #e1e4e8);
+  border-radius: 8px;
+  overflow-x: auto;
+  margin: 12px 0 28px 0;
+  background: var(--color-background-primary, #fff);
+  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.03);
+}
+
+.hc-table {
+  width: 100%;
+  margin: 0;
+  border-collapse: collapse;
+  font-size: 0.88rem;
+  text-align: left;
+}
+
+.hc-table th {
+  background: var(--color-background-secondary, #f6f8fa);
+  border-bottom: 1px solid var(--color-background-border, #e1e4e8);
+  padding: 8px 10px;
+  font-size: 0.76rem;
+  font-weight: 600;
+  text-transform: uppercase;
+  letter-spacing: 0.03em;
+  color: var(--color-foreground-muted, #57606a);
+  white-space: nowrap;
+}
+
+.hc-table th.hc-center,
+.hc-table td.hc-center {
+  text-align: center;
+}
+
+.hc-table td {
+  padding: 8px 10px;
+  border-bottom: 1px solid var(--color-background-border, #eaecef);
+  vertical-align: middle;
+}
+
+.hc-table tbody tr:last-child td {
+  border-bottom: none;
+}
+
+.hc-table tbody tr:hover {
+  background: rgba(175, 184, 193, 0.08);
+}
+
+.hc-sym {
+  font-family: var(--font-stack--monospace, monospace);
+  font-size: 0.92rem;
+  font-weight: 600;
+  color: var(--color-foreground-primary, #24292f);
+  background: none;
+  padding: 0;
+}
+
+.hc-status-yes {
+  display: inline-flex;
+  align-items: center;
+  justify-content: center;
+  width: 24px;
+  height: 24px;
+  border-radius: 999px;
+  font-size: 0.82rem;
+  font-weight: 700;
+  background: var(--hc-green-bg);
+  color: var(--hc-green-text);
+  border: 1px solid var(--hc-green-border);
+}
+
+.hc-status-no {
+  display: inline-flex;
+  align-items: center;
+  justify-content: center;
+  width: 24px;
+  height: 24px;
+  color: var(--color-foreground-muted, #8c959f);
+  opacity: 0.45;
+  font-size: 0.9rem;
+}
+
+.hc-sec-badge {
+  font-family: var(--font-stack--monospace, monospace);
+  font-size: 0.78rem;
+  color: var(--color-foreground-secondary, #57606a);
+  background: var(--color-background-secondary, #f6f8fa);
+  border: 1px solid var(--color-background-border, #e1e4e8);
+  padding: 1px 6px;
+  border-radius: 4px;
+  white-space: nowrap;
+}
+
+.hc-posix-link {
+  display: inline-flex;
+  align-items: center;
+  gap: 3px;
+  font-size: 0.76rem;
+  font-weight: 500;
+  color: var(--hc-blue-text);
+  background: var(--hc-blue-bg);
+  border: 1px solid var(--hc-blue-border);
+  padding: 1px 7px;
+  border-radius: 999px;
+  text-decoration: none;
+  white-space: nowrap;
+}
+
+.hc-posix-link:hover {
+  text-decoration: underline;
+}

diff  --git a/libc/docs/conf.py b/libc/docs/conf.py
index f914a0bb2a20af..169a056c47be1f 100644
--- a/libc/docs/conf.py
+++ b/libc/docs/conf.py
@@ -63,13 +63,6 @@
 # directories to ignore when looking for source files.
 exclude_patterns = ["_build"]
 
-rst_prolog = """
-.. role::  raw-html(raw)
-    :format: html
-
-.. |check| replace:: :raw-html:`&#x2705`
-"""
-
 myst_substitutions = {
     "check": "\N{WHITE HEAVY CHECK MARK}",
 }
@@ -102,6 +95,7 @@
     source_directory="libc/docs/",
     html_title="The LLVM C Library",
     local_static_path=["_static"],
+    extra_css_files=["status.css"],
 )
 
 # Add any paths that contain custom themes here, relative to this directory.

diff  --git a/libc/docs/dev/building_docs.md b/libc/docs/dev/building_docs.md
index a1b3e99f4b502e..796f5d096f5c03 100644
--- a/libc/docs/dev/building_docs.md
+++ b/libc/docs/dev/building_docs.md
@@ -59,17 +59,17 @@ The output is written to `<build-dir>/tools/libc/docs/html/`. Open
 ## Header Status Pages (Auto-generated)
 
 The per-header implementation status pages under `docs/headers/` are
-**not** hand-written RST. They are generated at build time by
+**not** hand-written Markdown. They are generated at build time by
 `libc/utils/docgen/docgen.py`, which:
 
 1. Reads YAML function and macro definitions from `libc/utils/docgen/<header>.yaml`.
 2. Checks implementation status against platform `entrypoints.txt` files (excluding `TODO` stubs).
 3. Checks `libc/include/llvm-libc-macros/` and `libc/include/<header>.yaml` for macro definitions.
-4. Emits an RST `list-table` showing each symbol's implementation status,
-   C standard section, and POSIX link.
+4. Emits a MyST Markdown page with styled HTML tables showing each symbol's
+   implementation status, C standard section, and POSIX link.
 
 If you add a new function and regenerate, these pages update automatically.
-Do **not** hand-edit the generated RST files in `docs/headers/` — your
+Do **not** hand-edit the generated `.md` files in `docs/headers/` — your
 changes will be overwritten the next time the docs are built.
 
 ## Troubleshooting

diff  --git a/libc/utils/docgen/docgen.py b/libc/utils/docgen/docgen.py
index f6172cd1c26fb6..3714eca6254d8c 100755
--- a/libc/utils/docgen/docgen.py
+++ b/libc/utils/docgen/docgen.py
@@ -7,8 +7,9 @@
 #
 # ===----------------------------------------------------------------------===##
 from argparse import ArgumentParser, Namespace
+import html
 from pathlib import Path
-from typing import Dict
+from typing import Callable, Dict
 import os
 import sys
 
@@ -95,102 +96,100 @@ def check_api(header: Header, api: Dict):
         raise DocgenAPIFormatError("\n".join(errors))
 
 
-def print_tbl_dir(name):
-    print(
-        f"""
-.. list-table::
-  :widths: auto
-  :align: center
-  :header-rows: 1
-
-  * - {name}
-    - Implemented
-    - C23 Standard Section
-    - POSIX Docs"""
+def _status_badge_html(implemented: bool) -> str:
+    if implemented:
+        return (
+            '<span class="hc-status-yes" title="Implemented">'
+            '<span aria-hidden="true">✓</span>'
+            '<span class="hc-sr-only">Implemented</span></span>'
+        )
+    return (
+        '<span class="hc-status-no" title="Not Implemented">'
+        '<span aria-hidden="true">–</span>'
+        '<span class="hc-sr-only">Not Implemented</span></span>'
     )
 
 
-def print_functions_rst(header: Header, functions: Dict):
-    tbl_hdr = "Functions"
-    print(tbl_hdr)
-    print("=" * len(tbl_hdr))
-
-    print_tbl_dir("Function")
-
-    for name in sorted(functions.keys()):
-        print(f"  * - {name}")
-
-        if header.implements_fn(name):
-            print("    - |check|")
-        else:
-            print("    -")
-
-        if "c-definition" in functions[name]:
-            print(f'    - {functions[name]["c-definition"]}')
-        else:
-            print("    -")
-
-        if "in-latest-posix" in functions[name]:
-            print(
-                f"    - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/{name}.html>`__"
-            )
-        elif "removed-in-posix-2008" in functions[name]:
-            print(
-                f"    - `removed in POSIX.1-2008 <https://pubs.opengroup.org/onlinepubs/007904875/functions/{name}.html>`__"
-            )
-        elif "removed-in-posix-2024" in functions[name]:
-            print(
-                f"    - `removed in POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9699919799.2018edition/functions/{name}.html>`__"
-            )
-        else:
-            print("    -")
-
-
-def posix_basedefs_url(header: Header) -> str:
-    """Return the Open Group basedefs URL for a header."""
-    posix_header_name = header.name.replace("/", "_")
-    return f"https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/{posix_header_name}.html"
+def _c_section_html(item: Dict) -> str:
+    sec = item.get("c-definition")
+    if sec:
+        return f'<span class="hc-sec-badge">{html.escape(str(sec))}</span>'
+    return '<span class="hc-status-no" aria-label="Not in C23">–</span>'
 
 
-def print_macros_rst(header: Header, macros: Dict):
-    tbl_hdr = "Macros"
-    print(tbl_hdr)
-    print("=" * len(tbl_hdr))
-
-    print_tbl_dir("Macro")
-
-    for name in sorted(macros.keys()):
-        print(f"  * - {name}")
-
-        if header.implements_macro(name):
-            print("    - |check|")
-        else:
-            print("    -")
-
-        if "c-definition" in macros[name]:
-            print(f'    - {macros[name]["c-definition"]}')
-        else:
-            print("    -")
-
-        if "in-latest-posix" in macros[name]:
-            print(f"    - `POSIX.1-2024 <{posix_basedefs_url(header)}>`__")
-        else:
-            print("    -")
-    print()
-
-
-def print_impl_status_rst(header: Header, api: Dict):
-    print("=" * len(header.name))
-    print(header.name)
-    print("=" * len(header.name))
-    print()
-
-    # the macro and function sections are both optional
-    if "macros" in api:
-        print_macros_rst(header, api["macros"])
-
-    if "functions" in api:
-        print_functions_rst(header, api["functions"])
+def _posix_link_html(header: Header, name: str, kind: str, item: Dict) -> str:
+    base = (
+        f"functions/{name}.html"
+        if kind == "function"
+        else f"basedefs/{header.name.replace('/', '_')}.html"
+    )
+    if "in-latest-posix" in item:
+        url = f"https://pubs.opengroup.org/onlinepubs/9799919799/{base}"
+        return f'<a class="hc-posix-link" href="{url}">POSIX.1-2024 ↗</a>'
+    if "removed-in-posix-2008" in item:
+        url = f"https://pubs.opengroup.org/onlinepubs/007904875/{base}"
+        return f'<a class="hc-posix-link" href="{url}">Removed (2008) ↗</a>'
+    if "removed-in-posix-2024" in item:
+        url = f"https://pubs.opengroup.org/onlinepubs/9699919799.2018edition/{base}"
+        return f'<a class="hc-posix-link" href="{url}">Removed (2024) ↗</a>'
+    return '<span class="hc-status-no" aria-label="Not in POSIX">–</span>'
+
+
+def print_symbol_table_md(
+    header: Header,
+    section_title: str,
+    col_label: str,
+    items: Dict,
+    is_implemented_fn: Callable[[str], bool],
+    kind: str,
+):
+    print(
+        f"## {section_title}\n\n```{{raw}} html\n"
+        '<div class="hc-table-wrap"><table class="hc-table">\n'
+        f"  <thead><tr><th>{col_label}</th>"
+        '<th class="hc-center">Status</th>'
+        '<th class="hc-center">C23 Section</th>'
+        '<th class="hc-center">POSIX Docs</th></tr></thead>\n'
+        "  <tbody>"
+    )
+    for name in sorted(items.keys()):
+        obj = items[name] or {}
+        row_id = html.escape(f"{kind}-{name.replace(' ', '-')}", quote=True)
+        status = _status_badge_html(is_implemented_fn(name))
+        c_sec = _c_section_html(obj)
+        posix = _posix_link_html(header, name, kind, obj)
+        print(
+            f'    <tr id="{row_id}">'
+            f'<td><code class="hc-sym">{html.escape(name)}</code></td>'
+            f'<td class="hc-center">{status}</td>'
+            f'<td class="hc-center">{c_sec}</td>'
+            f'<td class="hc-center">{posix}</td></tr>'
+        )
+    print("  </tbody>\n</table></div>\n```\n")
+
+
+def print_header_status_md(header: Header, api: Dict):
+    print(f"# {header.name}\n")
+
+    if api.get("macros"):
+        print_symbol_table_md(
+            header,
+            "Macros",
+            "Macro",
+            api["macros"],
+            header.implements_macro,
+            "macro",
+        )
+
+    if api.get("functions"):
+        print_symbol_table_md(
+            header,
+            "Functions",
+            "Function",
+            api["functions"],
+            header.implements_fn,
+            "function",
+        )
 
 
 # This code implicitly relies on docgen.py being in the same dir as the yaml
@@ -217,4 +216,4 @@ def parse_args() -> Namespace:
     header = Header(args.header_name)
     check_api(header, header.api)
 
-    print_impl_status_rst(header, header.api)
+    print_header_status_md(header, header.api)

diff  --git a/libc/utils/docgen/docgen_test.py b/libc/utils/docgen/docgen_test.py
index 6b1048edd13ed7..27a3af3c10bea3 100644
--- a/libc/utils/docgen/docgen_test.py
+++ b/libc/utils/docgen/docgen_test.py
@@ -8,12 +8,15 @@
 # ===----------------------------------------------------------------------===##
 """Unit tests for docgen and header implementation status evaluation."""
 
+from contextlib import redirect_stdout
+import io
 from pathlib import Path
 import sys
 import tempfile
 import unittest
 
 sys.path.insert(0, str(Path(__file__).parent))
+from docgen import print_header_status_md
 from header import Header, _is_stub_file
 
 
@@ -72,6 +75,47 @@ def test_implements_macro(self):
         self.assertTrue(Header("unistd.h").implements_macro("SEEK_SET"))
         self.assertTrue(Header("float.h").implements_macro("NAN"))
 
+    def test_md_output_generation(self):
+        hdr = Header("stdio.h")
+        api = {
+            "macros": {"EOF": {"c-definition": "7.23.1", "in-latest-posix": None}},
+            "functions": {
+                "printf": {"c-definition": "7.23.6.3", "in-latest-posix": None},
+                "missing_fn": {"c-definition": "7.23.6.99"},
+            },
+        }
+        buf = io.StringIO()
+        with redirect_stdout(buf):
+            print_header_status_md(hdr, api)
+        out = buf.getvalue()
+        lines = {line.strip() for line in out.splitlines()}
+        self.assertIn("# stdio.h", out)
+        self.assertIn("## Macros", out)
+        self.assertIn("## Functions", out)
+        self.assertIn('<table class="hc-table">', out)
+        self.assertTrue(
+            any(
+                'id="macro-EOF"' in l
+                and 'title="Implemented"' in l
+                and "basedefs/stdio.h.html" in l
+                for l in lines
+            )
+        )
+        self.assertTrue(
+            any(
+                'id="function-printf"' in l
+                and 'title="Implemented"' in l
+                and "functions/printf.html" in l
+                for l in lines
+            )
+        )
+        self.assertTrue(
+            any(
+                'id="function-missing_fn"' in l and 'title="Not Implemented"' in l
+                for l in lines
+            )
+        )
+
 
 if __name__ == "__main__":
     unittest.main()


        


More information about the libc-commits mailing list