[bug#67755,v6,8/8] gnu: Add imhex.

Message ID f92b783e929b6e04923006a348409eb07b6b4e00.1742403600.git.liliana.prikler@gmail.com
State New
Headers
Series gnu: Add imhex |

Commit Message

Liliana Marie Prikler March 19, 2025, 5 p.m. UTC
  * gnu/packages/hexedit.scm (make-imhex-patterns, imhex): New variables.

Change-Id: I114d3a6c0dae32ea434a77a6bd88b8ff6870b70c
---
Changes from v5:
* Outlined make-imhex-patterns.
* Use keep lists rather than delete lists.
* Unbundle jthread.

I haven't sorted the inputs yet, but IMHO they should be sorted.
Same goes for the #:use-module lines, which would require sorting in an
extra commit.

Would you like to explain this note?
+        ;; NOTE: there is an issue with the way the test library is linked
+        ;; with the output binaries. Tests are intrusive and should not be
+        ;; shipped with the release, when the issue is fixed we could add a
+        ;; phase which builds the package with the tests and runs the
+        ;; testsuite and a second build phase which prepares the output
+        ;; binary.
IMHO it is the build system that should separate test-only code from installed
code.

 gnu/packages/hexedit.scm | 177 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 177 insertions(+)
  

Comments

Sergio Pastor Pérez March 19, 2025, 8:14 p.m. UTC | #1
On 3/19/25 18:00, Sergio Pastor Pérez wrote:
> Changes from v5:
> * Outlined make-imhex-patterns.

Looks good.

> * Use keep lists rather than delete lists.

That's fine by me.

> * Unbundle jthread.

Thanks again for taking care of this.

> I haven't sorted the inputs yet, but IMHO they should be sorted.
> Same goes for the #:use-module lines, which would require sorting in an
> extra commit.

Yes. I think they should be sorted too, my bad.

> Would you like to explain this note?
> +        ;; NOTE: there is an issue with the way the test library is linked
> +        ;; with the output binaries. Tests are intrusive and should not be
> +        ;; shipped with the release, when the issue is fixed we could add a
> +        ;; phase which builds the package with the tests and runs the
> +        ;; testsuite and a second build phase which prepares the output
> +        ;; binary.
> IMHO it is the build system that should separate test-only code from installed
> code.

I added this note after the developers told me that, for the release 
build, we should not chose the cmake build type that includes the some 
extra teststing, because they affect the ImHex binary, I'm not sure if 
it was instrumentation code or something else that could hinder 
performance. To be honest, it's been a year since I made this note, so I 
don't remember the name of the `#:build-type` that we should not use. I 
think, the default one that the `cmake-build-system` chooses is fine, 
`RelWithDebInfo`.

> +(define-public imhex
 > [...]
> +      (inputs
> +       (list yara
> +             boost
> +             capstone
> +             curl
> +             edlib

I think this last patch series you've sent, v6, is missing the `edlib` 
patch so this won't build. Could you make sure before pushing that the 
`edlib` patch has been applied?


Thanks for the efforts!


Best regards,
Sergio.
  
Liliana Marie Prikler March 19, 2025, 8:58 p.m. UTC | #2
Am Mittwoch, dem 19.03.2025 um 21:14 +0100 schrieb Sergio Pastor Pérez:
> I think this last patch series you've sent, v6, is missing the
> `edlib` patch so this won't build. Could you make sure before pushing
> that the `edlib` patch has been applied?
Oh, yeah, that's my bad, having used HEAD~8 instead of HEAD~9.

Cheers
  

Patch

diff --git a/gnu/packages/hexedit.scm b/gnu/packages/hexedit.scm
index ed30e882847..0ab684ded1b 100644
--- a/gnu/packages/hexedit.scm
+++ b/gnu/packages/hexedit.scm
@@ -28,11 +28,24 @@  (define-module (gnu packages hexedit)
   #:use-module (gnu packages)
   #:use-module (gnu packages autotools)
   #:use-module (gnu packages compression)
+  #:use-module (gnu packages gl)
   #:use-module (gnu packages man)
   #:use-module (gnu packages cpp)
   #:use-module (gnu packages gcc)
+  #:use-module (gnu packages tls)
+  #:use-module (gnu packages curl)
+  #:use-module (gnu packages llvm)
+  #:use-module (gnu packages ruby)
+  #:use-module (gnu packages glib)
+  #:use-module (gnu packages boost)
+  #:use-module (gnu packages backup)
   #:use-module (gnu packages python)
+  #:use-module (gnu packages libffi)
   #:use-module (gnu packages ncurses)
+  #:use-module (gnu packages antivirus)
+  #:use-module (gnu packages fontutils)
+  #:use-module (gnu packages pkg-config)
+  #:use-module (gnu packages engineering)
   #:use-module (gnu packages pretty-print)
   #:use-module (guix download)
   #:use-module (guix git-download)
@@ -206,6 +219,170 @@  (define-public imhex-pattern-language
 for specifying patterns in the ImHex Hex Editor.")
     (license license:lgpl2.1)))
 
+;; imhex-patterns can not currently be built by imhex-pattern-language alone,
+;; see above for a rationale.  Thus, we only return an origin.
+(define (make-imhex-patterns version sha256-hash)
+  (origin
+    (method git-fetch)
+    (uri (git-reference
+          (url "https://github.com/WerWolv/ImHex-Patterns")
+          (commit (string-append "ImHex-v" version))))
+    (file-name (git-file-name "imhex-patterns" version))
+    (sha256 sha256-hash)))
+
+(define-public imhex
+  (let* ((version "1.37.4")
+         (imhex-patterns
+          (make-imhex-patterns
+           version
+           (base32 "0m9g93fzmj2rsgaq25y4mmfigjh1xxyh41zjs6lp5ydsl5hhrn6q"))))
+    (package
+      (name "imhex")
+      (version version)
+      (source
+       (origin
+         (method git-fetch)
+         (uri (git-reference
+               (url "https://github.com/WerWolv/ImHex")
+               (commit (string-append "v" version))
+               (recursive? #t)))
+         (file-name (git-file-name name version))
+         (sha256
+          (base32 "0l3fpizkz2ykdirbn9alddnnsg75w6kwpp92nvmird13l80z1sdr"))
+         (modules '((guix build utils) (ice-9 ftw) (ice-9 match)))
+         (snippet
+          #~(begin
+              ;; XXX: imhex-pattern-language is missing the necessary packaging
+              ;; structure to be linked independently.  See the comment on its
+              ;; package.
+              (copy-recursively #$imhex-pattern-language
+                                "lib/external/pattern_language")
+              ;; Drop `imhex-patterns' in the source tree.
+              (copy-recursively #$imhex-patterns "ImHex-Patterns")
+
+              ;; NOTE: `libwolv' does not have an install target. Until the
+              ;; maintainers create one, it will remain bundled.
+              ;; NOTE: `libromfs' it's meant to be bundled and cannot be
+              ;; compiled independently. Until the maintainers support
+              ;; building it independently, it will remain bundled.
+              ;; NOTE: `hashlibplus' has been left as a submodule since it's a
+              ;; fork which only makes sense within ImHex.
+              ;; XXX: `imgui' is a fork with several experimental features.
+              ;; Unbundle once they're upstreamed.
+              (with-directory-excursion "lib/third_party"
+                (for-each
+                 (lambda (dir)
+                   (unless (member dir '("." ".."
+                                         "HashLibPlus" "libwolv" "libromfs"
+                                         "imgui"
+                                         ;; Needs source to include miniaudio.h
+                                         "miniaudio"
+                                         "microtar")) ; XXX: unbundle
+                     (delete-file-recursively dir)))
+                 (scandir "."))
+
+                ;; Force use of system miniaudio.
+                (delete-file "miniaudio/include/miniaudio.h")
+
+                (for-each
+                 (match-lambda
+                   ((src . dst) (copy-recursively src dst)))
+                 `((#$(package-source xdgpp) . "xdgpp"))))
+
+              ;; Adjust CMake build scripts accordingly.
+              (substitute* "cmake/build_helpers.cmake"
+                (("add_subdirectory\\(\\$\\{THIRD_PARTY_.*\\}/jthread .*\\)")
+                 "")
+                (("set\\(JTHREAD_LIBRARIES .*\\)") ""))
+
+              ;; Update sources.
+              (substitute* (append (find-files "lib/libimhex" "\\.[ch](pp)?")
+                                   (find-files "main" "\\.[ch](pp)?")
+                                   (find-files "plugins" "\\.[ch](pp)?"))
+                (("#include <jthread\\.hpp>") ""))
+              (substitute* "plugins/ui/source/ui/menu_items.cpp"
+                (("\\.\\./\\.\\./\\.\\./\\.\\./lib/libimhex/include/")
+                 ""))))))
+      (build-system cmake-build-system)
+      (arguments
+       (list
+        ;; NOTE: there is an issue with the way the test library is linked
+        ;; with the output binaries. Tests are intrusive and should not be
+        ;; shipped with the release, when the issue is fixed we could add a
+        ;; phase which builds the package with the tests and runs the
+        ;; testsuite and a second build phase which prepares the output
+        ;; binary.
+        #:configure-flags
+        ''("-DIMHEX_ENABLE_UNIT_TESTS=ON"
+           "-DIMHEX_OFFLINE_BUILD=ON"
+           ;; NOTE: required for the `validate-runpath' phase.
+           ;; If OFF, the pluggings won't be able to find `libimhex.so'.
+           "-DIMHEX_PLUGIN_ADD_INSTALL_PREFIX_TO_RPATH=ON"
+
+           "-DUSE_SYSTEM_NLOHMANN_JSON=ON"
+           "-DUSE_SYSTEM_CAPSTONE=ON"
+           "-DUSE_SYSTEM_LUNASVG=ON"
+           "-DUSE_SYSTEM_CLI11=ON"
+           "-DUSE_SYSTEM_BOOST=ON"
+           "-DUSE_SYSTEM_EDLIB=ON"
+           "-DUSE_SYSTEM_YARA=ON"
+           "-DUSE_SYSTEM_LLVM=ON"
+           "-DUSE_SYSTEM_FMT=ON"
+           "-DUSE_SYSTEM_NFD=ON")
+        #:phases
+        #~(modify-phases %standard-phases
+            (add-after 'unpack 'fix-paths
+              (lambda _
+                (substitute* "main/gui/source/window/linux_window.cpp"
+                  (("dbus-send")
+                   #$(file-append dbus "/bin/dbus-send")))
+                (substitute* "cmake/build_helpers.cmake"
+                  (("Boost REQUIRED")
+                   "Boost COMPONENTS regex REQUIRED"))))
+            (add-before 'check 'build-tests
+              (lambda _
+                (invoke "make" "unit_tests"))))))
+      (native-inputs
+       (list cli11
+             nlohmann-json
+             pkg-config
+             python
+             python-wrapper
+             ruby
+             gcc-14))
+      (inputs
+       (list yara
+             boost
+             capstone
+             curl
+             edlib
+             fmt
+             glfw
+             libarchive
+             libffi
+             llvm-17
+             lunasvg
+             plutovg
+             mbedtls
+             mesa
+             miniaudio
+             nativefiledialog-extended
+             xz
+             fontconfig
+             lz4
+             `(,zstd "lib")
+             zlib
+             freetype))
+      (home-page "https://imhex.werwolv.net")
+      (synopsis "Hex Editor to display, decode and analyze binary data")
+      (description "ImHex is a hex editor with many advanced features that can
+often only be found in paid applications.  Such features are a completely
+custom binary template and pattern language to decode and highlight structures
+in the data, a graphical node-based data processor to pre-process values
+before they're displayed, a disassembler, diffing support, bookmarks and much
+much more.")
+      (license license:gpl2))))
+
 (define-public bvi
   (package
     (name "bvi")