删除工作区的 Cargo.toml 会触发版本错误。

huangapple go评论62阅读模式
英文:

Deleting workspace Cargo.toml triggers version error

问题

I'm reading a rust project. Deleting the workspace cargo.toml and running tests in eth_rpc_client gives the following error. It appears to be related to the version of eth2_hashing.

➜  eth_rpc_client git:(master) ✗ cargo test
    Updating crates.io index
    Updating git repository `https://github.com/aurora-is-near/lighthouse.git`
error: failed to select a version for the requirement `eth2_hashing = "0.3.0"`
candidate versions found which didn't match: 0.2.0, 0.1.0
location searched: crates.io index
required by package `merkle_proof v0.2.0 (https://github.com/aurora-is-near/lighthouse.git?tag=v3.5.1-wasm#ce4e2b44)`
    ... which satisfies git dependency `merkle_proof` of package `eth_rpc_client v0.1.0 (/Users/paulyu/paul_playground/rainbow-bridge/eth2near/eth_rpc_client)`

Here's a summary of the relevant parts for your reference.

英文:

I'm reading a rust project. Deleting the workspace cargo.toml and run test in eth_rpc_client gives out following error. I'm speculating if there's something around patch.crate-io, but cargo.toml of eth_rpc_client use same version as workspace does.

➜  eth_rpc_client git:(master) ✗ cargo test
    Updating crates.io index
    Updating git repository `https://github.com/aurora-is-near/lighthouse.git`
error: failed to select a version for the requirement `eth2_hashing = "^0.3.0"`
candidate versions found which didn't match: 0.2.0, 0.1.0
location searched: crates.io index
required by package `merkle_proof v0.2.0 (https://github.com/aurora-is-near/lighthouse.git?tag=v3.5.1-wasm#ce4e2b44)`
    ... which satisfies git dependency `merkle_proof` of package `eth_rpc_client v0.1.0 (/Users/paulyu/paul_playground/rainbow-bridge/eth2near/eth_rpc_client)`
.
├── Cargo.lock
├── Cargo.toml // workspace cargo.toml
├── contract_wrapper
├── eth2-contract-init
├── eth2near-block-relay
├── eth2near-block-relay-rs
├── eth_rpc_client
├── ethashproof
├── finality-update-verify
├── logger
├── rust-toolchain
└── target

workspace Cargo.toml

[workspace]

members = [
    "contract_wrapper",
    "eth2-contract-init",
    "eth2near-block-relay-rs",
    "eth_rpc_client",
    "finality-update-verify",
    "logger",
]

[patch]
[patch.crates-io]
eth2_ssz = { git = "https://github.com/aurora-is-near/lighthouse.git", tag = "v3.5.1-wasm"  }
eth2_ssz_types = { git = "https://github.com/aurora-is-near/lighthouse.git", tag = "v3.5.1-wasm"  }
eth2_hashing = { git = "https://github.com/aurora-is-near/lighthouse.git", tag = "v3.5.1-wasm"  }
tree_hash = { git = "https://github.com/aurora-is-near/lighthouse.git", tag = "v3.5.1-wasm"}
tree_hash_derive = { git = "https://github.com/aurora-is-near/lighthouse.git", tag = "v3.5.1-wasm"}
eth2_serde_utils = { git = "https://github.com/aurora-is-near/lighthouse.git", tag = "v3.5.1-wasm" }
eth2_ssz_derive = { git = "https://github.com/aurora-is-near/lighthouse.git", tag = "v3.5.1-wasm" }

package Cargo.toml

[package]
name = "eth_rpc_client"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
types =  { git = "https://github.com/aurora-is-near/lighthouse.git", tag = "v3.5.1-wasm" }
tree_hash = { git = "https://github.com/aurora-is-near/lighthouse.git", tag = "v3.5.1-wasm" }
merkle_proof = { git = "https://github.com/aurora-is-near/lighthouse.git", tag = "v3.5.1-wasm" }
eth2_hashing = { git = "https://github.com/aurora-is-near/lighthouse.git", tag = "v3.5.1-wasm" }
eth2_ssz = { git = "https://github.com/aurora-is-near/lighthouse.git", tag = "v3.5.1-wasm" }
log = { version = "0.4", features = ["std", "serde"] }
serde_json = "1.0.74"
serde = { version = "1.0", features = ["derive"] }
ethereum-types = { version = "0.14.1", features = ["rlp", "serialize"],  default-features = false }
reqwest = { version = "0.11", features = ["blocking"] }
eth-types = { path = "../../contracts/near/eth-types/" }
contract_wrapper = { path = "../contract_wrapper" }
clap = { version = "3.1.6", features = ["derive"] }
tokio = { version = "1.1", features = ["macros", "rt", "time"] }
env_logger = "0.9.0"
borsh = "0.9.3"
futures = { version = "0.3.21", default-features = false }
async-std = "1.12.0"
hex = "*"
toml = "0.5.9"
finality-update-verify = { path = "../finality-update-verify" }
atomic_refcell = "0.1.8"
bitvec = "*"

prometheus = { version = "0.9", features = ["process"] }
lazy_static = "1.4"
warp = "0.2"
thread = "*"
dotenv = "0.15.0"

ref: https://github.com/aurora-is-near/rainbow-bridge/tree/master/eth2near

答案1

得分: 1

是的,[patch] 部分非常重要。

在你的 eth_rpc_client 包中,eth2_hashing 依赖项指向了正确的 GitHub 存储库,但这并不是导致错误的原因。请注意错误消息中的 "required by package merkle_proof"。如果我们查看 merkle_proof 包的 Cargo.toml

[dependencies]
eth2_hashing = "0.3.0"

这将尝试在 crates.io 上查找版本 0.3.0,但并不存在。拥有 [patch] 部分将基本上重定向了该包的位置。

要解决这个问题,你可以选择要么将你的 GitHub 存储库中的 所有 包都明确指向彼此,要么在你的 eth_rpc_client 包中包含 [patch.crates-io]。如果你有多个需要它的包,考虑将它们放在一个 workspace 中,这样你可以将所有的修补程序都放在一个地方。

英文:

Yes, the [patch] section is very important.

The eth2_hashing dependency in your eth_rpc_client crate points to the correct GitHub repository, but that's not what is causing the error. Notice the "required by package merkle_proof" in the error message. If we look at the Cargo.toml of the merkle_proof package, it contains:

[dependencies]
eth2_hashing = "0.3.0"

This will try to look for version 0.3.0 of it on crates.io, which doesn't exist. Having the [patch] section will essentially redirect where that package is found.

To resolve this, you can either change all the packages in your GitHub repository to point to each other explicitly, or include a [patch.crates-io] in your eth_rpc_client package. If you have multiple packages needing it, consider keeping them in a workspace so you can have your patches all in one place.

huangapple
  • 本文由 发表于 2023年4月20日 09:09:00
  • 转载请务必保留本文链接:https://go.coder-hub.com/76059850.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定