-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Add unstable --output-format
option to cargo rustdoc
#12252
Conversation
r? @ehuss (rustbot has picked a reviewer for you, use r? to override) |
I'm a little confused about the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the contribution!
Haven't read through the entire change. Just wondering if you could add tests that verify without the -Z flag Cargo will fail, for both rustdoc and doc commands.
Thanks! Added a couple more. |
3a3bc74
to
f3eb1e6
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the contribution. Really appreciate the effort of working on this.
However, the current implementation went a bit off the rails. There are a few parts we can discuss.
Fingerprint detection for <crate>.json
#12103 is an issue originated from #12100. The most important line in description of #12103 is missing in the current patch:
This would allow cargo to reason about it and take it into account in the fingerprinting logic.
If we look into #12100 carefully, we shall the change touched this piece of code:
cargo/src/cargo/core/compiler/context/compilation_files.rs
Lines 439 to 442 in 928b956
let path = self | |
.out_dir(unit) | |
.join(unit.target.crate_name()) | |
.join("index.html"); |
This is the core logic Cargo determines where final output artifacts are located. We should do some trict here in order to make the fingerprint (the re-compile detection) takes <crate>.json
into account.
In order to do so, Unit
or some other types involved in the above code may need to know about --output-format
. This is one non-easy part.
Where to pass the --output-format
to rustdoc
On the other hand, we need a place to apppend rustdoc --output-format
. The current fix found a place target_rustdoc_args
, which is just a coincidence. It is for cargo rustdoc -- <args>
trailing args only. Cargo should have a way to prevent contributor adding args into it (probably a way to make the semantic clearer). What we need is like --crate-type
, which was also a cargo rustc -- --crate-type
trailing argument and then got promoted as a normal argument. Presumbly we can follow its tracking issue to see what we can design for --output-format
for rustdoc.
Tests to verify the behavior
The current added tests are good enough to verify -Z
flag on-off and basic usage of `--output-format. Some cases are missing:
- Should bail when without
-Z unstable-options
. - No recompile of run the same command multiple times.
- Recompile if change format.
- Check if each dependency outputs
<crate>json
forcargo doc
. - Check if only the requested package outputs
<crate>.json
forcargo rustdoc
.
Focus on cargo rustdoc
maybe?
Chances are that the output <crate>.json
may collide with each other. Search collision_doc
in this testsuite and you'll find some examples of doc collisions. We may or may not need to fix it. Maybe just make JSON collides like what HTML have done so far. However, if you do feel working on both cargo doc
and cargo rustdoc
are too distacting, we can focus on cargo rustdoc
first. That's also the original issue author suggesting.
Sorry I don't have too many ideas on te implementaion side at this moment. I'll try writing down more thoughts if needed.
r? @weihanglo It looks like you have this covered, but feel free to reassign it back to me if you want. |
Is it safe to say that we should add a, e.g. |
It's really tempting to do that! I feel a bit uncertain to add more fields onto |
@ehuss do you have any input on adding a new field on |
|
Ack. I will move forward with this and the rest of the requested changes and ping back. I will try to focus on |
PR updated. All comments were addressed. A major change in this revision is allowing |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the update!
There are some nits and unresolved comments, and then we're ready to go!
We achieved this by: * Handle `--output-format` argument, accepting `html` or `json` * If `json` is passed, we append the following in `prepare_rustdoc`: 1. `-Zunstable-options` 2. `--output-format` Fixes rust-lang#12103 Signed-off-by: Charalampos Mitrodimas <charmitro@posteo.net>
Resolved! |
Great job! Thanks a lot for the collaboration :) @bors r+ |
Could you add a new doc entry of https://doc.rust-lang.org/nightly/cargo/reference/unstable.html for this feature? You can take this as a reference: 4e45f58#diff-e35cef716988e9f7122a9c90479aa9204e61d1f41b094c0d183a44e0ca271eaaR83-R469 I've created the tracking issue here #13283 |
In this PR or create a follow-up? |
This PR is now in the bors merge queue, so a follow-up would be better :) |
This is a follow-up to rust-lang#12252. Signed-off-by: Charalampos Mitrodimas <charmitro@posteo.net>
This is a follow-up to rust-lang#12252. Signed-off-by: Charalampos Mitrodimas <charmitro@posteo.net>
☀️ Test successful - checks-actions |
This is a follow-up to rust-lang#12252. Signed-off-by: Charalampos Mitrodimas <charmitro@posteo.net>
This is a follow-up to rust-lang#12252. Signed-off-by: Charalampos Mitrodimas <charmitro@posteo.net>
Add documentation entry for unstable `--output-format` flag This is a follow-up to #12252 adding a documentation entry for the newly supported unstable flag `--output-format`.
Update cargo 8 commits in 3e428a38a34e820a461d2cc082e726d3bda71bcb..84976cd699f4aea56cb3a90ce3eedeed9e20d5a5 2024-01-09 20:46:36 +0000 to 2024-01-12 15:55:43 +0000 - fix(resolver): do not panic when sorting empty summaries (rust-lang/cargo#13287) - Implementation of shallow libgit2 fetches behind an unstable flag (rust-lang/cargo#13252) - Add documentation entry for unstable `--output-format` flag (rust-lang/cargo#13284) - doc: add `public` info in `cargo-add` man page. (rust-lang/cargo#13272) - More docs on prerelease compat (rust-lang/cargo#13286) - Add unstable `--output-format` option to `cargo rustdoc` (rust-lang/cargo#12252) - feat: Add `rustc` style errors for manifest parsing (rust-lang/cargo#13172) - Document why `du` function uses mutex (rust-lang/cargo#13273) r? ghost
This is a follow-up to rust-lang#12252. Signed-off-by: Charalampos Mitrodimas <charmitro@posteo.net>
Add unstable
--output-format
option to "rustdoc"We achieved this by:
--output-format
argument, acceptinghtml
orjson
json
inCompileMode::Doc
.json
is passed, we append the following inprepare_rustdoc
:-Zunstable-options
--output-format=json
Fixes #12103