You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

删除Rust工作区Cargo.toml后运行测试触发版本错误求助

问题:删除Rust工作区Cargo.toml后执行cargo test出现依赖版本匹配错误

我正在研究一个Rust项目,删除工作区的Cargo.toml文件后,在eth_rpc_client目录下执行cargo test命令时出现如下错误:

➜  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

原工作区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" }

eth_rpc_client的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"

问题原因

原工作区的Cargo.toml通过[patch.crates-io]配置,将eth2_hashing等依赖指向了自定义Git仓库的v3.5.1-wasm标签版本。删除工作区配置后,merkle_proof依赖会尝试从crates.io拉取eth2_hashing ^0.3.0,但crates.io上仅存在0.2.0和0.1.0版本,导致版本匹配失败。

解决方法

  1. 恢复工作区Cargo.toml:直接恢复删除的工作区配置文件,Cargo会自动应用原有的patch规则,从指定Git仓库拉取符合要求的依赖版本。
  2. 在eth_rpc_client中添加patch配置:若不想恢复工作区文件,可在eth_rpc_client目录的Cargo.toml末尾添加以下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" }

添加完成后重新执行cargo test即可解决问题。

内容的提问来源于stack exchange,提问作者Paul Yu

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.24 12:37:51