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

Move manpages generation to an xtask #645

Merged
merged 6 commits into from
Nov 24, 2024
Merged

Conversation

AlexTMjugador
Copy link
Collaborator

@AlexTMjugador AlexTMjugador commented Nov 19, 2024

PR #596 brought forward automatic generation of Linux manual pages for Oxipng, which is executed every time Oxipng is built. However, while building manpages on every build is convenient for Oxipng development and doing so didn't catch my attention initially, it introduces noticeable inefficiencies for crates using Oxipng as a library: during their build, Oxipng manpages are also built, even though most dependent crates won't use such artifacts, as they are not considered part of the public Oxipng crate API or even appropriate for non-human consumption.

Moreover, generating manpages depends on clap, which is a heavyweight dependency: according to a fresh cargo build --timings --release on my development workstation, its clap_builder dependency is the third most time consuming unit to build, totalling 1.5 s (out of 11.7 s, or 12.8%). And there is no way for dependent crates to turn this off: build-dependencies cannot be conditional on crate features. Potentially using other cfg hacks to either enable or disable manpage generation is unergonomic, if not outright disallowed. Besides reducing their compilation time cost, dependent crates may also want to trim the size of their dependency tree, avoiding unnecessary dependency downloads in the process.

Therefore, a better solution to conditionally build manpages in a way convenient for both Oxipng maintainers and downstream consumers is needed. My proposal implemented in this PR is to leverage the cargo-xtask convention to define an auxiliary crate to move the manpage generation logic and dependencies to, which is not part of the oxipng crate published on crates.io. That way Oxipng maintainers and packagers can still generate manpages at request with ease, without any automation being noticeable to uninterested crate consumers. And as a side benefit, Oxipng maintainers can also benefit from slightly faster iteration times due to the lack of a build script for the main crate.

The new mangen xtask can be run at any time with cargo xtask mangen. The generated manpages are now available at target/xtask/mangen/manpages. Existing deployment scripts were updated accordingly.

PR #596 brought forward automatic generation of Linux manual pages for
Oxipng, which is executed every time Oxipng is built. However, while
building manpages on every build is convenient for Oxipng development
and doing so didn't catch my attention initially, it introduces
noticeable inefficiencies for crates using Oxipng as a library: during
their build, Oxipng manpages are also built, even though most dependent
crates won't use such artifacts, as they are not considered part of the
public Oxipng crate API or even appropriate for non-human consumption.

Moreover, generating manpages depends on `clap`, which is a heavyweight
dependency: according to a fresh `cargo build --timings --release` on my
development workstation, its `clap_builder` dependency is the third most
time consuming unit to build, totalling 1.5 s (out of 11.7 s, or 12.8%).
And there is no way for dependent crates to turn this off:
[`build-dependencies` cannot be conditional on crate
features](https://doc.rust-lang.org/cargo/reference/specifying-dependencies.html#platform-specific-dependencies).
Potentially using other `cfg` hacks to either enable or disable
manpage generation is unergonomic, if not outright disallowed. Besides
reducing their compilation time cost, dependent crates may also want to
trim the size of their dependency tree, avoiding unnecessary dependency
downloads in the process.

Therefore, a better solution to conditionally build manpages in a way
convenient for both Oxipng maintainers and downstream consumers is
needed. My proposal implemented in this PR is to leverage the
[`cargo-xtask`](https://github.com/matklad/cargo-xtask) convention to
define an auxiliary crate to move the manpage generation logic and
dependencies to, which is to be used exclusively by Oxipng maintainers
and not part of the `oxipng` crate published on `crates.io`. That way
Oxipng maintainers and packagers can still generate manpages at request
with ease, without any automation being noticeable to uninterested crate
consumers. And as a side benefit, Oxipng maintainers can also benefit
from slightly faster iteration times due to the lack of a build script
for the main crate.

The new `mangen` xtask can be run at any time with `cargo xtask mangen`.
The generated manpages are now available at `target/xtask/mangen/manpages`.
Existing deployment scripts were updated accordingly.
@AlexTMjugador AlexTMjugador added T-Techdebt Internal changes to improve software maintainability dependencies Pull requests that update a dependency file labels Nov 19, 2024
Copy link
Collaborator

@andrews05 andrews05 left a comment

Choose a reason for hiding this comment

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

Thanks @AlexTMjugador, great to see this done! I think xtask was always the better solution, I just didn't have any experience with it.

Copy link
Collaborator

@andrews05 andrews05 left a comment

Choose a reason for hiding this comment

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

Looks good!
Shall we do another release?

@AlexTMjugador
Copy link
Collaborator Author

Yes, I think we can proceed with a new patch or minor release. However, I'd like to get #642 merged before doing the release, as it's likely to be a pretty welcome improvement for those using Docker.

@AlexTMjugador AlexTMjugador merged commit c81a863 into master Nov 24, 2024
13 checks passed
@AlexTMjugador AlexTMjugador deleted the refactor/mangen-xtask branch November 24, 2024 12:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dependencies Pull requests that update a dependency file T-Techdebt Internal changes to improve software maintainability
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants