anchor: Fresh project `anchor build` fails with "lock file version 4 requires `-Znext-lockfile-bump`"

Issue

Running anchor build or anchor test in a fresh project initialized with anchor-cli fails with the following:

error: failed to parse lock file at: /Users/{user}/{project_dir}/anchor/Cargo.lock
Caused by:
  lock file version 4 requires `-Znext-lockfile-bump

Environment Details

Apple silicon (m1)

anchor --version
anchor-cli 0.30.1

cargo --version
cargo 1.85.0-nightly (4c39aaff6 2024-11-25)

solana --version
solana-cli 2.0.17 (src:7104d713; feat:607245837, client:Agave)

I ended up in this state after running cargo build-sbf --force-tools-install to resolve the error: not a directory: '.../solana-release/bin/sdk/sbf/dependencies/platform-tools/rust/lib' error as recommended here

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 3
  • Comments: 32

Commits related to this issue

Most upvoted comments

You can fix this simply by changing the version field of Cargo.lock as https://github.com/coral-xyz/anchor/issues/3393#issuecomment-2507904307 suggested:

- version = 4
+ version = 3

The reason why it happens is because Anchor v0.30 uses Solana v1.18, and Solana v1.18 depends on rustc 1.75, but the new version (4) of Cargo.lock has only been stabilized in rustc 1.78 (as mentioned in https://github.com/rust-lang/cargo/issues/14655#issuecomment-2400237392).

Solana build tools have recently been updated to use rustc 1.79, which is available since Solana v2.1, and it’s also what the master branch of Anchor uses (https://github.com/coral-xyz/anchor/pull/3339).

Anchor v0.31 (https://github.com/coral-xyz/anchor/pull/3259) will support Solana v2, meaning this issue will be resolved automatically. In the meantime, you can just use the fix mentioned at the beginning of this comment.

I get the same exact problem! Seems like they outsourced QA to the users 🤣

anchor is simply broken now. such issue shouldn’t exists at all. can’t finish a hello world now.

Why this issue is closed? The problem still exists… 😦

You can fix this simply by changing the version field of Cargo.lock as #3393 (comment) suggested:

- version = 4
+ version = 3

The reason why it happens is because Anchor v0.30 uses Solana v1.18, and Solana v1.18 depends on rustc 1.75, but the new version (4) of Cargo.lock has only been stabilized in rustc 1.78 (as mentioned in rust-lang/cargo#14655 (comment)).

Solana build tools have recently been updated to use rustc 1.79, which is available since Solana v2.1, and it’s also what the master branch of Anchor uses (#3339).

Anchor v0.31 (#3259) will support Solana v2, meaning this issue will be resolved automatically. In the meantime, you can just use the fix mentioned at the beginning of this comment.

this does not work as re-running anchor build sets it back to 4…

user@computer:~/solana/program$ cargo build-sbf
error: package `solana-program v2.1.5` cannot be built because it requires rustc 1.79.0 or newer, while the currently active rustc version is 1.75.0-dev
Note that this is the rustc version that ships with Solana tools and not your system's rustc version. Use `solana-install update` or head over to https://docs.solanalabs.com/cli/install to install a newer version.
Either upgrade to rustc 1.79.0 or newer, or use
cargo update solana-program@2.1.5 --precise ver
where `ver` is the latest version of `solana-program` supporting rustc 1.75.0-dev
user@computer:~/solana/program$ rustc --version
rustc 1.83.0 (90b35a623 2024-11-26)

Using the tutorial on the Solanas website and changing the version of the Cargo.lock file to 3 gives me this error which makes my head twist as i have rustc 1.83 installed. Sorry Im new, am i missing something obvious here?

Hey there @Sandalo100, @notnullonline, @CarlTornberg, @HiPipilu, @waqasraza123, @kuchaguangjie, @6758f6, @n13 and @xcaptain - I hope you don’t mind the ping.

First of all, sorry to hear you’re having issues getting this to work. I’d like to make sure you can get started so feel free to reply with more context if the below doesn’t work for you.

Yesterday I spun up a new project and got the same issue. Here’s how I managed to get to a (consistently) working setup on my system.

1. Make sure to have rust 1.79.0 as the active version

I was on a higher version of Rust but this seemed to be the main problem. I tried a few versions and ended up using 1.79.0 to get into a working state.

I used rustup default 1.79.0-aarch64-apple-darwin - you probably need to change this tag if you’re not on a machine with Apple Silicon. You can check rustup show to see some of the other toolchains, this way you’ll probably figure out what tag you need.

You should end up with these versions:

$ rustup default 1.79.0-aarch64-apple-darwin
# This will install the toolchain
$ rustc --version                           
rustc 1.79.0 (129f3b996 2024-06-10)
$ cargo --version 
cargo 1.79.0 (ffa9cf99a 2024-06-03)
$ rustup --version                          
rustup 1.27.1 (54dd3d00f 2024-04-24)
info: This is the version for the rustup toolchain manager, not the rustc compiler.
info: The currently active `rustc` version is `rustc 1.79.0 (129f3b996 2024-06-10)`

2. Be sure to be on version 2.0.21 of Solana (Agave client)

I installed the agave version of Solana as per the official docs.

You should get the following version:

solana --version
solana-cli 2.0.21 (src:99ac0105; feat:607245837, client:Agave)

If you have the agave tools installed but are on a different version, you can switch like so:

agave-install init 2.0.21

3. Be sure to be on version 0.30.1 of Anchor

 $ avm use latest
Now using anchor version 0.30.1.

4. Create a new project to check if the above works

anchor init my-test --test-template jest --no-install
cd my-test 
pnpm install
anchor test

If that last command doesn’t fail, you should be good to go.

5. Bonus: use create-solana-program to scaffold a new project.

The command uses create-solana-program to create a new project. It has a bunch of nice extra features to explore and I recommend you to check it out!

pnpx create-solana-program --anchor --client js --rust 1.79.0 --solana 2.0.21 my-test
# follow the prompts
cd my-test
pnpm install
pnpm generate
pnpm programs:test
pnpm clients:js:test

anchor is simply broken now. such issue shouldn’t exists at all. can’t finish a hello world now.

yep. for someone like me who is trying to build a sol program for the first time, the status “closed” doesn’t feel right. even if manually editing the lock file works for some, i think it should be pointed out that while this workaround can temporarily unblock you, it’s advisable to find a proper fix

@waqasraza123 What kind of problems? Can you post?

this: lock file version 4 requires `-Znext-lockfile-bump.

I uninstalled everything, anchor, mocha, node, even linux because I use wsl ubuntu on windows… and in the end I got the same error… I’m losing my hair, I try everything (of course, helped by gemini and chatgpt and nothing) it only gets worse. Thanks friends

user@computer:~/solana/program$ cargo build-sbf
error: package `solana-program v2.1.5` cannot be built because it requires rustc 1.79.0 or newer, while the currently active rustc version is 1.75.0-dev
Note that this is the rustc version that ships with Solana tools and not your system's rustc version. Use `solana-install update` or head over to https://docs.solanalabs.com/cli/install to install a newer version.
Either upgrade to rustc 1.79.0 or newer, or use
cargo update solana-program@2.1.5 --precise ver
where `ver` is the latest version of `solana-program` supporting rustc 1.75.0-dev
user@computer:~/solana/program$ rustc --version
rustc 1.83.0 (90b35a623 2024-11-26)

Using the tutorial on the Solanas website and changing the version of the Cargo.lock file to 3 gives me this error which makes my head twist as i have rustc 1.83 installed. Sorry Im new, am i missing something obvious here?

I get the same problem after set version = 3

Changing version of lockfile from 4 to 3 helped me. So if anything try that first and see if that fixes

Hey there @Sandalo100, @notnullonline, @CarlTornberg, @HiPipilu, @waqasraza123, @kuchaguangjie, @6758f6, @n13 and @xcaptain - I hope you don’t mind the ping.

First of all, sorry to hear you’re having issues getting this to work. I’d like to make sure you can get started so feel free to reply with more context if the below doesn’t work for you.

Yesterday I spun up a new project and got the same issue. Here’s how I managed to get to a (consistently) working setup on my system.

1. Make sure to have rust 1.79.0 as the active version

I was on a higher version of Rust but this seemed to be the main problem. I tried a few versions and ended up using 1.79.0 to get into a working state.

I used rustup default 1.79.0-aarch64-apple-darwin - you probably need to change this tag if you’re not on a machine with Apple Silicon. You can check rustup show to see some of the other toolchains, this way you’ll probably figure out what tag you need.

You should end up with these versions:

$ rustup default 1.79.0-aarch64-apple-darwin
# This will install the toolchain
$ rustc --version                           
rustc 1.79.0 (129f3b996 2024-06-10)
$ cargo --version 
cargo 1.79.0 (ffa9cf99a 2024-06-03)
$ rustup --version                          
rustup 1.27.1 (54dd3d00f 2024-04-24)
info: This is the version for the rustup toolchain manager, not the rustc compiler.
info: The currently active `rustc` version is `rustc 1.79.0 (129f3b996 2024-06-10)`

2. Be sure to be on version 2.0.21 of Solana (Agave client)

I installed the agave version of Solana as per the official docs.

You should get the following version:

solana --version
solana-cli 2.0.21 (src:99ac0105; feat:607245837, client:Agave)

If you have the agave tools installed but are on a different version, you can switch like so:

agave-install init 2.0.21

3. Be sure to be on version 0.30.1 of Anchor

 $ avm use latest
