为什么“运行货物安装...”失败并显示“错误:2021 版不稳定”虽然“2018 版”被指定?
虽然上周这是有效的,但现在突然在为我的 rust 应用程序构建 docker 映像时,以下命令失败 -
RUN cargo install --target x86_64-unknown-linux-musl --path .
出现错误 -
编译 ed25519 v1.4.0 错误:2021 版不稳定,只能与 -Z 不稳定选项一起使用。
错误:无法编译 config-client v0.1.0 (/home/rust/src)
,中间工件可以在 /home/rust/src/target
中找到
原因为: 无法编译 ed25519
以下是我的 Cargo.toml 文件:
[package]
name = "application-xyz"
version = "0.1.0"
authors = ["Dev Team <[email protected]>"]
edition = "2018"
[dependencies]
anyhow = "1.0"
bytes = "1.0.1"
clap = "2.33.3"
log = "0.4.14"
log4rs = "1.0.0"
mustache = "0.9.0"
nats = "0.9.7"
prost = "0.7"
prost-types = "0.7"
reqwest = { version = "0.11.3", features = ["blocking", "json"] }
serde = { version = "1.0.125", features = ["derive"] }
[build-dependencies]
prost-build = "0.7"
我的 docker 文件是:
FROM containers.abc.com/rust-musl-builder:1.51 as builder
#Add protobuf sources as well as app source code.
COPY model/src ./model/src
COPY application-xyz:/build.rs ./build.rs
COPY application-xyz:/Cargo.toml ./Cargo.toml
COPY application-xyz:/src ./src
COPY application-xyz:/src/protobuf ./src/protobuf
RUN cargo install --target x86_64-unknown-linux-musl --path .
有解决办法吗?尽管指定了“2018 版”,为什么货物仍尝试从“2021 版”下载?为什么它下载几乎所有的库,尽管它没有在任何地方指定?
Though this was working last week, suddenly now while building docker image for my rust application the following command fails-
RUN cargo install --target x86_64-unknown-linux-musl --path .
with errors-
Compiling ed25519 v1.4.0
error: edition 2021 is unstable and only available with -Z unstable-options.
error: failed to compile config-client v0.1.0 (/home/rust/src)
, intermediate artifacts can be found at /home/rust/src/target
Caused by:
could not compile ed25519
Following is my Cargo.toml file:
[package]
name = "application-xyz"
version = "0.1.0"
authors = ["Dev Team <[email protected]>"]
edition = "2018"
[dependencies]
anyhow = "1.0"
bytes = "1.0.1"
clap = "2.33.3"
log = "0.4.14"
log4rs = "1.0.0"
mustache = "0.9.0"
nats = "0.9.7"
prost = "0.7"
prost-types = "0.7"
reqwest = { version = "0.11.3", features = ["blocking", "json"] }
serde = { version = "1.0.125", features = ["derive"] }
[build-dependencies]
prost-build = "0.7"
My docker file is:
FROM containers.abc.com/rust-musl-builder:1.51 as builder
#Add protobuf sources as well as app source code.
COPY model/src ./model/src
COPY application-xyz:/build.rs ./build.rs
COPY application-xyz:/Cargo.toml ./Cargo.toml
COPY application-xyz:/src ./src
COPY application-xyz:/src/protobuf ./src/protobuf
RUN cargo install --target x86_64-unknown-linux-musl --path .
Any fix for this? Why cargo tries to download from 'edition 2021' though 'edition 2018' was specified? And why it downloads almost all the libraries though it has not been specified anywhere?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
版本是由每个正在编译的 crate 单独选择的。
ed25519
crate 的当前版本需要支持 2021 版的编译器。 (您可以通过 docs.rs 方便的源代码视图找到这一点: https ://docs.rs/crate/ed25519/1.4.0/source/Cargo.toml.orig)如果您尝试使用固定编译器版本(或较旧的版本)编译 Rust 二进制文件版本可能在您的发行版包管理器中),那么在您的项目/容器配置中包含
Cargo.lock
文件非常重要。锁定文件指定每个包的确切版本,以便您的构建不会被需要更新编译器功能的新库版本破坏。但是,有一个问题:
cargo install
默认忽略锁定文件。因此,您还需要更改命令以将--locked
标志传递给cargo install
。(您还应该考虑使用较新的 Rust 编译器版本,这样您就不必使用可能存在已知错误的旧版本库。)
Editions are separately chosen by each crate being compiled. The current revision of the
ed25519
crate requires a compiler that supports the 2021 edition. (You can find this out through docs.rs's handy source view: https://docs.rs/crate/ed25519/1.4.0/source/Cargo.toml.orig)If you're trying to compile Rust binaries using a fixed compiler version (or an older version that might be in your distro package manager), then it's important to include a
Cargo.lock
file in your project/container configuration. The lock file specifies exact versions of each crate, so that your build cannot be broken by new library versions requiring newer compiler features.However, there's a catch:
cargo install
ignores the lock file by default. So, you'll also need to change your command to pass the--locked
flag tocargo install
.(You should also consider using a newer Rust compiler version, so that you don't have to use old versions of libraries that may have known bugs.)