-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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 with explicit manifest path has wrong warnings/errors paths #8506
Comments
This is a feature of Cargo where errors and path names (especially for debuginfo) are always relative to the workspace root. IDEs need to account for workspaces when building Cargo projects and most projects have a workspace root at the root of the repository as well. |
I don't think trying to force all Rust projects (or workspaces) to exist at the root of a VSCode Workspace is reasonable. There are definitely cases, such as mine, where Rust is just a piece of the larger whole, and not the sole thing. That aside, back when I was using a Rust workspace, where the workspace It sounds like my only option for continuing to use Cargo and get warnings/errors to work is to supply a I'm guessing you would be opposed to having an option to specify a base path or entirely virtual workspace for Cargo to use? |
To be clear we're not trying to force anything. I'm trying to explain how things work today and what tools IDEs have to learn about compilations (e.g. |
Thanks for the response Alex. Just to make sure we're on the same page, I'm observing the following behavior: With no workspace, Does that sound correct? Based on this, it seems like Cargo has all the functionality I want, it's just a matter of being able to set what that base path is without needing to have a Cargo workspace (seeing as this is unfortunately not an option for me). Does that seem reasonable? Fortunately with what I've discovered this morning, it seems like I can make things work as is due to dependencies using absolute paths, but it would certainly be nicer to get this working properly with VSCode Workspace relative paths and akin to how Cargo workspaces work. |
Yes that all sounds correct, and it's true that Cargo doesn't have a knob to specify the base directory. What it does give, though, is |
I think we may be talking about slightly different things here. The Hopefully that helps explain why the only relative path solution I'm currently aware of involves trying to insert a shim somewhere to process those paths, or adding functionality to Cargo to do it. As to the debug stuff you mentioned, I've only been able to test this stuff on MacOS so I'm unsure the behavior on Windows/Linux. If it's important, I can test this there as well. On MacOS, I get stuff like the following in my dSYM:
It seems like this works because there's still an absolute path included ( |
Er yes so these are problems to work around or problems to solve, but I'm pointing out how this is unlikely to change in Cargo. I don't know how best this would be fixed in IDEs, though. |
Could you explain the current design behind working directories and paths? It seems a bit inconsistent right now in that all crates seem to be compiled with the working directory of either the root crate or the Cargo workspace, and only the root crate/Cargo workspace crates use relative paths for their root If everything used absolute paths, that would also address my issue. I was originally thinking relative paths would be nicer for the paths embedded in the output, but by default any non-local and non-vendored Cargo dependencies will end up using absolute paths, so some sort of post-build path sanitization is likely to be needed regardless. Thoughts? |
There isn't really a special case here. The design is that paths are printed relative to the workspace in use. The workspace may only have on crate if no Sorry I don't have a ton of time to talk about this issue. If you'd like to open a feature request please feel free, but this issue as-is as a bug report isn't correct on Cargo. |
When running a command like
cargo build --manifest-path Some/Nested/crate
, cargo will invokerustc
with a working directory ofSome/Nested/crate
and a relative source path ofsrc/lib.rs
. This is problematic because it means that all the warnings and errors output byrustc
will usesrc/lib.rs
as the path instead ofSome/Nested/crate/src/lib.rs
, and as a result the VSCode problem matcher is unable to find any of the files. I tested taking the command output by cargo's verbose, and running it with the full relative path, and as expected the warnings/errors have the correct relative path. It seems like cargo either shouldn't change the working directory (which I imagine is done for a good reason, also mentioned in #8148), or it should prepend the manifest path directory before printing the output.The text was updated successfully, but these errors were encountered: