From: Harish Sadineni <[email protected]>

Rust support in the upstream kernel on riscv64 currently only works
with the LLVM/Clang toolchain, not gcc [1]. Add a sanity check that
fails the build with a clear error message if TOOLCHAIN is not set
to "clang" when building a riscv64 kernel with rust support enabled,
pointing the user to the required local.conf/recipe override.

Also add lld-native as a dependency for riscv64, since
lld is required when linking the kernel with clang.

[1] https://docs.kernel.org/rust/arch-support.html

Signed-off-by: Harish Sadineni <[email protected]>
---
 meta/classes-recipe/kernel-yocto-rust.bbclass | 20 +++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/meta/classes-recipe/kernel-yocto-rust.bbclass 
b/meta/classes-recipe/kernel-yocto-rust.bbclass
index 49f2bfc1ae..819b382838 100644
--- a/meta/classes-recipe/kernel-yocto-rust.bbclass
+++ b/meta/classes-recipe/kernel-yocto-rust.bbclass
@@ -25,3 +25,23 @@ do_kernel_configme:append () {
 # More details in: 
https://lists.openembedded.org/g/openembedded-core/message/229336
 # Disable ccache for kernel build if kernel rust support is enabled to 
workaround this.
 CCACHE_DISABLE ?= "1"
+
+# Rust support in the kernel on riscv64 only works with the LLVM/Clang
+# toolchain, not gcc:
+# https://docs.kernel.org/rust/arch-support.html
+do_check_riscv64_toolchain() {
+    if [ "${TARGET_ARCH}" = "riscv64" ] && [ "${TOOLCHAIN}" != "clang" ]; then
+        bbfatal "Rust support in the kernel on riscv64 requires the clang" \
+                "toolchain, but TOOLCHAIN is set to '${TOOLCHAIN}'. Set" \
+                "TOOLCHAIN:riscv64 = \"clang\" in kernel recipe (or) set" \
+                "TOOLCHAIN:pn-linux-yocto = \"clang\" in local.conf to build 
a" \
+                "riscv64 kernel with rust enabled. See" \
+                "https://docs.kernel.org/rust/arch-support.html for details."
+    fi
+}
+
+addtask do_check_riscv64_toolchain before do_fetch
+
+# lld is required when building the kernel with clang.
+DEPENDS:append:riscv64 = " lld-native"
+RUST_KERNEL_TASK_DEPENDS:append:riscv64 = " lld-native:do_populate_sysroot"
-- 
2.51.0

-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group.
View/Reply Online (#241088): 
https://lists.openembedded.org/g/openembedded-core/message/241088
Mute This Topic: https://lists.openembedded.org/mt/120297398/21656
Group Owner: [email protected]
Unsubscribe: https://lists.openembedded.org/g/openembedded-core/unsub 
[[email protected]]
-=-=-=-=-=-=-=-=-=-=-=-

  • [OE-core] [PATCH v2] kernel-yo... Sadineni, Harish via lists.openembedded.org

Reply via email to