Build fails with Error: Pear requires a 'dev' or 'nightly' version of rustc even after a successful rustup override set nightly
Asked Answered
H

3

7
  • Windows 10
  • rustup 1.23.1 (3df2264a9 2020-11-30)
  • default rustc 1.50.0 (cb75ad5db 2021-02-10)
  • project rustc 1.52.0-nightly (4a8b6f708 2021-03-11)
  • rocket = "0.4.4"

I'm trying to build a rust project with rocket but I always get this error when compiling, even after successfully overwriting the project's toolchain:

D:\GitHub\Learning-Rust\poke_api> rustup override set nightly
info: using existing install for 'nightly-x86_64-pc-windows-msvc'
info: override toolchain for 'D:\GitHub\Learning-Rust\poke_api' set to 'nightly-x86_64-pc-windows-msvc'

  nightly-x86_64-pc-windows-msvc unchanged - rustc 1.52.0-nightly (4a8b6f708 2021-03-11)

PS D:\GitHub\Learning-Rust\poke_api> cargo build
   Compiling winapi v0.3.9
   Compiling serde_derive v1.0.124
   Compiling rocket v0.4.7
   Compiling pear_codegen v0.1.4
   Compiling rocket_codegen v0.4.7
   Compiling proc-macro2 v1.0.24
   Compiling pq-sys v0.4.6
   Compiling aho-corasick v0.6.10
   Compiling serde_json v1.0.64
error: failed to run custom build command for `pear_codegen v0.1.4`

Caused by:
  process didn't exit successfully: `D:\GitHub\Learning-Rust\poke_api\target\debug\build\pear_codegen-e182711746033ac9\build-script-build` (exit code: 101)
  --- stderr
  Error: Pear requires a 'dev' or 'nightly' version of rustc.
  Installed version: 1.48.0 (2020-11-16)
  Minimum required:  1.31.0-nightly (2018-10-05)
  thread 'main' panicked at 'Aborting compilation due to incompatible compiler.', C:\Users\gabre\.cargo\registry\src\github.com-1ecc6299db9ec823\pear_codegen-0.1.4\build.rs:24:13
  note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
warning: build failed, waiting for other jobs to finish...
error: build failed
Haerle answered 12/3, 2021 at 18:44 Comment(7)
This could be an issues with environment variables. Does it work if you try running cargo +nightly build?Travax
Can't reproduce unless you have the RUSTUP_TOOLCHAIN environment variable set to "stable" or some other non-nightly toolchain. That variable and directly in the command as @Travax mentioned are the only methods with higher precedence than the directory override, see here.Thordia
when i tried to do cargo +nightly build it sent me an error: error: no such subcommand: +nightly @TravaxHaerle
How can I change the RUSTUP_TOOLCHAIN environment variable? @ThordiaHaerle
Hmmm if you're getting that error, then there might be an problem with your rustup/cargo install. When you run cargo, it should be executing the version installed by rustup, or it wont be able to use the rustup toolchains. You could try removing and reinstalling rustup to see if that fixes the problemTravax
From the answer for cargo +nightly error : no such subcommand, it sounds like you've installed a version of cargo that is separate from the one installed via rustup, it is probably causing your configuration problemThordia
I've reinstalled rust and it ran just fine, thanks guys for the help!Haerle
U
16

I had a similar issue while using rocket. Same error message too, Error: Pear requires a 'dev' or 'nightly' version of rustc.

If you get to the get-started page on rocket framework website. It says, "Rocket makes abundant use of Rust's syntax extensions and other advanced, unstable features. Because of this, we'll need to use a nightly version of Rust."

My issue was I was not using a nightly version of rust. Running this on my terminal in my project directory did it for me.

rustup override set nightly

If you check the cargo version for that directory after,

cargo version

you will confirm it has switched to nightly version

Uncompromising answered 18/6, 2021 at 14:17 Comment(0)
S
1

My issue was with rust-analyser that wouldn't start because multiple rocket dependencies needed nightly or dev version of rustc.

These steps fixed my issue:

  1. Switch to nightly for my rocket project by running rustup override set nightly inside the app folder.
  2. Remove all target folders in my project. (I also had one in root)
  3. Manually remove the faulty cached packages from cargo cache. cd ~/.cargo/registry/cache/github.com-xxxxxxxxxxxx && rm -r pear_codegen-0.1.5/
Succotash answered 3/12, 2022 at 8:56 Comment(0)
I
0

Failed compilation even with nightly

It looks like you have some outdated dependencies (pear-codegen probably being the one that causes trouble), updating these may resolve the compilation issues.

General notes on how to override the toolchain

Using rustups override works fine, but it is bound to your local rustup configuration and not specified inside the project.

In order to achieve this, thereby making the project more portable and allowing others to always use the correct toolchain, I would recommend the toolchain file. It can look something like this (example taken from linked page) and will accurately specify the required toolchain only for the containing project.

# rust-toolchain.toml
[toolchain]
channel = "nightly-2020-07-10"
components = [ "rustfmt", "rustc-dev" ]
targets = [ "wasm32-unknown-unknown", "thumbv2-none-eabi" ]
profile = "minimal"

For your purposes a simple configuration like this will most likely be all you need, although adding the components you want to use would be beneficial.

[toolchain]
channel = "nightly"
Isooctane answered 18/6, 2021 at 16:33 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.