rust-lang / rustup

The Rust toolchain installer
https://rust-lang.github.io/rustup/
Apache License 2.0
6.15k stars 886 forks source link

Force-reinstall a toolchain #2820

Open jonas-schievink opened 3 years ago

jonas-schievink commented 3 years ago

Describe the problem you are trying to solve

My computer is haunted, and if I don't set the right environment variables before rustup update, the toolchain it installs will fail to use any procedural macros with fun errors like

error: /nix/store/90illc73xfs933d06daq6d41njs8yh66-glibc-2.32-37/lib/libc.so.6: version `GLIBC_2.33' not found (required by /home/jonas/dev/nrf-hal/target/debug/deps/libcortex_m_rt_macros-67ec7e8a841acd06.so)
   --> /home/jonas/.cargo/registry/src/github.com-1ecc6299db9ec823/cortex-m-rt-0.6.13/src/lib.rs:403:1
    |
403 | extern crate cortex_m_rt_macros as macros;
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Describe the solution you'd like

Because I re-learn this fun fact after every Rust release, I end up with broken toolchains a lot. It would be helpful if rustup supported a way to force a reinstallation of a toolchain and all of its components and targets, without having to use rustup uninstall, since that would mean I have to reinstall every component and target I use.

rbtcollins commented 3 years ago

Perhaps we should solve the haunting?

jyn514 commented 3 years ago

Perhaps we should solve the haunting?

This is NixOS - it has virtual environments with different versions of libc installed.

@jonas-schievink it's surprising to me that affects the toolchain itself - are you sure cargo clean and then running cargo build in nix-shell doesn't work?

yaymukund commented 3 years ago

Thanks for opening this issue, I was just about to report it myself.

@jyn514 I'm on NixOS as well and experienced this exact error. A cargo clean did not suffice. I had to rustup uninstall and rustup install, then it worked.

est31 commented 3 years ago

The issue is that rustup on nix os runs patchelf on the downloaded executables, there is a custom patch. However, when you update your OS and run nix garbage collection, it removes the libraries that the patched executables point to. One could think about rustup recording the installed toolchains as gc roots and thus preventing the used libraries from being garbage collected, but this makes old libraries stay around if you want to keep older pinned toolchains around for bisection purposes. A command to force-reinstall all installed toolchains and re-run patchelf would be the best, because then one can safely discard of the old libraries.

rbtcollins commented 3 years ago

Can you just rerun patchelf?

On Sun, 29 Aug 2021 at 02:14, est31 @.***> wrote:

The issue is that rustup on nix os runs patchelf on the downloaded executables, there is a custom. However, when you update your OS and run nix garbage collection, it removes the libraries that the patched executables point to. One could think about rustup recording the installed toolchains as gc roots and thus preventing them from being garbage collected, but this makes old libraries stay around if you want to keep older pinned toolchains around for bisection purposes. A command to force-reinstall all installed toolchains and re-run patchelf would be the best, because then one can safely discard of the old libraries.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/rust-lang/rustup/issues/2820#issuecomment-907706731, or unsubscribe https://github.com/notifications/unsubscribe-auth/AADZ7XWDXG5DLJ2YMVK45SDT7F3X5ANCNFSM474V53FQ .

est31 commented 3 years ago

@rbtcollins that would be an interesting question to find out. A force-reinstall feature is I think always helpful if e.g. the install became corrupted for some reason. I know that some projects using the android NDK like to mess up the NDK for example. Many package managers like apt have reinstall features.

kinnison commented 3 years ago

I think supporting a rustup update --reinstall type approach wouldn't be entirely mad. We could analyse the toolchain to try and acquire information about installed components, and then internally do an uninstall/install with appropriate arguments. It wouldn't be easy but it should be too complex to plumb in.