Why "Run cargo install ..." fails with "error: edition 2021 is unstable" though 'edition 2018' was specified?

Why "Run cargo install ..." fails with "error: edition 2021 is unstable" though 'edition 2018' was specified?

虽然这在上周工作,但现在突然在为我的 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 <dev@abc.com>"]
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 .

有什么解决办法吗?为什么 cargo 尝试从 'edition 2021' 下载,尽管指定了 'edition 2018'?为什么它下载了几乎所有的库,尽管它没有在任何地方指定?

版本由每个正在编译的板条箱单独选择。 ed25519 crate 的当前修订版需要支持 2021 版的编译器。 (您可以通过 docs.rs 方便的源代码视图找到它:https://docs.rs/crate/ed25519/1.4.0/source/Cargo.toml.orig

如果您尝试使用固定的编译器版本(或您的发行包管理器中可能存在的旧版本)编译 Rust 二进制文件,那么在您的 project/container 配置。锁定文件指定每个板条箱的确切版本,因此您的构建不会被需要更新编译器功能的新库版本破坏。

但是,有一个问题:cargo install 默认情况下忽略锁定文件。因此,您还需要更改命令以将 --locked 标志传递给 cargo install.

(您还应该考虑使用较新的 Rust 编译器版本,这样您就不必使用可能存在已知错误的旧版本库。)