Propagating features in workspace doesn't work

Dear Rustaceans, I am stuck with the following problem.
I have a workspace containing several crates organized like this:

Top level Cargo.toml:

[workspace]
members = [
"molar",
"molar_python", 
...
...
]

The crate molar has a feature gromacs, which turns on conditional compilation in several places and activates another dependency.

molar/Cargo.toml:

[features]
gromacs = ["dep:molar_gromacs"]

Now, when I'm compiling molar_python, which depends on molar, I want to propagate gromacs feature down to molar like this:

molar_python/Cargo.toml:

[dependencies]    
molar = {version = "0.8.0", path = "../molar", default-features = false}
...
[features]
gromacs = ["molar/gromacs"]

The idea is that when I do cargo build -p molar_python --features=gromacs the feature is propagated to molar crate, switches on the same feature there and sets all conditinal compilation properly. At least it should work like this according to the manual.
However, it doesn't work at all. Whatever I do I can't activate gromacs feature in molar crate indirectly from molar_python. The only way is to explicitly making it default in crate molar and removing default-features=flase in molar_python.

Am I missing something obvious? What is the correct way of doing this?

This happens in my molar crate.

When I clone your repo, set default-features = false for the molar dependency of your molar_python package and run:

cargo tree -p molar_python --features=gromacs -e features -i molar

I get:

molar v0.8.0 (/home/jofas/src/molar/molar)
ā””ā”€ā”€ molar_python v0.8.0 (/home/jofas/src/molar/molar_python)
    ā”œā”€ā”€ molar_python feature "default" (command-line)
    ā””ā”€ā”€ molar_python feature "gromacs" (command-line)
ā””ā”€ā”€ molar feature "gromacs"
    ā””ā”€ā”€ molar_python feature "gromacs" (command-line)

So

[features]
gromacs = ["molar/gromacs"]

works on my computer as expected. Maybe clearing your build cache with cargo clean and trying again will solve any issues you're having on your workstation?

Thank you! I was not aware that cargo tree can visualize this. It indeed seems that something is messed up with the cache because after cargo clean it indeed seem to work correctly.

1 Like