linux-doc.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 0/1] fix rustdoc build detection
@ 2025-11-21 11:05 Mauro Carvalho Chehab
  2025-11-21 11:05 ` [PATCH v2 1/1] docs: makefile: move rustdoc check to the build wrapper Mauro Carvalho Chehab
  0 siblings, 1 reply; 3+ messages in thread
From: Mauro Carvalho Chehab @ 2025-11-21 11:05 UTC (permalink / raw)
  To: Linux Doc Mailing List, Jonathan Corbet
  Cc: Mauro Carvalho Chehab, Mauro Carvalho Chehab, linux-kernel,
	Miguel Ojeda, Carlos Bilbao

Current logic doesn't use the right value for CONFIG_RUST. Instead,
it picks the value cached from a previous non-doc buid.

After analyzing the issue, it was not caused by changing the logic
to use the wrapper, but, instead, to the way .config is currently
parsed. For more details, see:

    https://lore.kernel.org/linux-doc/20251121101236.5b1f9989@foz.lan/

---

v2: changed patch description to better explain the issue.

Mauro Carvalho Chehab (1):
  docs: makefile: move rustdoc check to the build wrapper

 Documentation/Makefile          |  6 -----
 tools/docs/sphinx-build-wrapper | 41 +++++++++++++++++++++++++--------
 2 files changed, 32 insertions(+), 15 deletions(-)

-- 
2.51.1


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH v2 1/1] docs: makefile: move rustdoc check to the build wrapper
  2025-11-21 11:05 [PATCH v2 0/1] fix rustdoc build detection Mauro Carvalho Chehab
@ 2025-11-21 11:05 ` Mauro Carvalho Chehab
  2025-11-29 15:46   ` Jonathan Corbet
  0 siblings, 1 reply; 3+ messages in thread
From: Mauro Carvalho Chehab @ 2025-11-21 11:05 UTC (permalink / raw)
  To: Linux Doc Mailing List, Jonathan Corbet
  Cc: Mauro Carvalho Chehab, Alex Gaynor, Alice Ryhl, Andreas Hindborg,
	Benno Lossin, Björn Roy Baron, Boqun Feng, Carlos Bilbao,
	Danilo Krummrich, Gary Guo, Mauro Carvalho Chehab, Miguel Ojeda,
	Miguel Ojeda, Trevor Gross, linux-kernel, rust-for-linux

The makefile logic to detect if rust is enabled is not working
the way it was expected: instead of using the current setup
for CONFIG_RUST, it uses a cached version from a previous build.

The root cause is that the current logic inside docs/Makefile
uses a cached version of CONFIG_RUST, from the last time a non
documentation target was executed. That's perfectly fine for
Sphinx build, as it doesn't need to read or depend on any
CONFIG_*.

So, instead of relying at the cache, move the logic to the
wrapper script and let it check the current content of .config,
to verify if CONFIG_RUST was selected.

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
---
 Documentation/Makefile          |  6 -----
 tools/docs/sphinx-build-wrapper | 41 +++++++++++++++++++++++++--------
 2 files changed, 32 insertions(+), 15 deletions(-)

diff --git a/Documentation/Makefile b/Documentation/Makefile
index fda2bef8d9d8..e96ac6dcac4f 100644
--- a/Documentation/Makefile
+++ b/Documentation/Makefile
@@ -42,12 +42,6 @@ FONTS_CONF_DENY_VF ?= $(HOME)/deny-vf
 # User-friendly check for sphinx-build
 HAVE_SPHINX := $(shell if which $(SPHINXBUILD) >/dev/null 2>&1; then echo 1; else echo 0; fi)
 
-ifneq ($(wildcard $(srctree)/.config),)
-ifeq ($(CONFIG_RUST),y)
-	RUSTDOC=--rustdoc
-endif
-endif
-
 ifeq ($(HAVE_SPHINX),0)
 
 .DEFAULT:
diff --git a/tools/docs/sphinx-build-wrapper b/tools/docs/sphinx-build-wrapper
index d4943d952e2a..7a5fcef25429 100755
--- a/tools/docs/sphinx-build-wrapper
+++ b/tools/docs/sphinx-build-wrapper
@@ -119,6 +119,29 @@ class SphinxBuilder:
 
         return path
 
+    def check_rust(self):
+        """
+        Checks if Rust is enabled
+        """
+        self.rustdoc = False
+
+        config = os.path.join(self.srctree, ".config")
+
+        if not os.path.isfile(config):
+            return
+
+        re_rust = re.compile(r"CONFIG_RUST=(m|y)")
+
+        try:
+            with open(config, "r", encoding="utf-8") as fp:
+                for line in fp:
+                    if re_rust.match(line):
+                        self.rustdoc = True
+                        return
+
+        except OSError as e:
+            print(f"Failed to open {config}", file=sys.stderr)
+
     def get_sphinx_extra_opts(self, n_jobs):
         """
         Get the number of jobs to be used for docs build passed via command
@@ -236,6 +259,8 @@ class SphinxBuilder:
 
         self.get_sphinx_extra_opts(n_jobs)
 
+        self.check_rust()
+
         #
         # If venv command line argument is specified, run Sphinx from venv
         #
@@ -306,7 +331,7 @@ class SphinxBuilder:
 
             return subprocess.call(cmd, *args, **pwargs)
 
-    def handle_html(self, css, output_dir, rustdoc):
+    def handle_html(self, css, output_dir):
         """
         Extra steps for HTML and epub output.
 
@@ -327,7 +352,8 @@ class SphinxBuilder:
             except (OSError, IOError) as e:
                 print(f"Warning: Failed to copy CSS: {e}", file=sys.stderr)
 
-        if rustdoc:
+        if self.rustdoc:
+            print("Building rust docs")
             if "MAKE" in self.env:
                 cmd = [self.env["MAKE"]]
             else:
@@ -622,7 +648,7 @@ class SphinxBuilder:
         shutil.rmtree(self.builddir, ignore_errors=True)
 
     def build(self, target, sphinxdirs=None,
-              theme=None, css=None, paper=None, deny_vf=None, rustdoc=False,
+              theme=None, css=None, paper=None, deny_vf=None,
               skip_sphinx=False):
         """
         Build documentation using Sphinx. This is the core function of this
@@ -671,7 +697,7 @@ class SphinxBuilder:
 
             args.extend(["-D", f"latex_elements.papersize={paper}paper"])
 
-        if rustdoc:
+        if self.rustdoc:
             args.extend(["-t", "rustdoc"])
 
         if not sphinxdirs:
@@ -749,7 +775,7 @@ class SphinxBuilder:
             # Ensure that each html/epub output will have needed static files
             #
             if target in ["htmldocs", "epubdocs"]:
-                self.handle_html(css, output_dir, rustdoc)
+                self.handle_html(css, output_dir)
 
         #
         # Step 2: Some targets (PDF and info) require an extra step once
@@ -804,9 +830,6 @@ def main():
     parser.add_argument('--deny-vf',
                         help="Configuration to deny variable fonts on pdf builds")
 
-    parser.add_argument('--rustdoc', action="store_true",
-                        help="Enable rustdoc build. Requires CONFIG_RUST")
-
     parser.add_argument("-v", "--verbose", action='store_true',
                         help="place build in verbose mode")
 
@@ -834,7 +857,7 @@ def main():
 
     builder.build(args.target, sphinxdirs=args.sphinxdirs,
                   theme=args.theme, css=args.css, paper=args.paper,
-                  rustdoc=args.rustdoc, deny_vf=args.deny_vf,
+                  deny_vf=args.deny_vf,
                   skip_sphinx=args.skip_sphinx_build)
 
 if __name__ == "__main__":
-- 
2.51.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH v2 1/1] docs: makefile: move rustdoc check to the build wrapper
  2025-11-21 11:05 ` [PATCH v2 1/1] docs: makefile: move rustdoc check to the build wrapper Mauro Carvalho Chehab
