Failed to select a version for the requirement `rand = "^0.9.0"` - rust

I am getting this error every time while running cargo build:
error: failed to select a version for the requirement `rand = "^0.9.0"`
candidate versions found which didn't match: 0.8.5, 0.8.4, 0.8.3, ...
location searched: crates.io index
required by package `guessing_game v0.1.0 (D:\Adwait\Rust\project\guessing_game)`
Cargo.toml looks like this:
[package]
name = "guessing_game"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
rand = "0.9.0"

This error is caused because there is no version 0.9.0 available. Update it to 0.8.0. Cargo.toml should look like this.
[package]
name = "guessing_game"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
rand = "0.8.0"

I experienced this myself, I believe the confusion is stemming from the tutorial on Rust mentioning 0.9.0 as an example to understand upgrading Rust crates.
I'm not sure why they chose that example, since it doesn't exist. Would be a better idea to do 0.7.x being upgraded to 0.8.0 if you're new to Rust and want to play around with upgrading Rust crates.

Related

Why is wgpu failing to build in this crate?

I have recently been working on a game engine in rust and for rendering I have been planning on using the wgpu crate. When I add this to my dependancies wgpu-hal fails to build with 448 errors. my cargo.toml for this crate looks like this
[package]
name = "ferrogame"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
log = "0.4.17"
fern = {version = "0.6.1", features = ["colored"]}
chrono = "0.4.22"
winit = "0.27.2"
rapier3d = "0.15.0"
rapier2d = "0.15.0"
wgpu = "0.14.0"
[lib]
crate-type = ["rlib"]
This is especially strange because I made a new crate with only wgpu as a dependency and it compiled fine that time. I have tried updating rust and running cargo update but nothing has worked. How can I fix this?
This issue is due to a version conflict.
Rapier uses bevy at version 0.8, and bevy version 0.8 depends on wgpu at version 0.13

error: failed to select a version for `syn`

error: failed to select a version for `syn`. \
... required by package `serde_derive v1.0.125`\
... which satisfies dependency `serde_derive = "=1.0.125"` of package `serde v1.0.125`
... which satisfies dependency `serde = "^1.0.125"` of package `mongodb v2.1.0`\
... which satisfies dependency `mongodb = "^2.1"` of package `wagmeet v0.1.0
\(/mnt/e/College/Eighth Semester/Crypto_Capable/wagmeet_app)`\
versions that meet the requirements `^1.0.60` are: 1.0.86, 1.0.85, 1.0.84, 1.0.83, 1.0.82, 1.0.81, 1.0.80, 1.0.79, 1.0.78, 1.0.77, 1.0.76, 1.0.75, 1.0.74, 1.0.73, 1.0.72, 1.0.71, 1.0.70, 1.0.69, 1.0.68, 1.0.67, 1.0.66, 1.0.65, 1.0.64, 1.0.63, 1.0.62, 1.0.61, 1.0.60
all possible versions conflict with previously selected packages.
previously selected package `syn v1.0.57`\
... which satisfies dependency `syn = "=1.0.57"`
\ of package `near-sdk-core v3.0.1`
... which satisfies dependency `near-sdk-core = "=3.0.1"` of package `near-sdk-macros v3.0.1` \
... which satisfies dependency `near-sdk-macros = "=3.0.1"` \ of package `near-sdk v3.0.1`
... which satisfies dependency `near-sdk = "^3"` of package `wagmeet v0.1.0 `\
failed to select a version for `syn` which could resolve this conflict
Cargo.toml file
[package]
name = "wagmeet"
version = "0.1.0"
edition = "2021"
[lib]
crate-type = ["rlib","cdylib"]
[dependencies]
near-sdk = "^3.1.0"
near-contract-standards = "^3.1.1"
mongodb = "2.0.0"
bson = { version = "2", features = ["chrono-0_4"] } # Needed for using chrono datetime in doc
tokio = "1"
chrono = "0.4" # Used for setting DateTimes
serde = "1"
serde_derive = "1.0.135"
Update
added the cargo.toml file
I have tried various versions nothing seems to be working for now. Is mongoDb even compatible with Near protocol?
There is a conflict between two of your dependencies: near-sdk requires exactly syn version 1.0.57, and mongodb requires at least syn version 1.0.60. Clearly both cannot exist together.
You have few solutions:
Patch near-sdk to support later syn versions. This is usually not recommended.
Upgrade near-sdk to the pre-release 4.0.0 (currently 4.0.0-pre.7) that supports later syn versions. This is an unstable version, and may break.
Downgrade mongodb to a version that supports syn version 1.0.57. The latest version that supports that is 1.2.5, so you need to specify in your Cargo.toml mongodb = "=1.2.5". But this relies on an old, unsupported version.
There is no "best solution". All solutions are bad. I would probably upgrade near-sdk to 4.0.0, but what to do depends on your needs.
Try the following methods...
check your patched dependencies are pointed to the correct source repository
if you use other project's Cargo.lock or change some dependencies as you go, remove target folder and build again
check compilation logs for incorrect dependency paths!
update your Rust
delete .cargo and .rustup directories

Diesel cli '`database.sqlite3` is not a valid database URL. It should start with `postgres://`'

When running diesel migration run on a project with an sqlite database in the ENV, I get this error about not being a valid postgres url.
$ diesel migration run
thread 'main' panicked at '`database.sqlite3` is not a valid database URL. It should start with `postgres://`',
Cargo.toml from the project
[package]
name = "matrix_bot"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
diesel = { version = "1.4.4", features = ["sqlite"] }
dotenv = "0.15.0"
tokio = {version = "1.14.0", features = ["full"]}
matrix-sdk = "0.4.1"
the .env content
DATABASE_URL=database.sqlite3
If diesel_cli was installed with only the postgres feature enabled, it will no longer work for sqlite databases. The solution is to reinstall the cli via cargo
cargo install diesel_cli --no-default-features

Why do I get a build error for the resolver feature when I have up to date rustc and cargo version?

When I run the build command
cargo build-bpf --manifest-path=Cargo.toml --bpf-out-dir=dist/program
error: failed to download solana-frozen-abi v1.7.9
Caused by:
unable to get packages from source
Caused by:
failed to parse manifest at /home/USER/.cargo/registry/src/github.com-1ecc6299db9ec823/solana-frozen-abi-1.7.9/Cargo.toml
Caused by:
feature resolver is required
There have been people with similar issues but the cause was old rustc version. Mine looks ok
rustc --version
rustc 1.55.0-nightly (7c3872e6b 2021-06-24)
cargo --version
cargo 1.55.0-nightly (9233aa06c 2021-06-22)
My Cargo.toml file looks like
[package]
name = "test"
version = "0.0.1"
edition = "2018"
exclude = ["tests/**"]
[features]
no-entrypoint = []
test-bpf = []
[dependencies]
borsh = "0.8.2"
num-derive = "0.3"
num-traits = "0.2"
solana-program = "1.6.10"
spl-token = { version="3.1.1", features = [ "no-entrypoint" ] }
thiserror = "1.0"
[dev-dependencies]
solana-program-test = "1.6.10"
solana-sdk = "1.6.10"
[lib]
crate-type = ["cdylib", "lib"]
I have downloaded the metaplex rust code (exact same dependencies) and the build bpf command compiles successfully.
I have also tried running cargo clean which doesnt change anything.
I fixed it by updating to the latest version (1.7.9) of Solana (which is not the release version):
sh -c "$(curl -sSfL https://release.solana.com/v1.7.9/install)"
The same inputs from Cargo.toml do not mean the the Rust build will be repeatable on other machines — Cargo.lock contains the exact versions used. Additionally, cargo clean doesn't remove Cargo.lock
https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html

Force jlrs to use newer bindgen?

I'm trying to use the jlrs crate (v0.6),
which depends on jl-sys version 0.8,
which depends on bindgen version 0.54.1,
which is yanked.
When I run cargo update it says:
Updating crates.io index
error: failed to select a version for the requirement `bindgen = "^0.54.1"`
candidate versions found which didn't match: 0.55.1, 0.55.0, 0.54.0, ...
location searched: crates.io index
required by package `jl-sys v0.8.0`
... which is depended on by `jlrs v0.6.0`
So far as I can see, jl-sys requires exactly bindgen version 0.54.1, which has been yanked. Is there an easy way to persuade it to use a newer version?
#Herotar was right about the [patch] section being what I needed.
First I checked out https://github.com/Taaitaaiger/jlrs which contains the jl-sys source. Then I bumped the version of bindgen referenced in jl-sys to 0.55
Modified my Cargo.toml like this
[dependencies]
jlrs = "0.6"
jl-sys = "0.8.0"
[patch.crates-io]
jl-sys = { path = '/home/me/jlrs/jl_sys' }
Then it all worked.

Resources