Reputation: 9289
I have a binary Rust project which uses the workspaces to manage sub-crates.
Directory structure
/myapp
Cargo.toml
/src
/tests
test.rs
/crates
/printer
Cargo.toml
/src
myapp/Cargo.toml
[package]
name = "myapp"
[workspace]
members = ["crates/printer"]
Inside of test.rs
I can compile extern crate myapp;
to pull in the parts of the application that are exposed in src/lib.rs
. This works as expected.
However, when attempting to compile extern crate printer;
it errors that it cannot find it. I've confirmed that the printer package is correctly placed in the top-level Cargo.lock
file.
How do I include my sub-crates into the /tests
directory at the top level?
Upvotes: 2
Views: 1528
Reputation: 430318
There's nothing special about workspaces or even the concept of tests. If you want to use a crate in Rust code, you have to add it as a dependency:
[dependencies]
printer = { path = "crates/printer" }
See also:
Upvotes: 3