diff --git a/src/cli/common.rs b/src/cli/common.rs index 11f8f698e5..66d2209609 100644 --- a/src/cli/common.rs +++ b/src/cli/common.rs @@ -17,7 +17,7 @@ use tracing_subscriber::{EnvFilter, Registry, reload::Handle}; use crate::{ config::Cfg, - dist::{DistOptions, TargetTriple, ToolchainDesc}, + dist::{DistOptions, TargetTuple, ToolchainDesc}, errors::RustupError, install::{InstallMethod, UpdateStatus}, process::Process, @@ -510,8 +510,8 @@ pub(crate) fn ignorable_error( /// - The `force_non_host` flag is set to `false`. pub(crate) fn check_non_host_toolchain( toolchain: String, - host_arch: &TargetTriple, - target_triple: &TargetTriple, + host_arch: &TargetTuple, + target_triple: &TargetTuple, force_non_host: bool, ) -> Result<()> { if force_non_host || host_arch.can_run(target_triple)? { @@ -531,10 +531,10 @@ pub(crate) fn warn_if_host_is_emulated(process: &Process) { if process.var("RUSTUP_CI").is_ok() { return; } - if TargetTriple::is_host_emulated() { + if TargetTuple::is_host_emulated() { warn!( "Rustup is not running natively. It's running under emulation of {}.", - TargetTriple::from_host_or_build(process) + TargetTuple::from_host_or_build(process) ); warn!( "For best compatibility and performance you should reinstall rustup for your native CPU." diff --git a/src/cli/rustup_mode.rs b/src/cli/rustup_mode.rs index 50d4da2c68..10c40e0e13 100644 --- a/src/cli/rustup_mode.rs +++ b/src/cli/rustup_mode.rs @@ -44,7 +44,7 @@ use crate::{ command, component_for_bin, config::{ActiveSource, Cfg}, dist::{ - AutoInstallMode, DistOptions, PartialToolchainDesc, Profile, TargetTriple, + AutoInstallMode, DistOptions, PartialToolchainDesc, Profile, TargetTuple, download::DownloadCfg, manifest::{Component, ComponentStatus, ManifestWithHash}, }, @@ -982,13 +982,13 @@ async fn update( if !names.is_empty() { for name in names { // This needs another pass to fix it all up - if name.has_triple() { - let host_arch = TargetTriple::from_host_or_build(cfg.process); - let target_triple = name.clone().resolve(&host_arch)?.target; + if name.has_tuple() { + let host_arch = TargetTuple::from_host_or_build(cfg.process); + let target_tuple = name.clone().resolve(&host_arch)?.target; common::check_non_host_toolchain( name.to_string(), &host_arch, - &target_triple, + &target_tuple, force_non_host, )?; } @@ -1363,7 +1363,7 @@ async fn target_add( .map(|target| { Component::new( "rust-std".to_string(), - Some(TargetTriple::new(target)), + Some(TargetTuple::new(target)), false, ) }) @@ -1386,7 +1386,7 @@ async fn target_remove( .await?; for target in targets { - let target = TargetTriple::new(target); + let target = TargetTuple::new(target); let default_target = cfg.get_default_host_triple()?; if target == default_target { warn!( @@ -1476,9 +1476,9 @@ async fn component_add( fn get_target( target: Option, distributable: &DistributableToolchain<'_>, -) -> Option { +) -> Option { target - .map(TargetTriple::new) + .map(TargetTuple::new) .or_else(|| Some(distributable.desc().target.clone())) } diff --git a/src/cli/self_update.rs b/src/cli/self_update.rs index 2ef4726955..d23d82bd62 100644 --- a/src/cli/self_update.rs +++ b/src/cli/self_update.rs @@ -60,7 +60,7 @@ use crate::{ }, config::Cfg, dist::{ - DistOptions, PartialToolchainDesc, Profile, TargetTriple, ToolchainDesc, + DistOptions, PartialToolchainDesc, Profile, TargetTuple, ToolchainDesc, download::DownloadCfg, }, download::download_file, @@ -96,7 +96,7 @@ use windows::{delete_rustup_and_cargo_home, do_add_to_path, do_remove_from_path} pub(crate) use windows::{run_update, self_replace}; pub(crate) struct InstallOpts<'a> { - pub default_host_triple: Option, + pub default_host_tuple: Option, pub default_toolchain: Option, pub profile: Profile, pub no_modify_path: bool, @@ -108,7 +108,7 @@ pub(crate) struct InstallOpts<'a> { impl InstallOpts<'_> { fn install(self, cfg: &mut Cfg<'_>) -> Result> { let Self { - default_host_triple, + default_host_tuple, default_toolchain, profile, no_modify_path: _no_modify_path, @@ -119,12 +119,12 @@ impl InstallOpts<'_> { cfg.set_profile(profile)?; - if let Some(default_host_triple) = &default_host_triple { - // Set host triple now as it will affect resolution of toolchain_str - info!("setting default host triple to {}", default_host_triple); - cfg.set_default_host_triple(default_host_triple.to_owned())?; + if let Some(default_host_tuple) = &default_host_tuple { + // Set host tuple now as it will affect resolution of toolchain_str + info!("setting default host tuple to {}", default_host_tuple); + cfg.set_default_host_triple(default_host_tuple.to_owned())?; } else { - info!("default host triple is {}", cfg.get_default_host_triple()?); + info!("default host tuple is {}", cfg.get_default_host_triple()?); } let user_specified_something = default_toolchain.is_some() @@ -195,12 +195,12 @@ impl InstallOpts<'_> { writeln!(process.stdout().lock())?; - self.default_host_triple = Some(common::question_str( - "Default host triple?", + self.default_host_tuple = Some(common::question_str( + "Default host tuple?", &self - .default_host_triple + .default_host_tuple .take() - .unwrap_or_else(|| TargetTriple::from_host_or_build(process).to_string()), + .unwrap_or_else(|| TargetTuple::from_host_or_build(process).to_string()), process, )?); @@ -232,18 +232,18 @@ impl InstallOpts<'_> { fn validate(&self, process: &Process) -> Result<()> { common::warn_if_host_is_emulated(process); - let host_triple = self - .default_host_triple + let host_tuple = self + .default_host_tuple .as_ref() - .map(TargetTriple::new) - .unwrap_or_else(|| TargetTriple::from_host_or_build(process)); + .map(TargetTuple::new) + .unwrap_or_else(|| TargetTuple::from_host_or_build(process)); let partial_channel = match &self.default_toolchain { None | Some(MaybeOfficialToolchainName::None) => { ResolvableToolchainName::try_from("stable")? } Some(MaybeOfficialToolchainName::Some(s)) => s.into(), }; - let resolved = partial_channel.resolve(&host_triple)?; + let resolved = partial_channel.resolve(&host_tuple)?; trace!("Successfully resolved installation toolchain as: {resolved}"); Ok(()) } @@ -567,8 +567,8 @@ pub(crate) async fn install( anyhow!( "Pre-checks for host and toolchain failed: {e}\n\ If you are unsure of suitable values, the 'stable' toolchain is the default.\n\ - Valid host triples look something like: {}", - TargetTriple::from_host_or_build(cfg.process) + Valid host tuples look something like: {}", + TargetTuple::from_host_or_build(cfg.process) ) })?; @@ -740,7 +740,7 @@ fn check_existence_of_settings_file(cfg: &Cfg<'_>) -> Result<()> { PartialToolchainDesc::from_str("stable")?.resolve(&cfg.get_default_host_triple()?)?; if default_toolchain != inferred.to_string() { warn!("rustup will install the default toolchain as specified in the settings file,"); - warn!("instead of the one inferred from the default host triple."); + warn!("instead of the one inferred from the default host tuple."); } Ok(()) } @@ -790,15 +790,15 @@ fn current_install_opts(opts: &InstallOpts<'_>, process: &Process) -> String { format!( r"Current installation options: -- ` `default host triple: `{}` +- ` `default host tuple: `{}` - ` `default toolchain: `{}` - ` `profile: `{}` - modify PATH variable: `{}` ", - opts.default_host_triple + opts.default_host_tuple .as_ref() - .map(TargetTriple::new) - .unwrap_or_else(|| TargetTriple::from_host_or_build(process)), + .map(TargetTuple::new) + .unwrap_or_else(|| TargetTuple::from_host_or_build(process)), opts.default_toolchain .as_ref() .map(ToString::to_string) @@ -817,18 +817,18 @@ fn warn_if_default_linker_missing(process: &Process) { return; }; - // If we have the host triple, attempt to determine the CC/linker path that + // If we have the host tuple, attempt to determine the CC/linker path that // `cc-rs` would use, as this is *usually* why we need a linker to invoke. // // Doing it this way allows us to correctly diagnose quirky systems like // solaris and illumos that use `gcc` rather than `cc` for historical reasons. - let cc_tool = TargetTriple::from_host(process).and_then(|triple| { + let cc_tool = TargetTuple::from_host(process).and_then(|tuple| { // Fill in some dummy settings for `Build`/`Tool` to be able to properly // give us the metadata we want cc::Build::new() .opt_level(0) - .target(&triple) - .host(&triple) + .target(&tuple) + .host(&tuple) .try_get_compiler() .ok() }); @@ -1299,8 +1299,8 @@ pub(crate) async fn prepare_update(dl_cfg: &DownloadCfg<'_>) -> Result) -> Result) -> Result, process: &Process) -> Option } use cc::windows_registry; - let host_triple = if let Some(trip) = opts.default_host_triple.as_ref() { - trip.to_owned() + let host_tuple = if let Some(tuple) = opts.default_host_tuple.as_ref() { + tuple.to_owned() } else { - TargetTriple::from_host_or_build(process).to_string() + TargetTuple::from_host_or_build(process).to_string() }; - let installing_msvc = host_triple.contains("msvc"); - let have_msvc = windows_registry::find_tool(&host_triple, "cl.exe").is_some(); + let installing_msvc = host_tuple.contains("msvc"); + let have_msvc = windows_registry::find_tool(&host_tuple, "cl.exe").is_some(); if installing_msvc && !have_msvc { // Visual Studio build tools are required. // If the user does not have Visual Studio installed and their host // machine is i686 or x86_64 then it's OK to try an auto install. // Otherwise a manual install will be required. let has_any_vs = windows_registry::find_vs_version().is_ok(); - let is_x86 = host_triple.contains("i686") || host_triple.contains("x86_64"); + let is_x86 = host_tuple.contains("i686") || host_tuple.contains("x86_64"); if is_x86 && !has_any_vs { Some(VsInstallPlan::Automatic) } else { diff --git a/src/cli/setup_mode.rs b/src/cli/setup_mode.rs index e3a64e06a0..178b1e7ee4 100644 --- a/src/cli/setup_mode.rs +++ b/src/cli/setup_mode.rs @@ -121,7 +121,7 @@ pub async fn main( update_console_filter(process, &console_filter, quiet, verbose); let opts = InstallOpts { - default_host_triple: default_host, + default_host_tuple: default_host, default_toolchain, profile, no_modify_path, diff --git a/src/config.rs b/src/config.rs index fdb45a0d9c..43c3e01db9 100644 --- a/src/config.rs +++ b/src/config.rs @@ -11,7 +11,7 @@ use tracing::{debug, info, trace, warn}; use crate::{ cli::{common, self_update::SelfUpdateMode}, dist::{ - self, AutoInstallMode, DistOptions, PartialToolchainDesc, Profile, TargetTriple, + self, AutoInstallMode, DistOptions, PartialToolchainDesc, Profile, TargetTuple, ToolchainDesc, }, errors::RustupError, @@ -636,7 +636,7 @@ impl<'a> Cfg<'a> { // Do not permit architecture/os selection in channels as // these are host specific and toolchain files are portable. if let ResolvableToolchainName::Official(name) = &toolchain_name - && name.has_triple() + && name.has_tuple() { // Permit fully qualified names IFF the toolchain is installed. TODO(robertc): consider // disabling this and backing out https://github.com/rust-lang/rustup/pull/2141 (but provide @@ -779,7 +779,7 @@ impl<'a> Cfg<'a> { ) -> Result<(UpdateStatus, Toolchain<'_>)> { common::check_non_host_toolchain( toolchain.to_string(), - &TargetTriple::from_host_or_build(self.process), + &TargetTuple::from_host_or_build(self.process), &toolchain.target, force_non_host, )?; @@ -901,7 +901,7 @@ impl<'a> Cfg<'a> { // against the 'stable' toolchain. This provides early errors // if the supplied triple is insufficient / bad. PartialToolchainDesc::from_str("stable")? - .resolve(&TargetTriple::new(host_triple.clone()))?; + .resolve(&TargetTuple::new(host_triple.clone()))?; self.settings_file.with_mut(|s| { s.default_host_triple = Some(host_triple); Ok(()) @@ -909,7 +909,7 @@ impl<'a> Cfg<'a> { } #[tracing::instrument(level = "trace", skip_all)] - pub(crate) fn get_default_host_triple(&self) -> Result { + pub(crate) fn get_default_host_triple(&self) -> Result { self.settings_file .with(|s| Ok(get_default_host_triple(s, self.process))) } @@ -980,11 +980,11 @@ impl Debug for Cfg<'_> { } } -fn get_default_host_triple(s: &Settings, process: &Process) -> TargetTriple { +fn get_default_host_triple(s: &Settings, process: &Process) -> TargetTuple { s.default_host_triple .as_ref() - .map(TargetTriple::new) - .unwrap_or_else(|| TargetTriple::from_host_or_build(process)) + .map(TargetTuple::new) + .unwrap_or_else(|| TargetTuple::from_host_or_build(process)) } fn no_toolchain_error(process: &Process) -> anyhow::Error { diff --git a/src/dist/manifest.rs b/src/dist/manifest.rs index 545d0b68b9..b3c2933d9a 100644 --- a/src/dist/manifest.rs +++ b/src/dist/manifest.rs @@ -23,7 +23,7 @@ use anyhow::{Context, Result, anyhow, bail}; use serde::{Deserialize, Serialize}; use crate::{ - dist::{Profile, TargetTriple, ToolchainDesc, config::Config}, + dist::{Profile, TargetTuple, ToolchainDesc, config::Config}, errors::RustupError, toolchain::DistributableToolchain, }; @@ -105,16 +105,16 @@ pub struct Package { #[serde(from = "TargetsMap", into = "TargetsMap")] pub enum PackageTargets { Wildcard(TargetedPackage), - Targeted(BTreeMap), + Targeted(BTreeMap), } #[derive(Deserialize, Serialize)] #[serde(transparent)] -struct TargetsMap(BTreeMap); +struct TargetsMap(BTreeMap); impl From for PackageTargets { fn from(mut map: TargetsMap) -> Self { - let wildcard = TargetTriple::new("*"); + let wildcard = TargetTuple::new("*"); match (map.0.len(), map.0.entry(wildcard)) { (1, Entry::Occupied(entry)) => Self::Wildcard(entry.remove()), (_, _) => Self::Targeted(map.0), @@ -127,7 +127,7 @@ impl From for TargetsMap { match targets { PackageTargets::Wildcard(tpkg) => { let mut map = BTreeMap::new(); - map.insert(TargetTriple::new("*"), tpkg); + map.insert(TargetTuple::new("*"), tpkg); Self(map) } PackageTargets::Targeted(tpkgs) => Self(tpkgs), @@ -264,7 +264,7 @@ pub struct HashedBinary { pub struct Component { pub pkg: String, #[serde(with = "component_target")] - pub target: Option, + pub target: Option, // Older Rustup distinguished between components (which are essential) and // extensions (which are not). #[serde(default)] @@ -288,11 +288,11 @@ impl Hash for Component { } mod component_target { - use super::{Result, TargetTriple}; + use super::{Result, TargetTuple}; use serde::{Deserialize, Deserializer, Serializer}; pub fn serialize( - target: &Option, + target: &Option, serializer: S, ) -> Result { serializer.serialize_str(match target { @@ -303,9 +303,9 @@ mod component_target { pub fn deserialize<'de, D: Deserializer<'de>>( deserializer: D, - ) -> Result, D::Error> { + ) -> Result, D::Error> { Ok(match Option::::deserialize(deserializer)? { - Some(s) if s != "*" => Some(TargetTriple::new(s)), + Some(s) if s != "*" => Some(TargetTuple::new(s)), _ => None, }) } @@ -344,7 +344,7 @@ impl Manifest { self.get_package("rust").map(|p| &*p.version) } - pub(crate) fn get_legacy_components(&self, target: &TargetTriple) -> Result> { + pub(crate) fn get_legacy_components(&self, target: &TargetTuple) -> Result> { // Build a profile from the components/extensions. let result = self .get_package("rust")? @@ -360,7 +360,7 @@ impl Manifest { pub fn get_profile_components( &self, profile: Profile, - target: &TargetTriple, + target: &TargetTuple, ) -> Result> { // An older manifest with no profiles section. if self.profiles.is_empty() { @@ -462,7 +462,7 @@ impl Manifest { for component in &targ_pkg.components { let installed = component.contained_within(&config.components); - let component_target = TargetTriple::new(component.target()); + let component_target = TargetTuple::new(component.target()); // Get the component so we can check if it is available let component_pkg = self @@ -493,7 +493,7 @@ impl Manifest { } impl Package { - pub fn get_target(&self, target: Option<&TargetTriple>) -> Result<&TargetedPackage> { + pub fn get_target(&self, target: Option<&TargetTuple>) -> Result<&TargetedPackage> { match &self.targets { PackageTargets::Wildcard(tpkg) => Ok(tpkg), PackageTargets::Targeted(tpkgs) => { @@ -511,13 +511,13 @@ impl Package { } impl PackageTargets { - pub(crate) fn get<'a>(&'a self, target: &TargetTriple) -> Option<&'a TargetedPackage> { + pub(crate) fn get<'a>(&'a self, target: &TargetTuple) -> Option<&'a TargetedPackage> { match self { Self::Wildcard(tpkg) => Some(tpkg), Self::Targeted(tpkgs) => tpkgs.get(target), } } - pub fn get_mut<'a>(&'a mut self, target: &TargetTriple) -> Option<&'a mut TargetedPackage> { + pub fn get_mut<'a>(&'a mut self, target: &TargetTuple) -> Option<&'a mut TargetedPackage> { match self { Self::Wildcard(tpkg) => Some(tpkg), Self::Targeted(tpkgs) => tpkgs.get_mut(target), @@ -532,7 +532,7 @@ impl TargetedPackage { } impl Component { - pub fn new(pkg: String, target: Option, is_extension: bool) -> Self { + pub fn new(pkg: String, target: Option, is_extension: bool) -> Self { Self { pkg, target, @@ -543,7 +543,7 @@ impl Component { pub(crate) fn try_new( name: &str, distributable: &DistributableToolchain<'_>, - fallback_target: Option<&TargetTriple>, + fallback_target: Option<&TargetTuple>, ) -> Result { let manifest = distributable.get_manifest()?; for component_status in distributable.components()? { @@ -649,7 +649,7 @@ impl fmt::Display for ManifestVersion { #[cfg(test)] mod tests { use crate::RustupError; - use crate::dist::TargetTriple; + use crate::dist::TargetTuple; use crate::dist::manifest::Manifest; // Example manifest from https://public.etherpad-mozilla.org/p/Rust-infra-work-week @@ -662,8 +662,8 @@ mod tests { #[test] fn parse_smoke_test() { - let x86_64_unknown_linux_gnu = TargetTriple::new("x86_64-unknown-linux-gnu"); - let x86_64_unknown_linux_musl = TargetTriple::new("x86_64-unknown-linux-musl"); + let x86_64_unknown_linux_gnu = TargetTuple::new("x86_64-unknown-linux-gnu"); + let x86_64_unknown_linux_musl = TargetTuple::new("x86_64-unknown-linux-musl"); let pkg = Manifest::parse(EXAMPLE).unwrap(); diff --git a/src/dist/manifestation.rs b/src/dist/manifestation.rs index 174307d5fd..50c5d821d7 100644 --- a/src/dist/manifestation.rs +++ b/src/dist/manifestation.rs @@ -24,7 +24,7 @@ use tracing::{debug, info, warn}; use crate::{ diskio::{Executor, IO_CHUNK_SIZE, get_executor, unpack_ram}, dist::{ - DEFAULT_DIST_SERVER, Profile, TargetTriple, ToolchainDesc, + DEFAULT_DIST_SERVER, Profile, TargetTuple, ToolchainDesc, component::{Components, DirectoryPackage, Transaction}, config::Config, download::{DownloadCfg, DownloadStatus, File}, @@ -42,7 +42,7 @@ pub(crate) const CONFIG_FILE: &str = "multirust-config.toml"; #[derive(Debug)] pub struct Manifestation { installation: Components, - target_triple: TargetTriple, + target_tuple: TargetTuple, } #[derive(Debug)] @@ -87,12 +87,12 @@ impl Manifestation { /// it will be created as needed. If there's an existing install /// then the rust-install installation format will be verified. A /// bad installer version is the only reason this will fail. - pub fn open(prefix: InstallPrefix, triple: TargetTriple) -> Result { - // TODO: validate the triple with the existing install as well + pub fn open(prefix: InstallPrefix, target_tuple: TargetTuple) -> Result { + // TODO: validate the tuple with the existing install as well // as the metadata format of the existing install Ok(Self { installation: Components::open(prefix)?, - target_triple: triple, + target_tuple, }) } @@ -146,7 +146,7 @@ impl Manifestation { { for component in &components { match &component.target { - Some(t) if t != &self.target_triple => warn!( + Some(t) if t != &self.target_tuple => warn!( "skipping unavailable component {} for target {}", new_manifest.short_name(component), t @@ -215,14 +215,14 @@ impl Manifestation { // Uninstall components for component in update.components_to_uninstall { match (implicit_modify, &component.target) { - (true, Some(t)) if t != &self.target_triple => { + (true, Some(t)) if t != &self.target_tuple => { info!( "removing previous version of component {} for target {}", new_manifest.short_name(&component), t ); } - (false, Some(t)) if t != &self.target_triple => { + (false, Some(t)) if t != &self.target_tuple => { info!( "removing component {} for target {}", new_manifest.short_name(&component), @@ -416,11 +416,11 @@ impl Manifestation { let url = new_manifest .iter() - .find(|u| u.contains(&format!("{}{}", self.target_triple, ".tar.gz"))); + .find(|u| u.contains(&format!("{}{}", self.target_tuple, ".tar.gz"))); if url.is_none() { return Err(anyhow!( "binary package was not provided for '{}'", - self.target_triple, + self.target_tuple, )); } // Only replace once. The cost is inexpensive. @@ -595,7 +595,7 @@ impl Update { ) -> Result { // The package to install. let rust_package = new_manifest.get_package("rust")?; - let rust_target_package = rust_package.get_target(Some(&manifestation.target_triple))?; + let rust_target_package = rust_package.get_target(Some(&manifestation.target_tuple))?; changes.check_invariants(config)?; @@ -609,7 +609,7 @@ impl Update { let looks_like_v1 = config.is_none() && !installed_components.is_empty(); if looks_like_v1 { let mut profile_components = new_manifest - .get_profile_components(Profile::Default, &manifestation.target_triple)?; + .get_profile_components(Profile::Default, &manifestation.target_tuple)?; starting_list.append(&mut profile_components); } @@ -689,7 +689,7 @@ impl Update { result.components_to_install.push(component.clone()); } else if changes.explicit_add_components.contains(component) { match &component.target { - Some(t) if t != &manifestation.target_triple => info!( + Some(t) if t != &manifestation.target_tuple => info!( "component {} for target {} is up to date", new_manifest.short_name(component), t, diff --git a/src/dist/manifestation/tests.rs b/src/dist/manifestation/tests.rs index 29e87b7cbf..00691c29c1 100644 --- a/src/dist/manifestation/tests.rs +++ b/src/dist/manifestation/tests.rs @@ -15,7 +15,7 @@ use url::Url; use crate::{ dist::{ - DEFAULT_DIST_SERVER, Profile, TargetTriple, ToolchainDesc, + DEFAULT_DIST_SERVER, Profile, TargetTuple, ToolchainDesc, download::{DownloadCfg, DownloadTracker}, manifest::{Component, Manifest}, manifestation::{Changes, Manifestation, UpdateStatus}, @@ -317,7 +317,7 @@ async fn rename_component() { let adds = [Component::new( "bonus".to_string(), - Some(TargetTriple::new("x86_64-apple-darwin")), + Some(TargetTuple::new("x86_64-apple-darwin")), true, )]; @@ -357,7 +357,7 @@ async fn rename_component_new() { let adds = [Component::new( "bobo".to_string(), - Some(TargetTriple::new("x86_64-apple-darwin")), + Some(TargetTuple::new("x86_64-apple-darwin")), true, )]; // Install the basics from day 1 @@ -635,7 +635,7 @@ async fn unavailable_component() { let cx = TestContext::new(Some(edit), GZOnly); let adds = [Component::new( "bonus".to_string(), - Some(TargetTriple::new("x86_64-apple-darwin")), + Some(TargetTuple::new("x86_64-apple-darwin")), true, )]; @@ -734,7 +734,7 @@ async fn removed_component() { let cx = TestContext::new(Some(edit), GZOnly); let adds = [Component::new( "bonus".to_string(), - Some(TargetTriple::new("x86_64-apple-darwin")), + Some(TargetTuple::new("x86_64-apple-darwin")), true, )]; @@ -785,12 +785,12 @@ async fn unavailable_components_is_target() { let adds = [ Component::new( "rust-std".to_string(), - Some(TargetTriple::new("i686-apple-darwin")), + Some(TargetTuple::new("i686-apple-darwin")), false, ), Component::new( "rust-std".to_string(), - Some(TargetTriple::new("i686-unknown-linux-gnu")), + Some(TargetTuple::new("i686-unknown-linux-gnu")), false, ), ]; @@ -905,12 +905,12 @@ async fn update_preserves_extensions() { let adds = vec![ Component::new( "rust-std".to_string(), - Some(TargetTriple::new("i686-apple-darwin")), + Some(TargetTuple::new("i686-apple-darwin")), false, ), Component::new( "rust-std".to_string(), - Some(TargetTriple::new("i686-unknown-linux-gnu")), + Some(TargetTuple::new("i686-unknown-linux-gnu")), false, ), ]; @@ -955,12 +955,12 @@ async fn add_extensions_for_initial_install() { let adds = vec![ Component::new( "rust-std".to_string(), - Some(TargetTriple::new("i686-apple-darwin")), + Some(TargetTuple::new("i686-apple-darwin")), false, ), Component::new( "rust-std".to_string(), - Some(TargetTriple::new("i686-unknown-linux-gnu")), + Some(TargetTuple::new("i686-unknown-linux-gnu")), false, ), ]; @@ -984,12 +984,12 @@ async fn add_extensions_for_same_manifest() { let adds = vec![ Component::new( "rust-std".to_string(), - Some(TargetTriple::new("i686-apple-darwin")), + Some(TargetTuple::new("i686-apple-darwin")), false, ), Component::new( "rust-std".to_string(), - Some(TargetTriple::new("i686-unknown-linux-gnu")), + Some(TargetTuple::new("i686-unknown-linux-gnu")), false, ), ]; @@ -1018,12 +1018,12 @@ async fn add_extensions_for_upgrade() { let adds = vec![ Component::new( "rust-std".to_string(), - Some(TargetTriple::new("i686-apple-darwin")), + Some(TargetTuple::new("i686-apple-darwin")), false, ), Component::new( "rust-std".to_string(), - Some(TargetTriple::new("i686-unknown-linux-gnu")), + Some(TargetTuple::new("i686-unknown-linux-gnu")), false, ), ]; @@ -1046,7 +1046,7 @@ async fn add_extension_not_in_manifest() { let cx = TestContext::new(None, GZOnly); let adds = vec![Component::new( "rust-bogus".to_string(), - Some(TargetTriple::new("i686-apple-darwin")), + Some(TargetTuple::new("i686-apple-darwin")), true, )]; @@ -1059,7 +1059,7 @@ async fn add_extension_that_is_required_component() { let cx = TestContext::new(None, GZOnly); let adds = vec![Component::new( "rustc".to_string(), - Some(TargetTriple::new("x86_64-apple-darwin")), + Some(TargetTuple::new("x86_64-apple-darwin")), false, )]; @@ -1081,7 +1081,7 @@ async fn add_extensions_does_not_remove_other_components() { let adds = vec![Component::new( "rust-std".to_string(), - Some(TargetTriple::new("i686-apple-darwin")), + Some(TargetTuple::new("i686-apple-darwin")), false, )]; @@ -1097,7 +1097,7 @@ async fn remove_extensions_for_initial_install() { let cx = TestContext::new(None, GZOnly); let removes = vec![Component::new( "rustc".to_string(), - Some(TargetTriple::new("x86_64-apple-darwin")), + Some(TargetTuple::new("x86_64-apple-darwin")), false, )]; @@ -1110,12 +1110,12 @@ async fn remove_extensions_for_same_manifest() { let adds = vec![ Component::new( "rust-std".to_string(), - Some(TargetTriple::new("i686-apple-darwin")), + Some(TargetTuple::new("i686-apple-darwin")), false, ), Component::new( "rust-std".to_string(), - Some(TargetTriple::new("i686-unknown-linux-gnu")), + Some(TargetTuple::new("i686-unknown-linux-gnu")), false, ), ]; @@ -1124,7 +1124,7 @@ async fn remove_extensions_for_same_manifest() { let removes = vec![Component::new( "rust-std".to_string(), - Some(TargetTriple::new("i686-apple-darwin")), + Some(TargetTuple::new("i686-apple-darwin")), false, )]; @@ -1148,12 +1148,12 @@ async fn remove_extensions_for_upgrade() { let adds = vec![ Component::new( "rust-std".to_string(), - Some(TargetTriple::new("i686-apple-darwin")), + Some(TargetTuple::new("i686-apple-darwin")), false, ), Component::new( "rust-std".to_string(), - Some(TargetTriple::new("i686-unknown-linux-gnu")), + Some(TargetTuple::new("i686-unknown-linux-gnu")), false, ), ]; @@ -1164,7 +1164,7 @@ async fn remove_extensions_for_upgrade() { let removes = vec![Component::new( "rust-std".to_string(), - Some(TargetTriple::new("i686-apple-darwin")), + Some(TargetTuple::new("i686-apple-darwin")), false, )]; @@ -1193,7 +1193,7 @@ async fn remove_extension_not_in_manifest() { let removes = vec![Component::new( "rust-bogus".to_string(), - Some(TargetTriple::new("i686-apple-darwin")), + Some(TargetTuple::new("i686-apple-darwin")), true, )]; @@ -1227,7 +1227,7 @@ async fn remove_extension_not_in_manifest_but_is_already_installed() { let adds = [Component::new( "bonus".to_string(), - Some(TargetTriple::new("x86_64-apple-darwin")), + Some(TargetTuple::new("x86_64-apple-darwin")), true, )]; cx.update_from_dist(&adds, &[], false).await.unwrap(); @@ -1237,7 +1237,7 @@ async fn remove_extension_not_in_manifest_but_is_already_installed() { let removes = vec![Component::new( "bonus".to_string(), - Some(TargetTriple::new("x86_64-apple-darwin")), + Some(TargetTuple::new("x86_64-apple-darwin")), true, )]; cx.update_from_dist(&[], &removes, false).await.unwrap(); @@ -1251,7 +1251,7 @@ async fn remove_extension_that_is_required_component() { let removes = vec![Component::new( "rustc".to_string(), - Some(TargetTriple::new("x86_64-apple-darwin")), + Some(TargetTuple::new("x86_64-apple-darwin")), false, )]; @@ -1266,7 +1266,7 @@ async fn remove_extension_not_installed() { let removes = vec![Component::new( "rust-std".to_string(), - Some(TargetTriple::new("i686-apple-darwin")), + Some(TargetTuple::new("i686-apple-darwin")), false, )]; @@ -1282,7 +1282,7 @@ async fn remove_extensions_does_not_remove_other_components() { let cx = TestContext::new(None, GZOnly); let adds = vec![Component::new( "rust-std".to_string(), - Some(TargetTriple::new("i686-apple-darwin")), + Some(TargetTuple::new("i686-apple-darwin")), false, )]; @@ -1290,7 +1290,7 @@ async fn remove_extensions_does_not_remove_other_components() { let removes = vec![Component::new( "rust-std".to_string(), - Some(TargetTriple::new("i686-apple-darwin")), + Some(TargetTuple::new("i686-apple-darwin")), false, )]; @@ -1309,7 +1309,7 @@ async fn remove_extensions_does_not_hang_with_concurrent_downloads_override() { let adds = vec![Component::new( "rust-std".to_string(), - Some(TargetTriple::new("i686-apple-darwin")), + Some(TargetTuple::new("i686-apple-darwin")), false, )]; @@ -1317,7 +1317,7 @@ async fn remove_extensions_does_not_hang_with_concurrent_downloads_override() { let removes = vec![Component::new( "rust-std".to_string(), - Some(TargetTriple::new("i686-apple-darwin")), + Some(TargetTuple::new("i686-apple-darwin")), false, )]; @@ -1333,7 +1333,7 @@ async fn add_and_remove_for_upgrade() { let adds = vec![Component::new( "rust-std".to_string(), - Some(TargetTriple::new("i686-unknown-linux-gnu")), + Some(TargetTuple::new("i686-unknown-linux-gnu")), false, )]; @@ -1343,13 +1343,13 @@ async fn add_and_remove_for_upgrade() { let adds = vec![Component::new( "rust-std".to_string(), - Some(TargetTriple::new("i686-apple-darwin")), + Some(TargetTuple::new("i686-apple-darwin")), false, )]; let removes = vec![Component::new( "rust-std".to_string(), - Some(TargetTriple::new("i686-unknown-linux-gnu")), + Some(TargetTuple::new("i686-unknown-linux-gnu")), false, )]; @@ -1371,7 +1371,7 @@ async fn add_and_remove() { let adds = vec![Component::new( "rust-std".to_string(), - Some(TargetTriple::new("i686-unknown-linux-gnu")), + Some(TargetTuple::new("i686-unknown-linux-gnu")), false, )]; @@ -1379,13 +1379,13 @@ async fn add_and_remove() { let adds = vec![Component::new( "rust-std".to_string(), - Some(TargetTriple::new("i686-apple-darwin")), + Some(TargetTuple::new("i686-apple-darwin")), false, )]; let removes = vec![Component::new( "rust-std".to_string(), - Some(TargetTriple::new("i686-unknown-linux-gnu")), + Some(TargetTuple::new("i686-unknown-linux-gnu")), false, )]; @@ -1408,13 +1408,13 @@ async fn add_and_remove_same_component() { let adds = vec![Component::new( "rust-std".to_string(), - Some(TargetTriple::new("i686-apple-darwin")), + Some(TargetTuple::new("i686-apple-darwin")), false, )]; let removes = vec![Component::new( "rust-std".to_string(), - Some(TargetTriple::new("i686-apple-darwin")), + Some(TargetTuple::new("i686-apple-darwin")), false, )]; diff --git a/src/dist/mod.rs b/src/dist/mod.rs index 185f903a9b..5bd0449e0a 100644 --- a/src/dist/mod.rs +++ b/src/dist/mod.rs @@ -44,8 +44,8 @@ use prefix::InstallPrefix; pub mod temp; -pub(crate) mod triple; -pub(crate) use triple::*; +pub(crate) mod target_tuple; +pub(crate) use target_tuple::*; pub static DEFAULT_DIST_SERVER: &str = "https://static.rust-lang.org"; @@ -140,17 +140,17 @@ struct ParsedToolchainDesc { /// A toolchain descriptor from rustup's perspective. These contain /// 'partial target tuples', which allow toolchain names like /// 'stable-msvc' to work. Partial target tuples though are parsed -/// from a hardcoded set of known triples, whereas target tuples +/// from a hardcoded set of known tuples, whereas target tuples /// are nearly-arbitrary strings. #[derive(Debug, Clone, Eq, PartialEq, PartialOrd, Ord)] pub struct PartialToolchainDesc { pub channel: Channel, pub date: Option, - pub target: PartialTargetTriple, + pub target: PartialTargetTuple, } /// Fully-resolved toolchain descriptors. These always have full target -/// triples attached to them and are used for canonical identification, +/// tuples attached to them and are used for canonical identification, /// such as naming their installation directory. /// /// As strings they look like stable-x86_64-pc-windows-msvc or @@ -159,7 +159,7 @@ pub struct PartialToolchainDesc { pub struct ToolchainDesc { pub channel: Channel, pub date: Option, - pub target: TargetTriple, + pub target: TargetTuple, } #[derive(Debug, Clone, Eq, PartialEq, PartialOrd, Ord)] @@ -247,7 +247,7 @@ impl FromStr for PartialVersion { #[derive(Debug, Clone, Deserialize, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize)] #[serde(transparent)] -pub struct TargetTriple(String); +pub struct TargetTuple(String); // Linux hosts don't indicate clib in uname, however binaries only // run on boxes with the same clib, as expected. @@ -341,7 +341,7 @@ impl FromStr for ParsedToolchainDesc { } } -impl Deref for TargetTriple { +impl Deref for TargetTuple { type Target = str; fn deref(&self) -> &Self::Target { &self.0 @@ -371,7 +371,7 @@ fn is_32bit_userspace() -> bool { inner().unwrap_or(cfg!(target_pointer_width = "32")) } -impl TargetTriple { +impl TargetTuple { pub fn new(name: impl Into) -> Self { Self(name.into()) } @@ -410,7 +410,7 @@ impl TargetTriple { pub(crate) fn from_host(process: &Process) -> Option { #[cfg(windows)] - fn inner() -> Option { + fn inner() -> Option { use std::mem; /// Get the host architecture using `IsWow64Process2`. This function @@ -481,12 +481,12 @@ impl TargetTriple { // Default to msvc let arch = arch_primary().or_else(arch_fallback)?; - let msvc_triple = format!("{arch}-pc-windows-msvc"); - Some(TargetTriple(msvc_triple)) + let msvc_tuple = format!("{arch}-pc-windows-msvc"); + Some(TargetTuple(msvc_tuple)) } #[cfg(not(windows))] - fn inner() -> Option { + fn inner() -> Option { use std::ffi::CStr; use std::mem; @@ -504,7 +504,7 @@ impl TargetTriple { }; #[cfg(not(target_os = "android"))] - let host_triple = match (sysname, machine) { + let host_tuple = match (sysname, machine) { (b"Linux", b"x86_64") => Some(TRIPLE_X86_64_UNKNOWN_LINUX), (b"Linux", b"i686") => Some("i686-unknown-linux-gnu"), (b"Linux", b"mips") => Some(TRIPLE_MIPS_UNKNOWN_LINUX_GNU), @@ -538,7 +538,7 @@ impl TargetTriple { }; #[cfg(target_os = "android")] - let host_triple = match (sysname, machine) { + let host_tuple = match (sysname, machine) { (_, b"arm") => Some("arm-linux-androideabi"), (_, b"armv7l") => Some("armv7-linux-androideabi"), (_, b"armv8l") => Some("armv7-linux-androideabi"), @@ -548,7 +548,7 @@ impl TargetTriple { _ => None, }; - host_triple.map(TargetTriple::new) + host_tuple.map(TargetTuple::new) } if let Ok(tuple) = process.var("RUSTUP_OVERRIDE_HOST_TUPLE") { @@ -564,15 +564,15 @@ impl TargetTriple { Self::from_host(process).unwrap_or_else(Self::from_build) } - pub(crate) fn can_run(&self, other: &TargetTriple) -> Result { + pub(crate) fn can_run(&self, other: &TargetTuple) -> Result { // Most trivial shortcut of all if self == other { return Ok(true); } // Otherwise we need to parse things - let partial_self = PartialTargetTriple::new(&self.0) + let partial_self = PartialTargetTuple::new(&self.0) .ok_or_else(|| anyhow!(format!("Unable to parse target tuple: {}", self.0)))?; - let partial_other = PartialTargetTriple::new(&other.0) + let partial_other = PartialTargetTuple::new(&other.0) .ok_or_else(|| anyhow!(format!("Unable to parse target tuple: {}", other.0)))?; // First obvious check is OS, if that doesn't match there's no chance let ret = if partial_self.os != partial_other.os { @@ -597,7 +597,7 @@ impl FromStr for PartialToolchainDesc { type Err = anyhow::Error; fn from_str(name: &str) -> Result { let parsed: ParsedToolchainDesc = name.parse()?; - let target = PartialTargetTriple::new(parsed.target.as_deref().unwrap_or("")); + let target = PartialTargetTuple::new(parsed.target.as_deref().unwrap_or("")); target .map(|target| Self { @@ -611,10 +611,10 @@ impl FromStr for PartialToolchainDesc { impl PartialToolchainDesc { /// Create a toolchain desc using input_host to fill in missing fields - pub(crate) fn resolve(self, input_host: &TargetTriple) -> Result { - let host = PartialTargetTriple::new(&input_host.0).ok_or_else(|| { + pub(crate) fn resolve(self, input_host: &TargetTuple) -> Result { + let host = PartialTargetTuple::new(&input_host.0).ok_or_else(|| { anyhow!(format!( - "Provided host '{}' couldn't be converted to partial triple", + "Provided host '{}' couldn't be converted to partial tuple", input_host.0 )) })?; @@ -651,11 +651,11 @@ impl PartialToolchainDesc { Ok(ToolchainDesc { channel: self.channel, date: self.date, - target: TargetTriple(trip), + target: TargetTuple(trip), }) } - pub(crate) fn has_triple(&self) -> bool { + pub(crate) fn has_tuple(&self) -> bool { self.target.arch.is_some() || self.target.os.is_some() || self.target.env.is_some() } } @@ -672,7 +672,7 @@ impl FromStr for ToolchainDesc { Ok(Self { channel: parsed.channel, date: parsed.date, - target: TargetTriple(parsed.target.unwrap()), + target: TargetTuple(parsed.target.unwrap()), }) } } @@ -834,7 +834,7 @@ impl fmt::Display for AutoInstallMode { } } -impl fmt::Display for TargetTriple { +impl fmt::Display for TargetTuple { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { self.0.fmt(f) } @@ -1195,8 +1195,8 @@ async fn try_update_from_dist_( } for &target in targets { - let triple = TargetTriple::new(target); - all_components.insert(Component::new("rust-std".to_string(), Some(triple), false)); + let tuple = TargetTuple::new(target); + all_components.insert(Component::new("rust-std".to_string(), Some(tuple), false)); } let mut explicit_add_components: Vec<_> = all_components.into_iter().collect(); @@ -1457,7 +1457,7 @@ mod tests { } #[test] - fn compatible_host_triples() { + fn compatible_host_tuples() { static CASES: &[(&str, &[&str], &[&str])] = &[ ( // 64bit linux @@ -1502,11 +1502,11 @@ mod tests { for &(host, compatible, incompatible) in CASES { println!("host={host}"); - let host = TargetTriple::new(host); + let host = TargetTuple::new(host); assert!(host.can_run(&host).unwrap(), "host wasn't self-compatible"); for &other in compatible.iter() { println!("compatible with {other}"); - let other = TargetTriple::new(other); + let other = TargetTuple::new(other); assert!( host.can_run(&other).unwrap(), "host and other were unexpectedly incompatible" @@ -1514,7 +1514,7 @@ mod tests { } for &other in incompatible.iter() { println!("incompatible with {other}"); - let other = TargetTriple::new(other); + let other = TargetTuple::new(other); assert!( !host.can_run(&other).unwrap(), "host and other were unexpectedly compatible" diff --git a/src/dist/triple.rs b/src/dist/target_tuple.rs similarity index 83% rename from src/dist/triple.rs rename to src/dist/target_tuple.rs index 34aff1475c..50a81878e3 100644 --- a/src/dist/triple.rs +++ b/src/dist/target_tuple.rs @@ -5,13 +5,13 @@ use regex::Regex; pub mod known; #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)] -pub struct PartialTargetTriple { +pub struct PartialTargetTuple { pub arch: Option, pub os: Option, pub env: Option, } -impl PartialTargetTriple { +impl PartialTargetTuple { pub(crate) fn new(name: &str) -> Option { if name.is_empty() { return Some(Self { @@ -22,7 +22,7 @@ impl PartialTargetTriple { } // Prepending `-` makes this next regex easier since - // we can count on all triple components being + // we can count on all tuple components being // delineated by it. let name = format!("-{name}"); static RE: LazyLock = LazyLock::new(|| { @@ -58,7 +58,7 @@ mod test { use super::*; #[test] - fn test_partial_target_triple_new() { + fn test_partial_target_tuple_new() { let success_cases = vec![ ("", (None, None, None)), ("i386", (Some("i386"), None, None)), @@ -74,19 +74,19 @@ mod test { ]; for (input, (arch, os, env)) in success_cases { - let partial_target_triple = PartialTargetTriple::new(input); + let partial_target_tuple = PartialTargetTuple::new(input); assert!( - partial_target_triple.is_some(), + partial_target_tuple.is_some(), "expected `{input}` to create some partial target tuple; got None" ); - let expected = PartialTargetTriple { + let expected = PartialTargetTuple { arch: arch.map(String::from), os: os.map(String::from), env: env.map(String::from), }; - assert_eq!(partial_target_triple.unwrap(), expected, "input: `{input}`"); + assert_eq!(partial_target_tuple.unwrap(), expected, "input: `{input}`"); } let failure_cases = vec![ @@ -104,10 +104,10 @@ mod test { ]; for input in failure_cases { - let partial_target_triple = PartialTargetTriple::new(input); + let partial_target_tuple = PartialTargetTuple::new(input); assert!( - partial_target_triple.is_none(), - "expected `{input}` to be `None`, was: `{partial_target_triple:?}`" + partial_target_tuple.is_none(), + "expected `{input}` to be `None`, was: `{partial_target_tuple:?}`" ); } } diff --git a/src/dist/triple/known.rs b/src/dist/target_tuple/known.rs similarity index 100% rename from src/dist/triple/known.rs rename to src/dist/target_tuple/known.rs diff --git a/src/errors.rs b/src/errors.rs index bae5793cff..748a0339fb 100644 --- a/src/errors.rs +++ b/src/errors.rs @@ -12,7 +12,7 @@ use url::Url; use crate::{ dist::{ - Channel, TargetTriple, ToolchainDesc, + Channel, TargetTuple, ToolchainDesc, manifest::{Component, Manifest}, }, toolchain::{PathBasedToolchainName, ToolchainName}, @@ -111,7 +111,7 @@ pub enum RustupError { )] ToolchainIncompatible { toolchain: String, - target_triple: TargetTriple, + target_triple: TargetTuple, }, #[error("toolchain '{0}' is not installable")] ToolchainNotInstallable(String), @@ -155,14 +155,14 @@ pub enum RustupError { suggest_message(.suggestion))] UnknownTarget { desc: ToolchainDesc, - target: TargetTriple, + target: TargetTuple, suggestion: Option, }, #[error("toolchain '{}' does not have target '{}' installed{}\n", .desc, .target, suggest_message(.suggestion))] TargetNotInstalled { desc: ToolchainDesc, - target: TargetTriple, + target: TargetTuple, suggestion: Option, }, #[error( diff --git a/src/test.rs b/src/test.rs index 97e5460cda..90ae4d12b6 100644 --- a/src/test.rs +++ b/src/test.rs @@ -20,7 +20,7 @@ use std::process::Command; use anyhow::Result; use sha2::{Digest, Sha256}; -use crate::dist::TargetTriple; +use crate::dist::TargetTuple; use crate::process::TestProcess; #[cfg(windows)] @@ -135,14 +135,14 @@ fn tempdir_in_with_prefix>(path: P, prefix: &str) -> io::Result

String { if cfg!(target_os = "windows") { // For windows, this host may be different to the target: we may be // building with i686 toolchain, but on an x86_64 host, so run the // actual detection logic and trust it. let tp = TestProcess::default(); - return TargetTriple::from_host(&tp.process).unwrap().to_string(); + return TargetTuple::from_host(&tp.process).unwrap().to_string(); } let arch = if cfg!(target_arch = "x86") { "i686" diff --git a/src/test/dist.rs b/src/test/dist.rs index 48ba91b0d0..09a4c59e7a 100644 --- a/src/test/dist.rs +++ b/src/test/dist.rs @@ -13,7 +13,7 @@ use super::clitools::hard_link; use super::mock::MockInstallerBuilder; use super::{CROSS_ARCH1, CROSS_ARCH2, MULTI_ARCH1, create_hash, this_host_tuple}; use crate::dist::{ - DEFAULT_DIST_SERVER, Profile, TargetTriple, + DEFAULT_DIST_SERVER, Profile, TargetTuple, component::{Components, DirectoryPackage, Transaction}, manifest::{ Component, CompressionKind, HashedBinary, Manifest, ManifestVersion, Package, @@ -836,12 +836,12 @@ impl MockDistServer { for component in &target.components { tpkg.components.push(Component { pkg: component.name.to_owned(), - target: Some(TargetTriple::new(&component.target)), + target: Some(TargetTuple::new(&component.target)), is_extension: component.is_extension, }); } - targets.insert(TargetTriple::new(&target.target), tpkg); + targets.insert(TargetTuple::new(&target.target), tpkg); } manifest.packages.insert( diff --git a/src/toolchain.rs b/src/toolchain.rs index f13ef0aaf3..2dc0b23506 100644 --- a/src/toolchain.rs +++ b/src/toolchain.rs @@ -23,7 +23,7 @@ use crate::{ RustupError, config::{ActiveSource, Cfg, InstalledPath}, dist::{ - DistOptions, PartialToolchainDesc, TargetTriple, + DistOptions, PartialToolchainDesc, TargetTuple, component::{Component, Components}, prefix::InstallPrefix, }, @@ -588,14 +588,14 @@ impl<'a> Toolchain<'a> { } /// Get the list of installed targets for any toolchain - pub fn installed_targets(&self) -> anyhow::Result> { + pub fn installed_targets(&self) -> anyhow::Result> { Ok(self .installed_components()? .into_iter() .filter_map(|c| { c.name() .strip_prefix("rust-std-") - .map(|triple| TargetTriple::new(triple.to_string())) + .map(|triple| TargetTuple::new(triple.to_string())) }) .collect()) } diff --git a/src/toolchain/names.rs b/src/toolchain/names.rs index b9ea7404d4..f8f4a9208a 100644 --- a/src/toolchain/names.rs +++ b/src/toolchain/names.rs @@ -50,7 +50,7 @@ use std::{ use thiserror::Error; -use crate::dist::{PartialToolchainDesc, TargetTriple, ToolchainDesc}; +use crate::dist::{PartialToolchainDesc, TargetTuple, ToolchainDesc}; /// Errors related to toolchains #[derive(Error, Debug)] @@ -139,7 +139,7 @@ pub(crate) enum ResolvableToolchainName { impl ResolvableToolchainName { /// Resolve to a concrete toolchain name - pub fn resolve(&self, host: &TargetTriple) -> Result { + pub fn resolve(&self, host: &TargetTuple) -> Result { match self.clone() { ResolvableToolchainName::Custom(c) => Ok(ToolchainName::Custom(c)), ResolvableToolchainName::Official(desc) => { @@ -296,7 +296,7 @@ pub(crate) enum ResolvableLocalToolchainName { impl ResolvableLocalToolchainName { /// Resolve to a concrete toolchain name - pub fn resolve(&self, host: &TargetTriple) -> Result { + pub fn resolve(&self, host: &TargetTuple) -> Result { match self.clone() { ResolvableLocalToolchainName::Named(t) => { Ok(LocalToolchainName::Named(t.resolve(host)?)) @@ -482,7 +482,7 @@ mod tests { use crate::{ dist::{ PartialToolchainDesc, - triple::known::{LIST_ARCHS, LIST_ENVS, LIST_OSES}, + target_tuple::known::{LIST_ARCHS, LIST_ENVS, LIST_OSES}, }, toolchain::names::{CustomToolchainName, ResolvableToolchainName, ToolchainName}, }; diff --git a/tests/suite/cli_inst_interactive.rs b/tests/suite/cli_inst_interactive.rs index eb9cb40e60..0f793836fc 100644 --- a/tests/suite/cli_inst_interactive.rs +++ b/tests/suite/cli_inst_interactive.rs @@ -74,7 +74,7 @@ these changes will be reverted. Current installation options: - default host triple: [HOST_TUPLE] + default host tuple: [HOST_TUPLE] default toolchain: stable (default) profile: default modify PATH variable: no @@ -136,12 +136,12 @@ Rust is installed now. Great! } #[tokio::test] -async fn installer_shows_default_host_triple() { +async fn installer_shows_default_host_tuple() { let cx = CliTestContext::new(Scenario::SimpleV2).await; run_input(&cx.config, &["rustup-init", "--no-modify-path"], "2\n").with_stdout(snapbox::str![ [r#" ... -Default host triple? [[HOST_TUPLE]] +Default host tuple? [[HOST_TUPLE]] ... "#] ]); diff --git a/tests/suite/cli_rustup.rs b/tests/suite/cli_rustup.rs index 99f6aa8432..9581f8e23f 100644 --- a/tests/suite/cli_rustup.rs +++ b/tests/suite/cli_rustup.rs @@ -1599,13 +1599,13 @@ Default host: [HOST_TUPLE] // #846 #[tokio::test] -async fn set_default_host_invalid_triple() { +async fn set_default_host_invalid_tuple() { let cx = CliTestContext::new(Scenario::None).await; cx.config .expect(["rustup", "set", "default-host", "foo"]) .await .with_stderr(snapbox::str![[r#" -error: Provided host 'foo' couldn't be converted to partial triple +error: Provided host 'foo' couldn't be converted to partial tuple "#]]) .is_err(); @@ -1613,7 +1613,7 @@ error: Provided host 'foo' couldn't be converted to partial triple // #745 #[tokio::test] -async fn set_default_host_invalid_triple_valid_partial() { +async fn set_default_host_invalid_tuple_valid_partial() { let cx = CliTestContext::new(Scenario::None).await; cx.config .expect(["rustup", "set", "default-host", "x86_64-msvc"]) diff --git a/tests/suite/cli_v2.rs b/tests/suite/cli_v2.rs index fdd1d90e29..cfc84af3ed 100644 --- a/tests/suite/cli_v2.rs +++ b/tests/suite/cli_v2.rs @@ -5,7 +5,7 @@ use std::fs; use std::io::Write; use std::path::PathBuf; -use rustup::dist::TargetTriple; +use rustup::dist::TargetTuple; use rustup::dist::manifest::Manifest; use rustup::test::{ CROSS_ARCH1, CROSS_ARCH2, CliTestContext, Config, Scenario, create_hash, this_host_tuple, @@ -1930,7 +1930,7 @@ fn make_component_unavailable(config: &Config, name: &str, target: String) { let mut manifest = Manifest::parse(&manifest_str).unwrap(); { let std_pkg = manifest.packages.get_mut(name).unwrap(); - let target = TargetTriple::new(target); + let target = TargetTuple::new(target); let target_pkg = std_pkg.targets.get_mut(&target).unwrap(); target_pkg.bins = Vec::new(); } diff --git a/tests/suite/known_tuples.rs b/tests/suite/known_target_tuples.rs similarity index 73% rename from tests/suite/known_tuples.rs rename to tests/suite/known_target_tuples.rs index fd0b7385cc..34ea36bd66 100644 --- a/tests/suite/known_tuples.rs +++ b/tests/suite/known_target_tuples.rs @@ -3,12 +3,15 @@ use std::{collections::BTreeSet, io::Write}; use platforms::Platform; #[test] -fn gen_known_tuples() { - let out_path = "src/dist/triple/known.rs"; +fn gen_known_target_tuples() { + let out_path = "src/dist/target_tuple/known.rs"; let existing = std::fs::read_to_string(out_path).unwrap(); let (mut archs, mut oses, mut envs) = (BTreeSet::new(), BTreeSet::new(), BTreeSet::new()); - for (arch, os, env) in Platform::ALL.iter().map(|p| parse_triple(p.target_triple)) { + for (arch, os, env) in Platform::ALL + .iter() + .map(|p| parse_target_tuple(p.target_triple)) + { archs.insert(arch); oses.insert(os); if !env.is_empty() { @@ -50,12 +53,12 @@ fn gen_known_tuples() { } } -/// Parses the given triple into 3 parts (target architecture, OS and environment). +/// Parses the given target tuples into 3 parts (target architecture, OS and environment). /// /// # Discussion /// /// The current model of target tuples in Rustup requires some non-code knowledge to correctly generate the list. -/// For example, the parsing results of two 2-dash triples can be different: +/// For example, the parsing results of two 2-dash target tuples can be different: /// /// ```jsonc /// { arch: aarch64, os: linux, env: android } @@ -79,18 +82,18 @@ fn gen_known_tuples() { /// // for `x-y-z-w` /// { arch: x, os: y-z, env: w } /// ``` -fn parse_triple(triple: &str) -> (&str, &str, &str) { - match triple.split('-').collect::>()[..] { +fn parse_target_tuple(target_tuple: &str) -> (&str, &str, &str) { + match target_tuple.split('-').collect::>()[..] { [arch, os] => (arch, os, ""), [arch, os @ ("none" | "linux"), env] => (arch, os, env), - [arch, _, _] => (arch, &triple[(arch.len() + 1)..], ""), + [arch, _, _] => (arch, &target_tuple[(arch.len() + 1)..], ""), [arch, _, _, env] => ( arch, - &triple[(arch.len() + 1)..(triple.len() - env.len() - 1)], + &target_tuple[(arch.len() + 1)..(target_tuple.len() - env.len() - 1)], env, ), _ => panic!( - "Internal error while parsing target tuple `{triple}`, please file an issue at https://github.com/rust-lang/rustup/issues" + "Internal error while parsing target tuple `{target_tuple}`, please file an issue at https://github.com/rust-lang/rustup/issues" ), } } diff --git a/tests/suite/mod.rs b/tests/suite/mod.rs index 296102d67a..2fa175e633 100644 --- a/tests/suite/mod.rs +++ b/tests/suite/mod.rs @@ -9,5 +9,5 @@ mod cli_self_upd; mod cli_v1; mod cli_v2; mod dist_install; -mod known_tuples; +mod known_target_tuples; mod static_roots;