skip to Main Content

The default Rust Analyzer target directory is called target which conflicts with the name used when cargo build is run.

How can I change the target directory from target to some other name?

2

Answers


  1. Chosen as BEST ANSWER

    Go to Rust Analyzer Extension Settings, search for args.

    • Rust-Analyzer > Cargo: Extra Args

    Add the following two values:

    • --target-dir
    • target-rust-analyzer

  2. If you use rust-analyzer extension of VS Code, you can specify target directory using extension settings.

    1. Press Ctrl + ,
    2. Write rust-analyzer cargo target dir
    3. It would show options to set setting for User or Workspace. First apply to all projects you open, second only to currently opened project.
    4. You need Rust-analyzer › Cargo: Target Dir setting which is specifically for your use case.
    5. Setting value to my_some_value would mean that rust-analyzer files would be stored in target/my_some_value in workspace root. I myself set it to rust-analyzer so I can understand what it is.

    My VS Code settings.json:

    {
      "rust-analyzer.cargo.targetDir": "rust-analyzer"
    }
    

    You probably should to keep rust-analyzer files inside target directory like me because this is supported better by tooling:

    1. Entire target directory is ignored by default template of .gitignore/.hgignore created by cargo new so you don’t need to add rust-analyzer output directory manually.
    2. cargo clean would clean both normal cargo output and rust-analyzer output which is often good. Also, cargo clean almost never conflicts with rust-analyzer in my experience.
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search