Now using anchor version 0.30.1.

4. Create a new project to check if the above works

anchor init my-test --test-template jest --no-install
cd my-test 
pnpm install
anchor test

If that last command doesn’t fail, you should be good to go.

5. Bonus: use create-solana-program to scaffold a new project.

The command uses create-solana-program to create a new project. It has a bunch of nice extra features to explore and I recommend you to check it out!

pnpx create-solana-program --anchor --client js --rust 1.79.0 --solana 2.0.21 my-test
# follow the prompts
cd my-test
pnpm install
pnpm generate
pnpm programs:test
pnpm clients:js:test

For anyone new coming across this issue, this solution worked for me (apple silicon user)

I have never done Solana development before but the toolchain seems to be a complete mess - first impressions!

First I followed instructions from ChatGPT - nothing worked. Fair enough, I should have just used the official instructions, right?

They’re right here https://solana.com/docs/intro/installation

So I uninstalled everything, followed the official instructions, and after a ton of downloading, installing, and compiling, I got this error message on a brand new project

… an hour of downloading things anchor init anchor build “Error: -> lock file version 4 requires -Znext-lockfile-bump”

Not exactly confidence-inspiring.

Update: It seems like rust, solana, and anchor all have flexible version management… so therefore it seems one could simply write a bash script that contains the compatible versions of these tools in a table, and switches them all to compatible versions on a single command. The main issue is that the info which rust works with which solana and which anchor is all hidden somewhere in config files in binary code - it would save everyone a lot of headache to be able to verify that my currently active versions of these 3 tools are compatible with each other. like rust x.x works with solana x.x.x and anchor x.x.x…

add a new file touch rust-toolchain.toml then

[toolchain]
channel = "1.79.0"

It worked for me, but I also had to change the version in the Cargo.lock .

$ rustc --version
rustc 1.79.0 (129f3b996 2024-06-10)
$ cargo  --version
cargo 1.79.0 (ffa9cf99a 2024-06-03)
$ rustup --version
rustup 1.27.1 (54dd3d00f 2024-04-24)
info: This is the version for the rustup toolchain manager, not the rustc compiler.
info: The currently active `rustc` version is `rustc 1.79.0 (129f3b996 2024-06-10)`
$ solana --version
solana-cli 2.0.21 (src:99ac0105; feat:607245837, client:Agave)
$ avm use latest
Now using anchor version 0.30.1.
# Cargo.lock
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3

https://github.com/coral-xyz/anchor/issues/3392#issuecomment-2508412018 - tried it, but it didn’t work for me either, thank you for sharing.

However, this worked:

solana-install init 1.18.26
cargo build-sbf

I had a project that required 1.18.26 of solana tools. Then compiled it and stuff just worked. Maybe, it’ll help someone.

failed to parse lock file at fixed --> Caused by: lock file version 4 requires -Znext-lockfile-bump

fixed with:

cargo build-sbf -- -Znext-lockfile-bump

Realise with real eyes!!

There might be a better solution:

Refer: https://stackoverflow.com/a/79349131/1568658

You can fix this simply by changing the version field of Cargo.lock as #3393 (comment) suggested:

- version = 4
+ version = 3

The reason why it happens is because Anchor v0.30 uses Solana v1.18, and Solana v1.18 depends on rustc 1.75, but the new version (4) of Cargo.lock has only been stabilized in rustc 1.78 (as mentioned in rust-lang/cargo#14655 (comment)).

Solana build tools have recently been updated to use rustc 1.79, which is available since Solana v2.1, and it’s also what the master branch of Anchor uses (#3339).

Anchor v0.31 (#3259) will support Solana v2, meaning this issue will be resolved automatically. In the meantime, you can just use the fix mentioned at the beginning of this comment.

This answer works.

Edit:

And then it create more problems with the types in typescript if we change the version to 3.

user@computer:~/solana/program$ cargo build-sbf
error: package `solana-program v2.1.5` cannot be built because it requires rustc 1.79.0 or newer, while the currently active rustc version is 1.75.0-dev
Note that this is the rustc version that ships with Solana tools and not your system's rustc version. Use `solana-install update` or head over to https://docs.solanalabs.com/cli/install to install a newer version.
Either upgrade to rustc 1.79.0 or newer, or use
cargo update solana-program@2.1.5 --precise ver
where `ver` is the latest version of `solana-program` supporting rustc 1.75.0-dev
user@computer:~/solana/program$ rustc --version
rustc 1.83.0 (90b35a623 2024-11-26)

Using the tutorial on the Solanas website and changing the version of the Cargo.lock file to 3 gives me this error which makes my head twist as i have rustc 1.83 installed. Sorry Im new, am i missing something obvious here?

I know,look this page https://github.com/solana-labs/solana/issues/34987 it works