threads / patch / 64127

patch, 3 partsci: don't compile whole project when testing docs with Meson

Subject: [PATCH 0/3] ci: don't compile whole project when testing docs with Meson

## tl;dr

14 messages between Sep 11, 2025 and Sep 16, 2025. Diffs are folded; open one to read it.

replies: 13people: 3as markdown or json

Patrick Steinhardt· Sep 11, 2025, 09:16 UTC · lore
Hi,

these two patches introduce a new "docs" alias into Meson and use it in our "documentation" CI jobs so that we stop compiling all of Git only to verify the generated manpages. This fixes the issue reported by Gábor in [1].

Thanks!
Patrick
[1]: <aLCf0UaTxy5Nxpv/@szeder.dev>
---
Patrick Steinhardt (3):
      meson: introduce a "docs" alias to compile documentation only
      meson: print docs backend as part of the summary
      ci: don't compile whole project when testing docs with Meson
 Documentation/howto/meson.build     |  4 ++--
 Documentation/meson.build           |  8 ++++----
 Documentation/technical/meson.build |  4 ++--
 ci/test-documentation.sh            |  4 ++--
 contrib/contacts/meson.build        |  4 ++--
 contrib/subtree/meson.build         |  4 ++--
 meson.build                         | 10 ++++++++++
 7 files changed, 24 insertions(+), 14 deletions(-)

--- base-commit: ab427cd991100e94792fce124b0934135abdea4b change-id: 20250911-b4-pks-meson-docs-target-56d8a21e84bf

Patrick Steinhardt· Sep 11, 2025, 09:16 UTC · re: Patrick Steinhardt · lore

[PATCH 1/3] meson: introduce a "docs" alias to compile documentation only

Meson does not currently provide a target to compile documentation, only. Instead, users needs to compile the whole project, which may be way more than they really intend to do.

Introduce a new "docs" alias to plug this gap. This alias can be invoked e.g. with `meson compile docs`.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
 Documentation/howto/meson.build     | 4 ++--
 Documentation/meson.build           | 8 ++++----
 Documentation/technical/meson.build | 4 ++--
 contrib/contacts/meson.build        | 4 ++--
 contrib/subtree/meson.build         | 4 ++--
 meson.build                         | 7 +++++++
 6 files changed, 19 insertions(+), 12 deletions(-)
Show changes to 6 files +19 −12

Documentation/howto/meson.build, Documentation/meson.build, Documentation/technical/meson.build, contrib/contacts/meson.build, contrib/subtree/meson.build, meson.build

diff --git a/Documentation/howto/meson.build b/Documentation/howto/meson.build
index 81000028c0..ece20244af 100644
--- a/Documentation/howto/meson.build
+++ b/Documentation/howto/meson.build
@@ -29,7 +29,7 @@ howto_index = custom_target(
   output: 'howto-index.adoc',
 )
 
