Subject: Re: bug#49543: [PATCH] python-pycryptodome: Build HTML and info documentation and unbundle sphinx-rtd-theme and libtomcrypt

From: Maxime Devos <[email-masked]>
Date: Wed, 18 Aug 2021 13:01:10 +0200

Ludovic Courtès schreef op wo 11-08-2021 om 16:35 [+0200]:
> Hi Maxime,
> 
> Maxime Devos <[email-masked]> skribis:
> 
> > These two patches fix <https://issues.guix.gnu.org/49530>;.
> > The dependencies of python-pycryptodome (found with "guix refresh -l")
> > still build succesfully.
> 
> Neat.
> 
> > I performed the unbundling in build phases as I'm not sure
> > what is the proper way to use 'tar' from a snippet, and whether
> > the unbundling is done in a build phase or an 'origin' snippet
> > doesn't seem to matter much, as the bundled code is free software.
> 
> Usually, bundled software is removed from a snippet.
> 
> Also, when unbundling, it’s better if we can actually reuse the package
> in question (libtomcrypt here) as opposed to reusing its source, as you
> did here.

I have attached two new patches for unbundling libtomcrypt this way.
I left the documentation out for now, as I would prefer some kind of
generic solution that could be used by other packages using Sphinx
as well.

I had some trouble telling python to link to libtomcrypt.
I tried adding "tomcrypt" to "libraries" in ‘Extension’ forms in setup.py
but that doesn't seem to do anything, so I added
extra_link_args=['-ltomcrypt', '-ltommath'].  Do you know what's up with that?

The dependencies of python-pycryptodome, python2-pycryptodome and
python-pycryptodomex build successfully.

Greetings,
Maxime.
From a41b086246a5b59aab2d16eaeb91e0caafa706cc Mon Sep 17 00:00:00 2001
From: Maxime Devos <[email-masked]>
Date: Wed, 18 Aug 2021 00:43:16 +0200
Subject: [PATCH 1/2] gnu: python-pycryptodome: Unbundle libtomcrypt.

* gnu/packages/python-crypto.scm
  (pycryptodome-unbundle-tomcrypt-snippet): New variable.
  (python-pycryptodome)[source]{snippet}: Unbundle libtomcrypt.
  (python-pycryptodome)[source]{modules}: Add (guix build utils).
---
 gnu/packages/python-crypto.scm | 25 ++++++++++++++++++++++++-
 1 file changed, 24 insertions(+), 1 deletion(-)

diff --git a/gnu/packages/python-crypto.scm b/gnu/packages/python-crypto.scm
index d9102adcc9..265ab6d228 100644
--- a/gnu/packages/python-crypto.scm
+++ b/gnu/packages/python-crypto.scm
@@ -25,6 +25,7 @@
 ;;; Copyright © 2020 Justus Winter <[email-masked]>
 ;;; Copyright © 2020 Vinicius Monego <[email-masked]>
 ;;; Copyright © 2021 Maxim Cournoyer <[email-masked]>
+;;; Copyright © 2021 Maxime Devos <[email-masked]>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -44,6 +45,7 @@
 (define-module (gnu packages python-crypto)
   #:use-module (guix packages)
   #:use-module (guix download)
+  #:use-module (guix gexp)
   #:use-module (guix git-download)
   #:use-module (guix build-system python)
   #:use-module (gnu packages)
@@ -947,6 +949,22 @@ protocol (Javascript Object Signing and Encryption).")
 (define-public python2-josepy
   (package-with-python2 python-josepy))
 
+(define pycryptodome-unbundle-tomcrypt-snippet
+  #~(begin
+      ;; Unbundle libtomcrypt.
+      (delete-file-recursively "src/libtom")
+      (substitute* "src/DES.c"
+        (("#include \"libtom/tomcrypt_des.c\"")
+         "#include <tomcrypt.h>"))
+      (substitute* "setup.py"
+        (("include_dirs=\\['src/', 'src/libtom/'\\]")
+         ;; FIXME: why does '-ltomcrypt' need to be added
+         ;; manually, even when 'tomcrypt' is added to 'libraries'?
+         ;; This behaviour is not documented at
+         ;; <https://docs.python.org/3/extending/building.html>.
+         "include_dirs=['src/'], libraries=['tomcrypt', 'tommath'],
+ extra_link_args=['-ltomcrypt', '-ltommath']"))))
+
 (define-public python-pycryptodome
   (package
     (name "python-pycryptodome")
@@ -957,8 +975,13 @@ protocol (Javascript Object Signing and Encryption).")
        (uri (pypi-uri "pycryptodome" version))
        (sha256
         (base32
-         "1i4m74f88qj9ci8rpyzrbk2slmsdj5ipmwdkq6qk24byalm203li"))))
+         "1i4m74f88qj9ci8rpyzrbk2slmsdj5ipmwdkq6qk24byalm203li"))
+       (modules '((guix build utils)))
+       (snippet pycryptodome-unbundle-tomcrypt-snippet)))
     (build-system python-build-system)
+    (inputs
+     `(("libtomcrypt" ,libtomcrypt)
+       ("libtommath" ,libtommath)))
     (home-page "https://www.pycryptodome.org")
     (synopsis "Low-level cryptographic Python library")
     (description
-- 
2.32.0

From 5b3366c9ebead99f0c22d612552063189bd0551c Mon Sep 17 00:00:00 2001
From: Maxime Devos <[email-masked]>
Date: Wed, 18 Aug 2021 12:46:51 +0200
Subject: [PATCH 2/2] gnu: python-pycryptodomex: Unbundle libtomcrypt.

* gnu/packages/python-crypto.scm
  (python-pycryptodomex)[source]{snippet}: Unbundle libtomcrypt.
  (python-pycryptodomex)[source]{modules}: Add (guix build utils).
---
 gnu/packages/python-crypto.scm | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/gnu/packages/python-crypto.scm b/gnu/packages/python-crypto.scm
index 265ab6d228..0fd3c829e3 100644
--- a/gnu/packages/python-crypto.scm
+++ b/gnu/packages/python-crypto.scm
@@ -1034,7 +1034,9 @@ PyCryptodome variants, the other being python-pycryptodomex.")
        (method url-fetch)
        (uri (pypi-uri "pycryptodomex" version))
        (sha256
-        (base32 "0lbx4qk3xmwqiidhmkj8qa7bh2lf8bwzg0xjpsh2w5zqjrc7qnvv"))))
+        (base32 "0lbx4qk3xmwqiidhmkj8qa7bh2lf8bwzg0xjpsh2w5zqjrc7qnvv"))
+       (modules '((guix build utils)))
+       (snippet pycryptodome-unbundle-tomcrypt-snippet)))
     (description
      "PyCryptodome is a self-contained Python package of low-level
 cryptographic primitives.  It's not a wrapper to a separate C library like
-- 
2.32.0