Skip to content

Commit 74bd3d1

Browse files
authored
Add the thumbv7em-none-eabihf target (#3875)
This change adds support for the `thumbv7em-none-eabihf` target in rules_rust platform mappings. Currently `rules_rust` does not support this target, preventing me from utilizing the FPU in a closed project. I ran into this issue when trying to build for a `STM32H725IG` (Cortex-M7F). It also adds a brief unit test for `thumbv7em-none-eabihf` triple parsing.
1 parent 2ce620a commit 74bd3d1

2 files changed

Lines changed: 7 additions & 2 deletions

File tree

rust/platform/triple_mappings.bzl

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,9 @@ SUPPORTED_T2_PLATFORM_TRIPLES = {
5959
"riscv64gc-unknown-linux-gnu": _support(std = True, host_tools = False),
6060
"riscv64gc-unknown-none-elf": _support(std = True, host_tools = False),
6161
"s390x-unknown-linux-gnu": _support(std = True, host_tools = True),
62+
"thumbv6m-none-eabi": _support(std = True, host_tools = False),
6263
"thumbv7em-none-eabi": _support(std = True, host_tools = False),
64+
"thumbv7em-none-eabihf": _support(std = True, host_tools = False),
6365
"thumbv8m.main-none-eabi": _support(std = True, host_tools = False),
6466
"wasm32-unknown-emscripten": _support(std = True, host_tools = False),
6567
"wasm32-unknown-unknown": _support(std = True, host_tools = False),
@@ -283,12 +285,13 @@ _SYSTEM_TO_STDLIB_LINKFLAGS = {
283285
"windows": ["advapi32.lib", "ws2_32.lib", "userenv.lib", "Bcrypt.lib"],
284286
}
285287

286-
def cpu_arch_to_constraints(cpu_arch, *, system = None):
288+
def cpu_arch_to_constraints(cpu_arch, *, system = None, abi = None):
287289
"""Returns a list of constraint values which represents a triple's CPU.
288290
289291
Args:
290292
cpu_arch (str): The architecture to match constraints for
291293
system (str, optional): The system for the associated ABI value.
294+
abi (str, optional): The application binary interface required for the target platform
292295
293296
Returns:
294297
List: A list of labels to constraint values
@@ -299,7 +302,7 @@ def cpu_arch_to_constraints(cpu_arch, *, system = None):
299302
plat_suffix = _CPU_ARCH_TO_BUILTIN_PLAT_SUFFIX[cpu_arch]
300303

301304
# Patch armv7e-m to mf if hardfloat abi is selected
302-
if plat_suffix == "armv7e-m" and system == "eabihf":
305+
if plat_suffix == "armv7e-m" and (system == "eabihf" or abi == "eabihf"):
303306
plat_suffix = "armv7e-mf"
304307

305308
return ["@platforms//cpu:{}".format(plat_suffix)]
@@ -463,6 +466,7 @@ def triple_to_constraint_set(target_triple):
463466
constraint_set += cpu_arch_to_constraints(
464467
triple_struct.arch,
465468
system = triple_struct.system,
469+
abi = triple_struct.abi,
466470
)
467471
constraint_set += vendor_to_constraints(triple_struct.vendor)
468472
constraint_set += system_to_constraints(triple_struct.system)

test/unit/platform_triple/platform_triple_test.bzl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ def _construct_known_triples_test_impl(ctx):
123123
_assert_parts(env, triple("aarch64-fuchsia"), "aarch64", "unknown", "fuchsia", None)
124124
_assert_parts(env, triple("aarch64-unknown-linux-musl"), "aarch64", "unknown", "linux", "musl")
125125
_assert_parts(env, triple("thumbv7em-none-eabi"), "thumbv7em", None, "none", "eabi")
126+
_assert_parts(env, triple("thumbv7em-none-eabihf"), "thumbv7em", None, "none", "eabihf")
126127
_assert_parts(env, triple("thumbv8m.main-none-eabi"), "thumbv8m.main", None, "none", "eabi")
127128

128129
# Test all WASM32 targets

0 commit comments

Comments
 (0)