Downloading a root library crate using cargo

Normally, the root crate is local and cargo build downloads and builds the dependencies. cargo install downloads a root bin crate, builds it and puts the result under .cargo/bin.

Can Cargo be told to download from crates.io and build as staticlib a lib crate and to put it into a designated place relative to the invocation directory?

Use case: Invoking the download and build of a Rust library from within a C or C++ project's makefile when the C or C++ project uses the Rust library via FFI.

1 Like

Hmm. I just realized that the use case doesn't make much sense once the project depends on more than one Rust library. I guess the C or C++ project's repo should come with a wrapper crate that depends on the crates.io stuff like Gecko's gkrust-shared crate.

1 Like

cargo clone downloads a crate from crates.io and unpacks it in a subdirectory of the invocation directory.

$ cargo clone serde
$ cd serde
$ cargo build
4 Likes