From 62341f0c70bdef83683d93eeff198cad3bdfd2ce Mon Sep 17 00:00:00 2001 From: Alfie John Date: Mon, 28 Oct 2024 16:08:26 +1100 Subject: [PATCH] There are 2 types of downloads: 1. forc-binaries, which is of the format "{os}_{arch}" 2. Everything else, which is the standard "{arch}-{vendor}-{os}" Currently, we only use the "{os}_{arch}" URL if the component is forc, however the forc-binaries tarball contains plugins and executables not defined in the forc component. This PR extends the "{os}_{arch}" result to everything distributed from forc. --- src/target_triple.rs | 70 +++++++++++++++++++++----------------------- 1 file changed, 33 insertions(+), 37 deletions(-) diff --git a/src/target_triple.rs b/src/target_triple.rs index 8790a835..fd6c710d 100644 --- a/src/target_triple.rs +++ b/src/target_triple.rs @@ -1,5 +1,5 @@ use anyhow::{bail, Result}; -use component::{self, Component}; +use component::{self, Components}; use std::fmt; #[derive(Debug, Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Default)] @@ -53,40 +53,38 @@ impl TargetTriple { } pub fn from_component(component: &str) -> Result { - match Component::from_name(component).map(|c| c.name)?.as_str() { - component::FORC => { - let os = match std::env::consts::OS { - "macos" => "darwin", - "linux" => "linux", - unsupported_os => bail!("Unsupported os: {}", unsupported_os), - }; - let architecture = match std::env::consts::ARCH { - "aarch64" => "arm64", - "x86_64" => "amd64", - unsupported_arch => bail!("Unsupported architecture: {}", unsupported_arch), - }; - - Ok(Self(format!("{os}_{architecture}"))) - } - _ => { - let architecture = match std::env::consts::ARCH { - "aarch64" | "x86_64" => std::env::consts::ARCH, - unsupported_arch => bail!("Unsupported architecture: {}", unsupported_arch), - }; - - let vendor = match std::env::consts::OS { - "macos" => "apple", - _ => "unknown", - }; - - let os = match std::env::consts::OS { - "macos" => "darwin", - "linux" => "linux-gnu", - unsupported_os => bail!("Unsupported os: {}", unsupported_os), - }; - - Ok(Self(format!("{architecture}-{vendor}-{os}"))) - } + if Components::is_distributed_by_forc(component) { + let os = match std::env::consts::OS { + "macos" => "darwin", + "linux" => "linux", + unsupported_os => bail!("Unsupported os: {}", unsupported_os), + }; + let architecture = match std::env::consts::ARCH { + "aarch64" => "arm64", + "x86_64" => "amd64", + unsupported_arch => bail!("Unsupported architecture: {}", unsupported_arch), + }; + + Ok(Self(format!("{os}_{architecture}"))) + } + else { + let architecture = match std::env::consts::ARCH { + "aarch64" | "x86_64" => std::env::consts::ARCH, + unsupported_arch => bail!("Unsupported architecture: {}", unsupported_arch), + }; + + let vendor = match std::env::consts::OS { + "macos" => "apple", + _ => "unknown", + }; + + let os = match std::env::consts::OS { + "macos" => "darwin", + "linux" => "linux-gnu", + unsupported_os => bail!("Unsupported os: {}", unsupported_os), + }; + + Ok(Self(format!("{architecture}-{vendor}-{os}"))) } } } @@ -114,7 +112,6 @@ mod test_from_component { } #[test] - #[should_panic] // TODO: #654 will fix this fn plugins() { for plugin in Components::collect_plugins().unwrap() { let component = Component::from_name(&plugin.name).unwrap(); @@ -124,7 +121,6 @@ mod test_from_component { } #[test] - #[should_panic] // TODO: #654 will fix this fn executables() { for executable in Components::collect_plugin_executables().unwrap() { let components = Components::collect().unwrap();