Subject: [bug#71109] [PATCH] gnu: vulkan-tools: Wrap binaries with LD_LIBRARY_PATH.

From: nathan <[email-masked]>
Date: Sun, 2 Jun 2024 01:19:14 +0000

commit e156996c478a8e5d040ccf199437bcdbdbab63ed in vulkan-tools makes it 
use volk to load vulkan instead of a bunch of custom code in the repo.
volk uses dlopen("libvulkan.so.1").
i dont remember volk ever working, so this just propagated the bug to 
another program.
attached is a patch to hard-code the libvulkan.so path into volk.

vulkan-headers also has dlopen for libvulkan.so.
i dont know which programs use it, but next time we have to rebuild 
everything we may as well patch it.
i attached a patch that shows how to do it.

From 811d7567098e00711ee4c9c80afbe544ebe1c08e Mon Sep 17 00:00:00 2001
Message-ID: <811[email-masked]>
From: nathan <[email-masked]>
Date: Sat, 1 Jun 2024 21:14:13 -0400
Subject: [PATCH] example of how to patch patch of vulkan-loader into
 vulkan-headers

Change-Id: Ic674a4d965d8049e388d75137111ed0253ca3b18
---
 gnu/packages/vulkan.scm | 24 ++++++++++++++++++++++--
 1 file changed, 22 insertions(+), 2 deletions(-)

diff --git a/gnu/packages/vulkan.scm b/gnu/packages/vulkan.scm
index 4c53a19aba..2fc2feeeba 100644
--- a/gnu/packages/vulkan.scm
+++ b/gnu/packages/vulkan.scm
@@ -238,7 +238,8 @@ (define-public glslang
                    ;; include/SPIRV/{bitutils,hex_float}.h are Apache 2.0.
                    license:asl2.0))))
 
-(define-public vulkan-headers
+;; vulkan-headers, but without the path to vulkan-loader patched in.
+(define vulkan-headers/no-loader
   (package
     (name "vulkan-headers")
     (version "1.3.280.0")
@@ -255,6 +256,7 @@ (define-public vulkan-headers
     (build-system cmake-build-system)
     (arguments
      `(#:tests? #f))                    ; No tests.
+    (properties '((hidden? . #t)))
     (home-page
      "https://github.com/KhronosGroup/Vulkan-Headers")
     (synopsis "Vulkan Header files and API registry")
@@ -262,6 +264,24 @@ (define-public vulkan-headers
      "Vulkan-Headers contains header files and API registry for Vulkan.")
     (license (list license:asl2.0)))) ;LICENSE.txt
 
+(define-public vulkan-headers
+  (package
+    (inherit vulkan-headers/no-loader)
+    (arguments
+     (substitute-keyword-arguments (package-arguments vulkan-headers/no-loader)
+       ((#:phases phases #~%standard-phases)
+        #~(modify-phases #$phases
+            (add-after 'unpack 'patch-loader-path
+              (lambda* (#:key inputs #:allow-other-keys)
+                (substitute* "include/vulkan/vulkan.hpp"
+                  (("dlopen\\( \"libvulkan.so")
+                   (string-append "dlopen(\"" (assoc-ref inputs "vulkan-loader")
+                                  "/lib/libvulkan.so")))))))))
+    (inputs
+     (modify-inputs (package-inputs vulkan-headers/no-loader)
+       (prepend vulkan-loader)))
+    (properties '())))
+
 (define-public vulkan-loader
   (package
     (name "vulkan-loader")
@@ -318,7 +338,7 @@ (define-public vulkan-loader
            python
            wayland))
     (inputs
-     (list vulkan-headers libxrandr))
+     (list vulkan-headers/no-loader libxrandr))
     (native-search-paths
      (list (search-path-specification
             (variable "XDG_DATA_DIRS")

base-commit: fa7906d64881ee12e0c418136b44c73766e3d169
-- 
2.45.1

From ee4581690b6486a65bf0e4faed3f2c88cac70d9e Mon Sep 17 00:00:00 2001
Message-ID: <ee4[email-masked]>
From: nathan <[email-masked]>
Date: Sat, 1 Jun 2024 19:55:24 -0400
Subject: [PATCH] gnu: volk: Hard-code path of vulkan-loader for dynamic
 loading

* gnu/packages/vulkan.scm (volk):
[arguments]: use gexp.
<#:phases>: patch dlopen with libvulkan.so. fixes vulkan-tools and potentially
other programs too.
[input]: add vulkan-loader

Change-Id: I5ef0eb13d35e517b8947faddace641882a775b80
---
 gnu/packages/vulkan.scm | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/gnu/packages/vulkan.scm b/gnu/packages/vulkan.scm
index 4c53a19aba..215a592266 100644
--- a/gnu/packages/vulkan.scm
+++ b/gnu/packages/vulkan.scm
@@ -568,9 +568,18 @@ (define-public volk
                 "0x4jhc8n9c4k8svmmcaxxs613xbsav7wam94gacddlm738cwp13v"))))
     (build-system cmake-build-system)
     (arguments
-     '(#:tests? #f                      ;no test
-       #:configure-flags '("-DVOLK_INSTALL=ON" "-DVOLK_PULL_IN_VULKAN=ON")))
-    (inputs (list vulkan-headers))
+     (list
+      #:tests? #f                      ;no test
+      #:configure-flags #~(list "-DVOLK_INSTALL=ON" "-DVOLK_PULL_IN_VULKAN=ON")
+      #:phases
+      #~(modify-phases %standard-phases
+          (add-after 'unpack 'patch-loader-path
+            (lambda* (#:key inputs #:allow-other-keys)
+              (substitute* "volk.c"
+                (("dlopen\\(\"libvulkan.so")
+                 (string-append "dlopen(\"" (assoc-ref inputs "vulkan-loader")
+                                "/lib/libvulkan.so"))))))))
+    (inputs (list vulkan-headers vulkan-loader))
     (synopsis "Meta loader for Vulkan API")
     (description
      "Volk is a meta-loader for Vulkan.  It allows you to dynamically load

base-commit: fa7906d64881ee12e0c418136b44c73766e3d169
-- 
2.45.1