Description
Problem
It appears that when using workspaces and executing cargo
against a manifest with only workspace members (i.e., at the root of a repository), cargo doc
and cargo test --doc
execute rustdoc
in different directories. This interacts poorly with relative paths used in additional flags for rustdoc
(either from environment variables or a Cargo configuration file).
Depending on the relative paths involved (e.g., ./path
vs. ../path
), this causes one of cargo doc
or cargo test --doc
to fail with an error stating that the path cannot be found.
This is likely complicated, but at first I expected that relative paths would resolve the same way for both cargo doc
and cargo test --doc
when executed in the same directory.
Steps
- Create a repository with a workspace and a member package in a subdirectory.
- Create an HTML file at the root of the repository (its contents do not matter).
- Pass a relative path to this file to
rustdoc
via--html-in-header
using an environment variable or Cargo configuration file. - Execute
cargo doc
andcargo test --doc
from the root of the repository (using the workspace manifest).
See this commit in a workspace repository for an example of this problem. The CI for that project fails with similar errors on different operating systems.
Possible Solution(s)
I'm really not sure what is acceptable here. I encountered this when I tried to migrate away from using a simple shell script for generating documentation that uses the RUSTDOCFLAGS
environment variable.
Notes
I've encountered this using both stable and nightly toolchains on Windows 10 and Arch Linux.
Output of cargo version
: cargo 1.42.0 (86334295e 2020-01-31)
Output of cargo +nightly version
: cargo 1.44.0-nightly (7019b3ed3 2020-03-17)