How to change currently active version rust compiler?

207 Views Asked by At

I experienced problems when building Solana CLI 1.18.7 with Rust

When I run cargo build-sbf an error appears:

error: package bumpalo v3.15.4 cannot be built because it requires rustc 1.73.0 or newer, while the currently active rustc version is 1.72.0-dev
Either upgrade to rustc 1.73.0 or newer, or use
cargo update -p [email protected] --precise ver
where ver is the latest version of bumpalo supporting rustc 1.72.0-dev

It assumes currently active rustc version 1.72.0-dev, when I run rustup -V

rustup 1.27.0 (bbb9276d2 2024-03-08)
info: This is the version for the rustup toolchain manager, not the rustc compiler.
info: The currently active rustc version is rustc 1.76.0 (07dca489a 2024-02-04)

This is the same when I run rustc -V currently active rustc version is 1.76.0. When I downgrade Solana CLI, error package bumpalo detect rustc active version is 1.68.0.

How could this happen? Then how can I continue building Solana

1

There are 1 best solutions below

3
cyqsimon On

The repository probably has a rust-toolchain.toml file which pins a compiler version, thus why rustup/rustc/cargo --version reports different active toolchain versions in different directories.

If you have installed rust via rustup (which appears to be the case), you can specify a toolchain override on CLI like so: cargo +<TOOLCHAIN> <COMMAND>, in your case, try cargo +stable build-sbf. Alternatively, there is the RUSTUP_TOOLCHAIN environment variable you can set, which might be more convenient if you are writing a CI script for example.

All this is well documented in rust's official documentation.