Hi,
I have a hybrid project, where parts are written for native compilation and parts are written for wasm32-unknown-unknown. It's managed as a workspace with multiple crates. I'm using Visual Studio Code with the RLS extension for inline errors/warnings reporting.
To make the explanation easier, consider the following tree:
myproject/Cargo.toml
myproject/frontend/
myproject/backend/
myproject/datamodel/
myproject
is a workspace with three crates. frontend
only compiles for wasm32-unknown-unknown, backend
only compiles for x86-64, and datamodel
is used by both (included as a crate in frontend/Cargo.toml
and backend/Cargo.toml
using path = "../datamodel"
).
So far, this works fine, as long as I open only a single crate of the workspace. However, when I open up the whole workspace, RLS complains that it can't compile web-sys (which I use for the frontend) for the x86-64 target (duh). I can set a single target architecture for the whole project, but how can I set one per workspace member? There is a file frontend/.cargo/config
with the right settings, but apparently cargo only looks at the top level one. Setting the whole thing to compile for wasm32 wouldn't work either, since the backend uses things that don't work on that architecture (like actix-web).
The reason I don't want to simply only open single crates of the workspace is that in this situation RLS doesn't realize when files in myproject/datamodel
change, and keeps on complaining about references to things that are there. I have to restart RLS manually every time I want it to notice these changes.
The way I understand the documentation, it should actually work just by placing a .cargo/config
file into the crate. However, it says
If, for example, Cargo were invoked in
/projects/foo/bar/baz
which technically means that it doesn't matter where that .config
directory is, as long as you run cargo from there (since you can define an arbitrary parth to the Cargo.toml
file with command line parameters). Since RLS presumably runs cargo check
from the root directory instead of the individual workspace members, it never sees the frontend/.cargo/config
file.
So, does somebody know how to solve this issue?