1010
1111PRETTY_NAMES : Final = {"linux" : "Linux" , "macos" : "macOS" , "windows" : "Windows" }
1212
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+ ]
2418
2519
2620@functools .total_ordering
@@ -72,25 +66,28 @@ def auto_archs(platform: PlatformName) -> set[Architecture]:
7266 native_machine = platform_module .machine ()
7367
7468 # Cross-platform support. Used for --print-build-identifiers or docker builds.
75- host_platform = (
69+ host_platform : PlatformName = (
7670 "windows"
7771 if sys .platform .startswith ("win" )
7872 else ("macos" if sys .platform .startswith ("darwin" ) else "linux" )
7973 )
8074
81- result = set ( )
75+ native_architecture = Architecture ( native_machine )
8276
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 }
9491
9592 if platform == "linux" and Architecture .x86_64 in result :
9693 # x86_64 machines can run i686 containers
@@ -104,15 +101,21 @@ def auto_archs(platform: PlatformName) -> set[Architecture]:
104101 @staticmethod
105102 def all_archs (platform : PlatformName ) -> set [Architecture ]:
106103 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 },
110113 }
111114 return all_archs_map [platform ]
112115
113116 @staticmethod
114117 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 }
116119 auto_archs = Architecture .auto_archs (platform )
117120
118121 if bitness == "64" :
0 commit comments