diff mbox series

[scarthgap,1/2] rust-llvm: build and install the LLVM shared library

Message ID 20261120032846.2692732-2-sunilkumar.dora@windriver.com
State New
Headers show
Series rust: link LLVM dynamically | expand

Commit Message

Dora, Sunil Kumar Nov. 20, 2026, 3:28 a.m. UTC
From: Sunil Dora <sunilkumar.dora@windriver.com>

For the rustc segfault in [YOCTO #16058] rust has to link LLVM
dynamically. On master libLLVM.so comes from the llvm recipe, rust-llvm
was dropped there [1]. scarthgap still builds LLVM for rust from this
recipe and it builds only static libs. So add the shared lib here.

Need both LLVM_BUILD_LLVM_DYLIB and LLVM_LINK_LLVM_DYLIB. With only the
first one "llvm-config --link-shared --libs" gives the per component
libs (which don't exist) instead of -lLLVM-17. llvm-config and
llvm-tblgen stay static, so the native llvm-config rust uses keeps
working. master had the same two options for rust-llvm [2] when it
still had the recipe.

LLVM installs the lib as ${libdir}/llvm-rust/lib/libLLVM-17.so. Nothing
looks there at runtime, it is not a default loader path and the RUNPATH
of the rust binaries does not point there. So move it to ${libdir} and
keep a symlink behind, the -L path from llvm-config still works at link
time.

Package it as ${PN}-libllvm. Otherwise the .so goes to ${PN}-dev by the
default rules and rust would rdepend on a -dev package. Static libs are
still installed, rust without llvm-shared is not affected.

[1] https://git.openembedded.org/openembedded-core/commit/?id=c116828a876853cd5b53f7bd4607f0037fef4ee4
[2] https://git.openembedded.org/openembedded-core/commit/?id=2b6a6d4199e4eed65f20351d077a04a7cf9da460

[YOCTO #16058]

Signed-off-by: Sunil Dora <sunilkumar.dora@windriver.com>
---
 meta/recipes-devtools/rust/rust-llvm_1.75.0.bb | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/meta/recipes-devtools/rust/rust-llvm_1.75.0.bb b/meta/recipes-devtools/rust/rust-llvm_1.75.0.bb
index cba41c739e..76335dc055 100644
--- a/meta/recipes-devtools/rust/rust-llvm_1.75.0.bb
+++ b/meta/recipes-devtools/rust/rust-llvm_1.75.0.bb
@@ -47,6 +47,8 @@  EXTRA_OECMAKE = " \
     -DLLVM_ENABLE_LIBXML2=OFF \
     -DLLVM_ENABLE_FFI=OFF \
     -DLLVM_INSTALL_UTILS=ON \
+    -DLLVM_BUILD_LLVM_DYLIB=ON \
+    -DLLVM_LINK_LLVM_DYLIB=ON \
     -DLLVM_BUILD_EXAMPLES=OFF \
     -DLLVM_INCLUDE_EXAMPLES=OFF \
     -DLLVM_BUILD_TESTS=OFF \
@@ -84,15 +86,26 @@  export YOCTO_ALTERNATE_EXE_PATH = "${STAGING_LIBDIR}/llvm-rust/bin/llvm-config"
 do_install:append () {
     # we don't need any of this stuff to build Rust
     rm -rf "${D}/usr/lib/cmake"
+
+    # rustc links to libLLVM (llvm-shared in rust). Nothing searches
+    # llvm-rust/lib at runtime, so move the library to ${libdir} and keep
+    # a symlink for the -L path given by llvm-config.
+    for lib in ${D}${libdir}/llvm-rust/lib*/libLLVM-*.so; do
+        [ -f "$lib" ] && [ ! -L "$lib" ] || continue
+        mv "$lib" ${D}${libdir}/
+        ln -s ../../$(basename "$lib") "$lib"
+    done
 }
 
-PACKAGES =+ "${PN}-bugpointpasses ${PN}-llvmhello ${PN}-liblto"
+PACKAGES =+ "${PN}-bugpointpasses ${PN}-llvmhello ${PN}-liblto ${PN}-libllvm"
 
 # Add the extra locations to avoid the complaints about unpackaged files
 FILES:${PN}-bugpointpasses = "${libdir}/llvm-rust/lib/BugpointPasses.so"
 FILES:${PN}-llvmhello = "${libdir}/llvm-rust/lib/LLVMHello.so"
 FILES:${PN}-liblto = "${libdir}/llvm-rust/lib/libLTO.so.*"
+FILES:${PN}-libllvm = "${libdir}/libLLVM-*.so"
 FILES:${PN}-staticdev =+ "${libdir}/llvm-rust/*/*.a"
+RDEPENDS:${PN}-dev += "${PN}-libllvm"
 FILES:${PN} += "${libdir}/libLLVM*.so.* ${libdir}/llvm-rust/lib/*.so.* ${libdir}/llvm-rust/bin"
 FILES:${PN}-dev += "${datadir}/llvm ${libdir}/llvm-rust/lib/*.so ${libdir}/llvm-rust/include ${libdir}/llvm-rust/share ${libdir}/llvm-rust/lib/cmake"