4

I want to add the cargo dependencies rocket-okapi as git url, now I added the dependencies like in Cargo.toml this:

rocket-okapi = { git = "https://github.com/GREsau/okapi/tree/master/rocket-okapi"} 

but when I build the project using cargo build command ,shows error like this:

 $ cargo build Updating git repository `https://github.com/GREsau/okapi/tree/master/rocket-okapi` warning: spurious network error (2 tries remaining): unexpected http status code: 404; class=Http (34) warning: spurious network error (1 tries remaining): unexpected http status code: 404; class=Http (34) error: failed to get `rocket-okapi` as a dependency of package `fortune v0.1.0 (/workspaces/fortune)` Caused by: failed to load source for dependency `rocket-okapi` Caused by: Unable to update https://github.com/GREsau/okapi/tree/master/rocket-okapi Caused by: failed to fetch into: /home/codespace/.cargo/git/db/rocket-okapi-b6c0b0836896ac76 Caused by: network failure seems to have happened if a proxy or similar is necessary `net.git-fetch-with-cli` may help here https://doc.rust-lang.org/cargo/reference/config.html#netgit-fetch-with-cli Caused by: unexpected http status code: 404; class=Http (34) 

how to add the sub folder as dependencies in rust cargo? is it possible?

4
  • 1
    Did you perhaps mean to use https://github.com/GREsau/okapi.git instead of some random point in the repository's tree? Commented Jun 7, 2022 at 9:27
  • 1
    I read the official document from docs.rs/rocket_okapi/latest/rocket_okapi and it both using okapi and rocket-okapi.@gspr Commented Jun 7, 2022 at 9:32
  • 1
    this url works fine in my browser. @gspr Commented Jun 7, 2022 at 9:32
  • 1
    Do rocket_okapi = { git = "https://github.com/GREsau/okapi" }. See this reply to an issue. Commented Jun 7, 2022 at 9:35

1 Answer 1

4

There are a few things here that need a bit of clarification.

When you add a Git dependency to Cargo.toml, it expects a repository. The URL you put in there is a directory in the repository, so cargo freaks out.

Secondly, when a Git dependency is specified, cargo first looks in the repository root for a Cargo.toml file. If it cannot find any, it will search for any Cargo.toml files where the package name is the same as the dependency.

The dependency you specified, rocket-okapi, doesn't exist in the repository, so cargo gives up. Changing the name of the dependency to 'rocket_okapi' fixes this.

TL;DR: Use this

rocket_okapi = { git = "https://github.com/GREsau/okapi" } 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.