-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Rust-analyzer + rustc repo: build failures in the standard library are not shown in the editor any more #128726
Comments
Hmm... so Rust Analyser assumes a diagnostic item with a leading |
No, r-a runs |
@weihanglo This is a problem that affects all projects where one does not invoke cargo directly, and instead a wrapper script coordinates the build across a bunch of workspaces -- the directories in the output are relative to the workspace root where the problem occurred, but the workspace root is somewhere inside the repo. It's not just about some assumption RA makes, it is also confusing for users. E.g. this is output I get from
Can you tell which file the error occurs in? It's in the cranelift backend, but given just the error message, that's impossible to tell. Cargo got invoked as So far this only affected the cranelift and GCC backends, so only a few contributors were affected. Now it affects the entire standard library, making it a much bigger issue for rustc contributors. |
Likewise it also makes the paths semi useless in integrated terminals for editors where usually clicking it opens the file (as long as the path is relative to the opened workspace root) |
hmm. should rustc consider adding a (potentially unstable) option to change that? I.e. an option that will make it render the emitted paths as relative to the current working directory? (Or potentially, emit the paths as relative to a directory supplied to that command line option, so that even if a build tool like cargo changes the current working directory itself for some reason, we could still thread through the original directory and then have rustc compute paths as relative to that) My memory from other contexts is that this can be a hard problem to solve optimally, but I would imagine there are some at least half baked solutions that could serve us well here... |
That is exactly what rustc does already. Cargo however sets the current working directory of the rustc invocations it spawns to the root of the workspace (or the package dir in case of crates.io deps) to fix rust-lang/cargo#4788. In rust-lang/cargo#9887 (comment) I suggested having an option to make cargo set a parent directory of the workspace as current dir for the rustc invocation. |
Okay it sounds like I was basically suggesting that we work on addressing rust-lang/cargo#9887 . (In particular, when I included the generalization of an option that tells rustc "do your reporting relative to this directory I'm giving to you." For example, that generalization yields effectively absolute paths when one asks for directories relative to the root directory.) You (bjorn3) made an interesting point over there about that potentially interfering with diagnostics caching; it doesn't sound insurmountable, but it definitely complicates the most naive approach I was envisioning... |
heh, apparently I was complaining about this quite a long time ago: #47355 |
Yeah this is arguably a regression introduced by <rust-lang/cargo#4788>, but it essentially only affects projects that have "multi workspace repositories" with a custom build script (like rustc or Miri). It's been known for years but there is no easy fix that does not regress the "move build cache to different folder" case and it's not been anyone's priority to come up with a non-easy fix :(
|
I just discussed this with Felix, and I'm still catching up on the conversation in this thread, but there's an option that might be minimally disruptive to the two different use-cases mentioned: We could extend the json output to include both relative and absolute paths in different fields (or keep the current relative path field and add a field holding the absolute path to where the relative path starts from and let tools concatenate them themselves). (We also need to make a determination, I believe around the distinction between absolute paths and canonical paths, to account for symlinks.) |
Given that the issue affects tools and users reading rustc output (as I keep repeating), I don't see how this would help.
when there is an error in the cranelift backend. |
rust-lang/cargo#14752 plus #132390 are fixing this issue. :) |
Neat, that doesn't even require any changes on our side I take it? (given this is internal to bootstrap's invocations) |
Nope, it's all working on my machine with the existing RA. :) Even build errors in bootstrap itself are shown properly.
|
add unstable -Zroot-dir flag to configure the path from which rustc should be invoked This implements the proposal described [here](#9887 (comment)): we add a new flag, for now called `-Zroot-dir`, that configures the directory relative to which rustc is given the crate root filenames to build. (Files outside this directory are passed absolutely.) This is necessary to be able to fix (no github don't close that issue yet) rust-lang/rust#128726: in multi-workspace repositories that use scripts to manage a whole bunch of cargo invocations, currently the output cargo+rustc produce is often hard or even impossible to interpret for both human and machine consumption. This is because directories in the output are always relative to the workspace root, but when cargo is invoked many times for different workspaces, it is quite unclear what the workspace root is for the invocation that failed. So I suggest we should have a new flag that the build script in such a repo can set to the consistent "root dir" that the user would recognize as such (e.g., the root of the rustc source tree), and all paths emitted by cargo and rustc should be relative to that directory. I don't know all the places that cargo itself emits paths (if any), but this PR changes the way we invoke rustc to honor the new flag, so all paths emitted by rustc will be relative to the `-Zroot-dir`. See rust-lang/rust#132390 for the changes needed in rustc bootstrap to wire this up; together, that suffices to finally properly show errors in RA for all parts of the rustc src tree. :)
This is a consequence of #128534 plus rust-lang/cargo#9887: on a build failure in the sysroot,
x.py check library
now printsNote that the file name no longer includes the leading
library/
. As a consequence, RA cannot locate the error, so it is not shown in the IDE at all.This will make working on the standard library a lot more painful, unfortunately.
Cc @bjorn3 @epage @Veykril
The text was updated successfully, but these errors were encountered: