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?
CodePudding user response:
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 to cargo 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.)