rust-lang / rust-lang/rust-analyzer
`build.target` json file paths in `.cargo/config.toml` are resolved from wrong directory
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 16.9k
- Forks
- 2.2k
- Avg merge
- 1d 12h
- Merged PRs (30d)
- 72
Description
rust-analyzer version: 0.3.2096-standalone
rustc version: rustc 1.83.0-nightly (bd53aa3bf 2024-09-02)
editor or extension: VSCode (RA extension version: v0.3.2096)
repository link (if public, optional): here
steps to reproduce:
- Open root directory of example repository in VS Code
- Note that the Rust Analyzer VS Code plugin gives an error:
ERROR Flycheck failed to run the following command: CommandHandle { program: "/usr/bin/cargo", arguments: ["check", "--workspace", "--message-format=json-diagnostic-rendered-ansi", "--manifest-path", "/home/____/src/ra_target_json_path_resolution_bug/my_crate/Cargo.toml", "--keep-going", "--all-targets"], current_dir: Some("/home/____/src/ra_target_json_path_resolution_bug/my_crate") }, error=Cargo watcher failed, the command produced no valid metadata (exit code: ExitStatus(unix_wait_status(25856))):
error: target path "/home/____/src/ra_target_json_path_resolution_bug/my-custom-target.json" is not a valid file
Caused by:
No such file or directory (os error 2)
- Change directory into
my_crateand runcargo build - Note that no error is given
It appears that Cargo is resolving the target definition json file path relative to the directory that contains .cargo, as specified here. Rust Analyzer, on the other hand, is attempting to resolve the path relative to the my_crate directory.
(The issue is not specific to this nightly Rust toolchain build, I've observed it using other nightly toolchain versions too. It's difficult to test with stable Rust releases as custom targets generally require the build-std cargo feature, which is exclusive to nightly toolchains.)
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the Cargo watcher command from the issue with the example repository, comparing its current_dir with Cargo's handling of .cargo/config.toml and the my_crate/Cargo.toml manifest. Trace the build.target path handling and verify that the custom target JSON is resolved relative to the directory containing .cargo, while cargo build and rust-analyzer complete without the reported error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100