0

I have a workspace lets call my_workspace. my_workspace has a series of small libraries related but each one with their own responsibility. Something like:

[workspace]
members = [
    "my_lib_1",
    "my_lib_2",
    "my_lib_3",
    ...
]

And my_workspace are structured like this:

|my_lib_1/
|my_lib_2/
|my_lib_2/
|Cargo.toml
...

This workspace doesn't export any binaries only libraries.

The thing how I can configure my Cargo.toml to treat each members as a feature? to use like this:

# package that use the lib

[dependencies]
my_workspace = { ... , features = ["my_lib_1"] }

// inside of the package that use `my_workspace`
use my_workspace::my_lib_1;

fn do_something() {
    my_lib_1::whatever_that_exposes_this_lib();
}

I'm sorry if this is a noob question, but I can't find any information in the cargo documentation that would shed light on how to accomplish this.

cafce25
  • 15,907
  • 4
  • 25
  • 31
al3x
  • 589
  • 1
  • 4
  • 16
  • I believe, in each library, you should create it's own crate `Cargo.toml`. Then the main Cargo.toml can have a path in dependencies`my_workspace = { path = "path/to/my_workspace", features = ["my_lib_1"] }` – 99problems May 25 '23 at 16:07

1 Answers1

0

It seems like rust doesn't let me have a workspace as 'main' project, so instead I solved by adding a new crate that import all workspace members and reexport them with the features key in the Cargo.toml and the #[cfg(feature)] annotation in the lib.rs for each member.

al3x
  • 589
  • 1
  • 4
  • 16