-custom_target(
+doc_targets += custom_target(
   command: asciidoc_html_options,
   input: howto_index,
   output: 'howto-index.html',
@@ -51,7 +51,7 @@ foreach howto : howto_sources
     capture: true,
   )
 
-  custom_target(
+  doc_targets += custom_target(
     command: asciidoc_html_options,
     input: howto_stripped,
     output: fs.stem(howto_stripped.full_path()) + '.html',
diff --git a/Documentation/meson.build b/Documentation/meson.build
index e34965c5b0..44f94cdb7b 100644
--- a/Documentation/meson.build
+++ b/Documentation/meson.build
@@ -377,7 +377,7 @@ foreach manpage, category : manpages
       output: fs.stem(manpage) + '.xml',
     )
 
-    custom_target(
+    doc_targets += custom_target(
       command: [
         xmlto,
         '-m', '@INPUT0@',
@@ -400,7 +400,7 @@ foreach manpage, category : manpages
   endif
 
   if get_option('docs').contains('html')
-    custom_target(
+    doc_targets += custom_target(
       command: asciidoc_common_options + [
         '--backend=' + asciidoc_html,
         '--doctype=manpage',
@@ -452,7 +452,7 @@ if get_option('docs').contains('html')
     depends: documentation_deps,
   )
 
-  custom_target(
+  doc_targets += custom_target(
     command: [
       xsltproc,
       '--xinclude',
@@ -481,7 +481,7 @@ if get_option('docs').contains('html')
   ]
 
   foreach article : articles
-    custom_target(
+    doc_targets += custom_target(
       command: asciidoc_common_options + [
         '--backend=' + asciidoc_html,
         '--out-file=@OUTPUT@',
diff --git a/Documentation/technical/meson.build b/Documentation/technical/meson.build
index a13aafcfbb..858af811a7 100644
--- a/Documentation/technical/meson.build
+++ b/Documentation/technical/meson.build
@@ -46,7 +46,7 @@ api_index = custom_target(
   output: 'api-index.adoc',
 )
 
-custom_target(
+doc_targets += custom_target(
   command: asciidoc_html_options,
   input: api_index,
   output: 'api-index.html',
@@ -56,7 +56,7 @@ custom_target(
 )
 
 foreach article : api_docs + articles
-  custom_target(
+  doc_targets += custom_target(
     command: asciidoc_html_options,
     input: article,
     output: fs.stem(article) + '.html',
diff --git a/contrib/contacts/meson.build b/contrib/contacts/meson.build
index 73d82dfe52..c8fdb35ed9 100644
--- a/contrib/contacts/meson.build
+++ b/contrib/contacts/meson.build
@@ -20,7 +20,7 @@ if get_option('docs').contains('man')
     output: 'git-contacts.xml',
   )
 
-  custom_target(
+  doc_targets += custom_target(
     command: [
       xmlto,
       '-m', '@INPUT@',
@@ -39,7 +39,7 @@ if get_option('docs').contains('man')
 endif
 
 if get_option('docs').contains('html')
-  custom_target(
+  doc_targets += custom_target(
     command: asciidoc_common_options + [
       '--backend=' + asciidoc_html,
       '--doctype=manpage',
diff --git a/contrib/subtree/meson.build b/contrib/subtree/meson.build
index 98dd8e0c8e..46cdbcc30c 100644
--- a/contrib/subtree/meson.build
+++ b/contrib/subtree/meson.build
@@ -38,7 +38,7 @@ if get_option('docs').contains('man')
     output: 'git-subtree.xml',
   )
 
-  custom_target(
+  doc_targets += custom_target(
     command: [
       xmlto,
       '-m', '@INPUT@',
@@ -57,7 +57,7 @@ if get_option('docs').contains('man')
 endif
 
 if get_option('docs').contains('html')
-  custom_target(
+  doc_targets += custom_target(
     command: asciidoc_common_options + [
       '--backend=' + asciidoc_html,
       '--doctype=manpage',
diff --git a/meson.build b/meson.build
index b3dfcc0497..40b2a2dc54 100644
--- a/meson.build
+++ b/meson.build
@@ -2101,11 +2101,18 @@ endif
 
 subdir('bin-wrappers')
 if get_option('docs') != []
+  doc_targets = []
   subdir('Documentation')
 endif
 
 subdir('contrib')
 
+# Note that the target is intentionally configured after including the
+# 'contrib' directory, as some tool there also have their own manpages.
+if get_option('docs') != []
+  alias_target('docs', doc_targets)
+endif
+
 exclude_from_check_headers = [
   'compat/',
   'unicode-width.h',
-- 
2.51.0.450.g87641ccf93.dirty
Karthik Nayak· Sep 16, 2025, 09:14 UTC · re: Patrick Steinhardt · lore

Re: [PATCH 1/3] meson: introduce a "docs" alias to compile documentation only

Patrick Steinhardt <ps@pks.im> writes:
Show 7 quoted lines
> Meson does not currently provide a target to compile documentation,
> only. Instead, users needs to compile the whole project, which may be
> way more than they really intend to do.
>
> Introduce a new "docs" alias to plug this gap. This alias can be invoked
> e.g. with `meson compile docs`.
>

So earlier we would compile the documentation always (while the dependencies are met). Now we move this to a "docs" subcommand...

[snip]
Show 20 quoted lines
> diff --git a/meson.build b/meson.build
> index b3dfcc0497..40b2a2dc54 100644
> --- a/meson.build
> +++ b/meson.build
> @@ -2101,11 +2101,18 @@ endif
>
>  subdir('bin-wrappers')
>  if get_option('docs') != []
> +  doc_targets = []
>    subdir('Documentation')
>  endif
>
>  subdir('contrib')
>
> +# Note that the target is intentionally configured after including the
> +# 'contrib' directory, as some tool there also have their own manpages.
> +if get_option('docs') != []
> +  alias_target('docs', doc_targets)
> +endif
> +

Shouldn't we also add it to 'meson_options.txt' with default set to true? That would ensure that `meson compile` would also build the docs.

Show 6 quoted lines
>  exclude_from_check_headers = [
>    'compat/',
>    'unicode-width.h',
>
> --
> 2.51.0.450.g87641ccf93.dirty
Patrick Steinhardt· Sep 16, 2025, 09:55 UTC · re: Karthik Nayak · lore

Re: [PATCH 1/3] meson: introduce a "docs" alias to compile documentation only

On Tue, Sep 16, 2025 at 04:14:56AM -0500, Karthik Nayak wrote:
Show 24 quoted lines
> Patrick Steinhardt <ps@pks.im> writes:
> > diff --git a/meson.build b/meson.build
> > index b3dfcc0497..40b2a2dc54 100644
> > --- a/meson.build
> > +++ b/meson.build
> > @@ -2101,11 +2101,18 @@ endif
> >
> >  subdir('bin-wrappers')
> >  if get_option('docs') != []
> > +  doc_targets = []
> >    subdir('Documentation')
> >  endif
> >
> >  subdir('contrib')
> >
> > +# Note that the target is intentionally configured after including the
> > +# 'contrib' directory, as some tool there also have their own manpages.
> > +if get_option('docs') != []
> > +  alias_target('docs', doc_targets)
> > +endif
> > +
> 
> Shouldn't we also add it to 'meson_options.txt' with default set to
> true? That would ensure that `meson compile` would also build the docs.

We already have the "docs" option in "meson_options.txt". In fact, it is not even possible to have an option that is _not_ declared in that file :)

The option accepts an array of choices, where the choices can be "man" or "html" to build manpages, HTML sites, both or none. So as soon as the user made at least one choice we enable the "docs" target automatically.

Patrick
Karthik Nayak· Sep 16, 2025, 11:50 UTC · re: Patrick Steinhardt · lore

Re: [PATCH 1/3] meson: introduce a "docs" alias to compile documentation only

Patrick Steinhardt <ps@pks.im> writes:
Show 30 quoted lines
> On Tue, Sep 16, 2025 at 04:14:56AM -0500, Karthik Nayak wrote:
>> Patrick Steinhardt <ps@pks.im> writes:
>> > diff --git a/meson.build b/meson.build
>> > index b3dfcc0497..40b2a2dc54 100644
>> > --- a/meson.build
>> > +++ b/meson.build
>> > @@ -2101,11 +2101,18 @@ endif
>> >
>> >  subdir('bin-wrappers')
>> >  if get_option('docs') != []
>> > +  doc_targets = []
>> >    subdir('Documentation')
>> >  endif
>> >
>> >  subdir('contrib')
>> >
>> > +# Note that the target is intentionally configured after including the
>> > +# 'contrib' directory, as some tool there also have their own manpages.
>> > +if get_option('docs') != []
>> > +  alias_target('docs', doc_targets)
>> > +endif
>> > +
>>
>> Shouldn't we also add it to 'meson_options.txt' with default set to
>> true? That would ensure that `meson compile` would also build the docs.
>
> We already have the "docs" option in "meson_options.txt". In fact, it is
> not even possible to have an option that is _not_ declared in that file
> :)
>
Nice. I should've verified, I was merely looking at the diff-stat
> The option accepts an array of choices, where the choices can be "man"
> or "html" to build manpages, HTML sites, both or none. So as soon as the
> user made at least one choice we enable the "docs" target automatically.
>

Okay that makes sense! The default is set to '[]'. Okay looks good. Thanks for clarifying.

> Patrick
Patrick Steinhardt· Sep 11, 2025, 09:16 UTC · re: Patrick Steinhardt · lore

[PATCH 2/3] meson: print docs backend as part of the summary

Our documentation can be built with either Asciidoc or Asciidoctor as backend. When Meson is configured to build documentation, then it will automatically detect which of these tools is available and use them. It's not obvious to the user though which of these backends is used unless the user explicitly asks for one backend via `-Ddocs_backend=`.

Improve the status quo by printing the docs backend as part of the "backends" summary.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
 meson.build | 3 +++
 1 file changed, 3 insertions(+)
Show changes to meson.build +3 −0
diff --git a/meson.build b/meson.build
index 40b2a2dc54..4a504fc26d 100644
--- a/meson.build
+++ b/meson.build
@@ -2103,6 +2103,8 @@ subdir('bin-wrappers')
 if get_option('docs') != []
   doc_targets = []
   subdir('Documentation')
+else
+  docs_backend = 'none'
 endif
 
 subdir('contrib')
@@ -2251,6 +2253,7 @@ summary({
 
 summary({
   'csprng': csprng_backend,
+  'docs': docs_backend,
   'https': https_backend,
   'sha1': sha1_backend,
   'sha1_unsafe': sha1_unsafe_backend,
-- 
2.51.0.450.g87641ccf93.dirty
Patrick Steinhardt· Sep 11, 2025, 09:16 UTC · re: Patrick Steinhardt · lore

[PATCH 3/3] ci: don't compile whole project when testing docs with Meson

Our "documentation" CI jobs, unsurprisingly, performs a couple of tests on our documentation. The job knows to not only test the documentation generated by our Makefile, but also by Meson.

In the latter case with Meson we end up building the whole project, including all of the binaries. This is of course quite excessive and a waste of compute cycles, as we don't care about these binaries at all.

Fix this by using the new "docs" target that we introduced in the preceding commit.

Reported-by: SZEDER Gábor <szeder.dev@gmail.com>
Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
 ci/test-documentation.sh | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
Show changes to ci/test-documentation.sh +2 −2
diff --git a/ci/test-documentation.sh b/ci/test-documentation.sh
index 49f87f50fd..5e4fd8fbd7 100755
--- a/ci/test-documentation.sh
+++ b/ci/test-documentation.sh
@@ -48,13 +48,13 @@ check_unignored_build_artifacts
 
 # Build docs with Meson and AsciiDoc
 meson setup build-asciidoc -Ddocs=html,man -Ddocs_backend=asciidoc
-meson compile -C build-asciidoc
+meson compile -C build-asciidoc docs
 check_docs build-asciidoc AsciiDoc
 rm -rf build-asciidoc
 
 # Build docs with Meson and AsciiDoctor
 meson setup build-asciidoctor -Ddocs=html,man -Ddocs_backend=asciidoctor
-meson compile -C build-asciidoctor
+meson compile -C build-asciidoctor docs
 check_docs build-asciidoctor Asciidoctor
 rm -rf build-asciidoctor
 
-- 
2.51.0.450.g87641ccf93.dirty
Karthik Nayak· Sep 16, 2025, 09:16 UTC · re: Patrick Steinhardt · lore

Re: [PATCH 3/3] ci: don't compile whole project when testing docs with Meson

Patrick Steinhardt <ps@pks.im> writes:
Show 38 quoted lines
> Our "documentation" CI jobs, unsurprisingly, performs a couple of tests
> on our documentation. The job knows to not only test the documentation
> generated by our Makefile, but also by Meson.
>
> In the latter case with Meson we end up building the whole project,
> including all of the binaries. This is of course quite excessive and a
> waste of compute cycles, as we don't care about these binaries at all.
>
> Fix this by using the new "docs" target that we introduced in the
> preceding commit.
>
> Reported-by: SZEDER Gábor <szeder.dev@gmail.com>
> Signed-off-by: Patrick Steinhardt <ps@pks.im>
> ---
>  ci/test-documentation.sh | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/ci/test-documentation.sh b/ci/test-documentation.sh
> index 49f87f50fd..5e4fd8fbd7 100755
> --- a/ci/test-documentation.sh
> +++ b/ci/test-documentation.sh
> @@ -48,13 +48,13 @@ check_unignored_build_artifacts
>
>  # Build docs with Meson and AsciiDoc
>  meson setup build-asciidoc -Ddocs=html,man -Ddocs_backend=asciidoc
> -meson compile -C build-asciidoc
> +meson compile -C build-asciidoc docs
>  check_docs build-asciidoc AsciiDoc
>  rm -rf build-asciidoc
>
>  # Build docs with Meson and AsciiDoctor
>  meson setup build-asciidoctor -Ddocs=html,man -Ddocs_backend=asciidoctor
> -meson compile -C build-asciidoctor
> +meson compile -C build-asciidoctor docs
>  check_docs build-asciidoctor Asciidoctor
>  rm -rf build-asciidoctor
>
>

This makes sense. I really like how a lot of our CI config is forge agnostic. I opened the patch expecting to review GitHub/GitLab changes. Glad I didn't have to.

> --
> 2.51.0.450.g87641ccf93.dirty
Junio C Hamano· Sep 11, 2025, 17:02 UTC · re: Patrick Steinhardt · lore

Re: [PATCH 0/3] ci: don't compile whole project when testing docs with Meson

Patrick Steinhardt <ps@pks.im> writes:
> these two patches introduce a new "docs" alias into Meson and use it in
> our "documentation" CI jobs so that we stop compiling all of Git only to
> verify the generated manpages. This fixes the issue reported by Gábor in
> [1].
There are three patches ;-).

The end-user facing get_option() is called "docs", unlike what the "make" side understands, which is "make doc", even though internally we call the target internally as "doc_targets" (not "docs_target").

I wonder if we want to let people say "meson compile doc" to match the other world?

Will queue.  Thanks.
Show 26 quoted lines
>
> Thanks!
>
> Patrick
>
> [1]: <aLCf0UaTxy5Nxpv/@szeder.dev>
>
> ---
> Patrick Steinhardt (3):
>       meson: introduce a "docs" alias to compile documentation only
>       meson: print docs backend as part of the summary
>       ci: don't compile whole project when testing docs with Meson
>
>  Documentation/howto/meson.build     |  4 ++--
>  Documentation/meson.build           |  8 ++++----
>  Documentation/technical/meson.build |  4 ++--
>  ci/test-documentation.sh            |  4 ++--
>  contrib/contacts/meson.build        |  4 ++--
>  contrib/subtree/meson.build         |  4 ++--
>  meson.build                         | 10 ++++++++++
>  7 files changed, 24 insertions(+), 14 deletions(-)
>
>
> ---
> base-commit: ab427cd991100e94792fce124b0934135abdea4b
> change-id: 20250911-b4-pks-meson-docs-target-56d8a21e84bf
Patrick Steinhardt· Sep 15, 2025, 06:04 UTC · re: Junio C Hamano · lore

Re: [PATCH 0/3] ci: don't compile whole project when testing docs with Meson

On Thu, Sep 11, 2025 at 10:02:22AM -0700, Junio C Hamano wrote:
Show 8 quoted lines
> Patrick Steinhardt <ps@pks.im> writes:
> 
> > these two patches introduce a new "docs" alias into Meson and use it in
> > our "documentation" CI jobs so that we stop compiling all of Git only to
> > verify the generated manpages. This fixes the issue reported by Gábor in
> > [1].
> 
> There are three patches ;-).
Oops, yeah. I added the summary patch close before sending this out :)
Show 8 quoted lines
> The end-user facing get_option() is called "docs", unlike what the
> "make" side understands, which is "make doc", even though internally
> we call the target internally as "doc_targets" (not "docs_target").
> 
> I wonder if we want to let people say "meson compile doc" to match
> the other world?
> 
> Will queue.  Thanks.

The reason why I picked 'docs' is that the accompanying user-facing option is also named the same way. It's thus a bit more consistent with itself to call the target 'docs' as well.

So I slightly lean towards keeping 'docs', but I don't feel too strongly about it.

Patrick
Junio C Hamano· Sep 15, 2025, 23:13 UTC · re: Patrick Steinhardt · lore

Re: [PATCH 0/3] ci: don't compile whole project when testing docs with Meson

Patrick Steinhardt <ps@pks.im> writes:
Show 8 quoted lines
>> I wonder if we want to let people say "meson compile doc" to match
>> the other world?
>> 
>> Will queue.  Thanks.
>
> The reason why I picked 'docs' is that the accompanying user-facing
> option is also named the same way. It's thus a bit more consistent with
> itself to call the target 'docs' as well.

Sorry, but I am not sure what user-facing "docs" option you are referring to; is this some earlier mistake we made that is way too entrenched to fix? I do know about the "make docs" that barfs with "*** No rule to make target 'docs'. Stop.", and I would call it user-facing. I would say it is a bit too old to "correct" without disrupting existing users.

Thanks.
Patrick Steinhardt· Sep 16, 2025, 06:41 UTC · re: Junio C Hamano · lore

Re: [PATCH 0/3] ci: don't compile whole project when testing docs with Meson

On Mon, Sep 15, 2025 at 04:13:00PM -0700, Junio C Hamano wrote:
Show 17 quoted lines
> Patrick Steinhardt <ps@pks.im> writes:
> 
> >> I wonder if we want to let people say "meson compile doc" to match
> >> the other world?
> >> 
> >> Will queue.  Thanks.
> >
> > The reason why I picked 'docs' is that the accompanying user-facing
> > option is also named the same way. It's thus a bit more consistent with
> > itself to call the target 'docs' as well.
> 
> Sorry, but I am not sure what user-facing "docs" option you are
> referring to; is this some earlier mistake we made that is way too
> entrenched to fix?  I do know about the "make docs" that barfs with
> "*** No rule to make target 'docs'.  Stop.", and I would call it
> user-facing.  I would say it is a bit too old to "correct" without
> disrupting existing users.

I meant the Meson option `-Ddocs=man,html`. I feel it's more natural there if the accompanying target is also called "docs" there.

Another option is that we could also just have both. In that case users of the Makefile could continue to use the "doc" target with Meson, as they are used to. And users that are used to Meson can use the "docs" target.

Patrick
Junio C Hamano· Sep 16, 2025, 16:24 UTC · re: Patrick Steinhardt · lore

Re: [PATCH 0/3] ci: don't compile whole project when testing docs with Meson

Patrick Steinhardt <ps@pks.im> writes:
> I meant the Meson option `-Ddocs=man,html`. I feel it's more natural
> there if the accompanying target is also called "docs" there.

Ahh. OK, so if I said "meson -Ddocs=" to choose neither format, that would essentially be the same as "do build the binaries but not the docs"?

I guess that is from the very beginning 904339ed (Introduce support for the Meson build system, 2024-12-06) that get_option('docs') is part of the build system, so it *is* way too late to fix it now.

> Another option is that we could also just have both. In that case users
> of the Makefile could continue to use the "doc" target with Meson, as
> they are used to. And users that are used to Meson can use the "docs"
> target.

Meaning you'd allow one to be an alias for the other? I am not sure if it is worth it for something small like this. Let's leave things as they are.

Thanks.
Karthik Nayak· Sep 16, 2025, 09:17 UTC · re: Patrick Steinhardt · lore

Re: [PATCH 0/3] ci: don't compile whole project when testing docs with Meson

Patrick Steinhardt <ps@pks.im> writes:
Show 7 quoted lines
> Hi,
>
> these two patches introduce a new "docs" alias into Meson and use it in
> our "documentation" CI jobs so that we stop compiling all of Git only to
> verify the generated manpages. This fixes the issue reported by Gábor in
> [1].
>

One small question from my side on the first patch, regarding the build options. Looks good otherwise.

[snip]

← back to recent threads