10
10
11
11
PRETTY_NAMES : Final = {"linux" : "Linux" , "macos" : "macOS" , "windows" : "Windows" }
12
12
13
- ARCH_CATEGORIES : Final [dict [str , set [str ]]] = {
14
- "32" : {"i686" , "x86" },
15
- "64" : {"x86_64" , "AMD64" },
16
- "arm" : {"ARM64" , "aarch64" , "arm64" },
17
- }
18
-
19
- PLATFORM_CATEGORIES : Final [dict [PlatformName , set [str ]]] = {
20
- "linux" : {"i686" , "x86_64" , "aarch64" , "ppc64le" , "s390x" },
21
- "macos" : {"x86_64" , "arm64" , "universal2" },
22
- "windows" : {"x86" , "AMD64" , "ARM64" },
23
- }
13
+ ARCH_SYNONYMS : Final [list [dict [PlatformName , str | None ]]] = [
14
+ {"linux" : "x86_64" , "macos" : "x86_64" , "windows" : "AMD64" },
15
+ {"linux" : "i686" , "macos" : None , "windows" : "x86" },
16
+ {"linux" : "aarch64" , "macos" : "arm64" , "windows" : "ARM64" },
17
+ ]
24
18
25
19
26
20
@functools .total_ordering
@@ -72,25 +66,28 @@ def auto_archs(platform: PlatformName) -> set[Architecture]:
72
66
native_machine = platform_module .machine ()
73
67
74
68
# Cross-platform support. Used for --print-build-identifiers or docker builds.
75
- host_platform = (
69
+ host_platform : PlatformName = (
76
70
"windows"
77
71
if sys .platform .startswith ("win" )
78
72
else ("macos" if sys .platform .startswith ("darwin" ) else "linux" )
79
73
)
80
74
81
- result = set ( )
75
+ native_architecture = Architecture ( native_machine )
82
76
83
- # Replace native_machine with the matching machine for intel or arm
84
- if host_platform == platform :
85
- native_architecture = Architecture (native_machine )
86
- result .add (native_architecture )
87
- else :
88
- for arch_group in ARCH_CATEGORIES .values ():
89
- if native_machine in arch_group :
90
- possible_archs = arch_group & PLATFORM_CATEGORIES [platform ]
91
- if len (possible_archs ) == 1 :
92
- (cross_machine ,) = possible_archs
93
- result .add (Architecture (cross_machine ))
77
+ # we might need to rename the native arch to the machine we're running
78
+ # on, as the same arch can have different names on different platforms
79
+ if host_platform != platform :
80
+ for arch_synonym in ARCH_SYNONYMS :
81
+ if native_machine == arch_synonym .get (host_platform ):
82
+ synonym = arch_synonym [platform ]
83
+
84
+ if synonym is None :
85
+ # can't build anything on this platform
86
+ return set ()
87
+
88
+ native_architecture = Architecture (synonym )
89
+
90
+ result = {native_architecture }
94
91
95
92
if platform == "linux" and Architecture .x86_64 in result :
96
93
# x86_64 machines can run i686 containers
@@ -104,15 +101,21 @@ def auto_archs(platform: PlatformName) -> set[Architecture]:
104
101
@staticmethod
105
102
def all_archs (platform : PlatformName ) -> set [Architecture ]:
106
103
all_archs_map = {
107
- "linux" : {Architecture [item ] for item in PLATFORM_CATEGORIES ["linux" ]},
108
- "macos" : {Architecture [item ] for item in PLATFORM_CATEGORIES ["macos" ]},
109
- "windows" : {Architecture [item ] for item in PLATFORM_CATEGORIES ["windows" ]},
104
+ "linux" : {
105
+ Architecture .x86_64 ,
106
+ Architecture .i686 ,
107
+ Architecture .aarch64 ,
108
+ Architecture .ppc64le ,
109
+ Architecture .s390x ,
110
+ },
111
+ "macos" : {Architecture .x86_64 , Architecture .arm64 , Architecture .universal2 },
112
+ "windows" : {Architecture .x86 , Architecture .AMD64 , Architecture .ARM64 },
110
113
}
111
114
return all_archs_map [platform ]
112
115
113
116
@staticmethod
114
117
def bitness_archs (platform : PlatformName , bitness : Literal ["64" , "32" ]) -> set [Architecture ]:
115
- archs_32 = {Architecture [ item ] for item in ARCH_CATEGORIES [ "32" ] }
118
+ archs_32 = {Architecture . i686 , Architecture . x86 }
116
119
auto_archs = Architecture .auto_archs (platform )
117
120
118
121
if bitness == "64" :
0 commit comments