Crate features behave differently under `cargo install --locked` vs `build --release`

In my project https://github.com/sourcefrog/conserve/tree/261a94fb4def022ace890436a5784c2ec2e6b1d2

I have the strange behavior that cargo build --release succeeds, but cargo install --offline --locked --path . fails with errors about derive macros:

error: cannot find derive macro `Serialize` in this scope
  --> src/apath.rs:25:39
   |
25 | #[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)]
   |                                       ^^^^^^^^^

error: cannot find derive macro `Deserialize` in this scope
  --> src/apath.rs:25:50
   |
25 | #[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)]
   |                                                  ^^^^^^^^^^^

error: cannot find derive macro `Serialize` in this scope
  --> src/archive.rs:35:17
   |
35 | #[derive(Debug, Serialize, Deserialize)]
   |                 ^^^^^^^^^
...

It looks like the problem is that I didn't specify serde = { version = "1.0.104", features = ["derive"] } in my Cargo.toml. I had serde_derive = "1.0.104" and I had thought that was enough.

It's perhaps just my bug but it's quite surprising the dependency features seem to behave differently under install vs build. The same behavior occurs if I build in a clean directory, or do cargo clean.

That is unfortunately the sad truth about cargo features: they have all kinds of weird interactions with dev deps, build deps and workspaces, and that fixing this in cargo is not trivial.

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.