]> git.ipfire.org Git - thirdparty/openembedded/openembedded-core.git/commitdiff
libclc: split out of clang
authorRoss Burton <ross.burton@arm.com>
Mon, 21 Jul 2025 13:24:23 +0000 (14:24 +0100)
committerRichard Purdie <richard.purdie@linuxfoundation.org>
Mon, 21 Jul 2025 21:59:39 +0000 (22:59 +0100)
Split the libclc subproject out of the clang recipe and into a dedicated
libclc recipe.

This is useful because libclc is the OpenCL runtime library and as such
isn't target-specific and needs a native clang to build, not a target
libllvm.

Verified that nothing is dropped by adding clang and libclc to an image
and verifying that the file list is the same before and after this
change.

We need to patch the libclc CMakeLists to allow it to use an out-of-tree
prepare_builtins binary, discussion is ongoing with upstream to resolve
this properly.

Signed-off-by: Ross Burton <ross.burton@arm.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
meta/conf/distro/include/maintainers.inc
meta/recipes-devtools/clang/clang/0001-libclc-allow-existing-prepare-builtins-in-standalone.patch [new file with mode: 0644]
meta/recipes-devtools/clang/clang_git.bb
meta/recipes-devtools/clang/common.inc
meta/recipes-devtools/clang/libclc_git.bb [new file with mode: 0644]

index 6bfc2efb162fae1768ac1ae8275a91ab14c90bae..927aac16d6d192ff19eb0324ce0a40acfb73539a 100644 (file)
@@ -328,6 +328,7 @@ RECIPE_MAINTAINER:pn-libcap-ng = "Yi Zhao <yi.zhao@windriver.com>"
 RECIPE_MAINTAINER:pn-libcap-ng-python = "Yi Zhao <yi.zhao@windriver.com>"
 RECIPE_MAINTAINER:pn-libcgroup = "Unassigned <unassigned@yoctoproject.org>"
 RECIPE_MAINTAINER:pn-libcheck = "Yi Zhao <yi.zhao@windriver.com>"
+RECIPE_MAINTAINER:pn-libclc = "Khem Raj <raj.khem@gmail.com>"
 RECIPE_MAINTAINER:pn-libcomps = "Unassigned <unassigned@yoctoproject.org>"
 RECIPE_MAINTAINER:pn-libconvert-asn1-perl = "Tim Orling <tim.orling@konsulko.com>"
 RECIPE_MAINTAINER:pn-libcxx = "Khem Raj <raj.khem@gmail.com>"
diff --git a/meta/recipes-devtools/clang/clang/0001-libclc-allow-existing-prepare-builtins-in-standalone.patch b/meta/recipes-devtools/clang/clang/0001-libclc-allow-existing-prepare-builtins-in-standalone.patch
new file mode 100644 (file)
index 0000000..4692979
--- /dev/null
@@ -0,0 +1,57 @@
+From 348f846b206780646430d6477c04b7793b669f34 Mon Sep 17 00:00:00 2001
+From: Ross Burton <ross.burton@arm.com>
+Date: Wed, 16 Jul 2025 23:24:21 +0100
+Subject: [PATCH] allow external prepare_builtins
+
+In standalone cross builds, libclc can't build a native prepare_builtins.
+
+Hack the CMake to allow it to use an existing binary, which we build in the recipe.
+
+Upstream-Status: Inappropriate [discussion for a proper fix in https://github.com/llvm/llvm-project/issues/149814]
+Signed-off-by: Ross Burton <ross.burton@arm.com>
+---
+ libclc/CMakeLists.txt | 23 +++++++++++++++++------
+ 1 file changed, 17 insertions(+), 6 deletions(-)
+
+diff --git a/libclc/CMakeLists.txt b/libclc/CMakeLists.txt
+index 43e213b385f5..d4a6d096169e 100644
+--- a/libclc/CMakeLists.txt
++++ b/libclc/CMakeLists.txt
+@@ -181,17 +181,28 @@ set(LLVM_LINK_COMPONENTS
+   IRReader
+   Support
+ )
++
+ if( LIBCLC_STANDALONE_BUILD )
+-  add_llvm_executable( prepare_builtins utils/prepare-builtins.cpp )
+-  set( prepare_builtins_exe prepare_builtins )
+-  set( prepare_builtins_target prepare_builtins )
++  message("cross ${CMAKE_CROSSCOMPILING}")
++  if(CMAKE_CROSSCOMPILING)
++    find_program(PREPARE_BUILTINS prepare_builtins REQUIRED)
++    message("found ${PREPARE_BUILTINS}")
++    set( prepare_builtins_exe ${PREPARE_BUILTINS} )
++  else()
++    add_llvm_executable( prepare_builtins utils/prepare-builtins.cpp )
++    set( prepare_builtins_exe prepare_builtins )
++    set( prepare_builtins_target prepare_builtins )
++    target_compile_definitions( prepare_builtins PRIVATE ${LLVM_VERSION_DEFINE} )
++    # These were not properly reported in early LLVM and we don't need them
++    target_compile_options( prepare_builtins PRIVATE -fno-rtti -fno-exceptions )
++  endif()
+ else()
+   add_llvm_utility( prepare_builtins utils/prepare-builtins.cpp )
+   setup_host_tool( prepare_builtins PREPARE_BUILTINS prepare_builtins_exe prepare_builtins_target )
++  target_compile_definitions( prepare_builtins PRIVATE ${LLVM_VERSION_DEFINE} )
++  # These were not properly reported in early LLVM and we don't need them
++  target_compile_options( prepare_builtins PRIVATE -fno-rtti -fno-exceptions )
+ endif()
+-target_compile_definitions( prepare_builtins PRIVATE ${LLVM_VERSION_DEFINE} )
+-# These were not properly reported in early LLVM and we don't need them
+-target_compile_options( prepare_builtins PRIVATE -fno-rtti -fno-exceptions )
+ # Setup arch devices
+ set( r600--_devices cedar cypress barts cayman )
+-- 
+2.43.0
+
index 1210ca92de1ff4f46c8a788d5902eb851307bd1e..a85626c45abc478b7097799576f5d3c6ffdd0496 100644 (file)
@@ -131,7 +131,7 @@ HF[vardepvalue] = "${HF}"
 
 # Ensure that LLVM_PROJECTS does not contain compiler runtime components e.g. libcxx etc
 # they are enabled via LLVM_ENABLE_RUNTIMES
-LLVM_PROJECTS ?= "clang;clang-tools-extra;libclc;lld"
+LLVM_PROJECTS ?= "clang;clang-tools-extra;lld"
 
 # linux hosts (.so) on Windows .pyd
 SOLIBSDEV:mingw32 = ".pyd"
@@ -192,7 +192,7 @@ EXTRA_OECMAKE:append:class-target = "\
 
 DEPENDS = "binutils zlib zstd libffi libxml2 libxml2-native ninja-native swig-native spirv-tools-native llvm-tblgen-native"
 DEPENDS:append:class-nativesdk = " clang-crosssdk-${SDK_SYS} virtual/nativesdk-cross-binutils nativesdk-python3"
-DEPENDS:append:class-target = " clang-cross-${TARGET_ARCH} python3 ${@bb.utils.contains('TC_CXX_RUNTIME', 'llvm', 'compiler-rt libcxx', '', d)} spirv-llvm-translator-native"
+DEPENDS:append:class-target = " clang-cross-${TARGET_ARCH} python3 ${@bb.utils.contains('TC_CXX_RUNTIME', 'llvm', 'compiler-rt libcxx', '', d)}"
 
 RRECOMMENDS:${PN} = "binutils"
 RRECOMMENDS:${PN}:append:class-target = "${@bb.utils.contains('TC_CXX_RUNTIME', 'llvm', ' libcxx-dev', '', d)}"
@@ -259,7 +259,6 @@ do_install:append:class-native () {
         install -Dm 0755 ${B}${BINPATHPREFIX}/bin/clangd-indexer ${D}${bindir}/clangd-indexer
     fi
     install -Dm 0755 ${B}${BINPATHPREFIX}/bin/clang-tidy-confusable-chars-gen ${D}${bindir}/clang-tidy-confusable-chars-gen
-    install -Dm 0755 ${B}${BINPATHPREFIX}/bin/prepare_builtins ${D}${bindir}/prepare_builtins
 
     for f in `find ${D}${bindir} -executable -type f -not -type l`; do
         test -n "`file -b $f|grep -i ELF`" && ${STRIP} $f
@@ -295,11 +294,11 @@ do_install:append:class-nativesdk () {
     fi
 }
 
-PROVIDES:append:class-native = " llvm-native libclc-native"
-PROVIDES:append:class-target = " llvm libclc"
-PROVIDES:append:class-nativesdk = " nativesdk-llvm nativesdk-libclc"
+PROVIDES:append:class-native = " llvm-native"
+PROVIDES:append:class-target = " llvm"
+PROVIDES:append:class-nativesdk = " nativesdk-llvm"
 
-PACKAGES =+ "${PN}-libllvm ${PN}-libclang-python ${PN}-libclang-cpp ${PN}-tidy ${PN}-format ${PN}-tools ${PN}-clc \
+PACKAGES =+ "${PN}-libllvm ${PN}-libclang-python ${PN}-libclang-cpp ${PN}-tidy ${PN}-format ${PN}-tools \
              libclang llvm-linker-tools"
 
 BBCLASSEXTEND = "native nativesdk"
@@ -316,8 +315,6 @@ RDEPENDS:${PN}-tools += "\
   perl-module-term-ansicolor \
 "
 
-RPROVIDES:${PN}-clc = "${MLPREFIX}libclc"
-
 RRECOMMENDS:${PN}-tidy += "${PN}-tools"
 
 FILES:llvm-linker-tools = "${libdir}/LLVMgold* ${libdir}/libLTO.so.* ${libdir}/LLVMPolly*"
@@ -384,8 +381,6 @@ FILES:${PN} += "\
   ${nonarch_libdir}/${BPN}/*/include/ \
 "
 
-FILES:${PN}-clc += "${datadir}/clc"
-
 FILES:${PN}-libllvm =+ "\
   ${libdir}/libLLVM.so.${MAJOR_VER}.${MINOR_VER} \
   ${libdir}/libLLVM-${MAJOR_VER}.so \
index d66f9059b2e82228dd7a903d9bf7285262736899..d6280c2fbe38e27b8a561602e84b6fd674c95e5c 100644 (file)
@@ -59,6 +59,7 @@ SRC_URI = "\
     file://0036-libunwind-Use-gcs-instead-of-gcs-target-attribute.patch \
     file://0037-compiler-rt-Exclude-sync_fetch_and_-for-any-pre-ARMv.patch \
     file://0038-compiler-rt-Hardcode-uptr-sptr-typedefs-on-Mips-Linu.patch \
+    file://0001-libclc-allow-existing-prepare-builtins-in-standalone.patch \
 "
 # Fallback to no-PIE if not set
 GCCPIE ??= ""
diff --git a/meta/recipes-devtools/clang/libclc_git.bb b/meta/recipes-devtools/clang/libclc_git.bb
new file mode 100644 (file)
index 0000000..ed31de5
--- /dev/null
@@ -0,0 +1,43 @@
+SUMMARY = "Implementation of the library requirements of the OpenCL C programming language."
+HOMEPAGE = "https://libclc.llvm.org"
+SECTION = "devel"
+
+require common-clang.inc
+require common-source.inc
+
+LIC_FILES_CHKSUM = "file://libclc/LICENSE.TXT;md5=7cc795f6cbb2d801d84336b83c8017db"
+
+inherit cmake pkgconfig
+
+# Depend explicitly on clang-native instead of using TOOLCHAIN as the build
+# objects from this recipe are build explicitly using clang for GPU targets.
+# We could INHIBIT_DEFAULT_DEPS to avoid any other toolchain but then we need
+# to wrestle CMake to configure without a toolchain.
+DEPENDS += "clang-native spirv-llvm-translator-native"
+
+OECMAKE_SOURCEPATH = "${S}/libclc"
+B_NATIVE = "${B}-native"
+
+# Semicolon-separated list of targets to build
+LIBCLC_TARGETS ?= "all"
+
+EXTRA_OECMAKE = "-DLIBCLC_TARGETS_TO_BUILD=${LIBCLC_TARGETS} \
+                 -DPREPARE_BUILTINS=${B_NATIVE}/prepare_builtins"
+
+# Need to build a native prepare_builtins binary in target builds. The easiest
+# way to do this is with a second native cmake build tree.
+do_build_prepare_builtins() {
+    cmake --fresh -G Ninja \
+        -S ${OECMAKE_SOURCEPATH} -B ${B_NATIVE} \
+        -DCMAKE_TOOLCHAIN_FILE:FILEPATH=${WORKDIR}/toolchain-native.cmake \
+        -DLIBCLC_TARGETS_TO_BUILD=
+    cmake --build ${B_NATIVE} --target prepare_builtins
+}
+do_build_prepare_builtins:class-native() {
+    :
+}
+do_configure[prefuncs] += "do_build_prepare_builtins"
+
+FILES:${PN} += "${datadir}/clc"
+
+BBCLASSEXTEND = "native nativesdk"