@ 2025-11-29 15:46   ` Jonathan Corbet
  0 siblings, 0 replies; 3+ messages in thread
From: Jonathan Corbet @ 2025-11-29 15:46 UTC (permalink / raw)
  To: Mauro Carvalho Chehab, Linux Doc Mailing List
  Cc: Mauro Carvalho Chehab, Alex Gaynor, Alice Ryhl, Andreas Hindborg,
	Benno Lossin, Björn Roy Baron, Boqun Feng, Carlos Bilbao,
	Danilo Krummrich, Gary Guo, Mauro Carvalho Chehab, Miguel Ojeda,
	Miguel Ojeda, Trevor Gross, linux-kernel, rust-for-linux

Mauro Carvalho Chehab <mchehab+huawei@kernel.org> writes:

> The makefile logic to detect if rust is enabled is not working
> the way it was expected: instead of using the current setup
> for CONFIG_RUST, it uses a cached version from a previous build.
>
> The root cause is that the current logic inside docs/Makefile
> uses a cached version of CONFIG_RUST, from the last time a non
> documentation target was executed. That's perfectly fine for
> Sphinx build, as it doesn't need to read or depend on any
> CONFIG_*.
>
> So, instead of relying at the cache, move the logic to the
> wrapper script and let it check the current content of .config,
> to verify if CONFIG_RUST was selected.
>
> Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
> ---
>  Documentation/Makefile          |  6 -----
>  tools/docs/sphinx-build-wrapper | 41 +++++++++++++++++++++++++--------
>  2 files changed, 32 insertions(+), 15 deletions(-)

Applied, thanks.

jon

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2025-11-29 15:46 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-11-21 11:05 [PATCH v2 0/1] fix rustdoc build detection Mauro Carvalho Chehab
2025-11-21 11:05 ` [PATCH v2 1/1] docs: makefile: move rustdoc check to the build wrapper Mauro Carvalho Chehab
2025-11-29 15:46   ` Jonathan Corbet

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).