Conditionally Compiling a Crate in a Workspace

Is is possible to conditionally compile a member of a workspace. For example, given:

[workspace]
members = [
    "crate-a",
    "crate-b",
    "crate-c",
    "picky-crate",
]

Can I somehow make the picky-crate only compile in the presence of cfg=pickycrate="true")?

You can use -p Cargo flag to compile a chosen crate.

If crates are dependencies of each other, you can make picky-crate an optional dependency enabled by a Cargo feature.

There's default-members workspace field https://doc.rust-lang.org/cargo/reference/workspaces.html#package-selection

1 Like

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.