How do I specify conditional [Replace] for different build target


We have a rust project that has a dependency crate, we made changes to the dependency crate, but upstream cannot be done in a short time, so we keep a copy of the dependency crate locally, and use Replace tag in the root cargo.toml to point to the local replacement.

“foo:0.0.1” = { path = ‘…/…/foo-local’ }

The problem here is we have both linux and windows, we only want to override the dependency with local version for Windows, how do I do it?




I don’t think that’s possible directly.

You could try replacing it with a crate that itself is empty (only contains pub use foo::*), and adds either windows or linux version as a dependency.

BTW, [replace] has been obsoleted by a more robust [patch].