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

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?

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" }

Related

cargo version 2021 required on Solana anchor build

I am trying to run anchor build and am receiving the following response:
BPF SDK: /root/.local/share/solana/install/releases/1.8.0/solana-release/bin/sdk/bpf
Running: rustup toolchain list -v
Running: cargo +bpf build --target bpfel-unknown-unknown --release
error: failed to download `solana-frozen-abi v1.9.4`
Caused by:
unable to get packages from source
Caused by:
failed to parse manifest at `/root/.cargo/registry/src/github.com-1ecc6299db9ec823/solana-frozen-abi-1.9.4/Cargo.toml`
Caused by:
feature `edition2021` is required
consider adding `cargo-features = ["edition2021"]` to the manifest
PS: I have already tried suggestions at: Unable to specify `edition2021` in order to use unstable packages in Rust
It looks like your solana install is quite out of date. I would install either 1.8.11 or just run solana-install update
At times, also consider downloading to like in my case I had to change from 2021 in my Cargo.toml file to 2018 and this has worked

Cargo error: unable to get packages from source

error: failed to download `adler v1.0.2`
Caused by:
unable to get packages from source
Caused by:
failed to parse manifest at `/home/actionanand/.cargo/registry/src/github.com-1ecc6299db9ec823/adler-1.0.2/Cargo.toml`
Caused by:
could not parse input as TOML
Caused by:
unexpected character found: `\u{0}` at line 1 column 1
Rust .toml file was full of red line when we add new dependency
This is caused by the crash of internal package (say cargo)
we can solve this by following the steps
Please clear the cargo registry
rm -rf /home/username/.cargo/registry/
And follow the proceedure shown after this, if you use old version
For the reference, I've given the proceedure also below:
If you are trying to migrate from the previous edition (2018), the
process requires following these steps:
1. Start with `edition = "2018"` in `Cargo.toml`
2. Run `cargo fix --edition`
3. Modify `Cargo.toml` to set `edition = "2021"`
4. Run `cargo build` or `cargo test` to verify the fixes worked
More details may be found at
https://doc.rust-lang.org/edition-guide/editions/transitioning-an-existing-project-to-a-new-edition.html
You may need to to add --allow-no-vcs sometimes (it'll be prompted by the terminal) as below
cargo fix --edition --allow-no-vcs

How to use Apache Arrow's Datafusion 1.0.0-SNAPSHOT as a dependency in a Cargo project?

On the git repository for Datafusion, it says to add the following to the Cargo.toml file to use it as a library:
[dependencies]
datafusion = "1.0.0-SNAPSHOT"
I get this as an output when running cargo build
Updating crates.io index
error: failed to select a version for the requirement `datafusion = "^1.0.0-SNAPSHOT"`
candidate versions found which didn't match: 0.17.0, 0.16.0, 0.15.1, ...
location searched: crates.io index
required by package `hello_cargo v0.1.0 (/Users/jay/Projects/hello_cargo)`
I then tried to use 0.17.0 and ran cargo +nightly build:
error: failed to run custom build command for `arrow-flight v0.17.0`
Caused by:
process didn't exit successfully: `/Users/jay/Projects/hello_cargo/target/debug/build/arrow-flight-46000fbc5b8b474b/build-script-build` (exit code: 1)
--- stderr
Error: "Failed to locate format/Flight.proto in any parent directory"
warning: build failed, waiting for other jobs to finish...
error: build failed
It seems to work when I use version 0.16.0
As Cargo tells you:
candidate versions found which didn't match: 0.17.0, 0.16.0, 0.15.1, ...
There are no versions called 1.0.0-SNAPSHOT of this crate published to crates.io. If you wish to use unreleased code from a git repository, you need to use a git dependency:
[dependencies]
rand = { git = "https://github.com/apache/arrow/" }
See also:
Can I add a dependent crate that is a subdirectory in a git repository?

External dependency in Rust not loading from cargo run command

I am attempting to replicate code I found in a tutorial. I am using the following dependencies in my Cargo.toml file:
[dependencies]
iron = "0.5.1"
mime = "0.2.3"
router = "0.5.1"
urlencoded = "0.5.0"
I receive the following error message when I execute cargo run from the project's src directory:
Updating registry `https://github.com/rust-lang/crates.io-index`
An unknown error occurred
It hangs at "Updating registry" for roughly 15 minutes before the error appears. I would guess versioning as the issue, however the tutorial that I am using directly states that they included them as a way to avoid version mismatch with the example code.
I attempted to search for an answer but the error code is too vague to find anything.
The results of cargo run --verbose added:
Caused by:
the given version requirement is invalid
I am now getting:
failed to parse registry's information for: serde_json
and
failed to parse registry's information for: serde
when I compile/run with cargo with my listed dependencies and with "*" as the version, respectively.

Unable to update registry with byteorder

I have an error when I execute cargo run. I added the line byteorder = "0.3.13" to my Cargo.toml, and here is the output of cargo run --verbose:
Updating registry `https://github.com/rust-lang/crates.io-index`
Unable to update registry https://github.com/rust-lang/crates.io-index
Caused by:
failed to fetch `https://github.com/rust-lang/crates.io-index`
Caused by:
[9] Object not found - failed to find pack entry (c7c0b5bc32630012be674d1cacd1487d09a2c0b5)
When I remove the line, everything is ok. How do I fix this error?
Fixed ! I just reinstalled rust nightly with multirust :)

Resources