Skip to content

Conversation

@jkelley129
Copy link

Summary

This PR introduces a reproducible and automated process for generating the rustc(1) man page directly from the compiler’s help output, ensuring it always reflects the current CLI.


Details

  • Adds src/doc/man/generate-rustc-man.sh:
    A shell script that invokes help2man on any given rustc binary, via that binary’s --help -v output.

    • Produces src/doc/man/rustc.1
    • Script is robust to execution directory and always writes to the correct location.
  • Documentation in src/doc/man/README.md:

    • Explains the motivation, the step-by-step usage, prerequisites, and the rationale for making the man page solely reflect the actual compiler binary.
    • Documents command usage and expectations.

Rationale

  • Source of Truth:
    The man page is generated entirely from the compiler’s current help text, eliminating drift between documentation and reality.
  • Reproducible:
    The script ensures anyone can regenerate the man page exactly, as long as they have a target compiler binary and help2man installed.
  • Minimal coupling:
    By keeping the script and artifacts local to src/doc/man, there’s no need to depend on build system internals.

Usage

After building rustc, simply run:

./src/doc/man/generate-rustc-man.sh path/to/rustc
  • Requires help2man on the host system (apt install help2man, dnf install help2man, etc).

Notes

  • No changes are made to core Rust sources.
  • The man page should be regenerated if any CLI options/output are changed in the future.

Ready for feedback or further suggestions!

Generate the rustc.1 man page from `rustc --help -v` using help2man
to ensure the documentation stays in sync with the compiler’s actual
CLI behavior.

The generation logic lives in src/doc/man and writes rustc.1 to the
same directory, independent of the current working directory.
- Introduce `src/doc/man/generate-rustc-man.sh`, a robust script that generates the `rustc(1)` man page entirely from the current built binary’s `--help -v` output using help2man.
- Add `README.md` in the same directory to document the rationale, instructions, and prerequisites for this process.
- Ensures the man page always reflects the actual compiler behavior, avoids manual edits or duplication, and is easy to update as CLI options evolve.
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Dec 16, 2025
@rustbot
Copy link
Collaborator

rustbot commented Dec 16, 2025

r? @GuillaumeGomez

rustbot has assigned @GuillaumeGomez.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@GuillaumeGomez
Copy link
Member

Not too sure who's supposed to review this.

r? compiler

@rustbot rustbot added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Dec 16, 2025
@rustbot rustbot assigned SparrowLii and unassigned GuillaumeGomez Dec 16, 2025
@Kivooeo
Copy link
Member

Kivooeo commented Dec 16, 2025

I’m a bit unsure how to route and review this change, since it was redirected to a compiler team. As far as I understand it introduces new documentation-generation tooling and touches on how the rustc(1) man page is produced, and it’s not clear to me which team should be reviewing this or how it fits into our existing documentation processes

Could you clarify:

  • what problem this is intended to solve in the context of the current rustc documentation workflow?

  • whether this is meant as a proposal/experiment, or something you expect to be adopted as-is?

That would help figure out how (and by whom) this should be discussed further

@jkelley129
Copy link
Author

I noticed two different issues(#149875 and #98977) that mentioned the rustc man page being out of sync with the rustc --help output, and they both suggested using an script to generate the man page from the help output to keep documentation in sync. This PR was meant to be an implementation of that. I am open to any modifications or suggestions to the implementation or to make it fit better into the current documentation workflow.

I apologize for not linking the issues initially, that may have made it more clear.

@jyn514
Copy link
Member

jyn514 commented Dec 17, 2025

@Kivooeo i’m willing to review this if you can’t find a reviewer. i don’t have r+ permissions anymore though.

@Kivooeo
Copy link
Member

Kivooeo commented Dec 17, 2025

@Kivooeo i’m willing to review this if you can’t find a reviewer

Yeah, that's sounds really nice, thanks for taking time on it

also if you know, because I don't if we have to cooperate this with our release or infra teams to integrate this into our release process, like generate man before/with new release or only after editing cli flags, you might know this better

i don’t have r+ permissions anymore though.

Also not a problem

Do "r=me,jyn514" after approval, I'd only ask to be impartial as you can (for example README here is obviously written by ai, I'd prefer to see something more human if you share this. If it's important to clarify, I'm not writing this to criticize the author, but rather as something that could be improved, nothing personal)

r? jyn514

@rustbot rustbot assigned jyn514 and unassigned SparrowLii Dec 17, 2025
@rustbot
Copy link
Collaborator

rustbot commented Dec 17, 2025

jyn514 is not on the review rotation at the moment.
They may take a while to respond.

@Kivooeo
Copy link
Member

Kivooeo commented Dec 17, 2025

@bors delegate=jyn514

@bors
Copy link
Collaborator

bors commented Dec 17, 2025

✌️ @jyn514, you can now approve this pull request!

If @Kivooeo told you to "r=me" after making some further change, please make that change, then do @bors r=@Kivooeo

Copy link
Member

@jyn514 jyn514 left a comment

Choose a reason for hiding this comment

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

The setup in this PR is that people have to manually run the script in order to regenerate the man page, which is better than the current situation but not by much. I would like to see the following things before this gets merged:

  • A test that the man page stays up to date
  • A way to --bless that test with bootstrap

I believe you have not yet run this script since I don't see changes to the man page itself. Please do that and commit the diff so I can see what output it generates.

I think one way you could implement the test is as a run-make test that depends on help2man? I'm not sure if there's an existing way for run-make tests to depend on a command to be installed ... cc @jieyouxu, do you have opinions on this should work?

View changes since this review

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Dec 17, 2025
@rustbot
Copy link
Collaborator

rustbot commented Dec 17, 2025

Reminder, once the PR becomes ready for a review, use @rustbot ready.

Rewrite generate-rustc-man.sh to produce a complete, up-to-date man page
by combining help2man output with dynamically generated sections for codegen options
and static information
@jkelley129
Copy link
Author

Ok, I've updated the script to dynamically generate the CODEGEN OPTIONS section from rustc -C help output to fill in some missing information. The man page diff is now also included.

For the test + bless functionality: I'm happy to either wait for input on how run-make tests should work or I can start implementing a test now if you'd prefer. Let me know which approach you'd like!

@rust-log-analyzer
Copy link
Collaborator

The job tidy failed! Check out the build log: (web) (plain enhanced) (plain)

Click to see the possible cause of the failure (guessed by this bot)
fmt: checked 6602 files
tidy check
tidy [rustdoc_json (src)]: `rustdoc-json-types` modified, checking format version
tidy: Skipping binary file check, read-only filesystem
tidy [style (src)]: /checkout/src/doc/man/generate-rustc-man.sh:51: line longer than 100 chars
tidy [style (src)]: /checkout/src/doc/man/generate-rustc-man.sh:79: line longer than 100 chars
tidy [style (src)]: FAIL
removing old virtual environment
creating virtual environment at '/checkout/obj/build/venv' using 'python3.10' and 'venv'
creating virtual environment at '/checkout/obj/build/venv' using 'python3.10' and 'virtualenv'
Requirement already satisfied: pip in ./build/venv/lib/python3.10/site-packages (25.3)
linting python files
---
linting javascript files and applying suggestions
Running eslint on rustdoc JS files
info: ES-Check: there were no ES version matching errors!  🎉
typechecking javascript files
tidy: The following check failed: style (src)
Command `/checkout/obj/build/x86_64-unknown-linux-gnu/stage1-tools-bin/rust-tidy /checkout /checkout/obj/build/x86_64-unknown-linux-gnu/stage0/bin/cargo /checkout/obj/build 4 /node/bin/yarn --extra-checks=py,cpp,js,spellcheck` failed with exit code 1
Created at: src/bootstrap/src/core/build_steps/tool.rs:1612:23
Executed at: src/bootstrap/src/core/build_steps/test.rs:1358:29

Command has failed. Rerun with -v to see more details.
Bootstrap failed while executing `test src/tools/tidy tidyselftest --extra-checks=py,cpp,js,spellcheck`
Build completed unsuccessfully in 0:02:39
  local time: Wed Dec 17 19:10:48 UTC 2025
  network time: Wed, 17 Dec 2025 19:10:49 GMT
##[error]Process completed with exit code 1.

gsub(/=val$/, "", option)
printf ".TP\n\\fB-C %s\\fR=\\fIval\\fR\n%s\n", option, desc
}'
}
Copy link
Member

Choose a reason for hiding this comment

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

is there a way to get help2man to pass a custom flag here rather than open-coding something in bash? if we're doing it for codegen flags i'd rather do it consistently in rust throughout so we don't need an external dependency.

Copy link
Author

Choose a reason for hiding this comment

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

If I understand what you are saying, are you suggesting to add a flag to the rustc --help command(eg. --format-man) that will output all of the necessary information for help2man without needing to parse it from external sources like the rust -C help?
If so, I think that makes sense and I'm happy to do it, but correct me if I'm wrong.

Copy link
Member

@jyn514 jyn514 Dec 17, 2025

Choose a reason for hiding this comment

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

no, i'm asking:
a) does help2man support running rustc -C help instead of --help when it generates this output? if so, you could delete this bash and replace it with a call to help2man.
b) otherwise, if it doesn't support that, then i would like to avoid using help2man altogether and rewrite this bash logic into rust. we'd get rid of the bash script all together and put the rust code in a run-make test. we wouldn't modify the compiler.

either way, i don't want to have a bunch of awk no one knows how to maintain.

does that makes sense?

Copy link
Author

Choose a reason for hiding this comment

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

Yes, I understand what you are saying. I looked into it and it doesn't look like help2man supports two separate help options. You can specify a custom help option(which I use to specify verbose help output) but you can't have two and concatenate without using some separate logic to string them together, and it sounds like that's what you are trying to avoid, which makes sense.

I'm happy to rewrite this in Rust and use some custom logic to parse the help outputs rather than help2man if that's what you think the best next step.

Copy link
Member

Choose a reason for hiding this comment

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

You can specify a custom help option(which I use to specify verbose help output)

I'm wondering now if it makes sense to change rustc to accept both rustc --help -C help at once ... but that will be a big hassle since it has to go through an MCP. I think open-coding it in rust is not so bad, that will give us more flexibility in case help2man doesn't recognize some syntax we start using in the future.

yeah ok, let's do the rewrite into rust.

Copy link
Member

Choose a reason for hiding this comment

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

I've opened rust-lang/compiler-team#954 since I think that's a good change regardless of what we do here, I don't mind if you wait until we get a resolution there to work more on this.

Copy link
Author

Choose a reason for hiding this comment

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

I think I will wait until we have a decision there to start working more on the rust implementation.

Copy link
Member

Choose a reason for hiding this comment

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

👍 the MCP got approved. so i think we can simplify this quite a bit:

  • extend rustc so that —help -C help shows both help outputs
  • change help2man to use both those flags in a single invocation
  • add a UI test for the rustc change and a run-make test that the man page is up-to-date.

Copy link
Author

@jkelley129 jkelley129 Dec 18, 2025

Choose a reason for hiding this comment

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

Quick question about the implementation of the option combining, do you think it makes sense to only require the additional flag(eg. -C, -Z, -W), without needing the help subcommand? Basically
rustc --help -C -Z -W instead of
rustc --help -C help -Z help -W help
I just think it will be less verbose and still unambiguous because the --help option specifies a print-and-exit action anyway.

One consideration might be that it may require refactoring the current flag logic to not require a subcommand, which may affect current behavior, but I'm not sure.

Copy link
Member

Choose a reason for hiding this comment

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

I don’t think that’s worth it, no. That’s ambiguous with a codegen flag named -Z (which doesn’t exist today, but well, seems nicer to not have the ambiguity at all).

I don’t expect this to be very common so I don’t think we need to optimize for brevity.

@jyn514
Copy link
Member

jyn514 commented Dec 17, 2025

@jkelley129 i don't mind if you use an LLM to generate this code, but please disclose that that's what happening, and please do not use an LLM to generate your responses to my review comments.

@jkelley129
Copy link
Author

I am generating most of the code with an LLM, but I can assure you that I am not blindly copying and certainly not using it for review responses.

@jieyouxu
Copy link
Member

jieyouxu commented Dec 18, 2025

Just some context: so tbh I don't really care about the rustc man pages personally, since I just don't use them for rustc, and use either rustc --help or the rustc book. That being said, my take on this is:

  1. The current formulation that there's a random shellscript that you have to run manually is IMHO not really much better than the status quo. Somebody would have to remember to periodically run this and update the generated output.
  2. I don't want to add any more shellscripts if at all avoidable. Based on my experience, PRs making changes to shellscripts (or Makefiles or even Python scripts) don't tend to get reviewed, because either (1) the compiler/bootstrap maintainers aren't confident or comfortable reviewing the shellscript changes, or (2) the compiler/bootstrap maintainers don't want to review shellscript changes. Personally, I fall into camp (2), but I can't and won't speak for other reviewers. They tend to get added some time in the past, but don't tend to get maintained.

In all honesty, if it were just up to me to decide, I would rather just nuke the outdated manpages and just defer to rustc --help et al. But I guess people do use manpages so 🤷

So in that sense, I don't care to block this change simply because I don't care about the manpages.


However, specifically @jyn514 when you ask me about

I think one way you could implement the test is as a run-make test that depends on help2man? I'm not sure if there's an existing way for run-make tests to depend on a command to be installed ... cc @jieyouxu, do you have opinions on this should work?

That, properly implemented, would have to be some kind of compiletest capability directive which is fed information from a tool availability discovery in bootstrap. If you want the run-make test to actually faithfully report "ignored" and not "silently green" (which I consider deceptive tbh).

Furthermore, I'm not sure if CI has help2man installed, but if it does I'm not a huge fun to run the test in CI since it would be blocking. And quite honestly, I think it might be quite annoying to deal with if you have to fix/change the generation script too.


EDIT: I guess it also depends on which team is supposed to be maintaining this.

  • If it's supposed to be maintained by T-compiler, then do whatever.
  • If it's supposed to be maintained by T-bootstrap, then with a T-bootstrap maintainer hat on, I don't want to merge this.

@jieyouxu
Copy link
Member

jieyouxu commented Dec 18, 2025

Implementation wise, I didn't have time to look deep, but perhaps a potentially more maintainable approach is to:

  • Synthesize manpages entries from in-tree rustc because the in-tree rustc definitely knows about all the cli flags and such it accepts.
  • Perhaps some perma-unstable interal-use-only flag, like --print=rustc-internal-manpage, which bootstrap can use in some kind of doc(?) step that builds and queries an in-tree rustc.
  • If you have the perma-unstable internal-use-only flag, then you can also track the manpage output in a run-make with the diff() API, which already has auto-bless support.

I would be much less hesistant if the implementation approach adopted was akin to this, because of the auto-bless support, and in that case, I would actually be perfectly fine with making it (the test and the manpage output changes) blocking in CI.

But if the formulation is a manual shell script with no autobless, I would be very against a blocking test that tries to expect the manpage differences from --help output.

@apiraino
Copy link
Contributor

apiraino commented Dec 18, 2025

TIL we have a man page for rustc :-)

A few questions (not a full review) after a cursory look:

  • How is the man page currently generated/maintained? (We have the answer, it's that I don't know)
  • How does the suggested script to update the man page fits in our automation? My assumption here is that man pages are/will be automatically updated, correct?
  • If this procedure is approved, maybe I would also add some documentation on https://rustc-dev-guide.rust-lang.org/
  • What if tomorrow we also want to update src/doc/man/rustdoc.1? :)

This change adds new dependencies (help2man is also not installed by default on Debian - AFAICS). Was this discussed in some Rust space (e.g. on Zulip)? In general I feel this change would benefit from a wider discussion?

@@ -0,0 +1,97 @@
#!/bin/bash
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not a shell wizard so I've run this script through shellcheck v0.11 to have a second opinion:

$ shellcheck generate-rustc-man.sh 

In generate-rustc-man.sh line 3:
set -euo pipefail
         ^------^ SC3040 (warning): In POSIX sh, set option pipefail is undefined.


In generate-rustc-man.sh line 9:
trap "rm -f '$INCLUDE_FILE'" EXIT
             ^-----------^ SC2064 (warning): Use single quotes, otherwise this expands now rather than when signalled.

For more information:
  https://www.shellcheck.net/wiki/SC2064 -- Use single quotes, otherwise this...
  https://www.shellcheck.net/wiki/SC3040 -- In POSIX sh, set option pipefail ...

@jyn514
Copy link
Member

jyn514 commented Dec 18, 2025

@jieyouxu @apiraino y’all i’m already reviewing this lol. you don’t need to repeat the same comments i’ve already made.

@jyn514
Copy link
Member

jyn514 commented Dec 18, 2025

@jieyouxu if you would like to have a final review pass before that gets approved that seems fine to me, but i think having three people trying to change the design direction does more harm than good. the risks here are low. the man page is already horribly broken.

@jieyouxu
Copy link
Member

Fine by me.

@jkelley129
Copy link
Author

Ok, so a clarifying question on where you'd like me to go on this. I think what the idea right now is to instead write a run-make test with --bless support in Rust, using the new option-combining functionality with help2man. Do I have that right @jyn514?

@jyn514
Copy link
Member

jyn514 commented Dec 18, 2025

@jkelley129 yes, that's right. see https://doc.rust-lang.org/nightly/nightly-rustc/run_make_support/diff/struct.Diff.html for how to support --bless in a run-make test, there should be a bunch of existing examples you can copy.

That, properly implemented, would have to be some kind of compiletest capability directive which is fed information from a tool availability discovery in bootstrap. If you want the run-make test to actually faithfully report "ignored" and not "silently green" (which I consider deceptive tbh).

hm, ok. there should be docs for that at https://rustc-dev-guide.rust-lang.org/tests/directives.html#adding-a-directive. i would expect it to be called //@ needs-help2man or something like that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

10 participants