Subject: [bug#41778] [PATCH 0/3] Add ppsspp

From: Leo Prikler <[email-masked]>
Date: Tue, 30 Jun 2020 23:31:13 +0200

Am Dienstag, den 30.06.2020, 17:08 +0200 schrieb Nicolas Goaziou:
> Well, I still think dropping the note is appropriate, but I won't
> fight
> over it. Let me know if you find something that suits you better.
Don't get me wrong, I agree on dropping the note, but I didn't want to
resend the patch just to delete it (since deletion is a rather trivial
operation, simpler even than forming partial sentences to full ones in
comments).  Either way, I do have a better phrasing now, which I'll
attach.

> I applied your patches. I tweaked comments. In particular comments
> starting with two semicolons are full sentences and are supposed to
> start with a capital and end with a full stop.
Thanks you!  I managed to unbundle some more sources today and also
cleaned up my comments as I did so.

Regards, Leo
From 8d44bfdd8bfc0d9595ff1ecbc5fd5f00a5d1f4c5 Mon Sep 17 00:00:00 2001
From: Leo Prikler <[email-masked]>
Date: Tue, 30 Jun 2020 11:41:36 +0200
Subject: [PATCH 1/2] gnu: spirv-cross: Improve description.

* gnu/packages/vulkan.scm (spirv-cross)[description]: Simplify.
---
 gnu/packages/vulkan.scm | 8 +-------
 1 file changed, 1 insertion(+), 7 deletions(-)

diff --git a/gnu/packages/vulkan.scm b/gnu/packages/vulkan.scm
index 2e640f502c..fe37b59e26 100644
--- a/gnu/packages/vulkan.scm
+++ b/gnu/packages/vulkan.scm
@@ -144,13 +144,7 @@ parser,disassembler, validator, and optimizer for SPIR-V.")
     (synopsis "Parser for and converter of SPIR-V to other shader languages")
     (description
      "SPIRV-Cross tries hard to emit readable and clean output from the
-SPIR-V.  The goal is to emit GLSL or MSL that looks like it was written by
-a human and not awkward IR/assembly-like code.
-
-NOTE: Individual features are expected to be mostly complete, but it is
-possible that certain obscure GLSL features are not yet supported.  However,
-most missing features are expected to be ``trivial'' improvements at this
-stage.")
+SPIR-V, aiming to emit GLSL or MSL that looks like human-written code.")
     (license license:asl2.0)))
 
 (define-public glslang
-- 
2.27.0

From 655b614f643eeaac570dde3d999bb6fd29f55af6 Mon Sep 17 00:00:00 2001
From: Leo Prikler <[email-masked]>
Date: Tue, 30 Jun 2020 19:34:38 +0200
Subject: [PATCH 2/2] gnu: ppsspp: Unbundle more sources.

* gnu/packages/emulators (ppsspp)[source]: Update unbundling snippet.
[inputs]: Add cityhash, libzip, vulkan-headers, vulkan-loader, xxhash.
[arguments]<#:configure-flags>: Add -DUSE_SYSTEM_LIBZIP=ON.
Update comments accordingly.
---
 gnu/packages/emulators.scm | 79 ++++++++++++++++++++++++++++++--------
 1 file changed, 64 insertions(+), 15 deletions(-)

diff --git a/gnu/packages/emulators.scm b/gnu/packages/emulators.scm
index 8b39517e3f..8a9ca428a9 100644
--- a/gnu/packages/emulators.scm
+++ b/gnu/packages/emulators.scm
@@ -48,6 +48,7 @@
   #:use-module (gnu packages compression)
   #:use-module (gnu packages cross-base)
   #:use-module (gnu packages curl)
+  #:use-module (gnu packages digest)
   #:use-module (gnu packages elf)
   #:use-module (gnu packages fonts)
   #:use-module (gnu packages fontutils)
@@ -1858,25 +1859,69 @@ framework based on QEMU.")
        (modules '((guix build utils)))
        (snippet
         `(begin
-           ;; Unbundle sources.
-           (substitute* (list "Common/Vulkan/VulkanContext.cpp"
-                              "ext/native/thin3d/vulkan_utils.cpp"
-                              "GPU/Common/ShaderCommon.cpp"
-                              "GPU/Common/ShaderTranslation.cpp"
-                              "SDL/SDLMain.cpp")
+           ;; The following is quite a heavy-handed way of unbundling PPSSPP.
+           ;; There are still a number of external sources, that we don't
+           ;; remove here.  Some may be packaged, others are not.
+           ;; First, we patch existing sources to include the right headers.
+           (substitute* (append (list "ext/native/thin3d/vulkan_utils.cpp"
+                                      "ext/native/thin3d/thin3d_vulkan.cpp")
+                                (find-files "Common" ".*\\.(h|cpp)")
+                                (find-files "Core" ".*\\.(h|cpp)")
+                                (find-files "GPU" ".*\\.(h|cpp)")
+                                (find-files "SDL" ".*\\.(h|cpp)")
+                                (find-files "UI" ".*\\.(h|cpp)"))
+             ;; These headers are all hard-coded in the original source.
+             (("ext/cityhash/") "")
              (("ext/glslang/") "")
-             (("ext/SPIRV-Cross/") "spirv_cross/"))
-           ;; Patch CMakeLists.
+             (("ext/SPIRV-Cross/") "spirv_cross/")
+             (("ext/vulkan/") "vulkan/")
+             (("ext/xxhash.h") "xxhash.h")
+             ;; These definitions do not actually exist in the Vulkan headers,
+             ;; but PPSSPP defines them in ext/vulkan.
+             (("VK_FORMAT_BEGIN_RANGE") "VK_FORMAT_UNDEFINED")
+             (("VK_FORMAT_END_RANGE") "VK_FORMAT_ASTC_12x12_SRGB_BLOCK"))
+           ;; Next, we patch CMakeLists.
            (substitute* "CMakeLists.txt"
+             ;; Drop unnecessary includes and targets.
              (("include_directories\\(ext/glslang\\)") "")
+             (("include_directories\\(ext/xxhash\\)") "")
+             (("include_directories\\(ext/cityhash\\)") "")
+             (("set_target_properties\\(cityhash .*\\)") "")
+             ;; Fix linking to GLEW.
+             (("TARGET Ext::GLEW") "true")
+             (("target_link_libraries\\(native Ext::GLEW\\)")
+              "find_package(GLEW)\ntarget_link_libraries(native GLEW::GLEW)")
+             (("Ext::Snappy") "snappy")
+             ;; Don't search for cityhash/xxhash, we already have them.
+             (("add_library\\((city|xx)hash STATIC") "if()\nendif(")
+             (("ext/xxhash\\.[ch]") "")
+             (("ext/native/ext/cityhash/.*\\.(cpp|h)") "")
+             ;; Link all of spirv-cross.
              (("spirv-cross-glsl" all)
               (string-append all
                              " spirv-cross-core spirv-cross-cpp"
                              " spirv-cross-reflect spirv-cross-util")))
            (substitute* "ext/CMakeLists.txt"
+             (("add_subdirectory\\(glew\\)") "")
              (("add_subdirectory\\(glslang\\)") "")
+             (("add_subdirectory\\(snappy\\)") "")
              (("add_subdirectory\\(SPIRV-Cross-build\\)") ""))
-           (delete-file-recursively "ext/cmake")
+           ;; Finally, we can delete the bundled sources.
+           (for-each delete-file-recursively
+                     '("ext/cmake"
+                       "ext/glew"
+                       "ext/glslang" "ext/glslang-build"
+                       "ext/native/ext/cityhash"
+                       "ext/native/ext/libpng17"
+                       "ext/native/ext/libzip"
+                       "ext/snappy"
+                       "ext/SPIRV-Cross" "ext/SPIRV-Cross-build"
+                       "ext/vulkan"
+                       "ext/xxhash.c"
+                       "ext/xxhash.h"
+                       "ext/zlib"))
+           ;; Since we are not including git as an input, PPSSPP is confused
+           ;; about its version.  Let's fix that here.
            (substitute* "git-version.cmake"
              (("unknown") ,version))))))
     (build-system cmake-build-system)
@@ -1884,16 +1929,21 @@ framework based on QEMU.")
      `(("pkg-config" ,pkg-config)
        ("python" ,python)))
     (inputs
-     `(("ffmpeg" ,ffmpeg)
+     `(("cityhash" ,cityhash)
+       ("ffmpeg" ,ffmpeg)
        ("glew" ,glew)
        ("glslang" ,glslang)
        ("libpng" ,libpng)
+       ("libzip" ,libzip)
        ("mesa" ,mesa)
        ("sdl2" ,sdl2)
        ("snappy" ,snappy)
        ("spirv-cross" ,spirv-cross)
+       ("vulkan-headers" ,vulkan-headers)
+       ("vulkan-loader" ,vulkan-loader)
+       ("xxhash" ,xxhash)
        ("zlib" ,zlib)
-       ;; TODO: unbundle builds.
+       ;; TODO: unbundle armips.
        ("armips-source" ,(package-source armips))
        ("lang"
         ,(origin
@@ -1915,15 +1965,14 @@ framework based on QEMU.")
      `(#:out-of-source? #f
        #:configure-flags (list "-DUSE_DISCORD=OFF"
                                "-DUSE_SYSTEM_FFMPEG=ON"
-                               ;; For testing.
+                               "-DUSE_SYSTEM_LIBZIP=ON"
+                               ;; for testing
                                "-DUNITTEST=ON" "-DHEADLESS=ON")
        #:phases
        (modify-phases %standard-phases
          (add-after 'unpack 'add-external-sources
            (lambda* (#:key inputs #:allow-other-keys)
-             ;; TODO: unbundle builds.  Not only should we not copy these
-             ;; sources in, we should also remove as much from "ext/" as we
-             ;; can.
+             ;; TODO: unbundle armips.
              (copy-recursively (assoc-ref inputs "armips-source")
                                "ext/armips")
              ;; Some tests are externalised, so we add them here.
-- 
2.27.0