@@ -69,6 +69,7 @@ _CPU_ARCH_TO_BUILTIN_PLAT_SUFFIX = {
6969 "s390" : None ,
7070 "s390x" : "s390x" ,
7171 "thumbv6m" : "armv6-m" ,
72+ "thumbv7em" : "armv7e-m" ,
7273 "thumbv7m" : "armv7-m" ,
7374 "wasm32" : None ,
7475 "x86_64" : "x86_64" ,
@@ -81,6 +82,7 @@ _SYSTEM_TO_BUILTIN_SYS_SUFFIX = {
8182 "darwin" : "osx" ,
8283 "dragonfly" : None ,
8384 "eabi" : "none" ,
85+ "eabihf" : "none" ,
8486 "emscripten" : None ,
8587 "freebsd" : "freebsd" ,
8688 "fuchsia" : "fuchsia" ,
@@ -100,6 +102,7 @@ _SYSTEM_TO_BINARY_EXT = {
100102 "android" : "" ,
101103 "darwin" : "" ,
102104 "eabi" : "" ,
105+ "eabihf" : "" ,
103106 "emscripten" : ".js" ,
104107 "freebsd" : "" ,
105108 "fuchsia" : "" ,
@@ -118,6 +121,7 @@ _SYSTEM_TO_STATICLIB_EXT = {
118121 "android" : ".a" ,
119122 "darwin" : ".a" ,
120123 "eabi" : ".a" ,
124+ "eabihf" : ".a" ,
121125 "emscripten" : ".js" ,
122126 "freebsd" : ".a" ,
123127 "fuchsia" : ".a" ,
@@ -133,6 +137,7 @@ _SYSTEM_TO_DYLIB_EXT = {
133137 "android" : ".so" ,
134138 "darwin" : ".dylib" ,
135139 "eabi" : ".so" ,
140+ "eabihf" : ".so" ,
136141 "emscripten" : ".js" ,
137142 "freebsd" : ".so" ,
138143 "fuchsia" : ".so" ,
@@ -157,6 +162,7 @@ _SYSTEM_TO_STDLIB_LINKFLAGS = {
157162 "darwin" : ["-lSystem" , "-lresolv" ],
158163 "dragonfly" : ["-lpthread" ],
159164 "eabi" : [],
165+ "eabihf" : [],
160166 "emscripten" : [],
161167 # TODO(bazelbuild/rules_cc#75):
162168 #
@@ -187,12 +193,25 @@ _SYSTEM_TO_STDLIB_LINKFLAGS = {
187193 "windows" : ["advapi32.lib" , "ws2_32.lib" , "userenv.lib" , "Bcrypt.lib" ],
188194}
189195
190- def cpu_arch_to_constraints (cpu_arch ):
191- plat_suffix = _CPU_ARCH_TO_BUILTIN_PLAT_SUFFIX [cpu_arch ]
196+ def cpu_arch_to_constraints (cpu_arch , * , system = None ):
197+ """Returns a list of contraint values which represents a triple's CPU.
198+
199+ Args:
200+ cpu_arch (str): The architecture to match constraints for
201+ system (str, optional): The system for the associated ABI value.
192202
193- if not plat_suffix :
203+ Returns:
204+ List: A list of labels to constraint values
205+ """
206+ if cpu_arch not in _CPU_ARCH_TO_BUILTIN_PLAT_SUFFIX :
194207 fail ("CPU architecture \" {}\" is not supported by rules_rust" .format (cpu_arch ))
195208
209+ plat_suffix = _CPU_ARCH_TO_BUILTIN_PLAT_SUFFIX [cpu_arch ]
210+
211+ # Patch armv7e-m to mf if hardfloat abi is selected
212+ if plat_suffix == "armv7e-m" and system == "eabihf" :
213+ plat_suffix = "armv7e-mf"
214+
196215 return ["@platforms//cpu:{}" .format (plat_suffix )]
197216
198217def vendor_to_constraints (_vendor ):
@@ -203,10 +222,10 @@ def vendor_to_constraints(_vendor):
203222 return []
204223
205224def system_to_constraints (system ):
206- sys_suffix = _SYSTEM_TO_BUILTIN_SYS_SUFFIX [system ]
225+ if system not in _SYSTEM_TO_BUILTIN_SYS_SUFFIX :
226+ fail ("System \" {}\" is not supported by rules_rust" .format (system ))
207227
208- if not sys_suffix :
209- fail ("System \" {}\" is not supported by rules_rust" .format (sys_suffix ))
228+ sys_suffix = _SYSTEM_TO_BUILTIN_SYS_SUFFIX [system ]
210229
211230 return ["@platforms//os:{}" .format (sys_suffix )]
212231
@@ -342,7 +361,10 @@ def triple_to_constraint_set(target_triple):
342361 triple_struct = triple (target_triple )
343362
344363 constraint_set = []
345- constraint_set += cpu_arch_to_constraints (triple_struct .arch )
364+ constraint_set += cpu_arch_to_constraints (
365+ triple_struct .arch ,
366+ system = triple_struct .system ,
367+ )
346368 constraint_set += vendor_to_constraints (triple_struct .vendor )
347369 constraint_set += system_to_constraints (triple_struct .system )
348370 constraint_set += abi_to_constraints (
0 commit comments