Cargo: Git dependency with a path into a sub-folder location

Created on 27 Mar 2015  路  11Comments  路  Source: rust-lang/cargo

For dependencies we can have git = <url> or path = <path> but we cannot combine the two, in the cases where a cargo package lives somewhere nested inside of a git repo, i.e. not in the root of the repo. It would be very powerful to be able to provide a relative path into a git repo.

Use case: A repo that is a client library containing bindings in more than one language, and the Rust binding is under the rust folder inside that repo.

The workaround today is to submodule the repo into your own repo, and use a relative path config. This levies the requirement of using git of course.

Most helpful comment

You can actually do this today! When you depend on a git repository Cargo will crawl the entire repo looking for packages and you can depend on any of them.

All 11 comments

You can actually do this today! When you depend on a git repository Cargo will crawl the entire repo looking for packages and you can depend on any of them.

Oh ok, awesome! I thought it failed the first time I tried it, but I'll give it another shot. Thanks.

Fantastic! This worked like a charm.

I tried this and it worked, but it gives me the following warning:

warning: dependency (ethcore-transaction) specification is ambiguous. Only one of `git` or `path` is allowed. This will be considered an error in future versions

I am using the following dependency:

ethcore-transaction = { git = "https://github.com/paritytech/parity-ethereum", path = "ethcore/transaction", branch = "master" }

With the following cargo version:

cargo 1.31.0 (339d9f9c8 2018-11-16)

Is it safe to keep this?

@augustoteixeira you'll want to remove either git or path there, this'll become a hard error eventually

There is a huge git repo, from which I need a single folder (with its own cargo file and src folder).

What is the proper way to handle that?

Unfortunately git has no way to check out only one folder, so there's nothing to do there unfortunately.

I see. So when I was doing this:

subfolder = { git = "url_for_the_big_repo", path = "subfolder" }

which leads to the warning. Cargo was just doing the same as if I had typed this?

subfolder = { git = "url_for_the_big_repo" }

Correct!

Today I face the same issue, I was needing a sub folder inside a git repo. I think this should be implemented

Isn't crawling the whole git repo dangerous? What happens if two different subfolders contain crates with equal name? Will that be reported? I would certainly favor allowing explicit subfolders with a combination of git = "....." path="....."

Was this page helpful?
0 / 5 - 0 ratings