Programmatic Access/Use of Cargo

Hey Rust Devs,

I’m trying to run Cargo programmatically against crates I’ve downloaded. Since a project might have/distribute multiple crates and single crates are downloaded, I could use some advice on the following:

  1. Is there any API that will automatically resolve path dependencies that don’t exist on the file system by falling back to the crates registry as a source? Hope for this comes from the [documentation] ( Crates that have been uploaded to are guaranteed to have a version associated with them.
  2. If not, is it possible/easy to build a “fake” manifest/package that replaces the the path dependency with a registry dependency?
  3. Is this a ridiculous thing to try to attempt and going against the Rust philosophy?


I suspect @alexcrichton is the only breathing human who can answer these.

@brson I ended up doing something of this nature: Though, it won’t work correctly with other commands (like metadata). However, it did get the job done.

It turns out replacements must have specific versions and not version requirements (e.g. >= 1.0.0). This wasn’t going to do the trick for me. So I recreated the entire Package + Manifest + Summary with a new set of dependencies with the path dependencies replaced by registry backed dependencies.

Not quite, but you can programmaticaly construct a package with dependencies whose source is (just ignoring the path parameter), and then it'll pull them all from This is how cargo package works.


Hey once you're using Cargo's API all bets are off :slight_smile:

Perfect! Thanks @alexcrichton!

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