From 7c5d0288626493242afd6d2a9d73fa1e77b7a021 Mon Sep 17 00:00:00 2001 From: Tshepang Mbambo Date: Thu, 1 Jan 2026 16:42:38 +0200 Subject: [PATCH] use tuple instead of triple for env overrides --- build.rs | 24 ++++++++++++++++++------ src/cli/self_update.rs | 2 +- src/dist/mod.rs | 12 ++++++++---- src/test/clitools.rs | 2 +- 4 files changed, 28 insertions(+), 12 deletions(-) diff --git a/build.rs b/build.rs index c56f9df520..9fee97e9c3 100644 --- a/build.rs +++ b/build.rs @@ -3,20 +3,32 @@ use std::env; use platforms::Platform; fn from_build() -> Result { - let triple = - env::var("RUSTUP_OVERRIDE_BUILD_TRIPLE").unwrap_or_else(|_| env::var("TARGET").unwrap()); - if Platform::ALL.iter().any(|p| p.target_triple == triple) { - Ok(triple) + let tuple = { + if let Ok(tuple) = env::var("RUSTUP_OVERRIDE_BUILD_TUPLE") { + tuple + } else if let Ok(tuple) = env::var("RUSTUP_OVERRIDE_BUILD_TRIPLE") { + tuple + } else if let Ok(tuple) = env::var("TARGET") { + tuple + } else { + panic!( + "Unable to get target tuple from environment; Be sure that TARGET env var, or its override, is set" + ) + } + }; + if Platform::ALL.iter().any(|p| p.target_triple == tuple) { + Ok(tuple) } else { - Err(triple) + Err(tuple) } } fn main() { + println!("cargo::rerun-if-env-changed=RUSTUP_OVERRIDE_BUILD_TUPLE"); println!("cargo::rerun-if-env-changed=RUSTUP_OVERRIDE_BUILD_TRIPLE"); println!("cargo::rerun-if-env-changed=TARGET"); match from_build() { - Ok(triple) => eprintln!("Computed build based on target tuple: {triple:#?}"), + Ok(tuple) => eprintln!("Computed build based on target tuple: {tuple:#?}"), Err(s) => { eprintln!("Unable to parse target '{s}' as a known target tuple"); eprintln!( diff --git a/src/cli/self_update.rs b/src/cli/self_update.rs index e37dc2556f..483fa42d60 100644 --- a/src/cli/self_update.rs +++ b/src/cli/self_update.rs @@ -1285,7 +1285,7 @@ pub(crate) async fn prepare_update(dl_cfg: &DownloadCfg<'_>) -> Result Self { - if let Some(triple) = option_env!("RUSTUP_OVERRIDE_BUILD_TRIPLE") { - Self::new(triple) + if let Some(tuple) = option_env!("RUSTUP_OVERRIDE_BUILD_TUPLE") { + Self::new(tuple) + } else if let Some(tuple) = option_env!("RUSTUP_OVERRIDE_BUILD_TRIPLE") { + Self::new(tuple) } else { Self::new(env!("TARGET")) } @@ -549,8 +551,10 @@ impl TargetTriple { host_triple.map(TargetTriple::new) } - if let Ok(triple) = process.var("RUSTUP_OVERRIDE_HOST_TRIPLE") { - Some(Self(triple)) + if let Ok(tuple) = process.var("RUSTUP_OVERRIDE_HOST_TUPLE") { + Some(Self(tuple)) + } else if let Ok(tuple) = process.var("RUSTUP_OVERRIDE_HOST_TRIPLE") { + Some(Self(tuple)) } else { inner() } diff --git a/src/test/clitools.rs b/src/test/clitools.rs index 87c8e76151..8fa17c09cf 100644 --- a/src/test/clitools.rs +++ b/src/test/clitools.rs @@ -280,7 +280,7 @@ impl Config { format!("file://{}", distdir.to_string_lossy()), ); cmd.env("CARGO_HOME", self.cargodir.to_string_lossy().to_string()); - cmd.env("RUSTUP_OVERRIDE_HOST_TRIPLE", this_host_triple()); + cmd.env("RUSTUP_OVERRIDE_HOST_TUPLE", this_host_triple()); // These are used in some installation tests that unset RUSTUP_HOME/CARGO_HOME cmd.env("HOME", self.homedir.to_string_lossy().to_string());