Skip to content

-w json breaks cargo doc --message-format=json #15558

Open
@jyn514

Description

@jyn514

Problem

here is cargo, run on a toy crate:

$ RUSTDOCFLAGS="-Zunstable-options -wjson" cargo doc --message-format json
 Documenting whatever v0.1.0 (/home/jyn/src/whatever)
{"reason":"compiler-artifact","package_id":"path+file:///home/jyn/src/whatever#0.1.0","manifest_path":"/home/jyn/src/whatever/Cargo.toml","target":{"kind":["bin"],"crate_types":["bin"],"name":"whatever","src_path":"/home/jyn/src/whatever/src/main.rs","edition":"2024","doc":true,"doctest":false,"test":true},"profile":{"opt_level":"0","debuginfo":2,"debug_assertions":true,"overflow_checks":true,"test":false},"features":[],"filenames":[],"executable":null,"fresh":false}
{"reason":"build-finished","success":true}

this says "filenames": []. that is not correct. rustdoc generated an output file in /home/jyn/.local/lib/cargo/target/doc/whatever.json, which should be reported here.

my understanding is that for this to work, cargo needs rustdoc to support --print=file-names, which it doesn't currently.

Proposed Solution

  1. Add support for --print=file-names to rustdoc. I think this can be insta-stable; any other values should probably be unstable.
  2. Change cargo to run rustdoc --print=file-names before running it on the crate, just like it already does for rustc.
  3. Use that to emit filenames in cargo's own json output.

Notes

here is an strace of cargo running rustc --print=file-names:

[pid 20757] execve("/home/jyn/.local/lib/rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/rustc", ["/home/jyn/.local/lib/rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/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", "--print=sysroot", "--print=split-debuginfo", "--print=crate-name", "--print=cfg", "-Wwarnings"], 0x55bb1434c940 /* 73 vars */) = 0

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-json-outputArea: JSON message outputC-feature-requestCategory: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted`Command-docS-needs-mentorStatus: Issue or feature is accepted, but needs a team member to commit to helping and reviewing.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions