rust-lang / rust

Empowering everyone to build reliable and efficient software.
https://www.rust-lang.org
Other
97.24k stars 12.57k forks source link

Cargo doc fails for certain crates in a workspace with "no such file or directory (os error 2)" #126638

Open NotAFlyingGoose opened 3 months ago

NotAFlyingGoose commented 3 months ago

Problem

I'm working with a few other people on making a programming language in Rust and we've encountered an error in trying to create documentation for our workspace.

This is what we get:

 Documenting chrono v0.4.33
error: failed to render source code for `crates/syntax/src/lib.rs`: "crates/syntax/src/lib.rs": No such file or directory (os error 2)
  --> crates/syntax/src/lib.rs:1:1
   |
1  | / use std::mem;
2  | |
3  | | pub type SyntaxBuilder = eventree::SyntaxBuilder<TreeConfig>;
4  | | pub type SyntaxElement = eventree::SyntaxElement<TreeConfig>;
...  |
96 | |     Error,
97 | | }
   | |_^

 Documenting unicode-normalization v0.1.22
 Documenting itertools v0.13.0
error: could not document `syntax`
warning: build failed, waiting for other jobs to finish...

It's really confusing as it gives no other information.

I've seen other similar-ish issues here but they seem more like cargo itself couldn't be found whereas this is saying that crates/syntax/src/lib.rs couldn't be found (when it exists and the command even shows the contents of the file)

Steps

  1. git clone https://github.com/capy-language/capy
  2. cargo doc
  3. see error

Possible Solution(s)

No response

Notes

rustup update hasn't helped, and this error is replicable on my team member's machine

Version

cargo 1.79.0 (ffa9cf99a 2024-06-03)
release: 1.79.0
commit-hash: ffa9cf99a594e59032757403d4c780b46dc2c43a
commit-date: 2024-06-03
host: aarch64-apple-darwin
libgit2: 1.7.2 (sys:0.18.3 vendored)
libcurl: 8.4.0 (sys:0.4.72+curl-8.6.0 system ssl:(SecureTransport) LibreSSL/3.3.6)
ssl: OpenSSL 1.1.1w  11 Sep 2023
os: Mac OS 14.3.1 [64-bit]
ehuss commented 3 months ago

Transferred to rust-lang/rust because this looks to be a rustdoc issue.

veera-sivarajan commented 3 months ago

@rustbot label -needs-triage +T-rustdoc +D-confusing +A-diagnostics

chenyukang commented 3 months ago

interesting, seems because the current working dir is not correct when trying to read the source code, at here: https://github.com/rust-lang/rust/blob/31f8b70d2e18a0339c034e44c52aa3791c29f53c/src/librustdoc/html/sources.rs#L187

I cloned the code into /private/tmp, and add some logs:

emitting source for: crates/syntax/src/lib.rs
current working directory: /private/tmp/capy/crates/capy_macros
chenyukang commented 3 months ago

cc @GuillaumeGomez any ideas on this.

GuillaumeGomez commented 3 months ago

Added it into my TODO list. ^^'

Jauler commented 1 month ago

Hi,

:crossed_fingers: Maybe this can help triaging the issue. We have reproduced similar issue when having:

rustdocflags = [
  "--html-in-header", "<some html file with relative path>",
  "--html-after-content", "<some html file with relative path>",
  "--html-after-content", "<some html file with relative path>",
]

in .cargo/config. While generation with cargo doc fails with No such file or directory (os error 2), it succeeds ifcargo doc --no-deps` is used.