diff mbox series

[meta-lts-mixins,4/4] Fix RISC-V support

Message ID 20230823182512.1073623-5-scott.murray@konsulko.com
State New
Headers show
Series kirkstone/rust-1.68 branch updates | expand

Commit Message

Scott Murray Aug. 23, 2023, 6:25 p.m. UTC
Building Rust projects for RISC-V platforms was failing due to the
layer not including a copy of lib/oe/rust.py to get all the changes
from oe-core commit 1cfb9c8a ("rust-target-config: match riscv target
names with what rust expects").  Reverting the changes from that
commit seems likely to make things less robust, so instead add a
copy of the updated lib/oe/rust.py in lib/mixin and update callers
of arch_to_rust_arch to use it.  This is not ideal from an ease
of further maintenance perspective, but seems more inline with the
intent of matching the behavior of the Rust toolchain as it stands
in Mickledore branch.

Signed-off-by: Scott Murray <scott.murray@konsulko.com>
---
 classes/rust-common.bbclass        |  4 ++--
 classes/rust-target-config.bbclass |  2 +-
 conf/layer.conf                    |  4 ++++
 lib/mixin/rust.py                  | 13 +++++++++++++
 4 files changed, 20 insertions(+), 3 deletions(-)
 create mode 100644 lib/mixin/rust.py
diff mbox series

Patch

diff --git a/classes/rust-common.bbclass b/classes/rust-common.bbclass
index 8782727..a8971cd 100644
--- a/classes/rust-common.bbclass
+++ b/classes/rust-common.bbclass
@@ -51,7 +51,7 @@  def rust_base_triple(d, thing):
     if d.getVar('{}_ARCH'.format(thing)) == d.getVar('TARGET_ARCH') and target_is_armv7(d):
         arch = "armv7"
     else:
-        arch = oe.rust.arch_to_rust_arch(d.getVar('{}_ARCH'.format(thing)))
+        arch = mixin.rust.arch_to_rust_arch(d.getVar('{}_ARCH'.format(thing)))
 
     # Substituting "unknown" when vendor is empty will match rust's standard
     # targets when building native recipes (including rust-native itself)
@@ -77,7 +77,7 @@  def rust_base_triple(d, thing):
 
 
 # In some cases uname and the toolchain differ on their idea of the arch name
-RUST_BUILD_ARCH = "${@oe.rust.arch_to_rust_arch(d.getVar('BUILD_ARCH'))}"
+RUST_BUILD_ARCH = "${@mixin.rust.arch_to_rust_arch(d.getVar('BUILD_ARCH'))}"
 
 # Naming explanation
 # Yocto
diff --git a/classes/rust-target-config.bbclass b/classes/rust-target-config.bbclass
index 21a56ed..663b02c 100644
--- a/classes/rust-target-config.bbclass
+++ b/classes/rust-target-config.bbclass
@@ -343,7 +343,7 @@  def rust_gen_target(d, thing, wd, arch):
         if arch == "arm" and target_is_armv7(d):
             arch = 'armv7'
 
-    rust_arch = oe.rust.arch_to_rust_arch(arch)
+    rust_arch = mixin.rust.arch_to_rust_arch(arch)
 
     if abi:
         arch_abi = "{}-{}".format(rust_arch, abi)
diff --git a/conf/layer.conf b/conf/layer.conf
index b057c77..fa0cbd6 100644
--- a/conf/layer.conf
+++ b/conf/layer.conf
@@ -23,3 +23,7 @@  BBMASK:append = " meta/recipes-devtools/cargo/ meta/recipes-devtools/rust/ meta/
 # These are in bitbake.conf in langdale and up, adding them here to make
 # using the layer more turn-key seems reasonable.
 BB_BASEHASH_IGNORE_VARS:append = " RUST_BUILD_SYS RUST_HOST_SYS RUST_TARGET_SYS"
+
+# Since we cannot overlay the lib/oe version easily, make sure our backport
+# of rust.py in lib/mixin is picked up.
+OE_EXTRA_IMPORTS:append = " mixin.rust"
diff --git a/lib/mixin/rust.py b/lib/mixin/rust.py
new file mode 100644
index 0000000..185553e
--- /dev/null
+++ b/lib/mixin/rust.py
@@ -0,0 +1,13 @@ 
+#
+# Copyright OpenEmbedded Contributors
+#
+# SPDX-License-Identifier: MIT
+#
+
+# Handle mismatches between `uname -m`-style output and Rust's arch names
+def arch_to_rust_arch(arch):
+    if arch == "ppc64le":
+        return "powerpc64le"
+    if arch in ('riscv32', 'riscv64'):
+        return arch + 'gc'
+    return arch