Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
jnicholls opened this issue Mar 27, 2015 · 20 comments
Closed

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

jnicholls opened this issue Mar 27, 2015 · 20 comments

Comments

@jnicholls
Copy link

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
Copy link
Member

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
Copy link
Author

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

@Terkwood
Copy link

Fantastic! This worked like a charm.

@augustoteixeira
Copy link

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
Copy link
Member

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

@augustoteixeira
Copy link

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
Copy link
Member

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

@augustoteixeira
Copy link

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
Copy link
Member

Correct!

@marcotuna
Copy link

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

@brenzi
Copy link

brenzi commented Feb 13, 2019

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

kolloch added a commit to nix-community/crate2nix that referenced this issue Mar 11, 2020
Cargo does this for git repositories as well:

rust-lang/cargo#1462 (comment)

This will fix #33, #53 -- integration tests pending.

It depends on a nixpkgs buildRustCrate feature PR:

NixOS/nixpkgs#82155
kolloch added a commit to nix-community/crate2nix that referenced this issue Mar 12, 2020
Cargo does this for git repositories as well:

rust-lang/cargo#1462 (comment)

This will fix #33, #53 -- integration tests pending.

It depends on a nixpkgs buildRustCrate feature PR:

NixOS/nixpkgs#82155
kolloch added a commit to nix-community/crate2nix that referenced this issue Mar 12, 2020
Cargo does this for git repositories as well:

rust-lang/cargo#1462 (comment)

This will fix #33, #53 -- integration tests pending.

It depends on a nixpkgs buildRustCrate feature PR:

NixOS/nixpkgs#82155
@ManevilleF
Copy link

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

@askolesov
Copy link

Definitely need this feature. I encountered this today:

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

@sazzer
Copy link

sazzer commented May 15, 2021

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
Copy link

flyq commented Jul 5, 2021

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
Copy link

wseaton commented Jul 20, 2021

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
Copy link

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

steveej added a commit to steveej-forks/nixpkgs that referenced this issue Oct 23, 2021
this mimics the heuristic cargo uses for finding crates in their git
repositories [0].

[0]: rust-lang/cargo#1462
steveej added a commit to steveej-forks/nixpkgs that referenced this issue Oct 23, 2021
this mimics the heuristic cargo uses for finding crates in their git
repositories ([cargo-issue-1462]).

[cargo-issue-1462]: rust-lang/cargo#1462
mkg20001 pushed a commit to mkg20001/nixpkgs that referenced this issue Nov 18, 2021
this mimics the heuristic cargo uses for finding crates in their git
repositories ([cargo-issue-1462]).

[cargo-issue-1462]: rust-lang/cargo#1462
@Eh2406
Copy link
Contributor

Eh2406 commented May 5, 2022

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

@kaimast
Copy link

kaimast commented May 5, 2022

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

@TilakMaddy
Copy link

TilakMaddy commented May 12, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests