guix-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

01/01: gnu: mesa: Use symlinks instead of hard links.


From: Ludovic Courtès
Subject: 01/01: gnu: mesa: Use symlinks instead of hard links.
Date: Wed, 8 Nov 2017 03:25:16 -0500 (EST)

civodul pushed a commit to branch core-updates
in repository guix.

commit dcc00f54c619118d11982383102d2e9a1b86d080
Author: Ludovic Courtès <address@hidden>
Date:   Mon Nov 6 22:06:28 2017 +0100

    gnu: mesa: Use symlinks instead of hard links.
    
    This reduces the nar size (as shown by 'guix size') by 124 MiB, from
    169 MiB to 45 MiB (almost divided by 4!).
    
    * gnu/packages/gl.scm (mesa)[arguments]: Add #:modules.  Add
    'symlinks-instead-of-hard-links' phase.
---
 gnu/packages/gl.scm | 39 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 39 insertions(+)

diff --git a/gnu/packages/gl.scm b/gnu/packages/gl.scm
index 39f50a6..a9eccb5 100644
--- a/gnu/packages/gl.scm
+++ b/gnu/packages/gl.scm
@@ -305,6 +305,10 @@ also known as DXTn or DXTC) for Mesa.")
                 "--enable-llvm"))         ; default is x86/x86_64 only
              (_
               '("--with-dri-drivers=nouveau,r200,radeon,swrast"))))
+       #:modules ((ice-9 match)
+                  (srfi srfi-1)
+                  (guix build utils)
+                  (guix build gnu-build-system))
        #:phases
        (modify-phases %standard-phases
          (add-after
@@ -339,6 +343,41 @@ also known as DXTn or DXTC) for Mesa.")
                  ;; egl_gallium support.
                  (("\"gbm_dri\\.so")
                   (string-append "\"" out "/lib/dri/gbm_dri.so")))
+               #t)))
+         (add-after 'install 'symlinks-instead-of-hard-links
+           (lambda* (#:key outputs #:allow-other-keys)
+             ;; All the drivers and gallium targets create hard links upon
+             ;; installation (search for "hardlink each megadriver instance"
+             ;; in the makefiles).  This is no good for us since we'd produce
+             ;; nars that contain several copies of these files.  Thus, turn
+             ;; them into symlinks, which saves ~124 MiB.
+             (let* ((out    (assoc-ref outputs "out"))
+                    (lib    (string-append out "/lib"))
+                    (files  (find-files lib
+                                        (lambda (file stat)
+                                          (and (string-contains file ".so")
+                                               (eq? 'regular
+                                                    (stat:type stat))))))
+                    (inodes (map (compose stat:ino stat) files)))
+               (for-each (lambda (inode)
+                           (match (filter-map (match-lambda
+                                                ((file ino)
+                                                 (and (= ino inode) file)))
+                                              (zip files inodes))
+                             ((_)
+                              #f)
+                             ((reference others ..1)
+                              (format #t "creating ~a symlinks to '~a'~%"
+                                      (length others) reference)
+                              (for-each delete-file others)
+                              (for-each (lambda (file)
+                                          (if (string=? (dirname file)
+                                                        (dirname reference))
+                                              (symlink (basename reference)
+                                                       file)
+                                              (symlink reference file)))
+                                        others))))
+                         (delete-duplicates inodes))
                #t))))))
     (home-page "https://mesa3d.org/";)
     (synopsis "OpenGL implementation")



reply via email to

[Prev in Thread] Current Thread [Next in Thread]