Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

is it possible to use the path when using git to add the dependencies in rust cargo

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?

like image 467
Dolphin Avatar asked Sep 11 '25 14:09

Dolphin


1 Answers

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" }
like image 71
chilipepperhott Avatar answered Sep 13 '25 08:09

chilipepperhott