diff mbox series

[v2,3/3] mesa: bundle Clang OpenCL headers into meta-clc

Message ID 20250418-mesa-25-fixes-v2-3-e110ccfe291f@oss.qualcomm.com
State Under Review
Headers show
Series mesa: small improvements after 25.0 merge | expand

Commit Message

Dmitry Baryshkov April 18, 2025, 12:57 a.m. UTC
Add a patch bundling OpenCL headers into meta-clc. This removes extra
runtime dependencies when runnign meta-clc compiler.

Signed-off-by: Dmitry Baryshkov <dmitry.baryshkov@oss.qualcomm.com>
---
 ...d-an-option-to-force-inclusion-of-OpenCL-.patch | 57 ++++++++++++++++++++++
 meta/recipes-graphics/mesa/mesa.inc                |  3 +-
 2 files changed, 59 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/meta/recipes-graphics/mesa/files/0001-mesa-clc-add-an-option-to-force-inclusion-of-OpenCL-.patch b/meta/recipes-graphics/mesa/files/0001-mesa-clc-add-an-option-to-force-inclusion-of-OpenCL-.patch
new file mode 100644
index 0000000000000000000000000000000000000000..d65ba574d26da4088df272e7c589670ff1578747
--- /dev/null
+++ b/meta/recipes-graphics/mesa/files/0001-mesa-clc-add-an-option-to-force-inclusion-of-OpenCL-.patch
@@ -0,0 +1,57 @@ 
+From f9b6175e7c446a82c568ff1a214885d707c95f49 Mon Sep 17 00:00:00 2001
+From: Dmitry Baryshkov <dmitry.baryshkov@oss.qualcomm.com>
+Date: Wed, 16 Apr 2025 14:35:37 +0300
+Subject: [PATCH] mesa-clc: add an option to force inclusion of OpenCL headers
+
+Currently mesa-clc bundles OpenCL headers from Clang only if the static
+LLVM is used (which means Clang / LLVM are not present on the target
+system). In some cases (e.g. when building in OpenEmbedded environemnt)
+it is desirable to have shared LLVM library, but skip installing the
+whole Clang runtime just to compile shaders. Add an option that forces
+OpenCL headers to be bundled with the mesa-clc binary.
+
+Signed-off-by: Dmitry Baryshkov <dmitry.baryshkov@oss.qualcomm.com>
+Upstream-Status: Submitted [https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/34551]
+---
+ meson_options.txt                | 10 ++++++++++
+ src/compiler/clc/meson.build |  3 ++-
+ 2 files changed, 12 insertions(+), 1 deletion(-)
+
+diff --git a/meson_options.txt b/meson_options.txt
+index 18da31eff507..addd274ecef7 100644
+--- a/meson_options.txt
++++ b/meson_options.txt
+@@ -797,6 +797,16 @@ option(
+   description : 'Install the mesa-clc compiler (if needed for cross builds).'
+ )
+ 
++option(
++  'mesa-clc-bundle-headers',
++  type : 'combo',
++  value : 'auto',
++  choices : [
++    'enabled', 'auto'
++  ],
++  description : 'Bundle the OpenCL headers into the mesa-clc binary (default to bundle if static LLVM is used). Note, it might require rebuilding mesa-clc if opencl-c.h or opencl-c-base.h are changed (e.g. on Clang upgrades).'
++)
++
+ option(
+   'precomp-compiler',
+   type : 'combo',
+diff --git a/src/compiler/clc/meson.build b/src/compiler/clc/meson.build
+index 263eba527191..9ff61440f0da 100644
+--- a/src/compiler/clc/meson.build
++++ b/src/compiler/clc/meson.build
+@@ -11,7 +11,8 @@ _libmesaclc_c_args = []
+ _libmesaclc_cpp_args = ['-DLLVM_LIB_DIR="@0@"'.format(llvm_libdir)]
+ _libmesaclc_sources = []
+ 
+-if not _shared_llvm
++if not _shared_llvm or \
++    get_option('mesa-clc-bundle-headers') == 'enabled'
+   # LLVM 16 moved clang header path from using full version to only major version
+   if dep_llvm.version().version_compare('< 16')
+     # Prior to LLVM 16, this path used a full version
+-- 
+2.47.2
+
diff --git a/meta/recipes-graphics/mesa/mesa.inc b/meta/recipes-graphics/mesa/mesa.inc
index c76c5a075f1e2e81e887e77059c999014f742c4f..5062551b96c404f9267a1a9cd77f85635bc14edc 100644
--- a/meta/recipes-graphics/mesa/mesa.inc
+++ b/meta/recipes-graphics/mesa/mesa.inc
@@ -18,6 +18,7 @@  SRC_URI = "https://archive.mesa3d.org/mesa-${PV}.tar.xz \
            file://0001-meson-misdetects-64bit-atomics-on-mips-clang.patch \
            file://0001-meson-disable-SIMD-blake-optimisations-on-x32-host.patch \
            file://0001-freedreno-don-t-encode-build-path-into-binaries.patch\
+           file://0001-mesa-clc-add-an-option-to-force-inclusion-of-OpenCL-.patch \
 "
 
 SRC_URI[sha256sum] = "adf904d083b308df95898600ffed435f4b5c600d95fb6ec6d4c45638627fdc97"
@@ -193,7 +194,7 @@  MESA_NATIVE:class-native = ""
 
 PACKAGECONFIG[gallium] = "-Dgallium-drivers=${@strip_comma('${GALLIUMDRIVERS}')}, -Dgallium-drivers='', libdrm"
 PACKAGECONFIG[gallium-llvm] = "-Dllvm=enabled -Dshared-llvm=enabled, -Dllvm=disabled, llvm llvm-native elfutils"
-PACKAGECONFIG[libclc] = "-Dmesa-clc=${MESA_CLC} -Dinstall-mesa-clc=${INSTALL_MESA_CLC},,libclc spirv-tools spirv-llvm-translator ${MESA_NATIVE}"
+PACKAGECONFIG[libclc] = "-Dmesa-clc=${MESA_CLC} -Dinstall-mesa-clc=${INSTALL_MESA_CLC} -Dmesa-clc-bundle-headers=enabled,,libclc spirv-tools spirv-llvm-translator ${MESA_NATIVE}"
 PACKAGECONFIG[xa]  = "-Dgallium-xa=enabled, -Dgallium-xa=disabled"
 PACKAGECONFIG[va] = "-Dgallium-va=enabled,-Dgallium-va=disabled,libva-initial"
 PACKAGECONFIG[vdpau] = "-Dgallium-vdpau=enabled,-Dgallium-vdpau=disabled,libvdpau"