Skip to content

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

Closed

Description

@Nemo157

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]

Activity

  1. Nemo157 commented on Dec 2, 2021

    @Nemo157
    ContributorAuthor

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

  2. ehuss commented on Dec 5, 2021

    @ehuss
    Contributor

    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.

  3. jyn514 commented on Dec 6, 2021

    @jyn514
    Member

    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?

  4. ehuss commented on Dec 6, 2021

    @ehuss
    Contributor

    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.

  5. added a commit that references this issue on Dec 13, 2021
    a4cdd75
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-json-outputArea: JSON message outputC-bugCategory: bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions