Since I switched to the nightly toolchain, I can't compile in the stable toolchain

I was writing an API and wanted to add some macros. To debug them I switched to the nightly toolchain to use cargo expand. But now that I have finished I would like to reuse the stable toolchain, but an error appears when I try to compile in this toolchain. I can still compile in the nightly toolchain.

That the error I have when I use cargo build in the stable toolchain:

D:\Programmation\GitHub\napi>cargo build
   Compiling memchr v2.3.3
   Compiling ryu v1.0.5
error: failed to run custom build command for `ryu v1.0.5`

Caused by:
  could not execute process `D:\Programmation\GitHub\napi\target\debug\build\ryu-ac608a868ba8c732\build-script-build` (never executed)

Caused by:
  Access denied. (os error 5)
warning: build failed, waiting for other jobs to finish...
error: build failed

Sometimes it's another crate which raise an error

D:\Programmation\GitHub\napi>cargo build
   Compiling memchr v2.3.3
   Compiling ryu v1.0.5
error: failed to run custom build command for `memchr v2.3.3`

Caused by:
  could not execute process `D:\Programmation\GitHub\napi\target\debug\build\memchr-34ff87d5cae99c04\build-script-build` (never executed)

Caused by:
  Accès refusé. (os error 5)
warning: build failed, waiting for other jobs to finish...
error: build failed

Sounds like an error about the permissions set on files in the build folder. I recommend trying to delete the target folder.

1 Like

I've seen this a few times. Check if there are stray "cargo.exe" processes running, using Task Manager, and kill them if there are any. Then delete your 'target' directory, like Alice said. That has always fixed it for me.