[Buildroot] [[DO NOT MERGE] v3 7/7] package/llvm-project: add opencl-c-base.h on target
Antoine Coutant
antoine.coutant at smile.fr
Fri Nov 24 16:15:23 UTC 2023
rusticl depends on the mesa clc_compile_to_llvm_module function.
This function requires opencl-c-base.h when LLVM version >= 15.
The header is deleted automatically by CLANG_FILES_TO_REMOVE
post install target hook in llvm-project/clang package.
When rusticl is enabled, after the whole clang directory has
been removed, the header is copied back to
/usr/lib/clang/$(LLVM_PROJECT_VERSION)/include/
By default, the mesa3d variable used to retrieve the header
is set to the staging directory on the host machine. Thus
this variable must be set to /usr/lib<suffix> when
cross-compiling:
https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/25568
This patch is the actual version discussed on Mesa's merge request.
It works with buildroot but most not be the final version.
Signed-off-by: Antoine Coutant <antoine.coutant at smile.fr>
---
Running an app that uses rusticl leads to an error.
Example:
RUSTICL_ENABLE=panfrost clpeak
Platform: rusticl
Device: Mali-G52 (Panfrost)
Driver version : 23.2.1 (Linux ARM64)
Compute units : 2
Clock frequency : 800 MHz
Build Log: <built-in>:1:10: fatal error: 'opencl-c-base.h' file not found
Error executing LLVM compilation action.
Signed-off-by: Antoine Coutant <antoine.coutant at smile.fr>
---
package/llvm-project/clang/clang.mk | 9 ++++
...LIB_DIR-to-usr-lib-when-cross-compil.patch | 45 +++++++++++++++++++
2 files changed, 54 insertions(+)
create mode 100644 package/mesa3d/0005-clc-define-LLVM_LIB_DIR-to-usr-lib-when-cross-compil.patch
diff --git a/package/llvm-project/clang/clang.mk b/package/llvm-project/clang/clang.mk
index 0bafd6461b..09aac7f0ec 100644
--- a/package/llvm-project/clang/clang.mk
+++ b/package/llvm-project/clang/clang.mk
@@ -90,6 +90,15 @@ define HOST_CLANG_INSTALL_CLANG_TBLGEN
endef
HOST_CLANG_POST_INSTALL_HOOKS = HOST_CLANG_INSTALL_CLANG_TBLGEN
+# Rusticl needs opencl-c-base.h to be present on the target.
+define CLANG_OPENCL_C_BASE_HEADER_TO_TARGET
+ mkdir -p $(TARGET_DIR)/usr/lib/clang/$(LLVM_PROJECT_VERSION)/include
+ $(INSTALL) -D -m 0644 $(@D)/lib/Headers/opencl-c-base.h $(TARGET_DIR)/usr/lib/clang/$(LLVM_PROJECT_VERSION)/include/opencl-c-base.h
+endef
+ifeq ($(BR2_PACKAGE_MESA3D_RUSTICL),y)
+CLANG_POST_INSTALL_TARGET_HOOKS += CLANG_OPENCL_C_BASE_HEADER_TO_TARGET
+endif
+
# This option must be enabled to link libclang dynamically against libLLVM.so
HOST_CLANG_CONF_OPTS += -DLLVM_LINK_LLVM_DYLIB=ON
CLANG_CONF_OPTS += -DLLVM_LINK_LLVM_DYLIB=ON
diff --git a/package/mesa3d/0005-clc-define-LLVM_LIB_DIR-to-usr-lib-when-cross-compil.patch b/package/mesa3d/0005-clc-define-LLVM_LIB_DIR-to-usr-lib-when-cross-compil.patch
new file mode 100644
index 0000000000..e03aa5ae01
--- /dev/null
+++ b/package/mesa3d/0005-clc-define-LLVM_LIB_DIR-to-usr-lib-when-cross-compil.patch
@@ -0,0 +1,45 @@
+From 25eb672ca85b3a5f85b4e7a68c582b686c61c63d Mon Sep 17 00:00:00 2001
+From: Antoine Coutant <antoine.coutant at smile.fr>
+Date: Thu, 5 Oct 2023 14:58:26 +0200
+Subject: [PATCH] clc: define LLVM_LIB_DIR to /usr/lib when cross-compiling
+
+LLVM_LIB_DIR is a variable used for runtime compilations.
+While cross compiling, LLVM_LIB_DIR must be defined
+at the path of the libclang.so library on the target.
+
+llvm_libdir is the absolute path of libclang.so on the host
+machine. By default, libclang.so should be installed to
+`/usr/lib` on the target.
+
+v2: Set llvm_libdir to `/usr/lib<suffix>` because it is possible to define
+a custom suffix when compiling clang. The suffix is retrieved from
+llvm_libdir whose last term is "lib<suffix>".
+
+Signed-off-by: Antoine Coutant <antoine.coutant at smile.fr>
+---
+ src/compiler/clc/meson.build | 8 ++++++++
+ 1 file changed, 8 insertions(+)
+
+diff --git a/src/compiler/clc/meson.build b/src/compiler/clc/meson.build
+index 3ac1f5fc15a..60860fd5f9c 100644
+--- a/src/compiler/clc/meson.build
++++ b/src/compiler/clc/meson.build
+@@ -27,7 +27,15 @@ files_libmesaclc = files(
+ )
+
+ _libmesaclc_c_args = []
++# While cross-compiling, llvm_libdir contains the absolute path to llvm libraries
++# installed in the staging directory. LLVM_LIB_DIR is used for runtime
++# compilation on target and shouldn't contain the host absolute path (llvm_libdir)
++# but the path where libclang.so should be installed (/usr/lib<suffix>).
++if meson.is_cross_build()
++_libmesaclc_cpp_args = ['-DLLVM_LIB_DIR="/usr/@0@"'.format(llvm_libdir.split('/')[-1])]
++else
+ _libmesaclc_cpp_args = ['-DLLVM_LIB_DIR="@0@"'.format(llvm_libdir)]
++endif
+ _libmesaclc_sources = []
+
+ if get_option('opencl-external-clang-headers') \
+--
+2.25.1
+
--
2.25.1
More information about the buildroot
mailing list