rust-lang / cargo

The Rust package manager
https://doc.rust-lang.org/cargo
Apache License 2.0
12.75k stars 2.42k forks source link

Git dependency with a path into a sub-folder location #1462

Closed jnicholls closed 9 years ago

jnicholls commented 9 years ago

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.

alexcrichton commented 9 years ago

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.

jnicholls commented 9 years ago

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

Terkwood commented 5 years ago

Fantastic! This worked like a charm.

augustoteixeira commented 5 years ago

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?

alexcrichton commented 5 years ago

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

augustoteixeira commented 5 years ago

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?

alexcrichton commented 5 years ago

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

augustoteixeira commented 5 years ago

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" }
alexcrichton commented 5 years ago

Correct!

marcotuna commented 5 years ago

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

brenzi commented 5 years ago

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="....."

ManevilleF commented 3 years ago

What's the status of this? I'd like to use a git repo subfolder too

askolesov commented 3 years ago

Definitely need this feature. I encountered this today:

What happens if two different subfolders contain crates with equal name?

sazzer commented 3 years ago

Not only the issue of name clashes, but there's a performance cost to crawling a huge repo when the client can be told exactly where to look.

flyq commented 3 years ago

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="....."

I need it too, thanks google bring me here.

wseaton commented 3 years ago

There's an issue that can occur when there is a submodule inside of a repository, how do you explicitly depend on both the main folder and the sub-module without using path? Cargo automatically pulls the sub-module path into depends but the compiler doesn't like that.

Currently for one of my projects I have to do this to get cargo to properly pull the right versions and rust to compile:

[dependencies]
twitch_api2 = {git = "https://github.com/Emilgardis/twitch_api2", tag="v0.6.0-rc.1", features=["all"]}
twitch_oauth2 = { git = "https://github.com/Emilgardis/twitch_api2", tag="v0.6.0-rc.1", path="twitch_oauth2", features=["all"]}

Without this second line the compiler complains it can't find the crate, am I missing something?

 Compiling twitch_oauth2 v0.5.2 (https://github.com/Emilgardis/twitch_api2?tag=v0.6.0-rc.1#3b5f82ec)
   Compiling twitch_api2 v0.6.0-rc.1 (https://github.com/Emilgardis/twitch_api2?tag=v0.6.0-rc.1#3b5f82ec)
   Compiling twitch-dmenu v0.1.0 (/home/weaton/git/twitch-dmenu)
error[E0463]: can't find crate for `twitch_oauth2`
 --> src/main.rs:7:1
  |
7 | extern crate twitch_oauth2;
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ can't find crate
kkartaltepe commented 3 years ago

Still an issue especially when the submodules you dont want are hundreds of megabytes.

Eh2406 commented 2 years ago

Yes, you are mistaken. If it is not working, please open a new issue with a minimal repoducabe example.

kaimast commented 2 years ago

Sorry... I resolved my issue and deleted the earlier post.

TilakMaddy commented 5 months ago

Hello, I am trying to load a subfolder in git as a dependency by doing this

config = { git = "https://github.com/foundry-rs/foundry", path = "crates" }

But I get the following error! @jnicholls Can you help me please?

error: failed to load manifest for workspace member `/Users/tilakmadichetti/Documents/OpenSource/realaderyn/aderyn`

Caused by:
  failed to load manifest for dependency `aderyn_driver`

Caused by:
  failed to parse manifest at `/Users/tilakmadichetti/Documents/OpenSource/realaderyn/aderyn_driver/Cargo.toml`

Caused by:
  dependency (config) specification is ambiguous. Only one of `git` or `path` is allowed.