diff mbox series

[bug#63765,v6,09/10] gnu: python-lief: Update to 0.13.2.

Message ID fdf38ec0bb77e09b930ae88e1b6ea74680c3c387.1691240736.git.hako@ultrarare.space
State New
Headers show
Series gnu: python-lief: Update to 0.13.2. | expand

Commit Message

Hilton Chain Aug. 5, 2023, 1:19 p.m. UTC
* gnu/packages/patches/lief-unbundle-test-dependencies.patch: New file.
* gnu/local.mk (dist_patch_DATA): Add it.
* gnu/packages/python-xyz.scm (python-lief): Update to 0.13.2.
[snippet]: Unbundle third-party dependencies.
[build-system]: Switch to cmake-build-system
[native-inputs]: Add catch2, melkor, python-wrapper, python-tomli.
Remove cmake.
[inputs]: Add boost-leaf, frozen, mbedtls-apache, nlohmann-json, pybind11,
spdlog, tcb-span, utfcpp.
[outputs]: Add "python" output.
[home-page]: Update homepage.
(shrinkwrap)[inputs]: Replace python-lief to its "python" output.
---
 gnu/local.mk                                  |   1 +
 .../lief-unbundle-test-dependencies.patch     | 103 ++++++++++++++++
 gnu/packages/python-xyz.scm                   | 112 +++++++++++++++---
 3 files changed, 202 insertions(+), 14 deletions(-)
 create mode 100644 gnu/packages/patches/lief-unbundle-test-dependencies.patch
diff mbox series

Patch

diff --git a/gnu/local.mk b/gnu/local.mk
index 77707127a7..c79299a592 100644
--- a/gnu/local.mk
+++ b/gnu/local.mk
@@ -1544,6 +1544,7 @@  dist_patch_DATA =						\
   %D%/packages/patches/libwpd-gcc-compat.patch			\
   %D%/packages/patches/libxslt-generated-ids.patch		\
   %D%/packages/patches/libxt-guix-search-paths.patch		\
+  %D%/packages/patches/lief-unbundle-test-dependencies.patch	\
   %D%/packages/patches/lierolibre-check-unaligned-access.patch	\
   %D%/packages/patches/lierolibre-is-free-software.patch	\
   %D%/packages/patches/lierolibre-newer-libconfig.patch		\
diff --git a/gnu/packages/patches/lief-unbundle-test-dependencies.patch b/gnu/packages/patches/lief-unbundle-test-dependencies.patch
new file mode 100644
index 0000000000..d86126c657
--- /dev/null
+++ b/gnu/packages/patches/lief-unbundle-test-dependencies.patch
@@ -0,0 +1,103 @@ 
+From 0e0f105e984eeac51147b5fd87cf95668e8fa235 Mon Sep 17 00:00:00 2001
+From: Hilton Chain <hako@ultrarare.space>
+Date: Fri, 4 Aug 2023 10:57:32 +0800
+Subject: [PATCH] Use system Catch2 and Melkor.
+
+---
+ tests/CMakeLists.txt     | 47 ++++------------------------------------
+ tests/test_iterators.cpp |  2 +-
+ 2 files changed, 5 insertions(+), 44 deletions(-)
+
+diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
+index 1d34b711..cf79ab74 100644
+--- a/tests/CMakeLists.txt
++++ b/tests/CMakeLists.txt
+@@ -8,23 +8,6 @@ set(LIEF_EXAMPLES_DIRECTORY  "${PROJECT_SOURCE_DIR}/examples")
+ set(LIEF_EXAMPLES_BINARY_DIR "${PROJECT_BINARY_DIR}/examples")
+ 
+ 
+-# Catch
+-# =====
+-set(CATCH_VERSION 2.13.8)
+-set(CATCH_SHA256 SHA256=532f163e4f2db66dae33f1d0a279e8d9befec8bc6cca60d7b82155f7d06bd89c)
+-set(CATCH_URL "${THIRD_PARTY_DIRECTORY}/Catch2-${CATCH_VERSION}.zip" CACHE STRING "URL to the Catch repo")
+-
+-ExternalProject_Add(catch
+-    PREFIX         ${CATCH_PREFIX}
+-    URL            ${CATCH_URL}
+-    URL_HASH       ${CATCH_SHA256}
+-    CONFIGURE_COMMAND ""
+-    BUILD_COMMAND ""
+-    INSTALL_COMMAND ""
+-)
+-ExternalProject_Get_Property(catch source_dir)
+-set(CATCH_INCLUDE_DIR "${source_dir}" CACHE INTERNAL "Path to include folder for Catch")
+-
+ # Code covergage
+ # ==============
+ if(LIEF_COVERAGE)
+@@ -58,31 +41,6 @@ if(LIEF_COVERAGE)
+ endif()
+ 
+ 
+-# Fuzzing
+-# =======
+-if(UNIX AND NOT APPLE)
+-  set(MELKOR_VERSION ac2495b) # From the fork: https://github.com/romainthomas/elf_fuzzer
+-  set(MELKOR_SHA256 SHA256=8cccc4ca5e05e305215cc74761413746b660b76f5869a563f52cec1f23d79f2e)
+-  set(MELKOR_URL "${THIRD_PARTY_DIRECTORY}/Melkor_ELF_Fuzzer-${MELKOR_VERSION}.zip" CACHE STRING "URL to the Melkor package")
+-
+-  set(MELKOR_PREFIX      "${CMAKE_CURRENT_BINARY_DIR}/Melkor")
+-  set(MELKOR_INSTALL_DIR "${CMAKE_CURRENT_BINARY_DIR}/Melkor")
+-  ExternalProject_Add(MELKOR
+-   PREFIX            ${MELKOR_PREFIX}
+-   URL               ${MELKOR_URL}
+-   URL_HASH          ${MELKOR_SHA256}
+-   INSTALL_DIR       ${MELKOR_INSTALL_DIR}
+-   UPDATE_COMMAND    ""
+-   CONFIGURE_COMMAND ""
+-   INSTALL_COMMAND   ""
+-   BUILD_COMMAND     make clean && make
+-   BUILD_IN_SOURCE   ON)
+-
+-  ExternalProject_get_property(MELKOR SOURCE_DIR)
+-  set(MELKOR_BINARY "${SOURCE_DIR}/melkor")
+-  message(STATUS "${MELKOR_BINARY}")
+-endif()
+-
+ # Tests
+ # =====
+ add_executable(test_iterators "${CMAKE_CURRENT_SOURCE_DIR}/test_iterators.cpp")
+@@ -100,10 +58,13 @@ if (LIEF_COVERAGE)
+   target_link_libraries(test_iterators gcov)
+ endif()
+ 
+-add_dependencies(test_iterators catch LIB_LIEF)
++find_package(Catch2 REQUIRED)
++add_dependencies(test_iterators Catch2::Catch2 LIB_LIEF)
+ 
+ target_link_libraries(test_iterators LIB_LIEF)
+ 
++find_program(MELKOR_FOUND melkor REQUIRED)
++
+ add_test(test_iterators
+          ${CMAKE_CURRENT_BINARY_DIR}/test_iterators)
+ 
+diff --git a/tests/test_iterators.cpp b/tests/test_iterators.cpp
+index 2d837371..df3d2ed5 100644
+--- a/tests/test_iterators.cpp
++++ b/tests/test_iterators.cpp
+@@ -14,7 +14,7 @@
+  * limitations under the License.
+  */
+ #define CATCH_CONFIG_MAIN
+-#include <catch.hpp>
++#include <catch2/catch.hpp>
+ 
+ #include <LIEF/iterators.hpp>
+ 
+
+base-commit: 2d9855fc7f9d4ce6325245f8b75c98eb7663db60
+-- 
+2.41.0
+
diff --git a/gnu/packages/python-xyz.scm b/gnu/packages/python-xyz.scm
index b8e8097c7b..5066fcd1dd 100644
--- a/gnu/packages/python-xyz.scm
+++ b/gnu/packages/python-xyz.scm
@@ -167,6 +167,7 @@  (define-module (gnu packages python-xyz)
   #:use-module (gnu packages base)
   #:use-module (gnu packages bash)
   #:use-module (gnu packages bdw-gc)
+  #:use-module (gnu packages boost)
   #:use-module (gnu packages check)
   #:use-module (gnu packages cmake)
   #:use-module (gnu packages compression)
@@ -180,6 +181,7 @@  (define-module (gnu packages python-xyz)
   #:use-module (gnu packages djvu)
   #:use-module (gnu packages docker)
   #:use-module (gnu packages documentation)
+  #:use-module (gnu packages elf)
   #:use-module (gnu packages enchant)
   #:use-module (gnu packages file)
   #:use-module (gnu packages fonts)
@@ -213,6 +215,7 @@  (define-module (gnu packages python-xyz)
   #:use-module (gnu packages libusb)
   #:use-module (gnu packages linux)
   #:use-module (gnu packages llvm)
+  #:use-module (gnu packages logging)
   #:use-module (gnu packages machine-learning)
   #:use-module (gnu packages man)
   #:use-module (gnu packages markup)
@@ -33438,29 +33441,110 @@  (define-public python-misskey
 (define-public python-lief
   (package
     (name "python-lief")
-    (version "0.12.3")
+    (version "0.13.2")
     (source (origin
               (method git-fetch)
               (uri (git-reference
                     (url "https://github.com/lief-project/LIEF")
                     (commit version)))
               (file-name (git-file-name name version))
+              (patches (search-patches "lief-unbundle-test-dependencies.patch"))
+              (modules '((guix build utils)))
+              (snippet
+               '(begin (delete-file-recursively "third-party")
+                       (substitute* "api/python/config-default.toml"
+                         (("(ninja *= ).*" _ m)
+                          (string-append m "false\n")))))
               (sha256
                (base32
-                "11i6hqmcjh56y554kqhl61698n9v66j2qk1c1g63mv2w07h2z661"))))
-    (build-system python-build-system)
-    (native-inputs (list cmake))
+                "0y48x358ppig5xp97ahcphfipx7cg9chldj2q5zrmn610fmi4zll"))))
+    (build-system cmake-build-system)
     (arguments
      (list
-      #:tests? #f                  ;needs network
-      #:phases #~(modify-phases %standard-phases
-                   (replace 'build
-                     (lambda _
-                       (invoke
-                        "python" "setup.py" "--sdk" "build"
-                        (string-append
-                         "-j" (number->string (parallel-job-count)))))))))
-    (home-page "https://github.com/lief-project/LIEF")
+      #:imported-modules
+      `(,@%cmake-build-system-modules
+        (guix build python-build-system))
+      #:modules
+      '(((guix build python-build-system) #:prefix python:)
+        (guix build cmake-build-system)
+        (guix build utils))
+      #:configure-flags
+      #~'("-DBUILD_SHARED_LIBS=ON"
+          "-DLIEF_INSTALL_COMPILED_EXAMPLES=ON"
+          "-DLIEF_TESTS=ON"
+          ;; Use dependencies from Guix.
+          "-DLIEF_EXTERNAL_SPDLOG=ON"
+          "-DLIEF_OPT_EXTERNAL_LEAF=ON"
+          "-DLIEF_OPT_EXTERNAL_SPAN=ON"
+          "-DLIEF_OPT_FROZEN_EXTERNAL=ON"
+          "-DLIEF_OPT_MBEDTLS_EXTERNAL=ON"
+          "-DLIEF_OPT_NLOHMANN_JSON_EXTERNAL=ON"
+          "-DLIEF_OPT_PYBIND11_EXTERNAL=ON"
+          "-DLIEF_OPT_UTFCPP_EXTERNAL=ON")
+      #:phases
+      ;; Python bindings.
+      #~(modify-phases %standard-phases
+          (add-after 'unpack 'configure-python-build
+            (lambda* (#:key configure-flags build-type parallel-build?
+                      #:allow-other-keys)
+              (with-directory-excursion "api/python"
+                (substitute* "config-default.toml"
+                  ;; Honor `#:build-type'.
+                  (("(type *)= .*" _ m)
+                   (format #f "~a= \"~a\"~%"
+                           m build-type))
+                  ;; Honor `#:parallel-build?'.
+                  (("(parallel-jobs *)= .*" _ m)
+                   (format #f "~a= ~a~%"
+                           m (if parallel-build?
+                                 (parallel-job-count)
+                                 1))))
+                (substitute* "setup.py"
+                  ;; Honor `#:configure-flags'.
+                  (("(configure_cmd = .*)\n" _ m)
+                   (format #f "~a + [~a]~%"
+                           m (apply string-append
+                                    (map (lambda (flag)
+                                           (format #f "\"~a\"," flag))
+                                         (append configure-flags
+                                                 '("-DBUILD_SHARED_LIBS=OFF"))))
+                           ))))))
+          (add-after 'install 'chdir
+            (lambda _
+              (chdir "../source/api/python/")))
+          (add-after 'chdir 'ensure-no-mtimes-pre-1980
+            (assoc-ref python:%standard-phases 'ensure-no-mtimes-pre-1980))
+          (add-after 'ensure-no-mtimes-pre-1980 'enable-bytecode-determinism
+            (assoc-ref python:%standard-phases 'enable-bytecode-determinism))
+          (add-after 'enable-bytecode-determinism 'python-install
+            (lambda* (#:key inputs outputs #:allow-other-keys)
+              ((assoc-ref python:%standard-phases 'install)
+               #:inputs inputs
+               #:outputs outputs
+               #:configure-flags '()
+               #:use-setuptools? #t)))
+          (add-after 'python-install 'add-install-to-pythonpath
+            (assoc-ref python:%standard-phases 'add-install-to-pythonpath))
+          (add-after 'add-install-to-pythonpath 'add-install-to-path
+            (assoc-ref python:%standard-phases 'add-install-to-path))
+          (add-after 'add-install-to-path 'python-wrap
+            (assoc-ref python:%standard-phases 'wrap)))))
+    (native-inputs
+     (list catch2
+           melkor
+           python-wrapper
+           python-tomli))
+    (inputs
+     (list boost-leaf
+           frozen
+           mbedtls-apache
+           nlohmann-json
+           pybind11
+           spdlog
+           tcb-span
+           utfcpp))
+    (outputs '("out" "python"))
+    (home-page "https://lief-project.github.io/")
     (synopsis "Library to instrument executable formats")
     (description
      "@code{python-lief} is a cross platform library which can parse, modify
@@ -33508,7 +33592,7 @@  (define-public shrinkwrap
            python-poetry-core
            python-pypa-build
            python-pytest))
-    (inputs (list python-lief python-sh))
+    (inputs (list `(,python-lief "python") python-sh))
     (home-page "https://github.com/fzakaria/shrinkwrap")
     (synopsis "Emboss needed dependencies on the top level executable")
     (description