Skip to content

Can --workspace be removed from cargo check? #10717

Closed
@vbn

Description

@vbn

When running build scripts in the workspace, --workspace flag is used unconditionally. Even with rust-analyzer.cargo.noDefaultFeatures=true specified, this flag causes crates marked optional = true to be compiled (the feature for the crate is not turned on).

cargo help check says this:

       --workspace
           Check all members in the workspace.

Currently, the only workaround is to specify the following:

  "rust-analyzer.cargo.runBuildScripts": false,
  "rust-analyzer.procMacro.enable": false

However, this is a hack and a really big hammer which stops all uses of build scripts in the workspace. If --workspace flag is removed, the optional dependencies are ignored (for unspecified features) as expected.

I believe this behavior is problematic especially if rust-analyzer.cargo.noDefaultFeatures is set to true. rust-analyzer.cargo.noDefaultFeatures=true would be a good hint that the user doesn't want to compile everything in the workspace, but only some of the features.

Use case

In our internal project, a project has windows and linux specific dependencies. Some crates are linux only, they have build scripts which only work on linux. They are specified in Cargo.toml behind feature configuration. As long as the relevant feature is not turned on, those crates are not compiled. The dependencies are path specific and marked optional = true. Using rust-analyzer on this workspace will call cargo check --workspace which runs build scripts for dependencies including optional ones. This makes rust-analyzer status always broken.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-configconfigurationC-featureCategory: feature requestS-actionableSomeone could pick this issue up and work on it right now

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions