Cargo dev_dependencies

I have a package with a lib and I want to distribute it with two
examples - a CLI app & web app

Cargo supports examples and example dependencies that are not lib
dependencies can be put in a separate [dev-dependencies] section
of Cargo.toml

That's better than adding them to the regular [dependencies] section,
but is it possible to specify different dev_dependencies for the different examples?

Looking at the yew package (which would be one of my dependencies), I see that they have taken a 3rd route - put their examples inside the examples dir, but as separate projects with their own Cargo.toml files - they are independent of the top level Cargo.toml file...

Heya, in my experience this approach has been the cleanest, when "easy to see which examples need which dependencies" is a requirement.

It does mean:

  • having workspace Cargo.toml have a glob for the examples

  • in the readme, mentioning people should run:

    cargo run --package example_name` # instead of
    cargo run --example example_name

It's been the best compromise so far for maintenance, and consumers being able to see what dependencies they actually need.

I've spent hours trying different ways :man_facepalming:


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.