-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Hint that a new Rust release may be available #4869
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -47,6 +47,9 @@ | |
| - `RUSTUP_NO_BACKTRACE`. Disables backtraces on non-panic errors even when | ||
| `RUST_BACKTRACE` is set. | ||
|
|
||
| - `RUSTUP_RELEASE_HINT` (default: `1`). When set to `0`, suppresses the hint | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we have a strong reason to add this in addition to filesystem-based configuration? I am not a fan of the proliferation of environment variables that change rustup behavior.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @djc I don't think #4869 (comment) is considered "configuration" because it just notes the last timestamp the routine is run... |
||
| that is shown when a new stable Rust release is (likely) available. | ||
|
|
||
| - `RUSTUP_PERMIT_COPY_RENAME` *unstable*. When set, allows rustup to fall-back | ||
| to copying files if attempts to `rename` result in cross-device link | ||
| errors. These errors occur on OverlayFS, which is used by [Docker][dc]. This | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,7 +4,9 @@ use std::fmt::Display; | |
| use std::fs; | ||
| use std::io::{BufRead, Write}; | ||
| use std::path::Path; | ||
| use std::str::FromStr; | ||
| use std::sync::LazyLock; | ||
| use std::time::{SystemTime, UNIX_EPOCH}; | ||
| use std::{cmp, env}; | ||
|
|
||
| use anstyle::Style; | ||
|
|
@@ -17,15 +19,18 @@ use tracing_subscriber::{EnvFilter, Registry, reload::Handle}; | |
|
|
||
| use crate::{ | ||
| config::Cfg, | ||
| dist::{DistOptions, TargetTuple, ToolchainDesc}, | ||
| dist::{DistOptions, PartialToolchainDesc, TargetTuple, ToolchainDesc}, | ||
| errors::RustupError, | ||
| install::{InstallMethod, UpdateStatus}, | ||
| process::Process, | ||
| toolchain::{LocalToolchainName, Toolchain, ToolchainName}, | ||
| toolchain::{DistributableToolchain, LocalToolchainName, Toolchain, ToolchainName}, | ||
| utils::{self, ExitCode}, | ||
| }; | ||
|
|
||
| pub(crate) const WARN_COMPLETE_PROFILE: &str = "downloading with complete profile isn't recommended unless you are a developer of the rust language"; | ||
| const RELEASE_CYCLE_DAYS: i64 = 42; | ||
| const NOTIFY_INTERVAL_SECS: u64 = 24 * 60 * 60; | ||
| const FALLBACK_RELEASE_DATE: &str = "2026-04-17"; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For top-down style, these should be at the bottom of the module (current exceptions notwithstanding -- want to fix them up in a separate commit?). |
||
|
|
||
| pub(crate) fn confirm(question: &str, default: bool, process: &Process) -> Result<bool> { | ||
| write!(process.stdout().lock(), "{question} ")?; | ||
|
|
@@ -569,3 +574,61 @@ pub(super) fn update_console_filter( | |
| .expect("error reloading `EnvFilter` for console_logger"); | ||
| } | ||
| } | ||
|
|
||
| /// Notifies a user with a hint whenever a new Rust release is available. | ||
| /// This is only shown at max once per day and only if not in proxy mode. | ||
| pub(crate) fn notify_release(cfg: &Cfg<'_>) -> Result<()> { | ||
| if cfg.process.var("RUSTUP_RELEASE_HINT").ok().as_deref() == Some("0") { | ||
| return Ok(()); | ||
| } | ||
|
|
||
| let time_now = SystemTime::now() | ||
| .duration_since(UNIX_EPOCH) | ||
| .unwrap_or_default() | ||
| .as_secs(); | ||
|
|
||
| // Limit notifications to at most once per day. | ||
| // This is checked before loading the manifest to avoid unnecessary disk I/O. | ||
| let last_notified = cfg | ||
| .settings_file | ||
| .with(|s| Ok(s.last_release_notified_secs.unwrap_or(0)))?; | ||
| if time_now.saturating_sub(last_notified) < NOTIFY_INTERVAL_SECS { | ||
| return Ok(()); | ||
| } | ||
|
|
||
| let default_host = cfg.default_host_tuple()?; | ||
| let stable_desc = PartialToolchainDesc::from_str("stable")?.resolve(&default_host)?; | ||
| let distributable = DistributableToolchain::new(cfg, stable_desc) | ||
| .map_err(|e| anyhow!("stable toolchain unavailable: {e}"))?; | ||
| let release_date_str = distributable | ||
| .get_manifestation() | ||
| .and_then(|m| m.load_manifest()) | ||
| .ok() | ||
| .flatten() | ||
| .map(|m| m.date.clone()) | ||
| .unwrap_or_else(|| FALLBACK_RELEASE_DATE.to_owned()); | ||
|
Comment on lines
+603
to
+609
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IMO this combinator-heavy style makes it pretty hard to understand what's actually going on. Suggest using more actual |
||
|
|
||
| let today = chrono::DateTime::from_timestamp(time_now as i64, 0) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: suggest ditching the |
||
| .unwrap_or_default() | ||
| .date_naive(); | ||
|
|
||
| let release_date = chrono::NaiveDate::parse_from_str(&release_date_str, "%Y-%m-%d") | ||
| .map_err(|e| anyhow!("could not parse release date '{}': {e}", release_date_str))?; | ||
|
|
||
| // Skip the hint if fewer than 6 weeks have passed since the last known release. | ||
| if (today - release_date).num_days() < RELEASE_CYCLE_DAYS { | ||
| return Ok(()); | ||
| } | ||
|
|
||
| cfg.settings_file.with_mut(|s| { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I still think it might be harmful to write this in cc @Cloud0310 for potential interaction/collaboration regarding XDG.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agreed. Happy to collaborate with @Cloud0310 on this!
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @FranciscoTGouveia I don't think it should be in the For the moment I'll say just write it as a new file under |
||
| s.last_release_notified_secs = Some(time_now); | ||
| Ok(()) | ||
| })?; | ||
|
|
||
| writeln!( | ||
| cfg.process.stderr().lock(), | ||
| "hint: a new stable Rust release is available. Run `rustup update stable` to install it." | ||
| )?; | ||
|
|
||
| Ok(()) | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: I think it's a bit weird to start this with the negative case: cf. the documentation for
RUSTUP_AUTO_INSTALLright below.View changes since the review