I have a cargo workspace with one library ./raytracing
and one binary ./cli
. The two workspace members have different dependencies.
./raytracing/Cargo.toml:
[package]
name = "raytracer"
version = "0.1.0"
edition = "2021"
[dependencies]
rand = "0.8.5"
./cli/Cargo.toml:
[package]
name = "cli"
version = "0.1.0"
edition = "2021"
[dependencies]
raytracer = {path = "../raytracer"}
rand = "0.8.5"
rand_xorshift = "0.3.0"
Parent directory Cargo.toml (./Cargo.toml)
[package]
edition = "2021"
name = "raytracing"
version = "0.1.0"
[workspace]
members = [
"raytracer",
"cli",
]
[[bin]]
path = "cli/src/main.rs"
name = "cli"
Compiling both the raytracer and cli packages using cargo build -p works, however in VSCode rust-analyzer complains about my dependencies in the ./cli package when I import them in main.rs: Error
With your current setup you actually have two binaries compiled from the same source file: one from from ./cli/Cargo.toml
, and one from ./Cargo.toml
. ./Cargo.toml
doesn't declare any [dependencies]
so of course you're getting an error when trying to compile a binary form that. You haven't explained what you're trying to achieve, so I can't tell you the correct way to fix this problem. Generally, there's two things you can do:
./Cargo.toml
except the [workspace]
section. (normal)./cli/Cargo.toml
and move its [dependencies]
section to ./Cargo.toml
. (bit weird)