0


要点初见:切换老版本Rust并运行老版本cargo

初学Web3.0,在参考ethereum_book/第三章.asciidoc at master · JiangFengMA/ethereum_book · GitHub安装以太坊客户端Parity的过程中,遇到了一个因Rust版本过新导致的Bug:

mem::transmute::<SocketAddrV4, sockaddr_in>(v4);

具体Bug如下:

error[E0512]: cannot transmute between types of different sizes, or dependently-sized types
   --> /home/hhy/.cargo/registry/src/github.com-1ecc6299db9ec823/socket2-0.3.8/src/sockaddr.rs:153:9
    |
153 |         mem::transmute::<SocketAddrV4, sockaddr_in>(v4);
    |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |
    = note: source type: `SocketAddrV4` (48 bits)
    = note: target type: `sockaddr_in` (128 bits)

   Compiling term_size v0.3.1
For more information about this error, try `rustc --explain E0512`.
error: could not compile `socket2` due to previous error
warning: build failed, waiting for other jobs to finish...

根据AUR build error · Issue #1027 · Rigellute/spotify-tui · GitHub解释,是Rust版本1.64.0修改了Ipv4Addr、Ipv6Addr、SocketAddrV4和SocketAddrV6,导致内存长度对不上了:

Just wanted to add into this issue:

Rust in its version 1.64.0 made changes to Ipv4Addr, Ipv6Addr, SocketAddrV4 and SocketAddrV6. Also, when using

std::mem::transmute

it results in invalid memory accesses.
Rust 1.64.0 Compatibility Notes

With all of these, the newest version of Rust broke some crates, and now spotify-tui has problems with memory and different bit sizes and stuff.
So they recommend doing

cargo update

to mitigate for now, and it works as a workaround (adding the cargo update somewhere before it reads the Cargo.lock and Cargo.toml files and .patches.

I had to manually do the editing, building and compiling from "source" (AUR in Arch Linux).

Also, after running

makepkg si

with the cargo update command already in place, it updates the files but after that it is required to download updated versions of some of the dependencies/creates and 1 or 2 required http and also, obviously for all the update, network connection is required so the

--frozen

option had to be temporary removed.

For me, it built succesfully after that even using this PKGBUILD.

但要切换到适配以太坊客户端的Rust真的费了一大番功夫:

1、根据Rust官网安装 Rust - Rust 程序设计语言:

curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

这句安装的是最新版本的Rust(先下载rustup-init.sh脚本,而后自动运行),暂无在官网上看到提供任何过往版本的链接,而在Github官方仓库https://github.com/openethereum/parity-ethereum#chapter-003中只有1.25.1以及之前的版本tag分支;

2、根据Rustup:Rust 版本管理器 - Rust 版本指南 中文版,因以太坊客户端Parity需要1.24.0以上版本的nightly版本Rust,故在用1安装完Rust后运行

rustup install nightly-2018-08-01【错误示范】

即可切换Rust版本……才怪,Rust主要分cargo、rustc两个主要工具,运行上述install后cargo --version仍然是显示最新1.64.0版本,而且nightly-2018-08-01是非常上古的版本。

3、正确做法是查寻了Channels - The rustup book之后找到的:

rustup toolchain install nightly-2020-07-27

而后采用

rustup run nightly-2020-07-27 rustc --version

查寻版本即可确定已切换至旧版本:

Parity Ethereum Client.
  version Parity-Ethereum/v2.7.2-unstable-55c90d401-20200205/x86_64-unknown-linux-gnu/rustc1.47.0-nightly
Copyright 2015-2020 Parity Technologies (UK) Ltd.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

By Wood/Paronyan/Kotewicz/Drwięga/Volf/Greeff
   Habermeier/Czaban/Gotchac/Redman/Nikolsky
   Schoedon/Tang/Adolfsson/Silva/Palm/Hirsz et al.

之后需要调用nightly-2020-07-27版本的cargo、rustc都必须加rustup run nightly-2020-07-27前缀,即通过以下命令编译Parity release版:

rustup run nightly-2020-07-27 cargo build --release --features finacargo build --release --features final

或通过以下命令编译Parity debug版:

rustup run nightly-2020-07-27 cargo build

附:

编译Parity前需要安装:

sudo apt install llvm-dev libclang-dev clang

另如果

parity --version 

提示:

Command 'parity' not found, but can be installed with:
sudo snap install parity

只需

sudo cp ./target/debug/parity /usr/bin/

即可。

标签:

本文转载自: https://blog.csdn.net/m0_37857300/article/details/127113189
版权归原作者 BingLiHanShuang 所有, 如有侵权,请联系我们删除。

“要点初见:切换老版本Rust并运行老版本cargo”的评论:

还没有评论