Skip to content

Commit 4c2deb0

Browse files
committed
Improve FreeBSD tag construction
1 parent f59d00b commit 4c2deb0

File tree

3 files changed

+68
-41
lines changed

3 files changed

+68
-41
lines changed

crates/uv-distribution-types/src/prioritized_distribution.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -902,7 +902,7 @@ fn implied_platform_markers(filename: &WheelFilename) -> MarkerTree {
902902
tag_marker.and(MarkerTree::expression(MarkerExpression::String {
903903
key: MarkerValueString::PlatformMachine,
904904
operator: MarkerOperator::Equal,
905-
value: ArcStr::from(arch.name()),
905+
value: ArcStr::from(arch.linux_name()),
906906
}));
907907
marker.or(tag_marker);
908908
}

crates/uv-platform-tags/src/platform.rs

Lines changed: 58 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -151,21 +151,7 @@ pub enum Arch {
151151

152152
impl fmt::Display for Arch {
153153
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
154-
match *self {
155-
Self::Aarch64 => write!(f, "aarch64"),
156-
Self::Armv5TEL => write!(f, "armv5tel"),
157-
Self::Armv6L => write!(f, "armv6l"),
158-
Self::Armv7L => write!(f, "armv7l"),
159-
Self::Powerpc64Le => write!(f, "ppc64le"),
160-
Self::Powerpc64 => write!(f, "ppc64"),
161-
Self::Powerpc => write!(f, "ppc"),
162-
Self::X86 => write!(f, "i686"),
163-
Self::X86_64 => write!(f, "x86_64"),
164-
Self::S390X => write!(f, "s390x"),
165-
Self::LoongArch64 => write!(f, "loongarch64"),
166-
Self::Riscv64 => write!(f, "riscv64"),
167-
Self::Wasm32 => write!(f, "wasm32"),
168-
}
154+
write!(f, "{}", self.name())
169155
}
170156
}
171157

@@ -211,7 +197,7 @@ impl Arch {
211197
}
212198
}
213199

214-
/// Returns the canonical name of the architecture.
200+
/// Returns the standard name of the architecture in the Linux world.
215201
pub fn name(&self) -> &'static str {
216202
match self {
217203
Self::Aarch64 => "aarch64",
@@ -230,23 +216,61 @@ impl Arch {
230216
}
231217
}
232218

233-
/// Returns an iterator over all supported architectures.
234-
pub fn iter() -> impl Iterator<Item = Self> {
235-
[
236-
Self::Aarch64,
237-
Self::Armv5TEL,
238-
Self::Armv6L,
239-
Self::Armv7L,
240-
Self::Powerpc64Le,
241-
Self::Powerpc64,
242-
Self::Powerpc,
243-
Self::X86,
244-
Self::X86_64,
245-
Self::S390X,
246-
Self::LoongArch64,
247-
Self::Riscv64,
248-
]
249-
.iter()
250-
.copied()
219+
/// Returns the standard name of the architecture in the FreeBSD world.
220+
pub fn freebsd_name(&self) -> Option<&'static str> {
221+
match self {
222+
Self::Aarch64 => None,
223+
Self::Armv5TEL => Some("armv5"),
224+
Self::Armv6L => Some("armv6"),
225+
Self::Armv7L => Some("armv7"),
226+
Self::Powerpc64Le => Some("powerpc64le"),
227+
Self::Powerpc64 => Some("powerpc64"),
228+
Self::Powerpc => Some("powerpc"),
229+
Self::X86 => Some("i386"),
230+
Self::X86_64 => Some("amd64"),
231+
Self::S390X => None,
232+
Self::LoongArch64 => None,
233+
Self::Riscv64 => None,
234+
Self::Wasm32 => None,
235+
}
236+
}
237+
238+
/// Returns the standard name of the architecture in the NetBSD world.
239+
pub fn netbsd_name(&self) -> Option<&'static str> {
240+
match self {
241+
Self::Aarch64 => None,
242+
Self::Armv5TEL => Some("armv5"),
243+
Self::Armv6L => Some("armv6"),
244+
Self::Armv7L => Some("armv7"),
245+
Self::Powerpc64Le => Some("powerpc64le"),
246+
Self::Powerpc64 => Some("powerpc64"),
247+
Self::Powerpc => Some("powerpc"),
248+
Self::X86 => Some("i386"),
249+
Self::X86_64 => Some("amd64"),
250+
Self::S390X => None,
251+
Self::LoongArch64 => None,
252+
Self::Riscv64 => None,
253+
Self::Wasm32 => None,
254+
}
255+
}
256+
257+
258+
/// Returns the standard name of the architecture in the FreeBSD world.
259+
pub fn openbsd_name(&self) -> Option<&'static str> {
260+
match self {
261+
Self::Aarch64 => Some("arm64"),
262+
Self::Armv5TEL => Some("armv5"),
263+
Self::Armv6L => Some("armv6"),
264+
Self::Armv7L => Some("armv7"),
265+
Self::Powerpc64Le => Some("powerpc64le"),
266+
Self::Powerpc64 => Some("powerpc64"),
267+
Self::Powerpc => Some("powerpc"),
268+
Self::X86 => Some("i386"),
269+
Self::X86_64 => Some("amd64"),
270+
Self::S390X => None,
271+
Self::LoongArch64 => None,
272+
Self::Riscv64 => None,
273+
Self::Wasm32 => None,
274+
}
251275
}
252276
}

crates/uv-platform-tags/src/tags.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -553,22 +553,25 @@ fn compatible_tags(platform: &Platform) -> Result<Vec<PlatformTag>, PlatformErro
553553
}
554554
(Os::Windows, Arch::Aarch64) => vec![PlatformTag::WinArm64],
555555
(Os::FreeBsd { release }, arch) => {
556-
let release = release.replace(['.', '-'], "_");
557-
let release_arch = format!("{release}_{arch}");
556+
let release_tag = release.replace(['.', '-'], "_").to_lowercase();
557+
let arch_tag = arch.freebsd_name().unwrap_or(arch.name());
558+
let release_arch = format!("{release_tag}_{arch_tag}");
558559
vec![PlatformTag::FreeBsd {
559560
release_arch: SmallString::from(release_arch),
560561
}]
561562
}
562563
(Os::NetBsd { release }, arch) => {
563-
let release = release.replace(['.', '-'], "_");
564-
let release_arch = format!("{release}_{arch}");
564+
let release_tag = release.replace(['.', '-'], "_").to_lowercase();
565+
let arch_tag = arch.netbsd_name().unwrap_or(arch.name());
566+
let release_arch = format!("{release_tag}_{arch_tag}");
565567
vec![PlatformTag::NetBsd {
566568
release_arch: SmallString::from(release_arch),
567569
}]
568570
}
569571
(Os::OpenBsd { release }, arch) => {
570-
let release = release.replace(['.', '-'], "_");
571-
let release_arch = format!("{release}_{arch}");
572+
let release_tag = release.replace(['.', '-'], "_").to_lowercase();
573+
let arch_tag = arch.openbsd_name().unwrap_or(arch.name());
574+
let release_arch = format!("{release_tag}_{arch_tag}");
572575
vec![PlatformTag::OpenBsd {
573576
release_arch: SmallString::from(release_arch),
574577
}]

0 commit comments

Comments
 (0)