Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cargo runs rustc from the workspace root #8947

Open
jyn514 opened this issue Dec 5, 2020 · 3 comments
Open

Cargo runs rustc from the workspace root #8947

jyn514 opened this issue Dec 5, 2020 · 3 comments
Labels
A-documenting-cargo-itself Area: Cargo's documentation C-bug Category: bug

Comments

@jyn514
Copy link
Member

jyn514 commented Dec 5, 2020

Bug? Inconvenience? Who knows, but it confused me greatly.

Problem

I ran cargo build --lib -- -Z self-profile from src/librustdoc in a clone of https://github.com/rust-lang/rust/. I expected the output file to be in src/librustdoc/rustdoc-24097.mm_profdata, since that's where it would be if I ran rustc directly. Instead they showed up in the workspace root: rustdoc-24097.mm_profdata.

Steps

  1. git clone https://github.com/rust-lang/rust/
  2. cd rust/src/librustdoc
  3. git checkout 500b0f3c1ba651f31abc551ccbcf222f48e355a2
  4. cargo build --lib -- -Z self-profile

(but I think this is true in any workspace)

Possible Solution(s)

Run rustc from the src/librustdoc folder instead, which will put the file in the expected place.

Notes

Output of cargo version: cargo 1.50.0-nightly (bfca1cd 2020-11-24)

I don't think this is a bug per-se, but it would be nice to document, maybe.

@jyn514 jyn514 added the C-bug Category: bug label Dec 5, 2020
@bjorn3
Copy link
Member

bjorn3 commented Dec 5, 2020

From #4788:

To fix this issue the matter of cwd is now entirely excluded from compilation
command lines. Instead rustc is unconditionally invoked with a relative path
if the path is underneath the workspace root, and otherwise it's invoked as an
absolute path (in which case the cwd doesn't matter).

Another thing is that paths in error messages and warnings are derived from the given filename of the crate root. For example an error message would show foo/my_mod.rs if foo/lib.rs was passed as crate root and the error happens in my_mod.rs. If the cwd were to change between rustc invocations and thus, the filenames in warnings, cargo would cache the warnings with the old path, which is even more confusing.

@ehuss
Copy link
Contributor

ehuss commented Dec 5, 2020

Yea, it is very intentional that it runs in the workspace root. It is extremely rare that it matters, as files are usually emitted in specific paths. The profiling flags are unusual in that they dump files in the CWD. I'm not sure where it could be documented, as it is usually not important, and I doubt would be something that could be easily discoverable or searchable. But if you had some place in mind, feel free to elaborate what could help. (Perhaps https://doc.rust-lang.org/nightly/unstable-book/compiler-flags/self-profile.html could clarify what "current working directory" is when used with cargo?)

@jyn514
Copy link
Member Author

jyn514 commented Dec 5, 2020

Ok, adding this to the self-profile page seems like a good compromise. It's not wrong behavior, it's just confusing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-documenting-cargo-itself Area: Cargo's documentation C-bug Category: bug
Projects
None yet
Development

No branches or pull requests

3 participants