rustup: Tracking: Rustup should not perform implicit installations

Problem you are trying to solve

here is a transcript of a session with rustup

PS C:\Users\jyn\src\example> rustup toolchain list                              
nightly-x86_64-pc-windows-msvc (default)
1.74-x86_64-pc-windows-msvc
stage1
PS C:\Users\jyn\src\example> rustup uninstall nightly
info: uninstalling toolchain 'nightly-x86_64-pc-windows-msvc'
info: toolchain 'nightly-x86_64-pc-windows-msvc' uninstalled
PS C:\Users\jyn\src\example> rustup toolchain list   
1.74-x86_64-pc-windows-msvc
stage1
PS C:\Users\jyn\src\example> rustc
info: syncing channel updates for 'nightly-x86_64-pc-windows-msvc'
info: latest update on 2024-01-07, rust version 1.77.0-nightly (b6a8c762e 2024-01-06)
info: downloading component 'cargo'
^C
PS C:\Users\jyn\src\example> rustc +nightly
error: toolchain 'nightly-x86_64-pc-windows-msvc' is not installed
PS C:\Users\jyn\src\example> rustup --version
rustup 1.26.0 (5af9b9484 2023-04-05)
info: This is the version for the rustup toolchain manager, not the rustc compiler.
info: syncing channel updates for 'nightly-x86_64-pc-windows-msvc'

Proposed Solution & Progress

[The following behaviors of the current rustup should be changed:]

  • uninstalling the default toolchain happens silently. i would expect either a warning (by the same logic as https://github.com/rust-lang/rustup/issues/3319), or for rustup to switch to a different default toolchain.
  • running rustc afterwards implicitly reinstalls the toolchain.
  • I do not expect rustup to implicitly install in any case other than when rust-toolchain.toml is in the current directory. in fact, you can see that rustc +nightly does not implicitly install, only rustc by itself. [@rami3l: We shouldn’t do even that, instead we should let the user explicitly install the required toolchain with a command.]
  • running rustup --version also silently installs.
  • running rustup show also silently installs.

Notes

rustup 1.26.0 (5af9b9484 2023-04-05)

Tasks

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 1
  • Comments: 64 (49 by maintainers)

Most upvoted comments

I think as interactive prompt when a tty is attached might be good, but we should definitely:

  • socialise it well
  • consider adding an override to suppress this - rustup gets invoked from within vscode and other IDEs, and a code bug leading to an attached tty could easily result in ‘hung’ situations where rustup is asking for approval, which won’t be forthcoming. I think we have this for the initial install flow interactive questions already.

So maybe the guideline should be that rustup commands should never implicitly install, but invocations of the proxy should?

i would be happy with that. i originally wrote in this issue

I do not expect rustup to implicitly install in any case other than when rust-toolchain.toml is in the current directory. in fact, you can see that rustc +nightly does not implicitly install, only rustc by itself.

but i no longer feel as strongly about that; i only feel that—in the case where there’s no rust-toolchain.toml in the current directory—rustc and rustc +toolchain should be consistent with each other about whether they implicitly install.

@samestep makes some good points. So what was the rationale for not implicitly installing a toolchain?

  • #1397 argued that rustup show should not implicitly install a toolchain
  • #3943 argued that rustup --version should not implicitly install a toolchain

So maybe the guideline should be that rustup commands should never implicitly install, but invocations of the proxy should?

Oh for old powershell I’d do it like:

rustup show active-toolchain; if ($LASTEXITCODE -ne 0) { rustup toolchain install }

I am looking forward to this change, so thanks for working on it

re: breakage

Might I suggest adding the new behaviour (#3983), and then waiting a release or two before completely removing the implicit installs? My concern is having a path with some continuity; rustup toolchain install on <= 1.27.1 is an error, but after >= 1.28 it will be an error not to do so, leaving no grace period.

If there is need - perhaps some tool that is blocked waiting on the new behaviour - during the transitional period an extra flag could be added to opt-out of implicit installs, at the risk of some complexity. _https://github.com/rust-lang/rustup/pull/3985#issuecomment-2342313221_

@ickk It’s a perfectly reasonable suggestion. Let’s think about the available options together and find out how to do this properly.

Has that been changed recently? Or was it always an option to invoke rustup toolchain install without any arguments? Because it is highly non-obvious if going off what’s returned by rustup toolchain install --help.

@LukeMathWalker It’s a recent change in https://github.com/rust-lang/rustup/pull/3983. The actual syntax is suggested by @ChrisDenton IIRC.

We have also updated the help message:

> rustup --version
rustup 1.27.1+445 (15a7ec40f 2024-09-09)
[..]

> rustup toolchain install --help
Install or update the given toolchains, or by default the active toolchain

Usage: rustup[EXE] toolchain install [OPTIONS] [TOOLCHAIN]...
[..]

I’m just catching up with this whole conversation as a person who routinely relies on rustup show in Docker files to trigger a toolchain installation according to what’s inside the rust-toolchain.toml file.

What would be the recommended upgrade path for me? What command should I invoke after this update?

I explicitly don’t want to perform any compilation, so invoking cargo commands like check or build is not the way forward.

@LukeMathWalker You’d do rustup toolchain install/rustup install (without any arguments) to manually install the active toolchain starting from v1.28.0. I promise we’ll deliver the new release notes with a huge emphasis on this change.

rustup install

I think effectively no one is using main.

@djc That’s not entirely true: I use it as my daily driver :]

Note the use of “effectively”. 😉

(not reading up on the thread but as I was pinged) r-a would likely benefit from an explicit install step. I’m annoyed with checking out a repo that has a toolchain override in it just for r-a to hide the installation behind a fetching metadata step as its being installed while r-a invoked cargo metadata. Even better would be if we could query whether there is an override for the given dir so we could prompt the user (if desired, otherwise fallback to installing ourselves). Likewise was was said, having rustup management integration in the IDE would be nice as well (which would require querying more state about rustup things as well)

Oh also being able to query whether the toolchain for the dir needs to be installed of course

IMO if we introduce the need for rustup install where previously only cargo check was sufficient, or even if we introduce a prompt that asks for installation of the toolchain and users opt to run the suggested command or confirm the prompt like 99% of the time, then IMO we’ve made things worse for them.

The experience Daniel and I had over 5 or so years of supporting users here has been that rustup going out to the internet unpredictable is a significant problem.

Consider this breakdown instead:

  • IDE integrations’s can add code to manage the installed toolchain in a naive way very easily. IDE integrations -really- don’t behave well when versions change underneath them, so I think it will be better for everyone if this is a little more explicit. Not necessarily user-driven-selection, but rust-analyzer getting an error about an uninstalled toolchain - which it can then use to trigger an install and reload its state, is better than an implicit install that then leads to super confusing outcomes, after a user pulls a new version of something with a pinned nightly version. For instance.
  • CI - this is mixed, and has changed over the years. Now github includes rustup and a toolchain in their builder images. Some people will definitely need to make changes to their builds; many can probably make them a lot simpler, some will pay a small complexity tax
  • interactive use - this is where the most frustration I recall encountering was.
    • -most- users get stable installed when installing rustup, and this entire discussion is moot/irrelevant
    • some users will be working on, or download, crate sources that require a different toolchain version, and then will encounter this different behaviour

Separately, goenv, pyeng, nodenv - and others - all have an explicit model, and I haven’t seen any frustration at that on the 'net.

tl;dr, I think this is being over-thought! do we have any actual data of people using main and being unhappy with it?

So zooming out: IMO if we introduce the need for rustup install where previously only cargo check was sufficient, or even if we introduce a prompt that asks for installation of the toolchain and users opt to run the suggested command or confirm the prompt like 99% of the time, then IMO we’ve made things worse for them. So I wonder, do we think this is a likely scenario?

I actually think the case of running cargo via Rust-Analyzer is another good reason that implicit installations for common commands that it uses is a good thing, as a suggested command will not be as easily accessible when you’re running RA in your IDE and now it’s even more of a context switch.

(I think we should avoid mixing #988 into this issue – yes, that can happen, but it happens today and there would still be other ways it can happen if we require explicit toolchain installations.)

So I think there are like 5 paths potential ways to go:

  1. Released versions, toolchains are implicitly installed for rustup commands and the proxy
  2. Current main, toolchains are never implicitly installed, suggested command must be run by the user
  3. Some UX improvement: in terminals, prompt the user instead of requiring running the suggested command separately
  4. Partial rollback, clean boundary: rustup commands don’t implicitly install, proxy commands do
  5. Partial rollback, heuristics: rustup commands don’t implicitly install, “informational” proxy commands don’t implicitly install but other proxy commands do

After two more weeks of consideration, I still like (5) best:

  • Will do the expected thing in the common case (especially for inexperienced users)
  • Smoother experience than running a separate command or confirming a prompt
  • The heuristics probably won’t be too complex and won’t need a ton of maintenance over time
  • Closer to the current behavior so less likely to (negatively) surprise users

Downsides:

  • Heuristics introduce some additional complexity (maintenance over time)
  • Behavior is harder to fully understand
  • Implicit installation behavior might still be surprising to some users

We could also introduce a new environment variable (RUSTUP_IMPLICIT_INSTALL?) that could be used to disable implicit installations entirely which could help (separately from anything else).

@Veykril do you have opinions from the RA side of things?

So maybe the guideline should be that rustup commands should never implicitly install, but invocations of the proxy should?

@djc Hmmm, I’m afraid not, since that issue actually talked about the proxy.

That’s fair.

The current design is for maximal consistency and fewest surprises, as explained in #3635 (comment) (thanks, @jyn514!). I don’t think we should do different things for the proxy and for other rustup commands.

While optimizing for consistency and fewest surprises makes sense, I’m inclined to agree with @samestep that this might come at a non-trivial cost to developer experience, where cargo check requires a manual rustup invocation after someone updates the toolchain version in a rustup-toolchain.toml in your repo. I suppose this might happen with some regularity in projects that use nightly versions. So I don’t think it’s crazy to wonder about refined heuristics here.

@samestep in your experience, how often is the toolchain updated in projects you work on? Do you think it would still be prohibitive if the change was instead to put up an explicit prompt that you could just Enter on to move forward with installing the new toolchain?

Might make sense to have special handling for running the proxy with -V or --version?

Would you mind elaborating on this point? As I see it, there are other ways to make rustc (or other proxied binaries) print informational stuff other than the version info (e.g. rustc --print target-list) and whitelisting all that sounds too magical.

Not sure, allowlisting (I think we prefer to use “whitelisting” these days) both --version/-V and --print might still make sense? Or we could just decide that --version/-V is special because it is more often used as a sort of probe.

If the maintainers’ current plans are to remove implicit install behaviour altogether (that’s how this issue reads - I don’t necessarily agree with this, but w/e), a short message describing how to install the missing toolchain would pretty much be just as easy for the user

@ickk The message is already there, as per the description in https://github.com/rust-lang/rustup/pull/3985:

https://github.com/rust-lang/rustup/blob/e857897d74215c6f33db7b7360fbbb12a89b46b3/tests/suite/cli_v2.rs#L320-L336

If the maintainers’ current plans are to remove implicit install behaviour altogether (that’s how this issue reads - I don’t necessarily agree with this, but w/e), a short message describing how to install the missing toolchain would pretty much be just as easy for the user

I mean, I guess that’s pedantically true. But deciding on updating dependencies is totally Cargo’s domain.

that’s not what @samestep’s question is about, though. they’re asking about what version of cargo implicitly gets run when there’s a rust-toolchain file in that folder.

@samestep i don’t know; i haven’t been following this issue closely. you’d need to ask the rustup maintainers.

What would be the semantics here? Would it only install if there is a rust-toolchain.toml file or would it install any missing default toolchain?

@ChrisDenton My understanding is that it is expected to do anything rustc --version currently does before actually running that command on the corresponding rustc, it’s just that everything will become explicit now. So yes, this includes (and isn’t limited to) installing the toolchain specified in the rust-toolchain.toml file.

And presumably the rustup install alias.

Yes! As the two subcommands has been unified with #3596, that looks like a less painful move indeed. A single change for these two places!

@rami3l I’m not clear exactly where the plan is at on this, but with respect to this comment I think that convenience is how we got to the current place.

I believe it is much easier to write tools on top of very predictable systems, and that there is a convenience argument for implicit installs throughout. My suspicion (not validated via research) is that having no implicit installs, one command ensure that a toolchain is installed, is enough.

I have previously written about having one command to install, where an existing install is an error, and one to ensure an install, but I’m struggling to think of a place where the error ‘cannot install toolchain X, it is already installed’ would be useful. There is a clear nearby-case of linked toolchains where X can mean anything, but having a single command that errors when the linked path is different in that case, and has a --force override, seems like it would be sufficient.

@Doineann Thanks for your feedback! Yes, what you said is part of what we want to change with this issue, see the 2nd point.

sounds good to me 😃

@jyn514 Thanks a lot for filing this issue! I see basically two points being made here:

This is a nice suggestion, and I’m looking forward to implementing it 😃

  • running rustc afterwards implicitly reinstalls the toolchain. i do not expect rustup to implicitly install in any case other than when rust-toolchain.toml is in the current directory. in fact, you can see that rustc +nightly does not implicitly install, only rustc by itself.
  • running rustup --version also silently installs.

As for removing implicit installations, it’s already on our list (https://github.com/rust-lang/rustup/issues/3546#issuecomment-1831292725), but it seems to me that a separate issue hasn’t been created yet.

Would you mind if I split this issue into two so that they can be tracked separately? I personally suggest use #3546 to track the removal of implicit installations, and move the first point over to #3319. Does that sound okay to you?