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] (http://doc.crates.io/specifying-dependencies.html#specifying-path-dependencies). Crates that have been uploaded to crates.io 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?

Abe

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

@brson I ended up doing something of this nature: https://github.com/fossas/srclib-rust/blob/224966be8af5d17c63040837d2901f13b2ad728d/src/resolve.rs#L54. 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 crates.io (just ignoring the path parameter), and then it'll pull them all from crates.io. This is how cargo package works.

Yes!

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.