All of lore.kernel.org
 help / color / mirror / Atom feed
From: Alejandro Enedino Hernandez Samaniego <alejandro@enedino.org>
To: openembedded-core@lists.openembedded.org
Cc: Alejandro Enedino Hernandez Samaniego <alejandro@enedino.org>
Subject: [PATCH 2/2] rust: Enable baremetal targets
Date: Thu, 15 Dec 2022 00:32:24 -0700	[thread overview]
Message-ID: <20221215073224.3061128-2-alejandro@enedino.org> (raw)
In-Reply-To: <20221215073224.3061128-1-alejandro@enedino.org>

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>
---
 meta/classes-recipe/rust-common.bbclass        | 6 ++++++
 meta/classes-recipe/rust-target-config.bbclass | 5 ++++-
 2 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/meta/classes-recipe/rust-common.bbclass b/meta/classes-recipe/rust-common.bbclass
index 3338de7502..0f72e45e8c 100644
--- a/meta/classes-recipe/rust-common.bbclass
+++ b/meta/classes-recipe/rust-common.bbclass
@@ -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
 
diff --git a/meta/classes-recipe/rust-target-config.bbclass b/meta/classes-recipe/rust-target-config.bbclass
index 2710b4325d..7fd7128bcf 100644
--- a/meta/classes-recipe/rust-target-config.bbclass
+++ b/meta/classes-recipe/rust-target-config.bbclass
@@ -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:
-- 
2.34.1



  reply	other threads:[~2022-12-15  7:32 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-15  7:32 [PATCH 1/2] rust: Enable building rust from stable, beta and nightly channels Alejandro Enedino Hernandez Samaniego
2022-12-15  7:32 ` Alejandro Enedino Hernandez Samaniego [this message]
2022-12-15  9:04 ` [OE-core] " Alexander Kanavin
2022-12-15 15:38   ` Alejandro Enedino Hernandez Samaniego
2022-12-15 16:08     ` Alex Kiernan
2022-12-15 16:38       ` Alejandro Enedino Hernandez Samaniego
2022-12-15 18:01         ` Alexander Kanavin
     [not found]         ` <1731096B411C6A99.9432@lists.openembedded.org>
2022-12-15 18:02           ` Alexander Kanavin
2022-12-15 18:11             ` Alejandro Enedino Hernandez Samaniego
2022-12-15 18:23               ` Alejandro Enedino Hernandez Samaniego
2022-12-15 18:31                 ` Alexander Kanavin
2022-12-15 21:36                 ` Alex Kiernan
2022-12-15 21:45                   ` Alejandro Enedino Hernandez Samaniego
2022-12-15 22:33                     ` Alex Kiernan
2022-12-17  1:20                       ` Alejandro Enedino Hernandez Samaniego
2022-12-17 17:11                         ` Alex Kiernan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20221215073224.3061128-2-alejandro@enedino.org \
    --to=alejandro@enedino.org \
    --cc=openembedded-core@lists.openembedded.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.