Cargo error: unable to get packages from source - rust

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

Related

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

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

Rust: substrate node template build error

I have been following these instructions:
https://substrate.dev/docs/en/knowledgebase/getting-started/
https://substrate.dev/docs/en/tutorials/create-your-first-substrate-chain/setup
I get the following error after trying to run this code:
cd substrate-node-template
# NOTE: you should always use the `--release` flag
cargo build --release
# ^^ this will take a while!
This is the error, any idea what's happening?:
Downloaded approx v0.3.2
Downloaded parity-db v0.2.3
error: failed to parse manifest at /Users/ilyssaevans/.cargo/registry/src/github.com-1ecc6299db9ec823/parity-db-0.2.3/Cargo.toml
Caused by:
failed to parse the version requirement `0.11 ` for dependency `parking_lot`
Caused by:
expected comma after minor version number, found '\t'
zsh: command not found: #
run
cargo update -p parity-db
If this doesn't help please clear cargo cache and reinstall

How can I avoid rebuilding dependencies when `cargo install` fails due to a system configuration issue?

I'm trying to cargo install a project with many dependencies. One of the later dependencies fails to build due to some system configuration issue:
cargo install diesel_cli
... many dependencies here...
Compiling diesel_cli v1.4.1
error: linking with `cc` failed: exit code: 1
|
= note: ...large output removed...
= note: ld: library not found for -lmysqlclient
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Once I think I've solved the system configuration issue, I need to re-run cargo install, wait a while for the first set of dependencies to build, then see if I get past the failure.
How can I avoid rebuilding all of those dependencies?
The error message contains the directory containing the failed build artifacts:
error: failed to compile `diesel_cli v1.4.1`, intermediate artifacts can be found at `/var/folders/_b/d4_bd15x7s5g99cjvyhpw26w0000gp/T/cargo-installDQOdPD`
You can pass that directory via the --target-dir option (or setting the CARGO_TARGET_DIR environment variable) to use it again, avoiding rebuilding the dependencies:
cargo install diesel_cli --target-dir=/var/folders/_b/d4_bd15x7s5g99cjvyhpw26w0000gp/T/cargo-installDQOdPD

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