Skip to content

Commit

Permalink
Fix component URL if bundled within the forc tarball (#654)
Browse files Browse the repository at this point in the history
  • Loading branch information
alfiedotwtf committed Sep 29, 2024
1 parent 5905a32 commit 7be4618
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 37 deletions.
15 changes: 9 additions & 6 deletions component/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,12 +187,15 @@ impl Components {
Ok(executables)
}

pub fn is_distributed_by_forc(plugin_name: &str) -> bool {
let components = Self::from_toml(COMPONENTS_TOML).expect("Failed to parse components toml");
if let Some(forc) = components.component.get(FORC) {
return forc.executables.contains(&plugin_name.to_string());
};
false
pub fn is_distributed_by_forc(component: &str) -> bool {
Component::from_name(component)
.map(|comp| {
comp.name == FORC
|| Component::from_name(FORC)
.map(|forc| comp.tarball_prefix == forc.tarball_prefix)
.unwrap_or(false)
})
.unwrap_or(false)
}
}

Expand Down
59 changes: 28 additions & 31 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,37 @@ 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),
};
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}")))
}
_ => {
let architecture = match std::env::consts::ARCH {
"aarch64" | "x86_64" => std::env::consts::ARCH,
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 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),
};
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}")))
}
Ok(Self(format!("{architecture}-{vendor}-{os}")))
}
}
}

0 comments on commit 7be4618

Please # to comment.