
log is part of the normal graph; pretty_assertions is available only to tests, examples, and benchmarks.Understand it
Normal dependencies become part of a target graph, build dependencies support build scripts, and dev dependencies exist for tests and examples. The distinction keeps production graphs smaller and clearer.
Cargo separates dependencies by the role they play in a package. Normal [dependencies] are needed to build the library or binary target. [build-dependencies] are available to a build.rs script that runs during the build, often to generate files or detect native libraries. [dev-dependencies] support tests, examples, and benchmarks but are not ordinary runtime dependencies of the published library. The distinction helps make a package's requirements understandable.
Read the sample manifest and ask where each crate is used. A logging interface needed by production code belongs under normal dependencies. A prettier assertion formatter used only in tests belongs under dev dependencies. Moving it into normal dependencies may unnecessarily expand consumers' build graphs. Conversely, placing a production import under dev dependencies makes a normal build fail even if tests happen to compile in a different configuration.
Dependency kinds do not by themselves make a crate trustworthy or small. Versions, features, and transitive dependencies still matter. Use cargo tree with the relevant target or feature flags to inspect the resolved graph. Add one test-only helper and confirm cargo build does not need its API in production code. Then add a build script only if there is a real build-time task; generated code adds another layer to debug. Treat each manifest section as a statement of when that capability is actually required.
Read the code
[dependencies]
log = "0.4"
[dev-dependencies]
pretty_assertions = "1"log is part of the normal graph; pretty_assertions is available only to tests, examples, and benchmarks.
Practice starter
[dependencies]
log = "0.4"
pretty_assertions = "1"Try it
pretty_assertions is used only by the tests. Move it to the right section, then compare cargo tree -e normal before and after.
What success looks like: cargo tree -e normal no longer lists it, and cargo test still compiles the tests.
Check your understanding
Where does a test-only crate belong?
Reveal the answer
- dev-dependencies
- profile.release
- workspace
[dev-dependencies] are available to tests, examples, and benchmarks, and stay out of what consumers build.
Go deeper
Common misconception: “A crate used only in tests still has to be a normal dependency.”
Dev dependencies exist for tests and examples, so a test-only crate belongs under [dev-dependencies]. Normal dependencies become part of a target graph, and build dependencies support build scripts.
- Read the normal section:
logis under[dependencies], so library and binary code can import it, and consumers build it too. - Read the test helper:
pretty_assertionsis under[dev-dependencies], so only tests, examples, and benchmarks can import it. - Try the wrong import:
use pretty_assertions::assert_eq;insrc/lib.rsfails incargo buildas an unresolved import, though the same line works intests/.
Transfer challenge: Add a build.rs and a crate it uses under [build-dependencies]. Predict whether src/main.rs can import that crate, then check with cargo build.
Connections
- Check, Build, Run: Choose the cheapest command that proves the next fact
- Feature Design: Make optional capability additive and explicit
Learn this lesson with AI
Paste this into Claude, Codex, Cursor or another agent connected to Crabrix Academy. It contains only this lesson’s public details.
I'm learning Rust with Crabrix Academy. Teach me this lesson with the Crabrix Academy tools. Lesson: Dependency Kinds (courseId "projects", lessonId "dependency-kinds") Link: https://crabrix.com/learn/projects/dependency-kinds/ Goal: Normal dependencies become part of a target graph, build dependencies support build scripts, and dev dependencies exist for tests and examples. Practice: give me the lesson's exercise (crabrix_academy_get_exercise); I will write and run the code in Crabrix. Explain it step by step for my level, let me write the code myself, give hints before any solution, and do not mark anything as passed: only Crabrix checks do that.