How to use nightly for crate in workspace, stable for the rest?

I have a workspace containing 3 crates. I only want 1 of the crates to use rust nightly when compiling since I'm using an unstable feature.

Cargo doesn't allow me to do cargo build or cargo run from any of the stable crates due to it being on the stable channel. The 2 stable crates do not depend on the nightly crate.

1 Like

By default, cargo build (and thus any other command) builds every crate in the workspace.

If you want to change this behavior, you can use -p package on a specific command to only check/build/run the specified package and its dependencies, and you can set workspace.default-members to set the packages built by default when you do cargo command.

I have to tell you don't use this but my first thought on seeing the title was this crime against stability:


I think I'll skip on nightly-crimes... I tried using -p package but I still get the same error as I did previously:

Caused by:
  failed to parse manifest at `workspace/nightly_crate/Cargo.toml`

Caused by: 
  the cargo feature `named-profiles` requires a nightly version of Cargo, 
  but this is the `stable` channel

I've set default-members to contain the non-nightly crates too, same error above.

Does this include me running cargo build from the inside the crates as well? If I run from my non-nightly crate's directory I still get the same error as above.

Ah, you're using a nightly cargo feature... As I understand it, cargo always parses all of the manifests of the workspace, so it'll always trigger the cargo feature gate.

This is because cargo needs to know all of the information of all the crates in the workspace in order to know which packages to include in the working set and to do dependency resolution. So unfortunately for your situation I think this is by design.


This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.