Skip to content

Commit

Permalink
Add support for thumbv7em with hard float (#1871)
Browse files Browse the repository at this point in the history
* Fix triple mapping error handling

* Add thumbv7em and eabihf to triple mapping

* Add thumbv7em and eabihf to triple mapping

* Add thumbv7em and eabihf to triple mapping

* Add documentation

* Fix formatting

* refactor cpu_arch_to_constraints interface
  • Loading branch information
Codetector1374 authored Mar 15, 2023
1 parent b3cd596 commit 9e9853d
Showing 1 changed file with 29 additions and 7 deletions.
36 changes: 29 additions & 7 deletions rust/platform/triple_mappings.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ _CPU_ARCH_TO_BUILTIN_PLAT_SUFFIX = {
"s390": None,
"s390x": "s390x",
"thumbv6m": "armv6-m",
"thumbv7em": "armv7e-m",
"thumbv7m": "armv7-m",
"wasm32": None,
"x86_64": "x86_64",
Expand All @@ -81,6 +82,7 @@ _SYSTEM_TO_BUILTIN_SYS_SUFFIX = {
"darwin": "osx",
"dragonfly": None,
"eabi": "none",
"eabihf": "none",
"emscripten": None,
"freebsd": "freebsd",
"fuchsia": "fuchsia",
Expand All @@ -100,6 +102,7 @@ _SYSTEM_TO_BINARY_EXT = {
"android": "",
"darwin": "",
"eabi": "",
"eabihf": "",
"emscripten": ".js",
"freebsd": "",
"fuchsia": "",
Expand All @@ -118,6 +121,7 @@ _SYSTEM_TO_STATICLIB_EXT = {
"android": ".a",
"darwin": ".a",
"eabi": ".a",
"eabihf": ".a",
"emscripten": ".js",
"freebsd": ".a",
"fuchsia": ".a",
Expand All @@ -133,6 +137,7 @@ _SYSTEM_TO_DYLIB_EXT = {
"android": ".so",
"darwin": ".dylib",
"eabi": ".so",
"eabihf": ".so",
"emscripten": ".js",
"freebsd": ".so",
"fuchsia": ".so",
Expand All @@ -157,6 +162,7 @@ _SYSTEM_TO_STDLIB_LINKFLAGS = {
"darwin": ["-lSystem", "-lresolv"],
"dragonfly": ["-lpthread"],
"eabi": [],
"eabihf": [],
"emscripten": [],
# TODO(bazelbuild/rules_cc#75):
#
Expand Down Expand Up @@ -187,12 +193,25 @@ _SYSTEM_TO_STDLIB_LINKFLAGS = {
"windows": ["advapi32.lib", "ws2_32.lib", "userenv.lib", "Bcrypt.lib"],
}

def cpu_arch_to_constraints(cpu_arch):
plat_suffix = _CPU_ARCH_TO_BUILTIN_PLAT_SUFFIX[cpu_arch]
def cpu_arch_to_constraints(cpu_arch, *, system = None):
"""Returns a list of contraint values which represents a triple's CPU.
Args:
cpu_arch (str): The architecture to match constraints for
system (str, optional): The system for the associated ABI value.
if not plat_suffix:
Returns:
List: A list of labels to constraint values
"""
if cpu_arch not in _CPU_ARCH_TO_BUILTIN_PLAT_SUFFIX:
fail("CPU architecture \"{}\" is not supported by rules_rust".format(cpu_arch))

plat_suffix = _CPU_ARCH_TO_BUILTIN_PLAT_SUFFIX[cpu_arch]

# Patch armv7e-m to mf if hardfloat abi is selected
if plat_suffix == "armv7e-m" and system == "eabihf":
plat_suffix = "armv7e-mf"

return ["@platforms//cpu:{}".format(plat_suffix)]

def vendor_to_constraints(_vendor):
Expand All @@ -203,10 +222,10 @@ def vendor_to_constraints(_vendor):
return []

def system_to_constraints(system):
sys_suffix = _SYSTEM_TO_BUILTIN_SYS_SUFFIX[system]
if system not in _SYSTEM_TO_BUILTIN_SYS_SUFFIX:
fail("System \"{}\" is not supported by rules_rust".format(system))

if not sys_suffix:
fail("System \"{}\" is not supported by rules_rust".format(sys_suffix))
sys_suffix = _SYSTEM_TO_BUILTIN_SYS_SUFFIX[system]

return ["@platforms//os:{}".format(sys_suffix)]

Expand Down Expand Up @@ -342,7 +361,10 @@ def triple_to_constraint_set(target_triple):
triple_struct = triple(target_triple)

constraint_set = []
constraint_set += cpu_arch_to_constraints(triple_struct.arch)
constraint_set += cpu_arch_to_constraints(
triple_struct.arch,
system = triple_struct.system,
)
constraint_set += vendor_to_constraints(triple_struct.vendor)
constraint_set += system_to_constraints(triple_struct.system)
constraint_set += abi_to_constraints(
Expand Down

0 comments on commit 9e9853d

Please sign in to comment.