Source replacement for [dependencies] only but not for [build-dependencies]

I understand that cargo has a feature to replace dependency source to self-hosted: Source Replacement - The Cargo Book

How do I replace source.crates-io only for [dependencies] but not for [build-dependencies]?

I may be wrong, but at first glance it does not seem possible to have "global" replacements for a category of dependencies but not for another: if you want to "toggle" like that, then you will need to pinpoint the exact dependencies that you want to replace.

What is your use-case?

This is not possible. Currently Cargo has a limitation that it resolves only one set of dependencies used for everything (this has other side effects, such as dev deps adding unwanted features to no_std crates).

1 Like

I'm targeting a special platform, so we maintain a set of modified crates which is only for that platform (GitHub - mesalock-linux/crates-sgx). However, this is not for building environment (i.e., build dependencies). So we still want to use crates on crates-io for build dependencies. That's the use-case when we want to distinguish dependencies and bulid-dependencies. Thanks!

If a crate is used both by [dependencies] and [build-dependencies], we cannot replace only for [dependencies].

BTW, any GitHub issue of cargo related to this? If no, I’ll submit one to track the progress. (I believe this is a valid feature request.)

Maybe you can use #[cfg(platform)] inside the crate to make it compatible with both environments?

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.