]> git.ipfire.org Git - thirdparty/openembedded/openembedded-core-contrib.git/commitdiff
rust: Enable baremetal targets
authorAlejandro Hernandez Samaniego <alejandro@enedino.org>
Thu, 15 Dec 2022 07:32:24 +0000 (00:32 -0700)
committerRichard Purdie <richard.purdie@linuxfoundation.org>
Wed, 21 Dec 2022 10:16:25 +0000 (10:16 +0000)
Allow rust to build for baremetal targets by generating the proper target
triple, follow the format specified by rusts Triple [1], that is:

<arch>-<vendor>-<os>-<abi>

This is done automatically based on both TARGET_OS and TCLIBC.

For example, a riscv64 baremetal target triple would look like this:
riscv64gc-poky-none-elf

matching rusts own target triple for riscv64 according to platform-support [2]

[1] https://docs.rs/target-lexicon/latest/target_lexicon/struct.Triple.html
[2] https://doc.rust-lang.org/stable/rustc/platform-support.html

Signed-off-by: Alejandro Enedino Hernandez Samaniego <alejandro@enedino.org>
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
meta/classes-recipe/rust-common.bbclass
meta/classes-recipe/rust-target-config.bbclass

index 3338de75025ba627759636b6864aeae5b0bc4ab2..0f72e45e8c9c71fde9f655934eacadd63e20f4db 100644 (file)
@@ -66,6 +66,12 @@ def rust_base_triple(d, thing):
     elif "musl" in os:
         libc = "-musl"
         os = "linux"
+    elif "elf" in os:
+        libc = "-elf"
+        os = "none"
+    elif "eabi" in os:
+        libc = "-eabi"
+        os = "none"
 
     return arch + vendor + '-' + os + libc
 
index 2710b4325d47ade61193319f5ad26115822ed157..7fd7128bcfb701b7636d412cecc2c30a2f3aeaaf 100644 (file)
@@ -355,7 +355,10 @@ def rust_gen_target(d, thing, wd, arch):
     tspec['target-c-int-width'] = d.getVarFlag('TARGET_C_INT_WIDTH', arch_abi)
     tspec['target-endian'] = d.getVarFlag('TARGET_ENDIAN', arch_abi)
     tspec['arch'] = arch_to_rust_target_arch(rust_arch)
-    tspec['os'] = "linux"
+    if "baremetal" in d.getVar('TCLIBC'):
+        tspec['os'] = "none"
+    else:
+        tspec['os'] = "linux"
     if "musl" in tspec['llvm-target']:
         tspec['env'] = "musl"
     else: