Skip to content

Conversation

rami3l
Copy link
Member

@rami3l rami3l commented Aug 24, 2025

Closes #4445.

pub(crate) async fn from_local(
name: LocalToolchainName,
install_if_missing: bool,
install_if_missing: impl Fn() -> anyhow::Result<bool>,
Copy link
Member Author

@rami3l rami3l Aug 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change is made so that the self.should_auto_install() call is postponed to L64, and that the false positive in L60 can be suppressed.

@rami3l rami3l force-pushed the feat/warn-auto-install branch 7 times, most recently from b1d9725 to 8d25c01 Compare August 31, 2025 15:34
@rami3l rami3l marked this pull request as ready for review August 31, 2025 15:34
@rami3l rami3l marked this pull request as draft August 31, 2025 15:42
@rami3l rami3l force-pushed the feat/warn-auto-install branch 2 times, most recently from 39db6e4 to 7ab47c5 Compare September 1, 2025 12:05
@rami3l rami3l requested review from djc and ChrisDenton and removed request for djc September 1, 2025 12:07
@rami3l rami3l marked this pull request as ready for review September 1, 2025 12:07
Comment on lines 283 to 284
// Disable auto installation of active toolchain unless explicitly requested
cmd.env("RUSTUP_AUTO_INSTALL", "0");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure about this. IMO we should keep the defaults in the tests the same way they are when running real-world rustup, otherwise things get confusing.

Copy link
Member Author

@rami3l rami3l Sep 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@djc FYI this line should be a proof, not a requirement: the changes in this commit modulo this line will continue to work even if RUSTUP_AUTO_INSTALL is set to 1 or not set at all. How about unsetting it here?

Copy link
Contributor

@djc djc Sep 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unsetting it seems okay to me, as that should make it similar to the default behavior.

Copy link
Member Author

@rami3l rami3l Sep 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@djc Hmmm technically those fixes did work but now we are creating a lot of noises in the snapshot tests 🤔
I will try to find a way out of this.

Copy link
Member Author

@rami3l rami3l Sep 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@djc How about introducing another env var to remove this warning without disabling auto install?

Update: Okay, I think this means that the evaluation of self.should_auto_install() is not lazy enough. I'll try to fix that first.

Copy link
Contributor

@djc djc Sep 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we ship it like this I am afraid that we will spam the users. How about making it less frequent by using a global flag to ensure it's only printed once per process, and providing an extra flag to disable these messages?

I'm struggle to remember all the context here. Can you be more specific about what you're proposing? (Maybe with some "screenshots"/mock shell transcripts?)

Copy link
Member Author

@rami3l rami3l Oct 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@djc Of course. To elaborate, what I was suggesting is that, while trying to fix this issue, it seemed that the warning message is happening more frequently than necessary, however it isn't, because we now have somewhat surprising behaviors like this:

> # beta is not installed

> RUSTUP_AUTO_INSTALL=1 rustup +beta target remove aarch64-apple-darwin
info: syncing channel updates for 'beta-aarch64-apple-darwin'
info: latest update on 2025-09-28, rust version 1.91.0-beta.4 (aa7859c0d 2025-09-27)
info: downloading component(s)
[...]

... and every time this happens, the warning message will show up with this patch.

I am afraid rectifying this will bring breaking changes, and at the same time, shipping this patch as-is will, as I said earlier, spam the users.

So I am suggesting that, if we want to land this, maybe we should find a way to automatically and/or manually disable these messages:

How about making it less frequent by using a global flag to ensure it's only printed once per process, and providing an extra flag to disable these messages?

For example RUSTUP_AUTO_INSTALL_WARN=0 will stop these messages from showing up, and a static variable static HAS_WARNED_AUTO_INSTALL will prevent these messages from showing up twice in a single run. I admit these are not very good solutions, but I'm proposing this here so that we might have a direction to move forward. Maybe you have better options in mind? I'd love to hear 👂

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

because we now have somewhat surprising behaviors like this:

If you mean that the surprising behavior is that a toolchain is installed when a command is invoked to remove a target, I guess we should fix that separately/maybe first?

I am afraid rectifying this will bring breaking changes, and at the same time, shipping this patch as-is will, as I said earlier, spam the users.

I think you've gotten a bit too risk averse after our auto install adventure. But spamming definitely bad.

For example RUSTUP_AUTO_INSTALL_WARN=0 will stop these messages from showing up, and a static variable static HAS_WARNED_AUTO_INSTALL will prevent these messages from showing up twice in a single run. I admit these are not very good solutions, but I'm proposing this here so that we might have a direction to move forward. Maybe you have better options in mind? I'd love to hear 👂

I'm definitely not excited about an environment variable to "configure" this behavior but static that will allow for rate limiting this makes sense to me. A little spam might be a good thing incentive to turn off auto installs!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you've gotten a bit too risk averse after our auto install adventure.

@djc Yes you can probably say that... Be assured that this behavior is a faithful reproduction of that in the old version:

> docker run --rm -it rust:alpine sh

> rustup --version
rustup 1.27.1 (54dd3d00f 2024-04-24)
info: This is the version for the rustup toolchain manager, not the rustc compiler.
info: The currently active `rustc` version is `rustc 1.81.0 (eeb90cda1 2024-09-04)`

> rustup +beta target remove aarch64-apple-darwin
info: syncing channel updates for 'beta-aarch64-unknown-linux-musl'
1007.6 KiB / 1007.6 KiB (100 %) 567.4 KiB/s in  1s ETA:  0s
info: latest update on 2025-09-28, rust version 1.91.0-beta.4 (aa7859c0d 2025-09-27)
info: downloading component 'cargo'
^C

I still think we should rectify the behavior and I don't mind doing a separate PR first for this, but indeed constantly breaking others' workflow did put me into self-doubt every now and then.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it's constantly and when it did happen we figured out a way forward pretty quickly. But, it's definitely time to start planning for a release again so our releases don't get too big. As team lead, I think you should take the lead on that.

@rami3l rami3l force-pushed the feat/warn-auto-install branch from 7ab47c5 to 2f50a0a Compare September 22, 2025 08:49
@rami3l rami3l force-pushed the feat/warn-auto-install branch from 2f50a0a to e22e682 Compare September 22, 2025 08:51
This commit ensures that every test case relying on the
`RUSTUP_AUTO_INSTALL` config option is explicitly setting it,
and every other test case will pass regardless of its value.
@rami3l rami3l force-pushed the feat/warn-auto-install branch from e22e682 to 2e5dd94 Compare September 22, 2025 08:55
@rami3l rami3l requested a review from djc September 22, 2025 08:57
@rami3l rami3l marked this pull request as draft September 22, 2025 14:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Show that a toolchain download is due to auto installation
2 participants