From 7a5f476569a78a3d4ad3f654740a1ea51f86d42e Mon Sep 17 00:00:00 2001 From: Sylvestre Ledru Date: Fri, 27 Aug 2021 09:41:17 +0200 Subject: [PATCH] debian: Include SPIR-V (*.spv) outputs in libclc package This adds the following to the libclc-12 package: /usr/lib/clc/spirv64-mesa3d-.spv /usr/lib/clc/spirv-mesa3d-.spv Since Debian buster & Ubuntu 18.04 don't have the llvm-spirv package, they cannot support this feature. Therefore, as suggested by tjaalton, we make the control Build-Depends for spirv dependencies include "| hello". This causes the simple "hello world" package to be installed on these older distros, which is small and unrelated to llvm. Then, in debian/rules, we check to see if llvm-spirv is installed. Note that sbuild must use `--resolve-alternatives` for these older distributions, or sbuild won't search for the "hello" alternatives in the Build-Depends. Signed-off-by: Jordan Justen --- debian/changelog | 2 +- debian/control | 4 +++- debian/libclc-X.Y.install.in | 1 + debian/patches/libclc-llvm-spirv.diff | 13 +++++++++++++ debian/patches/series | 1 + debian/rules | 19 ++++++++++++++++++- 6 files changed, 37 insertions(+), 3 deletions(-) create mode 100644 debian/patches/libclc-llvm-spirv.diff diff --git a/debian/changelog b/debian/changelog index 726eb876..acbd7dab 100644 --- a/debian/changelog +++ b/debian/changelog @@ -117,7 +117,7 @@ llvm-toolchain-snapshot (1:13~++20210129063721+010b176cdefb-1~exp1) experimental llvm-toolchain-12 (1:12.0.1-5) unstable; urgency=medium [ Jordan Justen ] - * libclc: Include libclc spir-v outputs (used by Mesa opencl) + * Include SPIR-V (*.spv) outputs in libclc package -- Sylvestre Ledru Tue, 17 Aug 2021 10:19:22 +0200 diff --git a/debian/control b/debian/control index 20456ee6..16540475 100644 --- a/debian/control +++ b/debian/control @@ -19,7 +19,9 @@ Build-Depends: debhelper (>= 9.0), cmake, chrpath, texinfo, sharutils, ocaml-findlib [amd64 arm64 armhf ppc64el s390x], libctypes-ocaml-dev [amd64 arm64 armhf ppc64el s390x], dh-exec, dh-ocaml [amd64 arm64 armhf ppc64el s390x], - libpfm4-dev [linux-any], python3-setuptools, libz3-dev + libpfm4-dev [linux-any], python3-setuptools, libz3-dev, + llvm-spirv | hello, spirv-tools | hello +# "| hello" is for older buster/bionic distros without spirv support Build-Conflicts: oprofile, ocaml Standards-Version: 4.2.1 Homepage: https://www.llvm.org/ diff --git a/debian/libclc-X.Y.install.in b/debian/libclc-X.Y.install.in index 36023694..923094ff 100644 --- a/debian/libclc-X.Y.install.in +++ b/debian/libclc-X.Y.install.in @@ -1 +1,2 @@ usr/lib/clc/*.bc +#spv usr/lib/clc/*.spv diff --git a/debian/patches/libclc-llvm-spirv.diff b/debian/patches/libclc-llvm-spirv.diff new file mode 100644 index 00000000..d6a57203 --- /dev/null +++ b/debian/patches/libclc-llvm-spirv.diff @@ -0,0 +1,13 @@ +diff --git a/libclc/CMakeLists.txt b/libclc/CMakeLists.txt +index b8b5ceff086c..5964468358f2 100644 +--- a/libclc/CMakeLists.txt ++++ b/libclc/CMakeLists.txt +@@ -95,7 +95,7 @@ find_program( LLVM_CLANG clang PATHS ${LLVM_BINDIR} NO_DEFAULT_PATH ) + find_program( LLVM_AS llvm-as PATHS ${LLVM_BINDIR} NO_DEFAULT_PATH ) + find_program( LLVM_LINK llvm-link PATHS ${LLVM_BINDIR} NO_DEFAULT_PATH ) + find_program( LLVM_OPT opt PATHS ${LLVM_BINDIR} NO_DEFAULT_PATH ) +-find_program( LLVM_SPIRV llvm-spirv PATHS ${LLVM_BINDIR} NO_DEFAULT_PATH ) ++find_program( LLVM_SPIRV llvm-spirv PATHS ${LLVM_BINDIR}) + + # Print toolchain + message( "clang: ${LLVM_CLANG}" ) diff --git a/debian/patches/series b/debian/patches/series index 23b66509..2de0da72 100644 --- a/debian/patches/series +++ b/debian/patches/series @@ -143,3 +143,4 @@ lower-python-dep.diff scan-build-py-fix-analyze-path.diff scan-build-py-fix-default-bin.diff clang-soname-extract-version.diff +libclc-llvm-spirv.diff diff --git a/debian/rules b/debian/rules index c8caf683..a902df2d 100755 --- a/debian/rules +++ b/debian/rules @@ -140,6 +140,17 @@ else control_vars = '-Vdep:devlibs=libstdc++6-$(GCC_VERSION)-dev' endif +ifeq ($(shell which llvm-spirv),) +LLVM_SPIRV_INSTALLED = no +else +LLVM_SPIRV_INSTALLED = yes +endif + +LIBCLC_TARGETS_TO_BUILD="amdgcn--;amdgcn--amdhsa;r600--;nvptx--;nvptx64--;nvptx--nvidiacl;nvptx64--nvidiacl" +ifeq ($(LLVM_SPIRV_INSTALLED),yes) + LIBCLC_TARGETS_TO_BUILD := $(LIBCLC_TARGETS_TO_BUILD)";spirv-mesa3d-;spirv64-mesa3d-" +endif + # Disabled: # Host compiler does not support '-fuse-ld=lld' # USE_LLD_ARCHS := amd64 @@ -359,6 +370,12 @@ preconfigure: debian/llvm-$(LLVM_VERSION)-dev.install \ debian/llvm-$(LLVM_VERSION)-linker-tools.install + # Conditionally enable *.spv files. Debian buster and Ubuntu 18.04 + # don't have llvm-spirv to create the *.spv files. + if test "$(LLVM_SPIRV_INSTALLED)" = "yes"; then \ + sed -i -e "s|#spv\ ||g" debian/libclc-$(LLVM_VERSION).install; \ + fi + # Override this two targets. They are trying to manage the .in conversion for me override_dh_ocamlinit: override_dh_ocamlclean: @@ -539,7 +556,7 @@ debian-libclc-build: -DCMAKE_INSTALL_DATADIR=lib \ -DCMAKE_INSTALL_INCLUDEDIR=include \ -DLLVM_CONFIG=$(CURDIR)/$(TARGET_BUILD_STAGE2)/bin/llvm-config \ - -DLIBCLC_TARGETS_TO_BUILD="amdgcn--;amdgcn--amdhsa;r600--;nvptx--;nvptx64--;nvptx--nvidiacl;nvptx64--nvidiacl"; \ + -DLIBCLC_TARGETS_TO_BUILD=$(LIBCLC_TARGETS_TO_BUILD); \ make $(NJOBS) $(VERBOSE) touch $@