3

My question is What is the difference between dependencies and dev-dependencies in Cargo.toml. And for developing pallet, now I have to declare crate in dependencies

1 Answer 1

6

This is a general Rust concept:

https://doc.rust-lang.org/rust-by-example/testing/dev_dependencies.html

Basically, [dev-dependencies] are the crates you only need for compiling and running tests.

There are at least two advantages of separating test crates in this way:

  1. When compiling for release, these test crates are not compiled into your binary, which can save space and compilation time.

  2. Normally, the Rust compiler checks for and prohibits any cyclic dependencies. For [dev-dependencies], this check is ignored, allowing two crates to be dependent on eachother specifically for tests.

If you use a crate in your main code, you must include it as a [dependencies], however, if you only use it for tests, then you should place it as a [dev-dependencies].

If you are confused, I recommend to copy patterns from other crates found in Substrate.

3
  • Thank you, good stuff! Mar 30, 2022 at 2:40
  • What if you only want to use it for benchmarking and testing?
    – Yatusabes
    Oct 18, 2022 at 23:43
  • You make the dependency "optional" and then enable the dependency when runtime-benchmarks feature flag is enabled
    – Shawn Tabrizi
    Oct 19, 2022 at 17:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.