rustrust-cargocosmos-sdk

How to resolve "edition2021 is required" when compiling all cw-plus contracts in docker container?


I am trying to compile all contracts on the repo root. When running I get an error:

docker run --rm -v "$(pwd)":/code \
  --mount type=volume,source="$(basename "$(pwd)")_cache",target=/code/target \
  --mount type=volume,source=registry_cache,target=/usr/local/cargo/registry \
  cosmwasm/workspace-optimizer:0.12.4
"contracts/cw20-base", "contracts/cw20-ics20", "contracts/cw3-fixed-multisig", "contracts/cw3-flex-multisig", "contracts/cw4-group", "contracts/cw4-stake"]
Building "contracts/cw1-subkeys" ...
 Downloading crates ...
error: failed to download `pkcs8 v0.8.0`

Caused by:
  unable to get packages from source

Caused by:
  failed to parse manifest at `/usr/local/cargo/registry/src/github.com-1ecc6299db9ec823/pkcs8-0.8.0/Cargo.toml`

Caused by:
  feature `edition2021` is required

  The package requires the Cargo feature called `edition2021`, but that feature is not stabilized in this version of Cargo (1.55.0 (32da73ab1 2021-08-23)).
  Consider trying a newer version of Cargo (this may require the nightly release).
  See https://doc.rust-lang.org/nightly/cargo/reference/unstable.html#edition-2021 for more information about the status of this feature.

I tired to run this:

cargo fix --edition

as explained in the edition guide and also this:

rustup default nightly && rustup update

found in similar issues, but still no luck with it.

Current cargo version (but same result with stable one):

cargo 1.63.0-nightly (a4c1cd0eb 2022-05-18)

Any idea or direction on what to try to compile those contracts?


Solution

  • The Rust compiler in your Docker version is separate from the version on your system, and the version in the image isn't new enough to support the 2021 edition. You can fix this by using a newer version of the Docker image that has a newer Rust compiler:

    docker run --rm -v "$(pwd)":/code \
      --mount type=volume,source="$(basename "$(pwd)")_cache",target=/code/target \
      --mount type=volume,source=registry_cache,target=/usr/local/cargo/registry \
      cosmwasm/workspace-optimizer:0.12.6