cargo-component icon indicating copy to clipboard operation
cargo-component copied to clipboard

cargo-component as cargo command for rust-analyzer fails for non-component crates

Open ricochet opened this issue 2 years ago • 0 comments

After setting "cargo-component" as the custom cargo command for rust-analyzer in VS Code, it begins to fail to parse Cargo.toml's for non-cargo component crates.

"rust-analyzer.server.extraEnv": {
  "CARGO": "cargo-component"
}

Use case 1: workspaces

Cargo.toml of a workspace with only one package (repo):

[workspace]
members = [ "wasmcloud-test-util"]

An example error is:

Failed to read Cargo metadata from Cargo.toml file /Users/bhayes/repos/wasmCloud/wasmcloud-test/Cargo.toml, None: Failed to run `"cargo-component" "metadata" "--format-version" "1" "--manifest-path" "/Users/bhayes/repos/wasmCloud/wasmcloud-test/Cargo.toml" "--filter-platform" "aarch64-apple-darwin"`: `cargo metadata` exited with an error: error: manifest path `/Users/bhayes/repos/wasmCloud/wasmcloud-test/Cargo.toml` is a virtual manifest, but this command requires running against an actual package in this workspace

Running cargo metadata --format-version 1 --manifest-path /Users/bhayes/repos/wasmCloud/wasmcloud-test/Cargo.toml --filter-platform aarch64-apple-darwin succeeds. Working directory does not matter.

Use case 2: package with library

Cargo.toml of a package with a local library (repo):

Cargo metadata from Cargo.toml file /Users/bhayes/repos/wasmCloud/wash/Cargo.toml, None: Failed to run `"cargo-component" "metadata" "--format-version" "1" "--manifest-path" "/Users/bhayes/repos/wasmCloud/wash/Cargo.toml" "--filter-platform" "aarch64-apple-darwin"`: `cargo metadata` exited with an error: error: manifest `/Users/bhayes/repos/wasmCloud/wash/Cargo.toml` does not contain a `package.metadata` section

Running cargo metadata ... without "cargo-component" succeeds.

ricochet avatar Oct 10 '22 19:10 ricochet