1

The Rust Cargo.toml specification file allows for development dependencies section, e.g. [dev-dependencies]

Cargo.toml:

[dev-dependencies]
tempdir = "0.3"

What is the command to fetch and compile those development dependencies?

To be clear, I want to fetch and compile only the [dev-dependencies]. The Linked questions differ in that they address fetching and compiling all dependencies and then building the application.

JamesThomasMoon
  • 6,169
  • 7
  • 37
  • 63
  • What are you trying to accomplish by only fetching/building the dev dependencies? I don't think it's possible to build *only* the dev dependencies, but you can make Cargo *also* build the dev dependencies by running `cargo build --tests` – Herohtar Apr 27 '22 at 14:27
  • @ShadowMitia a closely related question. [@ShepMaster answer](https://github.com/rust-lang/cargo/issues/2644) references open Issue [rust-lang #2644](https://github.com/rust-lang/cargo/issues/2644) that _is_ directly related this Question. Another answer mentions [`cargo-chef`](https://stackoverflow.com/a/67257247/471376) which does not appear to have the capability I'm looking for. Thanks! – JamesThomasMoon Apr 27 '22 at 23:31

1 Answers1

-1

I do not have enough reputation so I just answer.

As declare by your link and rust-by-example, it is impossible to "build" a binary from dev-dependencies.

Sometimes there is a need to have dependencies for tests (or examples, or benchmarks) only. Such dependencies are added to Cargo.toml in the [dev-dependencies] section

To be sneaky, may be you can put some function under #[cfg(test)] and run cargo test so that your goal can be achieved.

A more appropriate way to selectively build by cargo using the feature flag, in cargo.toml and cargo command. You can take a look at the cargo command to toggle feature here and optional dependencies which help control categorizing of features.

Ricky Ng
  • 39
  • 1
  • 7
  • optional dependencies are not dev dependencies – alexzander Apr 27 '22 at 13:59
  • 2
    Additionally, this answer seems to misunderstand the question as wanting to build a binary from the dependencies -- they are only wanting to build (maybe a better term would have been *compile*) the dev dependencies into their intermediate libraries. – Herohtar Apr 27 '22 at 14:23