Skip to content

build.target json file paths in .cargo/config.toml are resolved from wrong directory #18033

@bravely-beep

Description

@bravely-beep

rust-analyzer version: 0.3.2096-standalone

rustc version: rustc 1.83.0-nightly (bd53aa3 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_crate and run cargo 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.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-cargocargo related issuesC-bugCategory: bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions