Skip to content

[libc][docgen] regen docgen via cmake #119628

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Jan 6, 2025

Conversation

nickdesaulniers
Copy link
Member

@nickdesaulniers nickdesaulniers commented Dec 11, 2024

Now, ninja docs-libc-html will re-run docgen.

Previously, we would run docgen offline, and commit the result.

Now we no longer need to do that; docgen is invoked from the
dependencies of the docs-libc-html target on demand. This
commit removes the dynamically generated .rst files (keeping
the static ones that haven't been converted to docgen), and
fixes up some mistakes I failed to cleanup recently since I
didn't have such automation in place to catch such bugs.

@nickdesaulniers nickdesaulniers marked this pull request as draft December 11, 2024 23:03
@llvmbot llvmbot added the libc label Dec 11, 2024
@llvmbot
Copy link
Member

llvmbot commented Dec 11, 2024

@llvm/pr-subscribers-libc

Author: Nick Desaulniers (nickdesaulniers)

Changes

Full diff: https://github.com/llvm/llvm-project/pull/119628.diff

1 Files Affected:

  • (modified) libc/docs/CMakeLists.txt (+9)
diff --git a/libc/docs/CMakeLists.txt b/libc/docs/CMakeLists.txt
index be09423d38e8e3..c8e9bcd29f612c 100644
--- a/libc/docs/CMakeLists.txt
+++ b/libc/docs/CMakeLists.txt
@@ -4,6 +4,15 @@ include(AddSphinxTarget)
 if (SPHINX_FOUND)
   if (${SPHINX_OUTPUT_HTML})
     add_sphinx_target(html libc)
+
+    list(APPEND docgen_list string strings)
+
+    foreach(stem IN LISTS docgen_list)
+      add_custom_target(${stem}_rst
+        COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/../utils/docgen/docgen.py ${stem}.h >
+                ${CMAKE_CURRENT_SOURCE_DIR}/headers/${stem}.rst)
+      add_dependencies(docs-libc-html ${stem}_rst)
+    endforeach()
   endif()
 endif()
 endif()

@nickdesaulniers nickdesaulniers marked this pull request as ready for review December 12, 2024 17:17
Comment on lines +20 to +48
string
strings
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder why these are being highlighted? Are they keywords in CMake? Perhaps I should make this a ; separated string?

Comment on lines 30 to 31
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/../utils/docgen/docgen.py ${stem}.h >
${CMAKE_CURRENT_SOURCE_DIR}/headers/${stem}.rst)
Copy link
Member Author

@nickdesaulniers nickdesaulniers Dec 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So there's probably a better way to do this. IIUC, it's going to run the command every time, which isn't necessary. We should only need to re-run the command in the input file (libc/utils/docgen/{stem}.yaml) is modified. Not sure yet how to express that in cmake...

Copy link
Member Author

@nickdesaulniers nickdesaulniers Dec 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like NEITHER SOURCES or DEPENDS prevents rebuilds upon reinvocations of ninja docs-libc-html...oh well

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ninja docs-libc-html -d explain prints useful info to debug that, but I don't plan to resolve that in this PR. Nice to have; not required.

Copy link
Contributor

@boomanaiden154 boomanaiden154 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the most part, we can't have any build targets modify the source directory. If we want to have a build command rerun docgen automatically, it should be a separate target and not under docs-libc-html.

The better way to do this would be to do something similar to #113739. Convert everything in the libc/docs directory to templates and as part of libc-docs-html, run docgen writing all the outputs to a folder in the build directory that we then run sphinx over.

@nickdesaulniers
Copy link
Member Author

nickdesaulniers commented Dec 19, 2024

So it looks like clang itself copies its rst files into the build dir. I can emulate the approach I think.

$ ninja copy-clang-rst-docs

@nickdesaulniers
Copy link
Member Author

ok, I have that working. One thing I think would be nice to add; I suspect there's a way to say that docgen depends on the yaml files. If those haven't changed, then docgen doesn't need to be rerun. Looking at these docs https://cmake.org/cmake/help/latest/command/add_custom_target.html, I'm not sure if that's DEPENDS or SOURCES.

Looks like I need to rebase this pr...

Copy link
Contributor

@boomanaiden154 boomanaiden154 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM with the latest approach.

@nickdesaulniers nickdesaulniers merged commit 98b3191 into llvm:main Jan 6, 2025
12 checks passed
@nickdesaulniers nickdesaulniers deleted the cmake_docgen branch January 6, 2025 17:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants