Skip to content
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

build: add doc target #384

Merged
merged 2 commits into from
Oct 3, 2022
Merged

build: add doc target #384

merged 2 commits into from
Oct 3, 2022

Conversation

Tachi107
Copy link
Contributor

@Tachi107 Tachi107 commented Oct 1, 2022

Here are the two commit messages:

  1. This patch adds a doc target generating Doxygen documentation similarly to build: add doc target zycore-c#51, but with some extra bits: if doxygen-awesome.css is found on the host system, CMake will automatically use it to generate themed documentation.

    Using doxygen_add_docs() requires setting the various Doxygen options in CMakeLists.txt, so there's currently a bit of duplication as the same options are also contained in Doxyfile and Doxyfile-themed. I couldn't remove the two standalone files as they are still required by the doc.yml CI/CD pipeline, as zydoc runs Doxygen itself; as a solution, zydoc could add support for a --doxygen-generated <path> flag that tells it to use already generated Doxygen documentation instead of generating its own.

  2. This patch tweaks the Makefile a bit to make it use the new doc target.

    A new configure target was added, that simply runs cmake -B build_dir, so that make doc doesn't require building the full project.

    I've also made a few minor changes like using cmake --build and cmake --install instead of plain make, as they lead to more concise commands and also make switching build backend easier (e.g. you simply need to add -G Ninja to the configure target, without having to replace all the make calls to ninja ones).

    Another fix was changing &> /dev/null to > /dev/null, as they broke the if statement on my system, and also because POSIX mandates that command -v should print to stdout on success, and shouldn't print anything on error (i.e. no stderr is involved).

@flobernd flobernd requested a review from athre0z October 1, 2022 16:53
@athre0z
Copy link
Member

athre0z commented Oct 2, 2022

Hi and thanks for the PR!

There's a few problems that I see with letting CMake generate this:

  • The documentation is now built every time I type make, which I find annoying because Doxygen spams a ton of stuff into my terminal, making it hard to see the actual relevant warnings from the C compiler
    • This can probably easily be fixed by introducing a default-OFF ZYDIS_BUILD_DOC option and/or cranking down Doxygen's verbosity
    • From the top of my head, I think my preference would be making this option default-ON and silencing Doxygen to only print errors. Documentation generation is sufficiently fast to not be annoying during development.
  • The configuration is now duplicated in two places, and without the duplication there is no obvious way forward to retain the current zydoc behavior: zydoc re-builds the documentation for every Zydis version on each build. It takes the Doxyfile from master and uses that to build documentation for all versions. The idea here was to have consistent documentation theming and configs across all versions. Admittedly, this approach has its drawbacks -- e.g. breaking Google-indexed links if Doxygen changes HTML generation -- but I'm also not looking forward to spending time on re-engineering this.

@Tachi107
Copy link
Contributor Author

Tachi107 commented Oct 2, 2022

  • The documentation is now built every time I type make, which I find annoying because Doxygen spams a ton of stuff into my terminal, making it hard to see the actual relevant warnings from the C compiler

    • This can probably easily be fixed by introducing a default-OFF ZYDIS_BUILD_DOC option and/or cranking down Doxygen's verbosity

That's true, and I find it quite annoying too. I'd personally make Doxygen quieter instead of adding a new build option, as I don't see why you wouldn't want to generate documentation if Doxygen is found on the host, and also because if you really want to you can already tell CMake to treat Doxygen as not found with -DCMAKE_DISABLE_FIND_PACKAGE_Doxyen=true. Verbosity can be reduced with Doxygen's QUIET option.

  • The configuration is now duplicated in two places, and without the duplication there is no obvious way forward to retain the current zydoc behavior: zydoc re-builds the documentation for every Zydis version on each build. It takes the Doxyfile from master and uses that to build documentation for all versions. The idea here was to have consistent documentation theming and configs across all versions. Admittedly, this approach has its drawbacks -- e.g. breaking Google-indexed links if Doxygen changes HTML generation -- but I'm also not looking forward to spending time on re-engineering this.

When looking at zydoc I didn't realize that it builds documentation for all branches, so my suggestion to tell zydoc to use already generated documentation is not actionable :/

I could write a little CMake script to tell CMake to import the options from the Doxyfile; does this sound reasonable to you?

Edit: done, the options are now read from the Doxyfile; here's the updated commit message: Using doxygen_add_docs() requires setting the various Doxygen options in CMakeLists.txt, so to avoid duplicating things in different places I wrote a bit of CMake code that parses the Doxyfile and sets the various options as CMake variables prefixed by DOXYGEN_. The "parser" is really basic, and does not handle values that span over multiple lines.

Copy link
Member

@athre0z athre0z left a comment

Choose a reason for hiding this comment

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

Thanks -- that solves all major pain points! :)

There appears to be an issue with the README.md being picked up, though. The index.html page is blank for me when documentation is built on your branch.

Screenshot_2022-10-02_20-19-51

CMakeLists.txt Show resolved Hide resolved

# Read Doxygen options from the Doxyfile and set them as CMake variables
# to accomodate doxygen_add_docs()
file(READ "Doxyfile" DOXYFILE)
Copy link
Member

Choose a reason for hiding this comment

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

Nit: this temporary variable DOXYFILE is upper-cased whereas later locals are lower-cased -- is there a reason for this?

This patch adds a doc target generating Doxygen documentation similarly
to <zyantific/zycore-c#51>, but with some extra
bits: if doxygen-awesome.css is found on the host system, CMake will
automatically use it to generate themed documentation.

Using `doxygen_add_docs()` requires setting the various Doxygen options
in CMakeLists.txt, so to avoid duplicating things in different places
I wrote a bit of CMake code that parses the Doxyfile and sets the
various options as CMake variables prefixed by DOXYGEN_. The "parser"
is really basic, and does not handle values that span over multiple
lines.
This patch tweaks the Makefile a bit to make it use the new doc target.

A new `configure` target was added, that simply runs
`cmake -B build_dir`, so that `make doc` doesn't require building the
full project.

I've also made a few minor changes like using `cmake --build` and
`cmake --install` instead of plain `make`, as they lead to more concise
commands and also make switching build backend easier (e.g. you simply
need to add `-G Ninja` to the `configure` target, without having to
replace all the `make` calls to `ninja` ones).

Another fix was changing `&> /dev/null` to `> /dev/null`, as they broke
the if statement on my system, and also because POSIX mandates that
`command -v` should print to stdout on success, and shouldn't print
anything on error (i.e. no stderr is involved).
@Tachi107
Copy link
Contributor Author

Tachi107 commented Oct 2, 2022 via email

Copy link
Member

@athre0z athre0z left a comment

Choose a reason for hiding this comment

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

LGTM, thanks! :)

@athre0z athre0z merged commit 109d08b into zyantific:master Oct 3, 2022
@Tachi107
Copy link
Contributor Author

Tachi107 commented Oct 3, 2022 via email

@Tachi107 Tachi107 deleted the doc-target branch October 3, 2022 17:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants