本文主要是介绍cargo 使用国内源镜像,引用 substrate 的 Contracts Pallet Crate 编译错误,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
问题
-
cargo 编译很慢
-
学习 https://substrate.dev/docs/en/tutorials/add-contracts-pallet/ 时,编译报错
...pallet-contracts v3.0.0error[E0308]: mismatched types--> /home/dhbm/.cargo/registry/src/mirrors.tuna.tsinghua.edu.cn-df7c3c540f42cdbd/pallet-contracts-3.0.0/src/exec.rs:802:30|802 | <T as Config>::Event::from(event).into(),| ^^^^^ expected associated type, found enum `pallet::Event`|= note: expected associated type `<T as frame_system::Config>::Event`found enum `pallet::Event<T>`= help: consider constraining the associated type `<T as frame_system::Config>::Event` to `pallet::Event<T>` or calling a method that returns `<T as frame_system::Config>::Event`= note: for more information, visit https://doc.rust-lang.org/book/ch19-03-advanced-traits.htmlerror: aborting due to previous error...
解决方案
当前使用的是 清华 源镜像,重新找了
https://cargo.budshome.com/reference/source-replacement.html
这里的脚本,挨个切换
$ cd ~/.cargo
$ cat config
[source.crates-io]
registry = "https://github.com/rust-lang/crates.io-index"# 指定镜像
# replace-with = '镜像源名' # 如:tuna、sjtu、ustc,或者 rustcc
# replace-with = 'ustc'
# replace-with = 'tuna'
# replace-with = 'sjtu'
# replace-with = 'rustcc'# 以下列举了 4 个 可用源,可以自行选用其中一个,注释掉以上对应的 replace-with
# 20210427 这个 ustc 怎么不能用呢
# 中国科学技术大学
[source.ustc]
registry = "https://mirrors.ustc.edu.cn/crates.io-index"
# >>> 或者 <<<
# registry = "git://mirrors.ustc.edu.cn/crates.io-index"# 上海交通大学
[source.sjtu]
registry = "https://mirrors.sjtug.sjtu.edu.cn/git/crates.io-index/"# 清华大学
[source.tuna]
registry = "https://mirrors.tuna.tsinghua.edu.cn/git/crates.io-index.git"# rustcc社区
[source.rustcc]
registry = "https://code.aliyun.com/rustcc/crates.io-index.git"
错误处理
-
以前遇到过的
Downloaded block-padding v0.1.5 (registry `git://mirrors.ustc.edu.cn/crates.io-index`)Downloaded bs58 v0.3.1 (registry `git://mirrors.ustc.edu.cn/crates.io-index`)error: failed to download from `https://crates-io.proxy.ustclug.org/api/v1/crates/globset/0.4.5/download`
-
今天遇到的错误
…
error[E0308]: mismatched types
–> /home/dhbm/.cargo/registry/src/mirrors.sjtug.sjtu.edu.cn-4f7dbcce21e258a2/pallet-contracts-3.0.0/src/exec.rs:802:30
|
802 | ::Event::from(event).into(),
| ^^^^^ expected associated type, found enumpallet::Event
|
= note: expected associated type<T as frame_system::Config>::Event
found enumpallet::Event<T>
= help: consider constraining the associated type<T as frame_system::Config>::Event
topallet::Event<T>
or calling a method that returns<T as frame_system::Config>::Event
= note: for more information, visit https://doc.rust-lang.org/book/ch19-03-advanced-traits.htmlerror: aborting due to previous error
…
解决错误
-
分别切换了 tuna , sjtu , ustc ,都是一样的错误
可能国内源还没有同步下来,只好改回原始的 source.crates-io (注释掉所有的 replace-with)漫长等待之后。还是这个错误啊!
那么还是换回去 tuna 源镜像
** 切换源镜像无需重启 -
切换一下 rustc 缺省版本
$ rustup default nightly-2021-04-15-x86_64-unknown-linux-gnu
info: using existing install for 'nightly-2021-04-15-x86_64-unknown-linux-gnu'info: default toolchain set to 'nightly-2021-04-15-x86_64-unknown-linux-gnu'nightly-2021-04-15-x86_64-unknown-linux-gnu unchanged - rustc 1.53.0-nightly (16bf626a3 2021-04-14
切换之前
cargo --versioncargo 1.48.0-nightly (75615f8e6 2020-09-29)
现在
$ cargo --versioncargo 1.53.0-nightly (65d57e6f3 2021-04-04)
- 改回 tuna 源镜像,重新编译,终于 ok!
$ cargo build --release
Compiling node-template v3.0.0 (/home/dhbm/3.0.2/substrate-node-template/node)Building [=======================> ] 917/919: node-template
这篇关于cargo 使用国内源镜像,引用 substrate 的 Contracts Pallet Crate 编译错误的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!