Making optional dependency compulsory and backwards compatibility

I have an optional dependency, for example

[dependencies]
foo = { version = "1", optional = true }

Now I want to make the dependency compulsory:

[dependencies]
foo = "1"

The problem is that dependent crates that had the optional feature foo enabled would now fail to compile because now foo is not an optional dependency any more. And I cannot add a dummy optional feature foo, because features and dependencies cannot have the same name. Is there a backwards compatible way to make foo non-optional?

Yes, you can rename the foo package

[dependencies]
foo_crate = { version = "1", optional = true, package = "foo" }

then add a foo feature

4 Likes

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.