Vscode-rust: RLS doesn't support multiple projects in a folder

Created on 18 Dec 2018  ·  4Comments  ·  Source: rust-lang/vscode-rust

If you open a folder which contains multiple rust projects (example below) you get the following error.

A Cargo.toml file must be at the root of the workspace in order to support all features

This error makes sense, but it would be nice to support all of the projects within a root folder rather than opening multiple windows (one per project).

Workspace
    project 1
        cargo.toml
    project 2
        cargo.toml

Most helpful comment

Hi, My usecase is a bit different.

How do I have non-dependent multiple projects that generate different non related binaries in a same repository?

I am planning to keep all my rust programs in a single repo for consistency and brevity. I am still a beginner and would prefer them all at one place.

The problem I am facing is that when I load the project directory in VS Code, I cannot build projects inside a directory. For example I have a project in /book/guessing_game with Cargo.toml in the guessing_game directory.

I want that the rust-extension should build and run the project as is. However, It doesn't. And it instead complains of the missing cargo.toml file in the root directory.

How can I achieve this?

All 4 comments

You need to use cargo workspaces for this:
https://doc.rust-lang.org/book/ch14-03-cargo-workspaces.html

Thanks, this is the solution

Hi, My usecase is a bit different.

How do I have non-dependent multiple projects that generate different non related binaries in a same repository?

I am planning to keep all my rust programs in a single repo for consistency and brevity. I am still a beginner and would prefer them all at one place.

The problem I am facing is that when I load the project directory in VS Code, I cannot build projects inside a directory. For example I have a project in /book/guessing_game with Cargo.toml in the guessing_game directory.

I want that the rust-extension should build and run the project as is. However, It doesn't. And it instead complains of the missing cargo.toml file in the root directory.

How can I achieve this?

This is the same problem I had. You need to create a new Cargo.toml in the root directory, and point it to those projects. Look through the link LaylConway provided.

If you are using git, you will also need to make a new .gitignore in the root. Use the .gitignore files generated by cargo new as reference for the rules you will need.

Was this page helpful?
0 / 5 - 0 ratings