-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Using --manifest-path, the filenames in error messages are relative to the manifest, not the current working directory #11007
Comments
Implement invocation strategy config Fixes #10793 This allows to change how we run build scripts (and `checkOnSave`), exposing two configs: - `once`: run the specified command once in the project root (the working dir of the server) - `per_workspace`: run the specified command per workspace in the corresponding workspace This also applies to `checkOnSave` likewise, though `once_in_root` is useless there currently, due to rust-lang/cargo#11007
Implement invocation strategy config Fixes #10793 This allows to change how we run build scripts (and `checkOnSave`), exposing two configs: - `once`: run the specified command once in the project root (the working dir of the server) - `per_workspace`: run the specified command per workspace in the corresponding workspace This also applies to `checkOnSave` likewise, though `once_in_root` is useless there currently, due to rust-lang/cargo#11007
Some other issues around relative path in error messages:
Basically, this is by design that always be relative to the workspace root. Most projects have a workspace at the root of the repository, and most IDE also depends on workspace when building Cargo projects. Maybe we do need a In the meanwhile, could you try if it helps with
Not ideal I know. Sorry about that :( |
I am not talking about workspace projects though. I am talking about using If you read the discussion at rust-lang/rust-analyzer#10793 and the other backlinks above, you will see that the current behavior is quite painful for IDEs in multi-workspace repos. I can try RUSTFLAGS but then the problem is that all builds inside and outside the IDE need to be somehow configured to use the same flags. |
Sorry for not being more clear 🙇🏾 By workspace root I mean the root path of either a Cargo workspace or a non-workspace Cargo package. (Just realized VS Code also has its own workspace definition 😅). Let's look into
Changing the behaviour of Footnotes
|
The situation with these multi-workspace (or multi-crate-no-workspace) git repos is that they come with a single script that does all the building ( |
This is not the case. Bootstrap runs all cargo processes from the rust-lang/rust root but still gets the truncated file paths. |
here is a way to reproduce the issue:
|
I think this is the same problem as #9427. |
It's unfortunate that this hack is necessary. A short summary of the background here: - Rust-Analyzer uses `x check --json-output` to show red underlines in the editor. - There are several different Cargo workspaces in rust-lang/rust, including src/bootstrap and src/tools/miri. - Cargo runs each invocation of rustc relative to the *workspace*, not to the current working directory of cargo itself. - Rustc prints file paths relative to its current working directory. As a result, it would print things like `config.rs:43:14` instead of `src/bootstrap/config.rs`. This adds a new flag to rustc to print the files as an absolute path instead of a relative path. I went with this approach instead of one of the wrapping tools for the following reasons: 1. Cargo considers changing the working directory to be a breaking change: rust-lang/cargo#11007 (comment). They have open feature requests for adding a flag to print absolute paths, but none have been implemented. 2. Bootstrap would potentially be able to parse and rewrite the paths that cargo emits, but I don't want to hard-code Cargo's JSON output format in both bootstrap.py and rustbuild; unlike rustbuild, bootstrap.py can't use `cargo_metadata` as a library. 3. Rust-Analyzer could potentially rewrite this output, but that wouldn't fix ctrl+click on the relative path when someone runs `cargo check`. In addition to adding and using the new flag, this also adds `local_rebuild` detection to bootstrap.py, so that I could test the change. Before: ``` error[E0425]: cannot find value `MIRI_DEFAULT_ARGS` in crate `miri` --> src/bin/miri.rs:269:33 | 269 | args.splice(1..1, miri::MIRI_DEFAULT_ARGS.iter().map(ToString::to_string)); | ^^^^^^^^^^^^^^^^^ help: a constant with a similar name exists: `MIRI_DEFLT_ARGS` | ::: src/lib.rs:128:1 | 128 | pub const MIRI_DEFLT_ARGS: &[&str] = &[ | ---------------------------------- similarly named constant `MIRI_DEFLT_ARGS` defined here ``` After: ``` error[E0425]: cannot find value `MIRI_DEFAULT_ARGS` in crate `miri` --> /home/jyn/src/rust/src/tools/miri/src/bin/miri.rs:269:33 | 269 | args.splice(1..1, miri::MIRI_DEFAULT_ARGS.iter().map(ToString::to_string)); | ^^^^^^^^^^^^^^^^^ help: a constant with a similar name exists: `MIRI_DEFLT_ARGS` | ::: /home/jyn/src/rust/src/tools/miri/src/lib.rs:128:1 | 128 | pub const MIRI_DEFLT_ARGS: &[&str] = &[ | ---------------------------------- similarly named constant `MIRI_DEFLT_ARGS` defined here ```
cargo/src/cargo/util/workspace.rs Lines 97 to 124 in 8881003
(note that miri is in a separate workspace, so this effectively strips |
FWIW, Miri is not a separate workspace, but the cranelift backend is. |
#9887 appears to ask for the same thing (shift messages to be relative to CWD), so closing in favor of that |
Problem
When using
--manifest-path
, the filenames in error messages are relative to the manifest given, not the directory cargo is invoked from.Steps
cargo-miri/src/main.rs
.cargo check --manifest-path cargo-miri/Cargo.toml
src/main.rs:21:17
Possible Solution(s)
Cargo could instruct rustc to print the paths relative to a given directory, or it could adjust the paths itself.
Notes
This also affects the rustc repo, where we have 3 workspaces currently (the main one, bootstrap, and codegen_cranelift). Errors in codegen_cranelift show paths that are quite hard to interpret since they are relative to
src/compiler/rustc_codegen_cranelift
, which is hard to users to even realize.Version
No response
The text was updated successfully, but these errors were encountered: