I think what I've said was ambiguous (because in cargo, the word target
has two very different meanings: "target triple" (arch/os/libc; host or target) and "target crate" in a package (lib, expamle, test)).
To rephrase:
Sections of dependencies table don't affect which target tripple the deps are compiled for, only which deps are available for each particular target crate.
In your example, dev-dependencies
make serde available for the following target crates:
- lib in unit-testing mode
- integration tests
- examples
Notably, serde is not made available for:
From cargo toml alone, it's not possible to say for which target triples the serde will be compiled. If it is included in transitive closure of stuff we build for host, it'll build for host. If it is included in transitive closure of stuff we build for target, it will be build for target. It might be build for both. An illustrative example would be
[dependencies]
proc-macro-that-uses-serde-inside = "1.0.0"
Here, serde will be build for host, despite being (indirectly), in the dependencies table.
The important implication in the current setup is:
dev-deps are not made available for lib
or build.rs
target crates. As downstream crates only build lib
and build
, and not any other kind of target crate, they can be ignorant of dev dependencies.
For publish.rs
, we only want to run that during development, we don't want to run it during the build of downstream crates. So we want to stick publish.rs
deps into the dev-dependencie
table.
One drawback here would be that dev-deps
would include the union of stuff we need for tests, and the stuff we need for publish, and those might have big symmetric difference. That is the same problem that we have today with the absence of binary-only dependencies: stuff you need in src/main.rs
"infects" src/lib.rs
also.