Message ID | 20250327221807.2551544-4-dmitry.baryshkov@oss.qualcomm.com |
---|---|
State | New |
Headers | show |
Series | mesa: upgrade to 25.0.2 | expand |
On Thu, 27 Mar 2025 at 23:18, Dmitry Baryshkov via lists.openembedded.org <dmitry.baryshkov=oss.qualcomm.com@lists.openembedded.org> wrote: > +Fix variables being passed to cmake when generating NATIVE build dir. > + > +Upstream-Status: Inappropriate [OE-Specific build-system fix] Please write a better, detailed explanation of what the patch does. Why do we need it in the first place? > -LLVM_TARGETS ?= "AMDGPU;${@get_llvm_host_arch(bb, d)}" > +LLVM_TARGETS ?= "AMDGPU;NVPTX;SPIRV;${@get_llvm_host_arch(bb, d)}" Why this addition? Needs to be explained in commit message. > +LLVM_PROJECTS = "${@bb.utils.contains('PACKAGECONFIG', 'libclc', 'clang;libclc', '', d)}" > + Same. > + -DLLVM_ENABLE_PROJECTS='${LLVM_PROJECTS}' \ > + -DLLVM_NATIVE_TRIPLE='${BUILD_SYS}' \ > + -DLLVM_NATIVE_C_COMPILER=\'${@ d.getVar('BUILD_CC').replace('ccache', '').strip()}\' \ > + -DLLVM_NATIVE_CXX_COMPILER=\'${@ d.getVar('BUILD_CXX').replace('ccache', '').strip()}\' \ > + -DLLVM_NATIVE_C_FLAGS='${BUILD_CFLAGS}' \ > + -DLLVM_NATIVE_CXX_FLAGS='${BUILD_CXXFLAGS}' \ > + -DLLVM_NATIVE_LD_FLAGS='${BUILD_LDFLAGS}' \ Same. > EXTRA_OECMAKE:append:class-target = "\ > @@ -89,6 +101,8 @@ EXTRA_OECMAKE:append:class-target = "\ > -DLLVM_HOST_TRIPLE=${TARGET_SYS} \ > -DLLVM_TABLEGEN=${STAGING_BINDIR_NATIVE}/llvm-tblgen${PV} \ > -DLLVM_CONFIG_PATH=${STAGING_BINDIR_NATIVE}/llvm-config${PV} \ > + -DLLVM_NATIVE_TOOL_DIR=${STAGING_BINDIR_NATIVE} \ > + -DCLANG_TABLEGEN=${STAGING_BINDIR_NATIVE}/clang-tblgen \ Same. > EXTRA_OECMAKE:append:class-nativesdk = "\ > @@ -96,6 +110,8 @@ EXTRA_OECMAKE:append:class-nativesdk = "\ > -DLLVM_HOST_TRIPLE=${SDK_SYS} \ > -DLLVM_TABLEGEN=${STAGING_BINDIR_NATIVE}/llvm-tblgen${PV} \ > -DLLVM_CONFIG_PATH=${STAGING_BINDIR_NATIVE}/llvm-config${PV} \ > + -DLLVM_NATIVE_TOOL_DIR=${STAGING_BINDIR_NATIVE} \ > + -DCLANG_TABLEGEN=${STAGING_BINDIR_NATIVE}/clang-tblgen \ Same. > # patch out build host paths for reproducibility > @@ -124,11 +140,26 @@ do_install() { > > # Remove opt-viewer: https://llvm.org/docs/Remarks.html > rm -rf ${D}${datadir}/opt-viewer > - rmdir ${D}${datadir} > + rmdir ${D}${datadir} || true Same. > + # Remove clang bits from target packages, we are not providing it for the system > + if ${@bb.utils.contains('PACKAGECONFIG', 'libclc', 'true', 'false', d)} && > + [ "${CLASSOVERRIDE}" != "class-native" ] ; then > + rm -f ${D}${bindir}/clang* > + rm -fr ${D}${libdir}/clang > + rm -fr ${D}${datadir}/clang > + > + rm -f ${D}${bindir}/scan* > + rm -fr ${D}${libdir}/libscanbuild > + rm -fr ${D}${datadir}/scan-build > + rm -fr ${D}${datadir}/scan-view > + > + rm -fr ${D}${libdir}/libear > + fi Why does this need to be done, if we're only adding libclc? Is it dependent on those bits being built? > +PROVIDES = "libclc" > +RPROVIDES:${PN}-clc += "libclc" Why these additions? Alex
On Fri, Mar 28, 2025 at 10:35:37AM +0100, Alexander Kanavin wrote: > On Thu, 27 Mar 2025 at 23:18, Dmitry Baryshkov via > lists.openembedded.org > <dmitry.baryshkov=oss.qualcomm.com@lists.openembedded.org> wrote: > > +Fix variables being passed to cmake when generating NATIVE build dir. > > + > > +Upstream-Status: Inappropriate [OE-Specific build-system fix] > > Please write a better, detailed explanation of what the patch does. > Why do we need it in the first place? ack > > > -LLVM_TARGETS ?= "AMDGPU;${@get_llvm_host_arch(bb, d)}" > > +LLVM_TARGETS ?= "AMDGPU;NVPTX;SPIRV;${@get_llvm_host_arch(bb, d)}" > > Why this addition? Needs to be explained in commit message. ack, I'll split it to a separate patch > > > +LLVM_PROJECTS = "${@bb.utils.contains('PACKAGECONFIG', 'libclc', 'clang;libclc', '', d)}" > > + > > Same. Well... This is kind of described in the commit message, but I will expand the clang part. > > > + -DLLVM_ENABLE_PROJECTS='${LLVM_PROJECTS}' \ > > + -DLLVM_NATIVE_TRIPLE='${BUILD_SYS}' \ > > + -DLLVM_NATIVE_C_COMPILER=\'${@ d.getVar('BUILD_CC').replace('ccache', '').strip()}\' \ > > + -DLLVM_NATIVE_CXX_COMPILER=\'${@ d.getVar('BUILD_CXX').replace('ccache', '').strip()}\' \ > > + -DLLVM_NATIVE_C_FLAGS='${BUILD_CFLAGS}' \ > > + -DLLVM_NATIVE_CXX_FLAGS='${BUILD_CXXFLAGS}' \ > > + -DLLVM_NATIVE_LD_FLAGS='${BUILD_LDFLAGS}' \ > > Same. > > > EXTRA_OECMAKE:append:class-target = "\ > > @@ -89,6 +101,8 @@ EXTRA_OECMAKE:append:class-target = "\ > > -DLLVM_HOST_TRIPLE=${TARGET_SYS} \ > > -DLLVM_TABLEGEN=${STAGING_BINDIR_NATIVE}/llvm-tblgen${PV} \ > > -DLLVM_CONFIG_PATH=${STAGING_BINDIR_NATIVE}/llvm-config${PV} \ > > + -DLLVM_NATIVE_TOOL_DIR=${STAGING_BINDIR_NATIVE} \ > > + -DCLANG_TABLEGEN=${STAGING_BINDIR_NATIVE}/clang-tblgen \ > > Same. > > > EXTRA_OECMAKE:append:class-nativesdk = "\ > > @@ -96,6 +110,8 @@ EXTRA_OECMAKE:append:class-nativesdk = "\ > > -DLLVM_HOST_TRIPLE=${SDK_SYS} \ > > -DLLVM_TABLEGEN=${STAGING_BINDIR_NATIVE}/llvm-tblgen${PV} \ > > -DLLVM_CONFIG_PATH=${STAGING_BINDIR_NATIVE}/llvm-config${PV} \ > > + -DLLVM_NATIVE_TOOL_DIR=${STAGING_BINDIR_NATIVE} \ > > + -DCLANG_TABLEGEN=${STAGING_BINDIR_NATIVE}/clang-tblgen \ > > Same. > > > # patch out build host paths for reproducibility > > @@ -124,11 +140,26 @@ do_install() { > > > > # Remove opt-viewer: https://llvm.org/docs/Remarks.html > > rm -rf ${D}${datadir}/opt-viewer > > - rmdir ${D}${datadir} > > + rmdir ${D}${datadir} || true > > Same. Ack > > > + # Remove clang bits from target packages, we are not providing it for the system > > + if ${@bb.utils.contains('PACKAGECONFIG', 'libclc', 'true', 'false', d)} && > > + [ "${CLASSOVERRIDE}" != "class-native" ] ; then > > + rm -f ${D}${bindir}/clang* > > + rm -fr ${D}${libdir}/clang > > + rm -fr ${D}${datadir}/clang > > + > > + rm -f ${D}${bindir}/scan* > > + rm -fr ${D}${libdir}/libscanbuild > > + rm -fr ${D}${datadir}/scan-build > > + rm -fr ${D}${datadir}/scan-view > > + > > + rm -fr ${D}${libdir}/libear > > + fi > > Why does this need to be done, if we're only adding libclc? Is it > dependent on those bits being built? This definitely is described in the commit message: 'Don't install clang into the target system, it is only used during the build process.' > > > +PROVIDES = "libclc" > > +RPROVIDES:${PN}-clc += "libclc" > > Why these additions? > > Alex >
On Fri, 28 Mar 2025 at 11:55, Dmitry Baryshkov <dmitry.baryshkov@oss.qualcomm.com> wrote: > > > + # Remove clang bits from target packages, we are not providing it for the system > > > + if ${@bb.utils.contains('PACKAGECONFIG', 'libclc', 'true', 'false', d)} && > > > + [ "${CLASSOVERRIDE}" != "class-native" ] ; then > > > + rm -f ${D}${bindir}/clang* > > > + rm -fr ${D}${libdir}/clang > > > + rm -fr ${D}${datadir}/clang > > > + > > > + rm -f ${D}${bindir}/scan* > > > + rm -fr ${D}${libdir}/libscanbuild > > > + rm -fr ${D}${datadir}/scan-build > > > + rm -fr ${D}${datadir}/scan-view > > > + > > > + rm -fr ${D}${libdir}/libear > > > + fi > > > > Why does this need to be done, if we're only adding libclc? Is it > > dependent on those bits being built? > > This definitely is described in the commit message: 'Don't install clang > into the target system, it is only used during the build process.' What I don't understand is why target executables are being built, if we only need to build a target library. If they can't be run directly, how are they used during the build process? Alex
diff --git a/meta/recipes-devtools/llvm/llvm/fix-native-compilation.patch b/meta/recipes-devtools/llvm/llvm/fix-native-compilation.patch new file mode 100644 index 000000000000..4d51b6617cc4 --- /dev/null +++ b/meta/recipes-devtools/llvm/llvm/fix-native-compilation.patch @@ -0,0 +1,67 @@ +From e94e529aefb28b65165e978daa2bfd89867ee8d0 Mon Sep 17 00:00:00 2001 +From: Dmitry Baryshkov <dmitry.baryshkov@oss.qualcomm.com> +Date: Fri, 21 Mar 2025 17:17:52 +0200 +Subject: [PATCH] cmake/modules/CrossCompile: fix NATIVE build setup + +Fix variables being passed to cmake when generating NATIVE build dir. + +Upstream-Status: Inappropriate [OE-Specific build-system fix] +Signed-off-by: Dmitry Baryshkov <dmitry.baryshkov@oss.qualcomm.com> + +Index: llvm-project-20.1.0.src/llvm/cmake/modules/CrossCompile.cmake +=================================================================== +--- llvm-project-20.1.0.src.orig/llvm/cmake/modules/CrossCompile.cmake ++++ llvm-project-20.1.0.src/llvm/cmake/modules/CrossCompile.cmake +@@ -23,19 +23,37 @@ function(llvm_create_cross_target projec + if (EXISTS ${LLVM_MAIN_SRC_DIR}/cmake/platforms/${toolchain}.cmake) + set(CROSS_TOOLCHAIN_FLAGS_INIT + -DCMAKE_TOOLCHAIN_FILE=\"${LLVM_MAIN_SRC_DIR}/cmake/platforms/${toolchain}.cmake\") ++ elseif (${target_name} STREQUAL NATIVE) ++ set(CROSS_TOOLCHAIN_FLAGS_INIT ++ -DCMAKE_C_COMPILER=\"${LLVM_NATIVE_C_COMPILER}\" ++ -DCMAKE_CXX_COMPILER=\"${LLVM_NATIVE_CXX_COMPILER}\" ++ -DCMAKE_C_FLAGS=\"${LLVM_NATIVE_C_FLAGS}\" ++ -DCMAKE_CXX_FLAGS=\"${LLVM_NATIVE_CXX_FLAGS}\" ++ -DCMAKE_EXE_LINKER_FLAGS=\"${LLVM_NATIVE_LD_FLAGS}\" ++ ) + elseif (NOT CMAKE_CROSSCOMPILING) + set(CROSS_TOOLCHAIN_FLAGS_INIT + -DCMAKE_C_COMPILER=${CMAKE_C_COMPILER} + -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER} + ) + endif() + set(CROSS_TOOLCHAIN_FLAGS_${target_name} ${CROSS_TOOLCHAIN_FLAGS_INIT} + CACHE STRING "Toolchain configuration for ${target_name}") + + # project specific version of the flags up above + set(CROSS_TOOLCHAIN_FLAGS_${project_name}_${target_name} "" + CACHE STRING "Toolchain configuration for ${project_name}_${target_name}") + ++ if (${target_name} STREQUAL NATIVE) ++ set(cross_flags ++ "-DLLVM_DEFAULT_TARGET_TRIPLE='${LLVM_NATIVE_TRIPLE}'") ++ else() ++ set(cross_flags ++ "-DLLVM_DEFAULT_TARGET_TRIPLE='${LLVM_TARGET_TRIPLE}'" ++ "-DLLVM_TARGET_ARCH='${LLVM_TARGET_ARCH}'" ++ "-DLLVM_TARGET_IS_CROSSCOMPILE_HOST=TRUE") ++ endif() ++ + if (buildtype) + set(build_type_flags "-DCMAKE_BUILD_TYPE=${buildtype}") + endif() +@@ -91,12 +111,11 @@ function(llvm_create_cross_target projec + -DCMAKE_C_COMPILER_LAUNCHER="${CMAKE_C_COMPILER_LAUNCHER}" + -DCMAKE_CXX_COMPILER_LAUNCHER="${CMAKE_CXX_COMPILER_LAUNCHER}" + ${CROSS_TOOLCHAIN_FLAGS_${target_name}} ${CMAKE_CURRENT_SOURCE_DIR} ++ #${CROSS_TOOLCHAIN_FLAGS_INIT} ${CMAKE_CURRENT_SOURCE_DIR} + ${CROSS_TOOLCHAIN_FLAGS_${project_name}_${target_name}} +- -DLLVM_TARGET_IS_CROSSCOMPILE_HOST=TRUE ++ ${cross_flags} + -DLLVM_TARGETS_TO_BUILD="${targets_to_build_arg}" + -DLLVM_EXPERIMENTAL_TARGETS_TO_BUILD="${experimental_targets_to_build_arg}" +- -DLLVM_DEFAULT_TARGET_TRIPLE="${LLVM_TARGET_TRIPLE}" +- -DLLVM_TARGET_ARCH="${LLVM_TARGET_ARCH}" + -DLLVM_ENABLE_PROJECTS="${llvm_enable_projects_arg}" + -DLLVM_EXTERNAL_PROJECTS="${llvm_external_projects_arg}" + -DLLVM_ENABLE_RUNTIMES="${llvm_enable_runtimes_arg}" diff --git a/meta/recipes-devtools/llvm/llvm_20.1.0.bb b/meta/recipes-devtools/llvm/llvm_20.1.0.bb index 7470d2b4d8a5..0fb336ee7747 100644 --- a/meta/recipes-devtools/llvm/llvm_20.1.0.bb +++ b/meta/recipes-devtools/llvm/llvm_20.1.0.bb @@ -26,8 +26,10 @@ LLVM_RELEASE = "${PV}" SRC_URI = "https://github.com/llvm/llvm-project/releases/download/llvmorg-${PV}/llvm-project-${PV}.src.tar.xz \ file://0007-llvm-allow-env-override-of-exe-path.patch \ file://0001-AsmMatcherEmitter-sort-ClassInfo-lists-by-name-as-we.patch \ + file://fix-native-compilation.patch \ file://llvm-config \ " + SRC_URI[sha256sum] = "4579051e3c255fb4bb795d54324f5a7f3ef79bd9181e44293d7ee9a7f62aad9a" UPSTREAM_CHECK_URI = "https://github.com/llvm/llvm-project" UPSTREAM_CHECK_REGEX = "llvmorg-(?P<pver>\d+(\.\d+)+)" @@ -56,19 +58,22 @@ def get_llvm_arch(bb, d, arch_var): def get_llvm_host_arch(bb, d): return get_llvm_arch(bb, d, 'HOST_ARCH') -PACKAGECONFIG ??= "libllvm" +PACKAGECONFIG ??= "libllvm libclc" # if optviewer OFF, force the modules to be not found or the ones on the host would be found PACKAGECONFIG[optviewer] = ",-DPY_PYGMENTS_FOUND=OFF -DPY_PYGMENTS_LEXERS_C_CPP_FOUND=OFF -DPY_YAML_FOUND=OFF,python3-pygments python3-pyyaml,python3-pygments python3-pyyaml" PACKAGECONFIG[libllvm] = "" +PACKAGECONFIG[libclc] = "" # # Default to build all OE-Core supported target arches (user overridable). # -LLVM_TARGETS ?= "AMDGPU;${@get_llvm_host_arch(bb, d)}" +LLVM_TARGETS ?= "AMDGPU;NVPTX;SPIRV;${@get_llvm_host_arch(bb, d)}" ARM_INSTRUCTION_SET:armv5 = "arm" ARM_INSTRUCTION_SET:armv4t = "arm" +LLVM_PROJECTS = "${@bb.utils.contains('PACKAGECONFIG', 'libclc', 'clang;libclc', '', d)}" + EXTRA_OECMAKE += "-DLLVM_ENABLE_ASSERTIONS=OFF \ -DLLVM_ENABLE_EXPENSIVE_CHECKS=OFF \ -DLLVM_ENABLE_PIC=ON \ @@ -82,6 +87,13 @@ EXTRA_OECMAKE += "-DLLVM_ENABLE_ASSERTIONS=OFF \ -DLLVM_VERSION_SUFFIX='${VER_SUFFIX}' \ -DLLVM_TEMPORARILY_ALLOW_OLD_TOOLCHAIN=ON \ -DCMAKE_BUILD_TYPE=Release \ + -DLLVM_ENABLE_PROJECTS='${LLVM_PROJECTS}' \ + -DLLVM_NATIVE_TRIPLE='${BUILD_SYS}' \ + -DLLVM_NATIVE_C_COMPILER=\'${@ d.getVar('BUILD_CC').replace('ccache', '').strip()}\' \ + -DLLVM_NATIVE_CXX_COMPILER=\'${@ d.getVar('BUILD_CXX').replace('ccache', '').strip()}\' \ + -DLLVM_NATIVE_C_FLAGS='${BUILD_CFLAGS}' \ + -DLLVM_NATIVE_CXX_FLAGS='${BUILD_CXXFLAGS}' \ + -DLLVM_NATIVE_LD_FLAGS='${BUILD_LDFLAGS}' \ " EXTRA_OECMAKE:append:class-target = "\ @@ -89,6 +101,8 @@ EXTRA_OECMAKE:append:class-target = "\ -DLLVM_HOST_TRIPLE=${TARGET_SYS} \ -DLLVM_TABLEGEN=${STAGING_BINDIR_NATIVE}/llvm-tblgen${PV} \ -DLLVM_CONFIG_PATH=${STAGING_BINDIR_NATIVE}/llvm-config${PV} \ + -DLLVM_NATIVE_TOOL_DIR=${STAGING_BINDIR_NATIVE} \ + -DCLANG_TABLEGEN=${STAGING_BINDIR_NATIVE}/clang-tblgen \ " EXTRA_OECMAKE:append:class-nativesdk = "\ @@ -96,6 +110,8 @@ EXTRA_OECMAKE:append:class-nativesdk = "\ -DLLVM_HOST_TRIPLE=${SDK_SYS} \ -DLLVM_TABLEGEN=${STAGING_BINDIR_NATIVE}/llvm-tblgen${PV} \ -DLLVM_CONFIG_PATH=${STAGING_BINDIR_NATIVE}/llvm-config${PV} \ + -DLLVM_NATIVE_TOOL_DIR=${STAGING_BINDIR_NATIVE} \ + -DCLANG_TABLEGEN=${STAGING_BINDIR_NATIVE}/clang-tblgen \ " # patch out build host paths for reproducibility @@ -124,11 +140,26 @@ do_install() { # Remove opt-viewer: https://llvm.org/docs/Remarks.html rm -rf ${D}${datadir}/opt-viewer - rmdir ${D}${datadir} + rmdir ${D}${datadir} || true # reproducibility sed -i -e 's,${WORKDIR},,g' ${D}/${libdir}/cmake/llvm/LLVMConfig.cmake fi + + # Remove clang bits from target packages, we are not providing it for the system + if ${@bb.utils.contains('PACKAGECONFIG', 'libclc', 'true', 'false', d)} && + [ "${CLASSOVERRIDE}" != "class-native" ] ; then + rm -f ${D}${bindir}/clang* + rm -fr ${D}${libdir}/clang + rm -fr ${D}${datadir}/clang + + rm -f ${D}${bindir}/scan* + rm -fr ${D}${libdir}/libscanbuild + rm -fr ${D}${datadir}/scan-build + rm -fr ${D}${datadir}/scan-view + + rm -fr ${D}${libdir}/libear + fi } do_install:append:class-native() { @@ -145,9 +176,11 @@ llvm_sysroot_preprocess() { ln -sf llvm-config ${SYSROOT_DESTDIR}${bindir_crossscripts}/llvm-config${PV} } -PACKAGES =+ "${PN}-bugpointpasses ${PN}-llvmhello ${PN}-libllvm ${PN}-liboptremarks ${PN}-liblto" +PACKAGES =+ "${PN}-bugpointpasses ${PN}-llvmhello ${PN}-libllvm ${PN}-liboptremarks ${PN}-liblto ${PN}-clc" +PROVIDES = "libclc" RRECOMMENDS:${PN}-dev += "${PN}-bugpointpasses ${PN}-llvmhello ${PN}-liboptremarks" +RPROVIDES:${PN}-clc += "libclc" FILES:${PN}-bugpointpasses = "\ ${libdir}/BugpointPasses.so \ @@ -180,6 +213,8 @@ FILES:${PN}-staticdev += "\ ${libdir}/*.a \ " +FILES:${PN}-clc += "${datadir}/clc" + INSANE_SKIP:${PN}-libllvm += "dev-so" BBCLASSEXTEND = "native nativesdk"
Current Mesa requires libclc in order to build Intel Gallium (iris) or Vulkan drivers. In order to unblock Mesa updates, build libclc (and clang) as a part of the build process. Don't install clang into the target system, it is only used during the build process. Proper handling of clang as a toolchain is a separate and much more complicated topic. Signed-off-by: Dmitry Baryshkov <dmitry.baryshkov@oss.qualcomm.com> --- .../llvm/llvm/fix-native-compilation.patch | 67 +++++++++++++++++++ meta/recipes-devtools/llvm/llvm_20.1.0.bb | 43 ++++++++++-- 2 files changed, 106 insertions(+), 4 deletions(-) create mode 100644 meta/recipes-devtools/llvm/llvm/fix-native-compilation.patch