Skip to contentSkip to conversation

rust: Use llvm instead of rust-llvm

PATCH In review [email protected] 3 participants 5 messages Oct 10, 2025 – Oct 14, 2025

lore
Share & tools
lore
#0 lore raw

PATCH v4 1/2 rust: Use llvm instead of rust-llvm

From: Deepesh Varatharajan <[email protected]>

Updated the Rust build to depend on llvm instead.

*Summary of discussion with the rust upstream about using latest LLVM instead of Rust maintained LLVM fork.
https://internals.rust-lang.org/t/can-we-use-proper-clang-instead-of-llvm-fork-what-rust-uses/23489

*Upstream LLVM is generally compatible:
- Rust does support building with upstream (vanilla) LLVM, especially the latest major release and the one or two preceding ones.
https://rustc-dev-guide.rust-lang.org/backend/updating-llvm.html#updating-llvm

*Impact on Yocto Rust upgrades:
- Rust upgrades shall always check for updates on rust forked llvm and backport the relevant patches to llvm.

*Regarding the rust forked llvm local patches:
- There are no local patches on rust forked llvm other than the backported fixes from llvm master.

*We are copying the natively built llvm-config binary into the target sysroot and running it. However, this llvm-config has compile time dependencies on various other arch's LLVM libraries because native-llvm is built for all oe-core supported targets.

Attempting to work around this by symlinking the missing libraries from the native sysroot into the target sysroot leads to mixed architectures in the final .rlib. Specifically, the object files extracted from those symlinked libraries within librustc_llvm-<hash>.rlib are built for the host, while others are correctly built for the target This results in linker failures due to file format not recognized.

To resolve this, we now build llvm-target also for all oe-core supported architectures in addition to the native-llvm build. This ensures that llvm-config and all associated libraries are built for the correct target, eliminating cross-architecture contamination and linker issues.

*We now add these flags "-Clink-arg=-lz -Clink-arg=-lzstd" because of this following diff otherwise we will get errors during link time.

Setup in rust-llvm
-DLLVM_ENABLE_ZLIB=OFF \
-DLLVM_ENABLE_ZSTD=OFF \
-DLLVM_ENABLE_FFI=OFF \

Setup in llvm
-DLLVM_ENABLE_FFI=ON \

*When multilibs enabled:

llvm-config expects static libraries to be located in the lib directory rather than lib64. However, since we are copying the natively built llvm-config to target sysroot and running it and llvm-config doesn't know anything about lib64 existence. To accommodate this without breaking multilib behavior, we are creating a symlink from 'lib' to 'lib64' directory.

Previously, when we depended on rust-llvm, this worked because we specified:
-DCMAKE_INSTALL_PREFIX:PATH=${libdir}/llvm-rust

With this setup, llvm-config was installed inside ${libdir}/llvm-rust, which included its own bin and lib directories. Thus, llvm-config located in bin would correctly find the libraries in the adjacent lib directory.

Even when multilib was enabled or not, llvm-config would still look for libraries under lib in this structure, so everything functioned as expected.

---
 meta/recipes-devtools/clang/llvm_git.bb   |  2 +-
 meta/recipes-devtools/rust/rust_1.90.0.bb | 17 +++++++++++++----
 2 files changed, 14 insertions(+), 5 deletions(-)
meta/recipes-devtools/clang/llvm_git.bb +1 -1
index d2b060ff88..2f47af8d7a 100644
@@ -27,7 +27,6 @@ OECMAKE_SOURCEPATH = "${S}/llvm"
 # https://github.com/llvm/llvm-project/blob/main/llvm/CMakeLists.txt
 LLVM_TARGETS_GPU ?= "${@bb.utils.contains_any('DISTRO_FEATURES', 'opencl opengl vulkan', 'AMDGPU;NVPTX;SPIRV', '', d)}"
 LLVM_TARGETS_TO_BUILD ?= "AArch64;ARM;BPF;Mips;PowerPC;RISCV;X86;LoongArch;${LLVM_TARGETS_GPU}"
-LLVM_TARGETS_TO_BUILD:class-target ?= "${@get_clang_host_arch(bb, d)};BPF;${LLVM_TARGETS_GPU}"
 
 LLVM_EXPERIMENTAL_TARGETS_TO_BUILD ?= ""
 
@@ -37,6 +36,7 @@ HF[vardepvalue] = "${HF}"
 
 EXTRA_OECMAKE += "-DCMAKE_BUILD_TYPE=MinSizeRel \
                   -DLLVM_ENABLE_BINDINGS=OFF \
+                  -DLLVM_INSTALL_UTILS=ON \
                   -DLLVM_ENABLE_FFI=ON \
                   -DLLVM_ENABLE_RTTI=ON \
                   -DLLVM_TARGETS_TO_BUILD='${LLVM_TARGETS_TO_BUILD}' \
meta/recipes-devtools/rust/rust_1.90.0.bb +13 -4
index 5d804c7398..0f154c981e 100644
@@ -7,7 +7,7 @@ LIC_FILES_CHKSUM = "file://COPYRIGHT;md5=11a3899825f4376896e438c8c753f8dc"
 inherit rust
 inherit cargo_common
 
-DEPENDS += "rust-llvm"
+DEPENDS += "llvm"
 # native rust uses cargo/rustc from binary snapshots to bootstrap
 # but everything else should use our native builds
 DEPENDS:append:class-target = " cargo-native rust-native"
@@ -28,8 +28,8 @@ PV .= "${@bb.utils.contains('RUST_CHANNEL', 'stable', '', '-${RUST_CHANNEL}', d)
 
 export FORCE_CRATE_HASH = "${BB_TASKHASH}"
 
-RUST_ALTERNATE_EXE_PATH ?= "${STAGING_LIBDIR}/llvm-rust/bin/llvm-config"
-RUST_ALTERNATE_EXE_PATH_NATIVE = "${STAGING_LIBDIR_NATIVE}/llvm-rust/bin/llvm-config"
+RUST_ALTERNATE_EXE_PATH ?= "${STAGING_BINDIR}/llvm-config"
+RUST_ALTERNATE_EXE_PATH_NATIVE = "${STAGING_BINDIR_NATIVE}/llvm-config"
 
 # We don't want to use bitbakes vendoring because the rust sources do their
 # own vendoring.
@@ -199,7 +199,7 @@ rust_runx () {
     unset CXXFLAGS
     unset CPPFLAGS
 
-    export RUSTFLAGS="${RUST_DEBUG_REMAP}"
+    export RUSTFLAGS="${RUST_DEBUG_REMAP} -Clink-arg=-lz -Clink-arg=-lzstd"
 
     # Copy the natively built llvm-config into the target so we can run it. Horrible,
     # but works!
@@ -213,6 +213,15 @@ rust_runx () {
         fi
     fi
 
+    # llvm-config expects static libraries to be in the 'lib' directory rather than 'lib64' when
+    # multilibs enabled. Since we are copying the natively built llvm-config into the target sysroot
+    # and executing it there, it will default to searching in 'lib', as it is unaware of the 'lib64'
+    # directory. To ensure llvm-config can locate the necessary libraries, create a symlink from 'lib'
+    # to 'lib64'.
+    if [ -d "${STAGING_DIR_TARGET}/usr/lib64" ] && [ ! -e "${STAGING_DIR_TARGET}/usr/lib" ]; then
+        ln -s lib64 "${STAGING_DIR_TARGET}/usr/lib"
+    fi
+
     oe_cargo_fix_env
 
     python3 src/bootstrap/bootstrap.py ${@oe.utils.parallel_make_argument(d, '-j %d')} "$@" --verbose
Signature · 1 line
2.49.0
#1 lore raw

PATCH v4 2/2 rust: Drop rust-llvm

From: Deepesh Varatharajan <[email protected]>

Dropping rust-llvm because now rust depends on llvm.

0001-AsmMatcherEmitter-sort-ClassInfo-lists-by-name-as-we.patch 0002-llvm-allow-env-override-of-exe-path.patch
(We have the above two patches in llvm)

---
 meta/conf/distro/include/maintainers.inc      |  1 -
 .../distro/include/rust_security_flags.inc    |  1 -
 meta/conf/distro/include/tcmode-default.inc   |  2 -
 ...r-sort-ClassInfo-lists-by-name-as-we.patch | 31 ------
 ...-llvm-allow-env-override-of-exe-path.patch | 33 -------
 .../recipes-devtools/rust/rust-llvm_1.90.0.bb | 98 -------------------
 6 files changed, 166 deletions(-)
 delete mode 100644 meta/recipes-devtools/rust/rust-llvm/0001-AsmMatcherEmitter-sort-ClassInfo-lists-by-name-as-we.patch
 delete mode 100644 meta/recipes-devtools/rust/rust-llvm/0002-llvm-allow-env-override-of-exe-path.patch
 delete mode 100644 meta/recipes-devtools/rust/rust-llvm_1.90.0.bb
meta/conf/distro/include/maintainers.inc +0 -1
index d2c613b8e9..6e15c6f3d0 100644
@@ -774,7 +774,6 @@ RECIPE_MAINTAINER:pn-ruby = "Ross Burton <[email protected]>"
 RECIPE_MAINTAINER:pn-run-postinsts = "Ross Burton <[email protected]>"
 RECIPE_MAINTAINER:pn-rust = "Randy MacLeod <[email protected]>"
 RECIPE_MAINTAINER:pn-rust-cross-canadian-${TRANSLATED_TARGET_ARCH} = "Randy MacLeod <[email protected]>"
-RECIPE_MAINTAINER:pn-rust-llvm = "Randy MacLeod <[email protected]>"
 RECIPE_MAINTAINER:pn-rxvt-unicode = "Unassigned <[email protected]>"
 RECIPE_MAINTAINER:pn-sassc = "Simone Weiß <[email protected]>"
 RECIPE_MAINTAINER:pn-sato-screenshot = "Ross Burton <[email protected]>"
meta/conf/distro/include/rust_security_flags.inc +0 -1
index 590bef17a0..f77c851197 100644
@@ -2,6 +2,5 @@
 SECURITY_CFLAGS:pn-rust-native = "${SECURITY_NO_PIE_CFLAGS}"
 SECURITY_CFLAGS:pn-rust-cross-${TARGET_ARCH} = "${SECURITY_NO_PIE_CFLAGS}"
 SECURITY_CFLAGS:pn-rust = "${SECURITY_NO_PIE_CFLAGS}"
-SECURITY_CFLAGS:pn-rust-llvm = "${SECURITY_NO_PIE_CFLAGS}"
 
 SECURITY_LDFLAGS:pn-rust-cross-arm = " -lssp_nonshared -lssp"
meta/conf/distro/include/tcmode-default.inc +0 -2
index 133608a6e7..ff10f14a6b 100644
@@ -43,7 +43,5 @@ PREFERRED_VERSION_cargo-native ?= "${RUSTVERSION}"
 PREFERRED_VERSION_libstd-rs ?= "${RUSTVERSION}"
 PREFERRED_VERSION_rust ?= "${RUSTVERSION}"
 PREFERRED_VERSION_rust-cross-${TARGET_ARCH} ?= "${RUSTVERSION}"
-PREFERRED_VERSION_rust-llvm ?= "${RUSTVERSION}"
-PREFERRED_VERSION_rust-llvm-native ?= "${RUSTVERSION}"
 PREFERRED_VERSION_rust-native ?= "${RUSTVERSION}"
 
meta/recipes-devtools/rust/rust-llvm/0001-AsmMatcherEmitter-sort-ClassInfo-lists-by-name-as-we.patch deleted +0 -31
deleted file mode 100644
index 48af6fc283..0000000000
@@ -1,31 +0,0 @@
-From 86940d87026432683fb6741cd8a34d3b9b18e40d Mon Sep 17 00:00:00 2001
-From: Alexander Kanavin <[email protected]>
-Date: Fri, 27 Nov 2020 10:11:08 +0000
-Subject: [PATCH] AsmMatcherEmitter: sort ClassInfo lists by name as well
-
-Otherwise, there are instances which are identical in
-every other field and therefore sort non-reproducibly
-(which breaks binary and source reproducibiliy).
-
-Upstream-Status: Submitted [https://reviews.llvm.org/D97477]
-Signed-off-by: Alexander Kanavin <[email protected]>
----
- llvm/utils/TableGen/AsmMatcherEmitter.cpp | 5 ++++-
- 1 file changed, 4 insertions(+), 1 deletion(-)
-
-diff --git a/llvm/utils/TableGen/AsmMatcherEmitter.cpp b/llvm/utils/TableGen/AsmMatcherEmitter.cpp
-index ccf0959389b..1f801e83b7d 100644
---- a/llvm/utils/TableGen/AsmMatcherEmitter.cpp
-+++ b/llvm/utils/TableGen/AsmMatcherEmitter.cpp
-@@ -359,7 +359,10 @@ public:
-     // name of a class shouldn't be significant. However, some of the backends
-     // accidentally rely on this behaviour, so it will have to stay like this
-     // until they are fixed.
--    return ValueName < RHS.ValueName;
-+    if (ValueName != RHS.ValueName)
-+        return ValueName < RHS.ValueName;
-+    // All else being equal, we should sort by name, for source and binary reproducibility
-+    return Name < RHS.Name;
-   }
- };
- 
meta/recipes-devtools/rust/rust-llvm/0002-llvm-allow-env-override-of-exe-path.patch deleted +0 -33
deleted file mode 100644
index 9be26677a9..0000000000
@@ -1,33 +0,0 @@
-From 7111770e8290082530d920e120995bf81431b0aa Mon Sep 17 00:00:00 2001
-From: Martin Kelly <[email protected]>
-Date: Fri, 19 May 2017 00:22:57 -0700
-Subject: [PATCH 12/18] llvm: allow env override of exe path
-
-When using a native llvm-config from inside a sysroot, we need llvm-config to
-return the libraries, include directories, etc. from inside the sysroot rather
-than from the native sysroot. Thus provide an env override for calling
-llvm-config from a target sysroot.
-
-Upstream-Status: Inappropriate [oe-core specific]
-Signed-off-by: Martin Kelly <[email protected]>
-Signed-off-by: Khem Raj <[email protected]>
----
- llvm/tools/llvm-config/llvm-config.cpp | 7 +++++++
- 1 file changed, 7 insertions(+)
-
---- a/llvm/tools/llvm-config/llvm-config.cpp
-+++ b/llvm/tools/llvm-config/llvm-config.cpp
-@@ -226,6 +226,13 @@ Typical components:\n\
- 
- /// Compute the path to the main executable.
- std::string GetExecutablePath(const char *Argv0) {
-+  // Hack for Yocto: we need to override the root path when we are using
-+  // llvm-config from within a target sysroot.
-+  const char *Sysroot = std::getenv("YOCTO_ALTERNATE_EXE_PATH");
-+  if (Sysroot != nullptr) {
-+    return Sysroot;
-+  }
-+
-   // This just needs to be some symbol in the binary; C++ doesn't
-   // allow taking the address of ::main however.
-   void *P = (void *)(intptr_t)GetExecutablePath;
meta/recipes-devtools/rust/rust-llvm_1.90.0.bb deleted +0 -98

98 lines not on this page · raw message

Signature · 1 line
2.49.0
#2 lore raw
In reply to [email protected]
Quoted 61 lines · Deepesh via lists.openembedded.org Varatharajan

From: Deepesh Varatharajan <[email protected]>

Updated the Rust build to depend on llvm instead.

*Summary of discussion with the rust upstream about using latest LLVM instead of Rust maintained LLVM fork.
https://internals.rust-lang.org/t/can-we-use-proper-clang-instead-of-llvm-fork-what-rust-uses/23489

*Upstream LLVM is generally compatible:
- Rust does support building with upstream (vanilla) LLVM, especially the latest major release and the one or two preceding ones.
https://rustc-dev-guide.rust-lang.org/backend/updating-llvm.html#updating-llvm

*Impact on Yocto Rust upgrades:
- Rust upgrades shall always check for updates on rust forked llvm and backport the relevant patches to llvm.

*Regarding the rust forked llvm local patches:
- There are no local patches on rust forked llvm other than the backported fixes from llvm master.

*We are copying the natively built llvm-config binary into the target sysroot and running it. However, this llvm-config has compile time dependencies on various other arch's LLVM libraries because native-llvm is built for all oe-core supported targets.

Attempting to work around this by symlinking the missing libraries from the native sysroot into the target sysroot leads to mixed architectures in the final .rlib. Specifically, the object files extracted from those symlinked libraries within librustc_llvm-<hash>.rlib are built for the host, while others are correctly built for the target This results in linker failures due to file format not recognized.

To resolve this, we now build llvm-target also for all oe-core supported architectures in addition to the native-llvm build. This ensures that llvm-config and all associated libraries are built for the correct target, eliminating cross-architecture contamination and linker issues.

*We now add these flags "-Clink-arg=-lz -Clink-arg=-lzstd" because of this following diff otherwise we will get errors during link time.

Setup in rust-llvm

(quoted diff) +0 -3
-DLLVM_ENABLE_ZLIB=OFF \
-DLLVM_ENABLE_ZSTD=OFF \
-DLLVM_ENABLE_FFI=OFF \

Setup in llvm
-DLLVM_ENABLE_FFI=ON \

*When multilibs enabled:

llvm-config expects static libraries to be located in the lib directory rather than lib64. However, since we are copying the natively built llvm-config to target sysroot and running it and llvm-config doesn't know anything about lib64 existence. To accommodate this without breaking multilib behavior, we are creating a symlink from 'lib' to 'lib64' directory.

Previously, when we depended on rust-llvm, this worked because we specified:
-DCMAKE_INSTALL_PREFIX:PATH=${libdir}/llvm-rust

With this setup, llvm-config was installed inside ${libdir}/llvm-rust, which included its own bin and lib directories. Thus, llvm-config located in bin would correctly find the libraries in the adjacent lib directory.

Quoted 5 lines

Even when multilib was enabled or not, llvm-config would still look for libraries under lib in this structure, so everything functioned as expected.

---

Hi Deepesh,

Thanks for the new version.

I suspect this series is responsible of the following error on the autobuilder:

AssertionError: Command 'export TARGET_VENDOR="-poky"; export PATH=/srv/pokybuild/yocto-worker/qemuarm64-tc/build/build-st-2164988/tmp/work/cortexa57-poky-linux/rust/1.90.0/recipe-sysroot-native/usr/bin/python3-native:/srv/pokybuild/yocto-worker/qemuarm64-tc/build/build-st-2164988/tmp/work/cortexa57-poky-linux/rust/1.90.0/recipe-sysroot-native/usr/bin:/srv/pokybuild/yocto-worker/qemuarm64-tc/build/build-st-2164988/tmp/work/cortexa57-poky-linux/rust/1.90.0/recipe-sysroot-native/usr/bin/aarch64-poky-linux:/srv/pokybuild/yocto-worker/qemuarm64-tc/build/build-st-2164988/tmp/hosttools:$PATH; export RUST_TARGET_PATH=/srv/pokybuild/yocto-worker/qemuarm64-tc/build/build-st-2164988/tmp/work/cortexa57-poky-linux/rust/1.90.0/rust-targets; export TEST_DEVICE_ADDR="192.168.7.2:12345"; cd /srv/pokybuild/yocto-worker/qemuarm64-tc/build/build-st-2164988/tmp/work/cortexa57-poky-linux/rust/1.90.0/sources/rustc-1.90.0-src; python3 src/bootstrap/bootstrap.py test --exclude src/bootstrap --exclude src/doc/rustc --exclude src/doc/rustdoc --exclude src/doc/unstable-book --exclude src/etc/test-float-parse --exclude src/librustdoc --exclude src/rustdoc-json-types --exclude src/tools/coverage-dump --exclude src/tools/jsondoclint --exclude src/tools/lint-docs --exclude src/tools/replace-version-placeholder --exclude src/tools/rust-analyzer --exclude src/tools/rustdoc-themes --exclude src/tools/rust-installer --exclude src/tools/test-float-parse --exclude src/tools/suggest-tests --exclude src/tools/tidy --exclude tests/assembly-llvm/asm/aarch64-outline-atomics.rs --exclude tests/codegen-llvm/issues/issue-122805.rs --exclude tests/codegen-llvm/thread-local.rs --exclude tests/mir-opt/ --exclude tests/run-make --exclude tests/run-make-fulldeps --exclude tests/rustdoc --exclude tests/rustdoc-json --exclude tests/rustdoc-js-std --exclude tests/ui/abi/stack-probes-lto.rs --exclude tests/ui/abi/stack-probes.rs --exclude tests/ui/codegen/mismatched-data-layouts.rs --exclude tests/codegen-llvm/rust-abi-arch-specific-adjustment.rs --exclude tests/ui/debuginfo/debuginfo-emit-llvm-ir-and-split-debuginfo.rs --exclude tests/ui/feature-gates/version_check.rs --exclude tests/ui-fulldeps/ --exclude tests/ui/process/nofile-limit.rs --exclude tidyselftest --no-doc --no-fail-fast --bless --target aarch64-poky-linux-gnu' returned non-zero exit status 1:
...
hread 'main' panicked at src/tools/remote-test-client/src/main.rs:351:5:
io::copy(&mut file, dst) failed with Connection reset by peer (os error 104)
note: run with RUST_BACKTRACE=1 environment variable to display a backtrace
error: test failed, to rerun pass -p rustc_driver_impl --lib

     Running unittests src/lib.rs (build/x86_64-unknown-linux-gnu/stage1-rustc/aarch64-poky-linux-gnu/release/deps/rustc_error_codes-e9a3d92a58a57e6f)
uploaded "/srv/pokybuild/yocto-worker/qemuarm64-tc/build/build-st-2164988/tmp/work/cortexa57-poky-linux/rust/1.90.0/sources/rustc-1.90.0-src/build/x86_64-unknown-linux-gnu/stage1-rustc/aarch64-poky-linux-gnu/release/deps/rustc_error_codes-e9a3d92a58a57e6f", waiting for result
...
2025-10-11 14:39:15,774 - oe-selftest - INFO - rust.RustSelfTestSystemEmulated.test_rust (subunit.RemotedTestCase)
2025-10-11 14:39:15,789 - oe-selftest - INFO -  ... FAIL

https://autobuilder.yoctoproject.org/valkyrie/#/builders/5/builds/2477
https://autobuilder.yoctoproject.org/valkyrie/#/builders/28/builds/2471
https://autobuilder.yoctoproject.org/valkyrie/#/builders/58/builds/571
https://autobuilder.yoctoproject.org/valkyrie/#/builders/66/builds/2490

Can you have a look at these errors, please?

Thanks,
Mathieu

Signature · 3 lines
Mathieu Dubois-Briand, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
#3 lore raw
In reply to [email protected]

Hi Deepesh,

Quoted 2 lines · Deepesh via lists.openembedded.org

+ -DLLVM_INSTALL_UTILS=ON \

Can you document what utility is needed here?

Also I’ve asked our LLVM team if they have any feedback on how we’re using llvm-config.

Cheers,
Ross

#4 lore raw
Quoted 8 lines · Ross Burton

CAUTION: This email comes from a non Wind River email account!
Do not click links or open attachments unless you recognize the sender and know the content is safe.

Hi Deepesh,

Quoted 1 line · Deepesh via lists.openembedded.org

+ -DLLVM_INSTALL_UTILS=ON \

Can you document what utility is needed here?

Sure

Quoted 5 lines

Also I’ve asked our LLVM team if they have any feedback on how we’re using llvm-config.

Cheers,
Ross