Optional local dependencies

Imagine the situation that you have a monorepo that is split unto the different github repos. The problem with this is that you have to always push the changes dependencies to the upstream for other deps to be seen. It'll be great having a machinery that allows for overwriting the remote dependencies with local ones without rewriting every toml file manually.

I imagine it be something like

[target.'cfg(debug_assertions)'.dependencies]
path = "../lib"

[target.'not(cfg(debug_assertions))'.dependencies]
path = "0.8.2"

The problem with that, stated

The same applies to cfg(debug_assertions), cfg(test) and cfg(proc_macro). These values will not work as expected and will always have the default value returned by rustc --print=cfg. There is currently no way to add dependencies based on these configuration values.

I also tried using patches

[dependencies]
blah = { git = "https://github.com/blahblah" }

[patch."https://github.com/blahblah"]
blah = { path = "../" }

but cargo always uses the remote dep for some reason.

Any suggestions on this one?

The patch approach should work. Double-check that the syntax and URLs match.

The patch can also be added to the local .cargo/config.toml.

2 Likes