Skip to content

cargo reports incorrect compiler-artifact path for rustdoc json #10149

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

Closed
Nemo157 opened this issue Dec 2, 2021 · 4 comments · Fixed by #10171
Closed

cargo reports incorrect compiler-artifact path for rustdoc json #10149

Nemo157 opened this issue Dec 2, 2021 · 4 comments · Fixed by #10171
Labels
A-json-output Area: JSON message output C-bug Category: bug

Comments

@Nemo157
Copy link
Member

Nemo157 commented Dec 2, 2021

Problem

When running a cargo rustdoc --message-format=json -- --output-format=json -Zunstable-options command the path reported for the final compiler-artifact message is wrong.

Steps

> cargo rustdoc --message-format=json -- --output-format=json -Zunstable-options | jq -sr 'last(.[] | select(.reason == "compiler-artifact")) | .executable'
 Documenting cargo-doc-tree v0.1.0 (/home/nemo157/sources/cargo-doc-tree)
    Finished dev [unoptimized + debuginfo] target(s) in 0.90s
/home/nemo157/.cargo/shared-target/doc/cargo_doc_tree/index.html
> ls /home/nemo157/.cargo/shared-target/doc/cargo_doc_tree/index.html /home/nemo157/.cargo/shared-target/doc/cargo_doc_tree.json
ls: cannot access '/home/nemo157/.cargo/shared-target/doc/cargo_doc_tree/index.html': No such file or directory
/home/nemo157/.cargo/shared-target/doc/cargo_doc_tree.json

Possible Solution(s)

No response

Notes

No response

Version

cargo 1.58.0-nightly (ad50d0d26 2021-11-17)
release: 1.58.0
commit-hash: ad50d0d266213e0cc4f6e526a39d96faae9a3842
commit-date: 2021-11-17
host: x86_64-unknown-linux-gnu
libgit2: 1.3.0 (sys:0.13.23 vendored)
libcurl: 7.79.1-DEV (sys:0.4.50+curl-7.79.1 vendored ssl:OpenSSL/1.1.1l)
os: Arch Linux [64-bit]
@Nemo157 Nemo157 added the C-bug Category: bug label Dec 2, 2021
@Nemo157
Copy link
Member Author

Nemo157 commented Dec 2, 2021

Hmmm, also relevant, that was in a binary crate, in a library-only crate there is no path given in the final message.

@ehuss
Copy link
Contributor

ehuss commented Dec 5, 2021

Including the path in the "executable" field was a mistake. I have posted #10171 to fix that.

As for getting the path when using the JSON output, that is a bit tricky. Cargo doesn't use the flags passed to cargo rustdoc or cargo rustc when computing the potential outputs. Cargo probably won't ever parse those arguments, and rustdoc doesn't have a mechanism to report its outputs.

Perhaps eventually a flag for the output format could be wired directly into cargo rustdoc if the JSON output is ever stabilized.

@jyn514
Copy link
Member

jyn514 commented Dec 6, 2021

Cargo probably won't ever parse those arguments, and rustdoc doesn't have a mechanism to report its outputs.

Perhaps eventually a flag for the output format could be wired directly into cargo rustdoc if the JSON output is ever stabilized.

I think it would be simpler to add a way for rustdoc to report its outputs; it shouldn't be too hard to do. What format does rustc use for that, something with --emit presumably?

@ehuss
Copy link
Contributor

ehuss commented Dec 6, 2021

Primarily through --print=file-names. It runs the command rustc - --crate-name ___ --print=file-names --crate-type bin --crate-type rlib --crate-type dylib --crate-type cdylib --crate-type staticlib --crate-type proc-macro, so that it knows the prefix and suffix of every crate type. Then there is a large amount of code for figuring out for different targets and scenarios the kind of outputs different commands generate.

Compared to rustdoc which is really basic:

CompileMode::Doc { .. } => {
let path = self
.out_dir(unit)
.join(unit.target.crate_name())
.join("index.html");
vec![OutputFile {
path,
hardlink: None,
export_path: None,
flavor: FileFlavor::Normal,
}]

Cargo needs to know the outputs before it runs rustc. rustdoc is a bit different, and I'm not sure how it could work to report the outputs.

@bors bors closed this as completed in a4cdd75 Dec 13, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-json-output Area: JSON message output C-bug Category: bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants