[PATCH] build: haskell-build-system: Support packages w. multiple libraries

OpenSubmitted by Philip Munksgaard.
Details
3 participants
  • Lars-Dominik Braun
  • Philip Munksgaard
  • zimoun
Owner
unassigned
Severity
normal
P
P
Philip Munksgaard wrote on 5 Apr 17:15 +0200
(address . guix-patches@gnu.org)(name . Philip Munksgaard)(address . philip@munksgaard.me)
8a396a9803fc35ee63f01e608f87ffb16863bc6d.1649171729.git.philip@munksgaard.me
As discussed in #53655 [0], haskell-build-system.scm does not currently
support packages which contain multiple libraries, such as attoparsec
[1]. Such libraries are often used for internal or convenience libraries, as
detailed in the documentation [2].

The current state of affairs means that attoparsec and any other libraries
with similar structure cannot be built on guix, nor can any library or
executable that depends on such a library.

Instead of assuming that `runhaskell Setup.hs --gen-pkg-config=...` always
outputs a single file, we detect whether the result was a directory. If so, we
need to handle each file independently in lexicographic order by calling the
new private function `install-from-config-file`.

Because `install-transitive-deps` can now be called multiple times for each
call to `register`, it has also been amended to support the files already
installed.

---
guix/build/haskell-build-system.scm | 34 ++++++++++++++++++-----------
1 file changed, 21 insertions(+), 13 deletions(-)

Toggle diff (64 lines)
diff --git a/guix/build/haskell-build-system.scm b/guix/build/haskell-build-system.scm
index ef6cb316ee..e827e23aba 100644
--- a/guix/build/haskell-build-system.scm
+++ b/guix/build/haskell-build-system.scm
@@ -217,11 +217,13 @@ (define* (register #:key name system inputs outputs #:allow-other-keys)
          (if (not (vhash-assoc id seen))
              (let ((dep-conf  (string-append src  "/" id ".conf"))
                    (dep-conf* (string-append dest "/" id ".conf")))
-               (when (not (file-exists? dep-conf))
+               (unless (file-exists? dep-conf*)
+                 (when (not (file-exists? dep-conf))
                    (error (format #f "File ~a does not exist. This usually means the dependency ~a is missing. Was checking conf-file ~a." dep-conf id conf-file)))
-               (copy-file dep-conf dep-conf*) ;XXX: maybe symlink instead?
-               (loop (vhash-cons id #t seen)
-                     (append lst (conf-depends dep-conf))))
+                 (copy-file dep-conf dep-conf*) ;XXX: maybe symlink instead?
+
+                 (loop (vhash-cons id #t seen)
+                       (append lst (conf-depends dep-conf*)))))
              (loop seen tail))))))
 
   (let* ((out (assoc-ref outputs "out"))
@@ -234,13 +236,12 @@ (define* (register #:key name system inputs outputs #:allow-other-keys)
                                     "/ghc-" version
                                     "/" name ".conf.d"))
          (id-rx (make-regexp "^id:[ \n\t]+([^ \t\n]+)$" regexp/newline))
-         (config-file (string-append out "/" name ".conf"))
+         (config-output (string-append out "/" name ".conf"))
          (params
-          (list (string-append "--gen-pkg-config=" config-file))))
+          (list (string-append "--gen-pkg-config=" config-output))))
     (run-setuphs "register" params)
-    ;; The conf file is created only when there is a library to register.
-    (when (file-exists? config-file)
-      (mkdir-p config-dir)
+
+    (define (install-from-config-file config-file)
       (let* ((contents (call-with-input-file config-file read-string))
              (config-file-name+id (match:substring (first (list-matches id-rx contents)) 1)))
 
@@ -270,10 +271,17 @@ (define* (register #:key name system inputs outputs #:allow-other-keys)
         (install-transitive-deps config-file %tmp-db-dir config-dir)
         (rename-file config-file
                      (string-append config-dir "/"
-                                    config-file-name+id ".conf"))
-        (invoke "ghc-pkg"
-                (string-append "--package-db=" config-dir)
-                "recache")))
+                                    config-file-name+id ".conf"))))
+
+    ;; The conf file is created only when there is a library to register.
+    (when (file-exists? config-output)
+      (mkdir-p config-dir)
+      (if (file-is-directory? config-output)
+          (for-each install-from-config-file (find-files config-output))
+          (install-from-config-file config-output))
+      (invoke "ghc-pkg"
+              (string-append "--package-db=" config-dir)
+              "recache"))
     #t))
 
 (define* (check #:key tests? test-target #:allow-other-keys)
-- 
2.35.1
Z
Z
zimoun wrote on 6 Apr 21:19 +0200
[PATCH core-updates v2 1/2] build: haskell-build-system: Remove trailing #t.
(address . 54729@debbugs.gnu.org)(name . zimoun)(address . zimon.toutoune@gmail.com)
20220406191908.2393054-1-zimon.toutoune@gmail.com
* guix/build/haskell-build-system.scm (configure, install, setup-compiler,
make-ghc-package-database, install-transitive-deps, check, haddock,
patch-cabal-file, generate-setuphs): Delete trailing #t.
---
guix/build/haskell-build-system.scm | 25 +++++++++----------------
1 file changed, 9 insertions(+), 16 deletions(-)

Toggle diff (91 lines)
diff --git a/guix/build/haskell-build-system.scm b/guix/build/haskell-build-system.scm
index ef6cb316ee..e2e5904dce 100644
--- a/guix/build/haskell-build-system.scm
+++ b/guix/build/haskell-build-system.scm
@@ -5,6 +5,7 @@
 ;;; Copyright © 2018, 2020 Ricardo Wurmus <rekado@elephly.net>
 ;;; Copyright © 2018 Alex Vong <alexvong1995@gmail.com>
 ;;; Copyright © 2021 John Kehayias <john.kehayias@protonmail.com>
+;;; Copyright © 2022 Simon Tournier <zimon.toutoune@gmail.com>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -118,8 +119,7 @@ (define* (configure #:key outputs inputs tests? (configure-flags '())
       (setenv "CONFIG_SHELL" "sh"))
     (run-setuphs "configure" params)
 
-    (setenv "GHC_PACKAGE_PATH" ghc-path)
-    #t))
+    (setenv "GHC_PACKAGE_PATH" ghc-path)))
 
 (define* (build #:key parallel-build? #:allow-other-keys)
   "Build a given Haskell package."
@@ -140,8 +140,7 @@ (define* (install #:key outputs #:allow-other-keys)
                          (new    (string-append static subdir)))
                     (mkdir-p (dirname new))
                     (rename-file static-lib new)))
-                (find-files lib "\\.a$"))))
-  #t)
+                (find-files lib "\\.a$")))))
 
 (define* (setup-compiler #:key system inputs outputs #:allow-other-keys)
   "Setup the compiler environment."
@@ -175,8 +174,7 @@ (define (make-ghc-package-database system inputs outputs)
               conf-files)
     (invoke "ghc-pkg"
             (string-append "--package-db=" %tmp-db-dir)
-            "recache")
-    #t))
+            "recache")))
 
 (define* (register #:key name system inputs outputs #:allow-other-keys)
   "Generate the compiler registration and binary package database files for a
@@ -273,21 +271,18 @@ (define (install-transitive-deps conf-file src dest)
                                     config-file-name+id ".conf"))
         (invoke "ghc-pkg"
                 (string-append "--package-db=" config-dir)
-                "recache")))
-    #t))
+                "recache")))))
 
 (define* (check #:key tests? test-target #:allow-other-keys)
   "Run the test suite of a given Haskell package."
   (if tests?
       (run-setuphs test-target '())
-      (format #t "test suite not run~%"))
-  #t)
+      (format #t "test suite not run~%")))
 
 (define* (haddock #:key outputs haddock? haddock-flags #:allow-other-keys)
   "Generate the Haddock documentation of a given Haskell package."
   (when haddock?
-    (run-setuphs "haddock" haddock-flags))
-  #t)
+    (run-setuphs "haddock" haddock-flags)))
 
 (define* (patch-cabal-file #:key cabal-revision #:allow-other-keys)
   (when cabal-revision
@@ -296,8 +291,7 @@ (define* (patch-cabal-file #:key cabal-revision #:allow-other-keys)
       ((original)
        (format #t "replacing ~s with ~s~%" original cabal-revision)
        (copy-file cabal-revision original))
-      (_ (error "Could not find a Cabal file to patch."))))
-  #t)
+      (_ (error "Could not find a Cabal file to patch.")))))
 
 (define* (generate-setuphs #:rest empty)
   "Generate a default Setup.hs if needed."
@@ -307,8 +301,7 @@ (define* (generate-setuphs #:rest empty)
     (with-output-to-file "Setup.hs"
       (lambda ()
         (format #t "import Distribution.Simple~%")
-        (format #t "main = defaultMain~%"))))
-  #t)
+        (format #t "main = defaultMain~%")))))
 
 (define %standard-phases
   (modify-phases gnu:%standard-phases

base-commit: e3e3381fdbc56f351063d9b4a49e99645b20d7d3
-- 
2.34.0
Z
Z
zimoun wrote on 6 Apr 21:19 +0200
[PATCH core-updates v2 2/2] build: haskell-build-system: Support multiple libraries.
(address . 54729@debbugs.gnu.org)
20220406191908.2393054-2-zimon.toutoune@gmail.com
From: Philip Munksgaard <philip@munksgaard.me>


The patch handles correctly the multiple registration of some package using
their own internal sub-libraries. It allows to call 'install-transitive-deps'
multiple times and deals with packages requiring a multiple registration.

* guix/build/haskell-build-system.scm (register)[install-transitive-deps]:
Guard also the destination direction.
[install-config-file]: New procedure.

Co-Authored-by: zimoun <zimon.toutoune@gmail.com>.
---
guix/build/haskell-build-system.scm | 87 ++++++++++++++++-------------
1 file changed, 49 insertions(+), 38 deletions(-)

Toggle diff (124 lines)
diff --git a/guix/build/haskell-build-system.scm b/guix/build/haskell-build-system.scm
index e2e5904dce..fb4aba28ea 100644
--- a/guix/build/haskell-build-system.scm
+++ b/guix/build/haskell-build-system.scm
@@ -6,6 +6,7 @@
 ;;; Copyright © 2018 Alex Vong <alexvong1995@gmail.com>
 ;;; Copyright © 2021 John Kehayias <john.kehayias@protonmail.com>
 ;;; Copyright © 2022 Simon Tournier <zimon.toutoune@gmail.com>
+;;; Copyright © 2022 Philip Munksgaard <philip@munksgaard.me>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -215,13 +216,50 @@ (define (install-transitive-deps conf-file src dest)
          (if (not (vhash-assoc id seen))
              (let ((dep-conf  (string-append src  "/" id ".conf"))
                    (dep-conf* (string-append dest "/" id ".conf")))
-               (when (not (file-exists? dep-conf))
+               (unless (file-exists? dep-conf*)
+                 (unless (file-exists? dep-conf)
                    (error (format #f "File ~a does not exist. This usually means the dependency ~a is missing. Was checking conf-file ~a." dep-conf id conf-file)))
-               (copy-file dep-conf dep-conf*) ;XXX: maybe symlink instead?
-               (loop (vhash-cons id #t seen)
-                     (append lst (conf-depends dep-conf))))
+                 (copy-file dep-conf dep-conf*) ;XXX: maybe symlink instead?
+                 (loop (vhash-cons id #t seen)
+                       (append lst (conf-depends dep-conf)))))
              (loop seen tail))))))
 
+  (define (install-config-file conf-file dest output:doc output:lib)
+      ;; Copy CONF-FILE to DEST removing reference to OUTPUT:DOC from
+      ;; OUTPUT:LIB and using install-transitive-deps.
+      (let* ((contents (call-with-input-file conf-file read-string))
+             (id-rx (make-regexp "^id:[ \n\t]+([^ \t\n]+)$" regexp/newline))
+             (config-file-name+id
+              (match:substring (first (list-matches id-rx contents)) 1)))
+
+        (when (or
+               (and
+                (string? config-file-name+id)
+                (string-null? config-file-name+id))
+               (not config-file-name+id))
+          (error (format #f "The package id for ~a is empty. This is a bug." conf-file)))
+
+        ;; Remove reference to "doc" output from "lib" (or "out") by rewriting the
+        ;; "haddock-interfaces" field and removing the optional "haddock-html"
+        ;; field in the generated .conf file.
+        (when output:doc
+          (substitute* conf-file
+            (("^haddock-html: .*") "\n")
+            (((format #f "^haddock-interfaces: ~a" output:doc))
+             (string-append "haddock-interfaces: " output:lib)))
+          ;; Move the referenced file to the "lib" (or "out") output.
+          (match (find-files output:doc "\\.haddock$")
+            ((haddock-file . rest)
+             (let* ((subdir (string-drop haddock-file (string-length output:doc)))
+                    (new    (string-append output:lib subdir)))
+               (mkdir-p (dirname new))
+               (rename-file haddock-file new)))
+            (_ #f)))
+        (install-transitive-deps conf-file %tmp-db-dir dest)
+        (rename-file conf-file
+                     (string-append dest "/"
+                                    config-file-name+id ".conf"))))
+
   (let* ((out (assoc-ref outputs "out"))
          (doc (assoc-ref outputs "doc"))
          (haskell  (assoc-ref inputs "haskell"))
@@ -231,7 +269,6 @@ (define (install-transitive-deps conf-file src dest)
          (config-dir (string-append lib
                                     "/ghc-" version
                                     "/" name ".conf.d"))
-         (id-rx (make-regexp "^id:[ \n\t]+([^ \t\n]+)$" regexp/newline))
          (config-file (string-append out "/" name ".conf"))
          (params
           (list (string-append "--gen-pkg-config=" config-file))))
@@ -239,39 +276,13 @@ (define (install-transitive-deps conf-file src dest)
     ;; The conf file is created only when there is a library to register.
     (when (file-exists? config-file)
       (mkdir-p config-dir)
-      (let* ((contents (call-with-input-file config-file read-string))
-             (config-file-name+id (match:substring (first (list-matches id-rx contents)) 1)))
-
-        (when (or
-                (and
-                  (string? config-file-name+id)
-                  (string-null? config-file-name+id))
-                (not config-file-name+id))
-          (error (format #f "The package id for ~a is empty. This is a bug." config-file)))
-
-        ;; Remove reference to "doc" output from "lib" (or "out") by rewriting the
-        ;; "haddock-interfaces" field and removing the optional "haddock-html"
-        ;; field in the generated .conf file.
-        (when doc
-          (substitute* config-file
-            (("^haddock-html: .*") "\n")
-            (((format #f "^haddock-interfaces: ~a" doc))
-             (string-append "haddock-interfaces: " lib)))
-          ;; Move the referenced file to the "lib" (or "out") output.
-          (match (find-files doc "\\.haddock$")
-            ((haddock-file . rest)
-             (let* ((subdir (string-drop haddock-file (string-length doc)))
-                    (new    (string-append lib subdir)))
-               (mkdir-p (dirname new))
-               (rename-file haddock-file new)))
-            (_ #f)))
-        (install-transitive-deps config-file %tmp-db-dir config-dir)
-        (rename-file config-file
-                     (string-append config-dir "/"
-                                    config-file-name+id ".conf"))
-        (invoke "ghc-pkg"
-                (string-append "--package-db=" config-dir)
-                "recache")))))
+      (if (file-is-directory? config-file)
+          (for-each (cut install-config-file <> config-dir doc lib)
+           (find-files config-file))
+          (install-config-file config-file config-dir doc lib))
+      (invoke "ghc-pkg"
+              (string-append "--package-db=" config-dir)
+              "recache"))))
 
 (define* (check #:key tests? test-target #:allow-other-keys)
   "Run the test suite of a given Haskell package."
-- 
2.34.0
Z
Z
zimoun wrote on 6 Apr 21:23 +0200
Re: bug#54729: [PATCH] build: haskell-build-system: Support packages w. multiple libraries
(address . 54729@debbugs.gnu.org)
87zgkyow1r.fsf@gmail.com
Hi,

Thanks for your patch. I have send a v2 ready for core-updates.

Ricardo or Lars, can you push this v2 to core-updates?

The simple test is to use attoparsec@0.14 from bug#53655 [1]. The
rebuild of this package takes less than half hour.

I have checked and rebuilt all the ghc- packages; nothing broken.




Cheers,
simon
L
L
Lars-Dominik Braun wrote on 7 Apr 08:08 +0200
(name . zimoun)(address . zimon.toutoune@gmail.com)
Yk5/xeYW4K4yDnLJ@noor.fritz.box
Hi simon,

Toggle quote (1 lines)
> Ricardo or Lars, can you push this v2 to core-updates?
I’d rather have this in a separate wip-haskell branch than let it sit
on core-updates indefinitely. Stackage also has a new release[1] using
GHC 9.0, which we could update to at the same time.

Any other Haskell changes we can batch into that branch?

Cheers,
Lars

P
P
Philip Munksgaard wrote on 7 Apr 08:49 +0200
7108deb8-613a-4f74-a525-c4bf21ec9118@www.fastmail.com
Hi Lars

On Thu, 7 Apr 2022, at 08:08, Lars-Dominik Braun wrote:
Toggle quote (2 lines)
> Any other Haskell changes we can batch into that branch?

I don't know of any finished patches, but there are some issues that would be nice to have fixed, like https://issues.guix.gnu.org/52152(which also applies to attoparsec) and https://issues.guix.gnu.org/54752. However, I think it's more important to get this current patch merged.

Best,
Philip
Z
Z
zimoun wrote on 7 Apr 09:35 +0200
(name . Lars-Dominik Braun)(address . lars@6xq.net)
86k0c14a7o.fsf@gmail.com
Hi Lars,

On Thu, 07 Apr 2022 at 08:08, Lars-Dominik Braun <lars@6xq.net> wrote:

Toggle quote (6 lines)
> I’d rather have this in a separate wip-haskell branch than let it sit
> on core-updates indefinitely. Stackage also has a new release[1] using
> GHC 9.0, which we could update to at the same time.
>
> Any other Haskell changes we can batch into that branch?

Ok, let’s do use this wip-haskell branch: fix the build system as this
v2 is doing and update LTS. Currently, the wip-haskell is at:
c1522b280137df2f670f47fa1e682e610406bb39 (Thu Sep 30 09:29:51 2021
+0200), so let me know once you have rebase it to the current master.


Cheers,
simon
P
P
Philip Munksgaard wrote on 7 Apr 10:25 +0200
797b714d-4274-46eb-9858-a51a17550b0c@www.fastmail.com
Hi again

On Thu, 7 Apr 2022, at 08:49, Philip Munksgaard wrote:
Toggle quote (11 lines)
> Hi Lars
>
> On Thu, 7 Apr 2022, at 08:08, Lars-Dominik Braun wrote:
>> Any other Haskell changes we can batch into that branch?
>
> I don't know of any finished patches, but there are some issues that
> would be nice to have fixed, like https://issues.guix.gnu.org/52152
> (which also applies to attoparsec) and
> https://issues.guix.gnu.org/54752. However, I think it's more important
> to get this current patch merged.

I've also created a new issue for invalid dependencies generated by multiple libraries in one package:

P
P
Philip Munksgaard wrote on 13 Apr 20:59 +0200
f1fedb67-1fcd-4cb1-9536-46d94d5684ba@www.fastmail.com
Hi again

On Thu, 7 Apr 2022, at 08:08, Lars-Dominik Braun wrote:
Toggle quote (4 lines)
> I’d rather have this in a separate wip-haskell branch than let it sit
> on core-updates indefinitely. Stackage also has a new release[1] using
> GHC 9.0, which we could update to at the same time.

Any news on this? Was the branch created? I can't seem to find it on https://git.savannah.gnu.org, and the changes haven't made it into master, as far as I can tell.

Best,
Philip
L
L
Lars-Dominik Braun wrote on 14 Apr 20:21 +0200
(name . Philip Munksgaard)(address . philip@munksgaard.me)
YlhmLNPFwROULK5v@noor.fritz.box
Hi Philip,

Toggle quote (2 lines)
> Any news on this? Was the branch created? I can't seem to find it on https://git.savannah.gnu.org, and the changes haven't made it into master, as far as I can tell.

sorry, I’ve been busy rebasing my new python-build-system (PEP 517) on
top of master.

I created the branch wip-haskell and pushed zimoun’s v2 – I
hope that’s alright with you Philip? (I didn’t check the patches
thoroughly, just tried to build attoparsec.)

Cheers,
Lars
P
P
Philip Munksgaard wrote on 15 Apr 10:19 +0200
(name . Lars-Dominik Braun)(address . lars@6xq.net)
4b2d1388-b5a1-4821-8ded-d75138352284@www.fastmail.com
Hi Lars

On Thu, 14 Apr 2022, at 20:21, Lars-Dominik Braun wrote:
Toggle quote (3 lines)
> sorry, I’ve been busy rebasing my new python-build-system (PEP 517) on
> top of master.

No worries, I just wanted to make sure it wasn't forgotten :-)

Toggle quote (4 lines)
> I created the branch wip-haskell and pushed zimoun’s v2 – I
> hope that’s alright with you Philip? (I didn’t check the patches
> thoroughly, just tried to build attoparsec.)

Yeah that sounds perfect.

Best,
Philip
?