Open
Description
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
- Add support for
--print=file-names
to rustdoc. I think this can be insta-stable; any other values should probably be unstable. - Change cargo to run
rustdoc --print=file-names
before running it on the crate, just like it already does for rustc. - 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