Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dev-dependencies are not allowed to be optional #1535

Closed
gnzlbg opened this issue May 24, 2019 · 3 comments
Closed

dev-dependencies are not allowed to be optional #1535

gnzlbg opened this issue May 24, 2019 · 3 comments

Comments

@gnzlbg
Copy link

gnzlbg commented May 24, 2019

Because dev-dependencies are not allowed to be optional (cc @ehuss), I have to make serde_test an unconditional dev-dependency, which means that it will always be part of the dependency graph of my crate when building it, and because serde_test requires std, this means that building my crate ends up always linking against the standard library.

My crate is a #[no_std] crate, so I cannot accept that, therefore, I cannot use serde_test for testing.

The only workaround I can think of, is to make serde_test an optional dependency of serde, and for serde to re-export it when this optional dependency is enabled. This way, I can optionally depend on serde, without any features, and I can add a cargo feature to my crate that is enabled only for testing, and that enabled the serde_test feature of serde. This would allow me to pull in serde_test optionally only when testing, allowing my application to only link against the standard library there, and not unconditionally (as it would be caused by an unconditional dev-dependency to serde_test).

@gnzlbg
Copy link
Author

gnzlbg commented May 24, 2019

I suppose that, alternatively, I can add serde_test as an optional, non-dev dependency. Hmm. Don't know what will work best.

@dtolnay
Copy link
Member

dtolnay commented May 24, 2019

Currently serde_test is designed to depend on serde so serde can't also depend on serde_test. I would recommend giving your crate an optional ordinary dependency on serde_test and following up with Cargo to improve the flexibility on their end.

@dtolnay dtolnay closed this as completed May 24, 2019
@Anders429
Copy link

Ran into this same issue, and wanted to add here that using -Z features=dev_dep on nightly was sufficient to resolve this problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants