为什么在指定了“2018版本”后,“运行cargo install…”失败并出现“错误:2021版本不稳定”的提示?

5
虽然这个命令上周还能正常运行,但我现在在构建我的 Rust 应用程序的 Docker 镜像时,该命令突然失败了 -。
RUN cargo install --target x86_64-unknown-linux-musl --path .

有错误的内容-

编译ed25519 v1.4.0 错误:版本2021不稳定,仅在使用-Z unstable-options时可用。

错误:无法编译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”?而且为什么它会下载几乎所有的库,即使在任何地方都没有指定呢?
1个回答

6
每个箱子编译时都可以分别选择版本。当前的ed25519货箱需要一个支持2021版本的编译器。(您可以通过docs.rs的方便源代码查看找到此信息:https://docs.rs/crate/ed25519/1.4.0/source/Cargo.toml.orig
如果您尝试使用固定的编译器版本(或者是可能包含于您发行版的较旧版本),那么在项目或容器配置中包含一个Cargo.lock文件非常重要。锁文件指定了每个箱子的精确版本,以便新库版本需要更高版本的编译器特性时不会破坏您的构建。
然而,有一个问题:cargo install默认情况下会忽略锁文件。因此,您还需要更改命令并传递--locked标志给cargo install
(您还应该考虑使用更新的Rust编译器版本,这样就不必使用可能存在已知错误的旧版本库。)

参见:https://github.com/rust-lang/cargo/issues/7169 - Jmb

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接