草庐IT

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

BingLiHanShuang 2023-04-04 原文

初学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/

即可。

有关要点初见:切换老版本Rust并运行老版本cargo的更多相关文章

  1. ruby - 如何从 ruby​​ 中的字符串运行任意对象方法? - 2

    总的来说,我对ruby​​还比较陌生,我正在为我正在创建的对象编写一些rspec测试用例。许多测试用例都非常基础,我只是想确保正确填充和返回值。我想知道是否有办法使用循环结构来执行此操作。不必为我要测试的每个方法都设置一个assertEquals。例如:describeitem,"TestingtheItem"doit"willhaveanullvaluetostart"doitem=Item.new#HereIcoulddotheitem.name.shouldbe_nil#thenIcoulddoitem.category.shouldbe_nilendend但我想要一些方法来使用

  2. ruby - 如何每月在 Heroku 运行一次 Scheduler 插件? - 2

    在选择我想要运行操作的频率时,唯一的选项是“每天”、“每小时”和“每10分钟”。谢谢!我想为我的Rails3.1应用程序运行调度程序。 最佳答案 这不是一个优雅的解决方案,但您可以安排它每天运行,并在实际开始工作之前检查日期是否为当月的第一天。 关于ruby-如何每月在Heroku运行一次Scheduler插件?,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/questions/8692687/

  3. ruby-on-rails - 如何在 ruby​​ 中使用两个参数异步运行 exe? - 2

    exe应该在我打开页面时运行。异步进程需要运行。有什么方法可以在ruby​​中使用两个参数异步运行exe吗?我已经尝试过ruby​​命令-system()、exec()但它正在等待过程完成。我需要用参数启动exe,无需等待进程完成是否有任何ruby​​gems会支持我的问题? 最佳答案 您可以使用Process.spawn和Process.wait2:pid=Process.spawn'your.exe','--option'#Later...pid,status=Process.wait2pid您的程序将作为解释器的子进程执行。除

  4. ruby - 无法运行 Rails 2.x 应用程序 - 2

    我尝试运行2.x应用程序。我使用rvm并为此应用程序设置其他版本的ruby​​:$rvmuseree-1.8.7-head我尝试运行服务器,然后出现很多错误:$script/serverNOTE:Gem.source_indexisdeprecated,useSpecification.Itwillberemovedonorafter2011-11-01.Gem.source_indexcalledfrom/Users/serg/rails_projects_terminal/work_proj/spohelp/config/../vendor/rails/railties/lib/r

  5. ruby-on-rails - Ruby on Rails with Haml - 如何从 erb 切换 - 2

    我正在从erb文件切换到HAML。我将hamlgem添加到我的系统中。我创建了app/views/layouts/application.html.haml文件。我应该只删除application.html.erb文件吗?此外,仍然有/public/index.html文件被呈现为默认页面。我想创建自己的默认index.html.haml页面。我应该把它放在哪里以及如何使系统呈现该文件而不是默认索引文件?谢谢! 最佳答案 是的,您可以删除任何已转换为HAML的View的ERB版本。至于你的另一个问题,删除public/index/h

  6. ruby-on-rails - 项目升级后 Pow 不会更改 ruby​​ 版本 - 2

    我在我的Rails项目中使用Pow和powifygem。现在我尝试升级我的ruby​​版本(从1.9.3到2.0.0,我使用RVM)当我切换ruby​​版本、安装所有gem依赖项时,我通过运行railss并访问localhost:3000确保该应用程序正常运行以前,我通过使用pow访问http://my_app.dev来浏览我的应用程序。升级后,由于错误Bundler::RubyVersionMismatch:YourRubyversionis1.9.3,butyourGemfilespecified2.0.0,此url不起作用我尝试过的:重新创建pow应用程序重启pow服务器更新战俘

  7. ruby - Sinatra:运行 rspec 测试时记录噪音 - 2

    Sinatra新手;我正在运行一些rspec测试,但在日志中收到了一堆不需要的噪音。如何消除日志中过多的噪音?我仔细检查了环境是否设置为:test,这意味着记录器级别应设置为WARN而不是DEBUG。spec_helper:require"./app"require"sinatra"require"rspec"require"rack/test"require"database_cleaner"require"factory_girl"set:environment,:testFactoryGirl.definition_file_paths=%w{./factories./test/

  8. ruby-on-rails - 在 ruby​​ .gemspec 文件中,如何指定依赖项的多个版本? - 2

    我正在尝试修改当前依赖于定义为activeresource的gem:s.add_dependency"activeresource","~>3.0"为了让gem与Rails4一起工作,我需要扩展依赖关系以与activeresource的版本3或4一起工作。我不想简单地添加以下内容,因为它可能会在以后引起问题:s.add_dependency"activeresource",">=3.0"有没有办法指定可接受版本的列表?~>3.0还是~>4.0? 最佳答案 根据thedocumentation,如果你想要3到4之间的所有版本,你可以这

  9. ruby-on-rails - 如果我将 ruby​​ 版本 2.5.1 与 rails 版本 2.3.18 一起使用会怎样? - 2

    如果我使用ruby​​版本2.5.1和Rails版本2.3.18会怎样?我有基于rails2.3.18和ruby​​1.9.2p320构建的rails应用程序,我只想升级ruby的版本,而不是rails,这可能吗?我必须面对哪些挑战? 最佳答案 GitHub维护apublicfork它有针对旧Rails版本的分支,有各种变化,它们一直在运行。有一段时间,他们在较新的Ruby版本上运行较旧的Rails版本,而不是最初支持的版本,因此您可能会发现一些关于需要向后移植的有用提示。不过,他们现在已经有几年没有使用2.3了,所以充其量只能让更

  10. ruby-on-rails - 获取 inf-ruby 以使用 ruby​​ 版本管理器 (rvm) - 2

    我安装了ruby​​版本管理器,并将RVM安装的ruby​​实现设置为默认值,这样'哪个ruby'显示'~/.rvm/ruby-1.8.6-p383/bin/ruby'但是当我在emacs中打开inf-ruby缓冲区时,它使用安装在/usr/bin中的ruby​​。有没有办法让emacs像shell一样尊重ruby​​的路径?谢谢! 最佳答案 我创建了一个emacs扩展来将rvm集成到emacs中。如果您有兴趣,可以在这里获取:http://github.com/senny/rvm.el

随机推荐