Skip to content

Commit

Permalink
There are 2 types of downloads:
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
alfiedotwtf committed Oct 28, 2024
1 parent 1b801e6 commit 62341f0
Showing 1 changed file with 33 additions and 37 deletions.
70 changes: 33 additions & 37 deletions src/target_triple.rs
Original file line number Diff line number Diff line change
@@ -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)]
Expand Down Expand Up @@ -53,40 +53,38 @@ impl TargetTriple {
}

pub fn from_component(component: &str) -> Result<Self> {
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}")))
}
}
}
Expand Down Expand Up @@ -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();
Expand All @@ -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();
Expand Down

0 comments on commit 62341f0

Please sign in to comment.