@@ -51,13 +51,99 @@ class ArchType:
5151 spir64 = 37
5252 kalimba = 38
5353 shave = 39
54-
54+ # Do not assume that these are 1:1 mapping. This should follow
55+ # canonical naming conventions for arm, etc. architectures.
56+ # See apple/swift PR #608
57+ @staticmethod
58+ def to_string (value ):
59+ if value == ArchType .arm :
60+ return "armv7"
61+ if value == ArchType .armeb :
62+ return "armeb"
63+ if value == ArchType .aarch64 :
64+ return "aarch64"
65+ if value == ArchType .aarch64_be :
66+ return "aarch64_be"
67+ if value == ArchType .bpfel :
68+ return "bpfel"
69+ if value == ArchType .bpfeb :
70+ return "bpfeb"
71+ if value == ArchType .hexagon :
72+ return "hexagon"
73+ if value == ArchType .mips :
74+ return "mips"
75+ if value == ArchType .mipsel :
76+ return "mipsel"
77+ if value == ArchType .mips64 :
78+ return "mips64"
79+ if value == ArchType .mips64el :
80+ return "mips64el"
81+ if value == ArchType .msp430 :
82+ return "msp430"
83+ if value == ArchType .ppc :
84+ return "ppc"
85+ if value == ArchType .ppc64 :
86+ return "ppc64"
87+ if value == ArchType .ppc64le :
88+ return "ppc64le"
89+ if value == ArchType .r600 :
90+ return "r600"
91+ if value == ArchType .amdgcn :
92+ return "amdgcn"
93+ if value == ArchType .sparc :
94+ return "sparc"
95+ if value == ArchType .sparcv9 :
96+ return "sparcv9"
97+ if value == ArchType .sparcel :
98+ return "sparcel"
99+ if value == ArchType .systemz :
100+ return "systemz"
101+ if value == ArchType .tce :
102+ return "tce"
103+ if value == ArchType .thumb :
104+ return "armv7"
105+ if value == ArchType .thumbeb :
106+ return "thumbeb"
107+ if value == ArchType .x86 :
108+ return "i386"
109+ if value == ArchType .x86_64 :
110+ return "x86_64"
111+ if value == ArchType .xcore :
112+ return "xcore"
113+ if value == ArchType .nvptx :
114+ return "nvptx"
115+ if value == ArchType .nvptx64 :
116+ return "nvptx64"
117+ if value == ArchType .le32 :
118+ return "le32"
119+ if value == ArchType .le64 :
120+ return "le64"
121+ if value == ArchType .amdil :
122+ return "amdil"
123+ if value == ArchType .amdil64 :
124+ return "amdil64"
125+ if value == ArchType .hsail :
126+ return "hsail"
127+ if value == ArchType .hsail64 :
128+ return "hsail64"
129+ if value == ArchType .spir :
130+ return "spir"
131+ if value == ArchType .spir64 :
132+ return "spir64"
133+ if value == ArchType .kalimba :
134+ return "kalimba"
135+ if value == ArchType .shave :
136+ return "shave"
137+ return "unknown"
138+ # Not 1:1, See to_string
55139 @staticmethod
56140 def from_string (string ):
57- if string == "arm" :
58- return ArchType .arm
141+ # Match big endian arm first
59142 if string == "armeb" :
60143 return ArchType .armeb
144+ # Catch-all for little endian arm
145+ if "arm" in string :
146+ return ArchType .arm
61147 if string == "aarch64" :
62148 return ArchType .aarch64
63149 if string == "aarch64_be" :
@@ -223,8 +309,8 @@ class Vendor:
223309
224310class Target :
225311 triple = None
226- sdk = OSType . MacOSX
227- arch = ArchType . x86_64
312+ sdk = None
313+ arch = None
228314 executable_suffix = ""
229315 dynamic_library_prefix = "lib"
230316 dynamic_library_suffix = ".dylib"
@@ -242,20 +328,30 @@ def __init__(self, triple):
242328 self .sdk = OSType .Win32
243329 self .dynamic_library_suffix = ".dll"
244330 self .executable_suffix = ".exe"
331+ elif "darwin" in triple :
332+ self .sdk = OSType .MacOSX
333+ else :
334+ print ("Unknown platform" )
335+
245336 self .triple = triple
337+
246338 comps = triple .split ('-' )
247- ArchType .from_string (comps [0 ])
339+ self . arch = ArchType .from_string (comps [0 ])
248340
249341 @staticmethod
250342 def default ():
251- triple = platform .machine () + "-"
343+ arch = ArchType .from_string (platform .machine ())
344+ triple = ArchType .to_string (arch )
252345 if platform .system () == "Linux" :
253- triple += "linux-gnu"
346+ if arch == ArchType .arm :
347+ triple += "-linux-gnueabihf"
348+ else :
349+ triple += "-linux-gnu"
254350 elif platform .system () == "Darwin" :
255- triple += "apple-darwin"
351+ triple += "- apple-darwin"
256352 elif platform .system () == "FreeBSD" :
257- # Make this working on 10 as well.
258- triple += "freebsd11.0"
353+ # Make this work on 10 as well.
354+ triple += "- freebsd11.0"
259355 else :
260356 # TODO: This should be a bit more exhaustive
261357 print ("unknown host os" )
@@ -264,21 +360,17 @@ def default():
264360
265361 @property
266362 def swift_triple (self ):
267- triple = ""
268- if self .arch == ArchType .x86_64 :
269- triple = "x86_64"
270- else :
271- print ("unknown arch for swift" )
272- return None
363+ triple = ArchType .to_string (self .arch )
273364 if self .sdk == OSType .MacOSX :
274365 return None
275366 elif self .sdk == OSType .Linux :
276- triple += "-pc -linux"
367+ triple += "-unknown -linux"
277368 elif self .sdk == OSType .FreeBSD :
278369 triple += "-unknown-freebsd"
279370 else :
280371 print ("unknown sdk for swift" )
281372 return None
373+
282374 return triple
283375
284376 @property
@@ -296,13 +388,7 @@ def swift_sdk_name(self):
296388
297389 @property
298390 def swift_arch (self ):
299- arch = ""
300- if self .arch == ArchType .x86_64 :
301- arch = "x86_64"
302- else :
303- print ("unknown arch for swift" )
304- return None
305- return arch
391+ return ArchType .to_string (self .arch )
306392
307393class TargetConditional :
308394 _sdk = None
0 commit comments