Skip to content

Commit

Permalink
Use x64 arch as default
Browse files Browse the repository at this point in the history
  • Loading branch information
filiptibell committed Mar 25, 2024
1 parent c2f893a commit 8f068ab
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 25 deletions.
13 changes: 8 additions & 5 deletions lib/description/arch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,19 @@ const ARCH_KEYWORDS: [(Arch, &[&str]); 4] = [
/**
Enum representing a system architecture, such as x86-64 or ARM.
*/
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
#[non_exhaustive]
pub enum Arch {
// NOTE: The ordering here is important! Putting arm architectures before
// x86 architectures prioritizes native binaries on ARM systems over x86
// binaries, which would most likely get emulated (eg. Rosetta on macOS)
Arm64, // aka AArch64
X64, // aka x86-64, AMD64
Arm32, // aka ARMv7
X86, // aka i686
Arm64,
// NOTE: We use X64 as our default architecture, since it's the most common
// and tools that don't specify an architecture are most likely using x86-64.
#[default]
X64,
Arm32,
X86,
}

impl Arch {
Expand Down
22 changes: 2 additions & 20 deletions lib/description/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ pub use self::toolchain::Toolchain;
pub enum DescriptionParseError {
#[error("unknown OS, or no OS detected")]
OS,
#[error("unknown arch, or no arch detected")]
Arch,
}

/**
Expand Down Expand Up @@ -53,7 +51,7 @@ impl Description {
let search_string = search_string.as_ref();

let os = OS::detect(search_string)?;
let arch = Arch::detect(search_string)?;
let arch = Arch::detect(search_string).unwrap_or_default();
let toolchain = Toolchain::detect(search_string);

Some(Self {
Expand Down Expand Up @@ -125,7 +123,7 @@ impl FromStr for Description {
type Err = DescriptionParseError;
fn from_str(s: &str) -> Result<Self, Self::Err> {
let os = OS::detect(s).ok_or(DescriptionParseError::OS)?;
let arch = Arch::detect(s).ok_or(DescriptionParseError::Arch)?;
let arch = Arch::detect(s).unwrap_or_default();
let toolchain = Toolchain::detect(s);

Ok(Self {
Expand Down Expand Up @@ -325,20 +323,4 @@ mod tests {
);
}
}

#[test]
fn parse_from_str_invalid_arch() {
const INVALID_ARCH_STRINGS: &[&str] = &[
"windows-x66-unknown",
"macos-barch32-unknown",
"linux-riskyV-unknown",
"linux-unknown-unknown",
];
for description in INVALID_ARCH_STRINGS {
assert_eq!(
description.parse::<Description>(),
Err(DescriptionParseError::Arch)
);
}
}
}

0 comments on commit 8f068ab

Please sign in to comment.