Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
code-cream opened this issue Nov 28, 2024 · 25 comments
Labels

Comments

@code-cream
Copy link

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

@619
Copy link

619 commented Nov 28, 2024

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

@acheroncrypto
Copy link
Collaborator

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.

@nabeel-uncx
Copy link

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...

@Sandalo100
Copy link

I have the same problem, has anyone found a solution? Thanks

@notnullonline
Copy link

Why this issue is closed? The problem still exists.. :(

@notamicrodose
Copy link

@nabeel-uncx thank you for sharing - this fix worked for me!

@CarlTornberg
Copy link

CarlTornberg commented Dec 10, 2024

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?

@bartfish
Copy link

#3392 (comment) - 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.

@Dante9988
Copy link

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

@HiPipilu
Copy link

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

@HiPipilu
Copy link

HiPipilu commented Dec 13, 2024

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 solana-labs/solana#34987
it works

@waqasraza123
Copy link

waqasraza123 commented Dec 14, 2024

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.

@ochikov
Copy link

ochikov commented Dec 16, 2024

@waqasraza123
What kind of problems? Can you post?

@kuchaguangjie
Copy link

kuchaguangjie commented Dec 17, 2024

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

@6758f6
Copy link

6758f6 commented Dec 17, 2024

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

@Sandalo100
Copy link

@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

@6758f6
Copy link

6758f6 commented Dec 18, 2024

@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

manually editing the lock file to version 3 "works" (anchor build don't fail) if you follow the getting started guide on solana.com using a fresh vps with ubuntu server 24.04 on clodzy.com. there's a $5 minimum top-up but it can be paid with SOL

@n13
Copy link

n13 commented Dec 22, 2024

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...

@xcaptain
Copy link

Same error here, changing 4 to 3 solved the problem but really hope you can release 0.31 or 0.30.2 soon, so others don't need to google and search this solution.

@Sandalo100
Copy link

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...

Yes, and yes. Same too me

@rchak007
Copy link

Same error here, changing 4 to 3 solved the problem but really hope you can release 0.31 or 0.30.2 soon, so others don't need to google and search this solution.

How did you change 4 to 3?

Yea its frustrating to struggle with installs instead of working on actual issues.

(base) $ anchor build
error: failed to parse lock file at: /......../Cargo.lock

Caused by:
lock file version 4 requires -Znext-lockfile-bump

@glaredark
Copy link

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.

I changed my rustc version from 1.83 to 1.75, problem solved.
Thanks a lot.

@beeman
Copy link

beeman commented Dec 30, 2024

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

@levibland
Copy link

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)

@smarulanda97
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests