I have a Rust library that implements a lint plugin. I want to include compiletest, but not require it outside of testing. What is the correct way to specify that the dependency is for testing only?
Asked
Active
Viewed 1.7k times
107
Shepmaster
- 388,571
- 95
- 1,107
- 1,366
llogiq
- 13,815
- 8
- 40
- 72
1 Answers
121
Yes. Use dev-dependencies. From the Cargo docs:
You can add a
[dev-dependencies]section to yourCargo.tomlwhose format is equivalent to[dependencies]:[dev-dependencies] tempdir = "0.3"Dev-dependencies are not used when compiling a package for building, but are used for compiling tests, examples, and benchmarks.
When possible, you should also use Cargo's resolver version 2 to better handle complicated dev-dependency cases.
Shepmaster
- 388,571
- 95
- 1,107
- 1,366
-
There is any command to add dev dependency like in Yarn: "yarn add xyz"? – Tomasz Waszczyk Dec 29 '20 at 13:42
-
4@TomaszWaszczyk [Is there a command to automatically add a crate to my Cargo.toml?](https://stackoverflow.com/a/32934310/155423). `cargo add --dev xyz` – Shepmaster Dec 29 '20 at 13:46