@@ -26,7 +26,7 @@ use crate::{
26
26
serde:: { sort_map_alphabetically, DeserializeFromStrUnchecked } ,
27
27
UrlWithTrailingSlash ,
28
28
} ,
29
- Channel , MatchSpec , Matches , NoArchType , PackageName , PackageUrl , ParseMatchSpecError ,
29
+ Arch , Channel , MatchSpec , Matches , NoArchType , PackageName , PackageUrl , ParseMatchSpecError ,
30
30
ParseStrictness , Platform , RepoDataRecord , VersionWithSource ,
31
31
} ;
32
32
@@ -93,7 +93,10 @@ pub trait RecordFromPath {
93
93
#[ sorted]
94
94
#[ derive( Debug , Deserialize , Serialize , Eq , PartialEq , Clone , Hash ) ]
95
95
pub struct PackageRecord {
96
- /// Optionally the architecture the package supports
96
+ /// Optionally the architecture the package supports. This is almost
97
+ /// always the second part of the `subdir` string. Except for `64` which
98
+ /// maps to `x86_64` and `32` which maps to `x86`. This will be `None` if
99
+ /// the package is `noarch`.
97
100
pub arch : Option < String > ,
98
101
99
102
/// The build string of the package
@@ -152,8 +155,11 @@ pub struct PackageRecord {
152
155
#[ serde( skip_serializing_if = "NoArchType::is_none" ) ]
153
156
pub noarch : NoArchType ,
154
157
155
- /// Optionally the platform the package supports
156
- pub platform : Option < String > , // Note that this does not match the [`Platform`] enum..
158
+ /// Optionally the platform the package supports.
159
+ /// Note that this does not match the [`Platform`] enum, but is only the first
160
+ /// part of the platform (e.g. `linux`, `osx`, `win`, ...).
161
+ /// The `subdir` field contains the `Platform` enum.
162
+ pub platform : Option < String > ,
157
163
158
164
/// Package identifiers of packages that are equivalent to this package but
159
165
/// from other ecosystems.
@@ -457,33 +463,17 @@ fn determine_subdir(
457
463
let platform = platform. ok_or ( ConvertSubdirError :: PlatformEmpty ) ?;
458
464
let arch = arch. ok_or ( ConvertSubdirError :: ArchEmpty ) ?;
459
465
460
- let plat = match platform. as_ref ( ) {
461
- "linux" => match arch. as_ref ( ) {
462
- "x86" => Ok ( Platform :: Linux32 ) ,
463
- "x86_64" => Ok ( Platform :: Linux64 ) ,
464
- "aarch64" => Ok ( Platform :: LinuxAarch64 ) ,
465
- "armv61" => Ok ( Platform :: LinuxArmV6l ) ,
466
- "armv71" => Ok ( Platform :: LinuxArmV7l ) ,
467
- "ppc64le" => Ok ( Platform :: LinuxPpc64le ) ,
468
- "ppc64" => Ok ( Platform :: LinuxPpc64 ) ,
469
- "s390x" => Ok ( Platform :: LinuxS390X ) ,
470
- _ => Err ( ConvertSubdirError :: NoKnownCombination { platform, arch } ) ,
471
- } ,
472
- "osx" => match arch. as_ref ( ) {
473
- "x86_64" => Ok ( Platform :: Osx64 ) ,
474
- "arm64" => Ok ( Platform :: OsxArm64 ) ,
475
- _ => Err ( ConvertSubdirError :: NoKnownCombination { platform, arch } ) ,
476
- } ,
477
- "windows" => match arch. as_ref ( ) {
478
- "x86" => Ok ( Platform :: Win32 ) ,
479
- "x86_64" => Ok ( Platform :: Win64 ) ,
480
- "arm64" => Ok ( Platform :: WinArm64 ) ,
481
- _ => Err ( ConvertSubdirError :: NoKnownCombination { platform, arch } ) ,
482
- } ,
483
- _ => Err ( ConvertSubdirError :: NoKnownCombination { platform, arch } ) ,
484
- } ?;
485
- // Convert back to Platform string which should correspond to known subdirs
486
- Ok ( plat. to_string ( ) )
466
+ match arch. parse :: < Arch > ( ) {
467
+ Ok ( arch) => {
468
+ let arch_str = match arch {
469
+ Arch :: X86 => "32" ,
470
+ Arch :: X86_64 => "64" ,
471
+ _ => arch. as_str ( ) ,
472
+ } ;
473
+ Ok ( format ! ( "{}-{}" , platform, arch_str) )
474
+ }
475
+ Err ( _) => Err ( ConvertSubdirError :: NoKnownCombination { platform, arch } ) ,
476
+ }
487
477
}
488
478
489
479
impl PackageRecord {
0 commit comments