Solana/Anchor error: (yanked dependencies) Failed to obtain package metadata: `cargo metadata` exited with an error: Updating crates.io index - rust

I just set up a new anchor project yesterday, every command runs smoothly.
Today I installed a new anchor project. I run anchor test to see if the project is set up correctly. I am getting this error:
Failed to obtain package metadata: `cargo metadata` exited with an error: Updating crates.io index
error: failed to select a version for the requirement `anchor-lang = "^0.23.0"`
candidate versions found which didn't match: 0.24.2
location searched: crates.io index
required by package `myAnchorProject v0.1.0 (.../programs/myAnchorProject)`
It is not clear what candidate versions mean. I deleted node_modules and install it with "#project-serum/anchor": "^0.24.2", still same error.
I clear the lib.rs and testing file to see something different, but it still gives the same error.
executing cargo update is giving same error

It's not the problem with dependency in your package.json is due to the use of yanked rust crate anchor-lang
all the other version the 0.24.2 have been yanked so you can't build any cargo project which has yanked dependeny.
refer here https://crates.io/crates/anchor-lang/versions
what you need to do get it working is
go to <your-project-root>/programs/myAnchorProject/cargo.toml.
I'm assuming your program name is myAnchorProject or replace it with your program name.
your current cargo.toml must look something like
...
<other content goes here>
...
[dependencies]
anchor-lang = "^0.23.0"
you need to upgrade the anchor-lang version to 0.24.2 or any other version if available which is not yanked.
so your final cargo.toml should look like
...
<other content goes here>
...
[dependencies]
anchor-lang = "^0.24.2"

Related

error: no matching package named `rocket_dyn_templates` found

I'm trying to build a small web server using Rust and the Rocket framework. For this I need the rocket_dyn_templates crate, so I did a cargo search rocket_dyn_templates, which gave as output
rocket_dyn_templates = "0.1.0-rc.2" # Dynamic templating engine integration for Rocket.
and added
rocket_dyn_templates = "0.1.0-rc2"
to the Cargo.toml file in my project.
However, when I try cargo run, cargo update or cargo package I always get the same output:
Updating crates.io index
error: no matching package named `rocket_dyn_templates` found
location searched: registry `crates-io`
required by package `calc v0.1.0 (/home/utilisateur/tmp/calc)`
I was expecting the crate to be found and downloaded, instead I keep getting the error message that no matching package was found. What am I doing wrong?
As cafce25 said, the issue was a missing . in the Cargo.toml file - it should be rc.2, not rc2.

rust-gpu complains about mismatching toolchain file

rust-gpu says:
Copy the rust-toolchain file to your project. (You must use the same version of Rust as rust-gpu.)
So I copied that file into my root getting rust-toolchain with contents:
# If you see this, run `rustup self update` to get rustup 1.23 or newer.
# NOTE: above comment is for older `rustup` (before TOML support was added),
# which will treat the first line as the toolchain name, and therefore show it
# to the user in the error, instead of "error: invalid channel name '[toolchain]'".
[toolchain]
channel = "nightly-2022-10-29"
components = ["rust-src", "rustc-dev", "llvm-tools-preview"]
# commit_hash = 9565dfeb4e6225177bbe78f18cd48a7982f34401
# Whenever changing the nightly channel, update the commit hash above, and make
# sure to change REQUIRED_TOOLCHAIN in crates/rustc_codegen_spirv/src/build.rs also.
Then I tried building by doing cargo-run, getting:
error: failed to run custom build command for `rustc_codegen_spirv v0.4.0-alpha.17 (https://github.com/EmbarkStudios/rust-gpu#fabcbd9c)`
Caused by:
process didn't exit successfully: `/home/makogan/rust_never_engine/target/debug/build/rustc_codegen_spirv-b4185236522e0515/build-script-build` (exit status: 1)
--- stdout
cargo:rerun-if-env-changed=RUSTGPU_SKIP_TOOLCHAIN_CHECK
--- stderr
error: wrong toolchain detected (found commit hash `e631891f7ad40eac3ef58ec3c2b57ecd81e40615`, expected `9565dfeb4e6225177bbe78f18cd48a7982f34401`).
Make sure your `rust_toolchain` file contains the following:
-------------
[toolchain]
channel = "nightly-2022-10-29"
components = ["rust-src", "rustc-dev", "llvm-tools-preview"]
I am confused, the toolchain file says the same thing as the error message, what did I do wrong?
You're running a different version of nightly than the crate requires.
To check the version of cargo try to run cargo --version from within the project directory. If it shows anything else than the version you specified in the rust-toolchain file then you can try and check out the list below for possible fixes.
Make sure that:
The cargo you're using is managed by rustup if it is cargo +stable --version should show a version number and not an error.
The rust-toolchain is in the same directory as Cargo.toml if it's not copy or move it there.
There is no override on the crates directory. You can list them with rustup override list if the crate where the error appears is listed you can unset it with rustup override unset from within the crate root.
In this specific case 3. was the culprit.

Rust-Analyzer failed to load workspace, failing because of dependencies

[ERROR rust_analyzer::reload] failed to switch workspaces:
rust-analyzer failed to load workspace:
Failed to read Cargo metadata from Cargo.toml file
/home/supreetsingh/Documents/SavedPrograms/Rust/remind-me/Cargo.toml,
cargo 1.57.0-nightly (7fbbf4e8f 2021-10-19): Failed to run `cargo metadata --manifest-path
/home/supreetsingh/Documents/SavedPrograms/Rust/remind-me/Cargo.toml`: `cargo metadata` exited with an error: Updating crates.io index error: failed to select a version for the requirement `phf = "^0.11"`
candidate versions found which didn't match: 0.10.1, 0.10.0, 0.9.0, ... location searched: crates.io index required by package `tokio-postgres v0.7.7` ... which satisfies dependency `tokio-postgres = "^0.7.7"` (locked to 0.7.7) of package `postgres v0.19.4` ... which satisfies dependency `postgres = "^0.19.4"` (locked to 0.19.4) of package `remind-me v0.1.0 (/home/supreetsingh/Documents/SavedPrograms/Rust/remind-me)
So this problem is just arising in one rust project of mine. Cargo is in the path and this problem arose when I added one new dependency to my project and now I am stuck with this.
I have tried looking for the answer on the internet and did not find success yet, I do not know what else to try next.
cargo metadata --manifest-path <path to the file>
Works in the console I do not know why is this not working right now.
I am running this on Manjaro and my text editor is Vim with YouCompleteMe being used for AutoComplete.
If someone can point out what is wrong with the dependencies, I would be very thankful.
Thanks.
phf 0.11 requires Rust 1.60. You need to either update your Rust compiler to at least that version, or follow the chain of dependencies and downgrade the postgres crate so that you don't require phf 0.11.

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?

Rust & Amethyst - Error [E0433]: failed to resolve: could not find `__rt` in `quote`

I'm learning Rust from "Practical Rust Projects" by Shing Lyu. I'm now trying to build a game following the steps in Chapter 4. I'm working on Ubuntu 18.04 LTS.
After installing Rust and the Amethyst command line, I created a new project via amethyst new cat_volleyball. The next step is to run the engine using cargo run --features=vulkan
. When I do so, I get the error prompt below. Do you have suggestions on how to fix this?
error[E0433]: failed to resolve: could not find `__rt` in `quote`
--> /home/alberto/.cargo/registry/src/github.com-1ecc6299db9ec823/err-derive-0.1.6/src/lib.rs:145:63
|
145 | fn display_body(s: &synstructure::Structure) -> Option<quote::__rt::TokenStream> {
| ^^^^ could not find `__rt` in `quote`
error: aborting due to previous error
For more information about this error, try `rustc --explain E0433`.
error: could not compile `err-derive`.
warning: build failed, waiting for other jobs to finish...
TL;DR Edit the Cargo.lock manually, please check the title below : How to force cargo to use yanked version of sub-dependency (for the proper steps)
Why this happens ?
This happened because in err-derive-0.1.6 is using quote-1.0.2 as dependency but in it's cargo.toml dependency declared like this:
[dependencies.quote]
version = "1.0.2"
This means cargo will use the latest minor update, so if quote-1.0.3 is out then cargo will use 1.0.3 instead 1.0.2. Please check caret-requirement. The problem in here is quote-1.0.3 breaks backward compatibility that comes from quote-1.0.2. In this case quote
How to force cargo to use specific version of sub-dependency
You can fix this issue by forcing the sub-dependency to use compatible version for your dependency.
This command will do it :
> cargo update -p quote --precise 1.0.2
How to force cargo to use yanked version of sub-dependency
Looks like quote-1.0.2 was yanked from crates.io, so command up above will not work because cargo will not be able to find the yanked version on crates.io . Since cargo update modifies the cargo.lock we can do it manually. To start clean :
Remove Cargo.lock
Run cargo update ( this will generate latest version Cargo.lock )
Edit Cargo.lock
Find the incompatible version of package in cargo.lock which is quote-1.0.3, It should look like this:
[[package]]
name = "quote"
version = "1.0.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"proc-macro2 1.0.9 (registry+https://github.com/rust-lang/crates.io-index)",
]
then simply change version to the compatible version in our case it is "1.0.2"
[[package]]
name = "quote"
version = "1.0.2"
After doing that do not run cargo update again, it will overwrite your changes and you'll not able to compile your project. Please remember this is a workaround for being able to continue the development, there is a reason to yank crates, do not use it in production it is best to wait dependent crates to update itself.
Note : In some cases you may get an error after editing cargo.lock:
error: Found argument 'Cargo.lock' which wasn't expected, or isn't valid in this context
#albus_c fixed this by doing :
A note for posterity: I fixed the issue removing rustc
(sudo apt remove rustc) and reinstalled as recommended on the Rust website,
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
After that everything worked fine.

Resources