unofficial mirror of guix-patches@gnu.org 
 help / color / mirror / Atom feed
From: Pierre Neidhardt <mail@ambrevar.xyz>
To: 42576@debbugs.gnu.org
Subject: [bug#42576] [PATCH 1/2] gnu: llvm: Move dynamic libraries to a separate "lib" output.
Date: Tue, 28 Jul 2020 11:58:22 +0200
Message-ID: <20200728095822.28375-1-mail@ambrevar.xyz> (raw)

* gnu/packages/llvm.scm (llvm)[arguments]: Set configure-flags to build
a dynamic library bundle in the "lib" output.
Add phases to move the /bin and /include directories to the "out" output.

The goal of this change is to reduce the closure size of LLVM dependents.

- The dynamic library bundles saves a few dozen MiB over the separate dynamic
  libraries.

- Removing the /bin and the /include directories from the dependent input
  saves about 35 MiB for LLVM 10.
---
 gnu/packages/llvm.scm | 65 +++++++++++++++++++++++++++++++++++--------
 1 file changed, 53 insertions(+), 12 deletions(-)

diff --git a/gnu/packages/llvm.scm b/gnu/packages/llvm.scm
index b7bc21ea6e..3e9d428b9f 100644
--- a/gnu/packages/llvm.scm
+++ b/gnu/packages/llvm.scm
@@ -99,7 +99,7 @@ as \"x86_64-linux\"."
        (base32
         "1pwgm6cr0xr5a0hrbqs1zvsvvjvy0yq1y47c96804wcs795s90yz"))))
     (build-system cmake-build-system)
-    (outputs '("out" "opt-viewer"))
+    (outputs '("out" "opt-viewer" "lib"))
     (native-inputs
      `(("python" ,python-2) ;bytes->str conversion in clang>=3.7 needs python-2
        ("perl"   ,perl)))
@@ -108,12 +108,18 @@ as \"x86_64-linux\"."
     (propagated-inputs
      `(("zlib" ,zlib)))                 ;to use output from llvm-config
     (arguments
-     `(#:configure-flags '("-DCMAKE_SKIP_BUILD_RPATH=FALSE"
-                           "-DCMAKE_BUILD_WITH_INSTALL_RPATH=FALSE"
-                           "-DBUILD_SHARED_LIBS:BOOL=TRUE"
-                           "-DLLVM_ENABLE_FFI:BOOL=TRUE"
-                           "-DLLVM_REQUIRES_RTTI=1" ; For some third-party utilities
-                           "-DLLVM_INSTALL_UTILS=ON") ; Needed for rustc.
+     `(#:configure-flags (list "-DCMAKE_SKIP_BUILD_RPATH=FALSE"
+                               "-DCMAKE_BUILD_WITH_INSTALL_RPATH=FALSE"
+                               ;; LLVM cannot enable BUILD_SHARED_LIBS with LLVM_LINK_LLVM_DYLIB.
+                               ;; "-DBUILD_SHARED_LIBS:BOOL=TRUE"
+                               "-DLLVM_BUILD_LLVM_DYLIB=ON"
+                               "-DLLVM_LINK_LLVM_DYLIB=ON"
+                               (string-append "-DCMAKE_INSTALL_PREFIX=" (assoc-ref %outputs "lib"))
+                               (string-append "-DCMAKE_INSTALL_RPATH=" (assoc-ref %outputs "lib")
+                                              "/lib")
+                               "-DLLVM_ENABLE_FFI:BOOL=TRUE"
+                               "-DLLVM_REQUIRES_RTTI=1" ; For some third-party utilities
+                               "-DLLVM_INSTALL_UTILS=ON") ; Needed for rustc.
 
        ;; Don't use '-g' during the build, to save space.
        #:build-type "Release"
@@ -128,14 +134,49 @@ as \"x86_64-linux\"."
              (setenv "LD_LIBRARY_PATH"
                      (string-append (getcwd) "/lib"))
              #t))
-         (add-after 'install 'install-opt-viewer
+         (add-after 'install 'install-bin
            (lambda* (#:key outputs #:allow-other-keys)
              (let* ((out (assoc-ref outputs "out"))
+                    (out-lib (string-append out "/lib"))
+                    (lib-output (assoc-ref outputs "lib"))
+                    (lib-bin (string-append lib-output "/bin")))
+               (mkdir-p out)
+               (rename-file (string-append lib-output "/bin")
+                            (string-append out "/bin"))
+               ;; llvm-config is required by most lib dependents.  It's only a
+               ;; few KiB, so it does not warrant a separate output.
+               (mkdir-p lib-bin)
+               (rename-file (string-append out "/bin/llvm-config")
+                            (string-append lib-bin "/llvm-config"))
+               (rename-file (string-append lib-output "/include")
+                            (string-append out "/include"))
+               (mkdir-p out-lib)
+               (if (file-exists? (string-append lib-output "/lib/cmake"))
+                   (rename-file (string-append lib-output "/lib/cmake")
+                                (string-append out-lib "/cmake"))
+                   ;; The cmake files change location in llvm 3.9.
+                   (begin
+                     (mkdir-p (string-append out "/share/llvm"))
+                     (rename-file (string-append lib-output "/share/llvm/cmake")
+                                  (string-append out "/share/llvm/cmake"))))
+               (for-each
+                (lambda (file)
+                  (rename-file file
+                               (string-append out-lib "/" (basename file))))
+                (find-files (string-append lib-output "/lib") "\\.a$"))
+               (for-each
+                (lambda (file)
+                  (symlink file
+                           (string-append out-lib "/" (basename file))))
+                (find-files (string-append lib-output "/lib") "\\.so")))
+             #t))
+         (add-after 'install 'install-opt-viewer
+           (lambda* (#:key outputs #:allow-other-keys)
+             (let* ((lib-output (assoc-ref outputs "lib"))
                     (opt-viewer-out (assoc-ref outputs "opt-viewer"))
-                    (opt-viewer-share-dir (string-append opt-viewer-out "/share"))
-                    (opt-viewer-dir (string-append opt-viewer-share-dir "/opt-viewer")))
-               (mkdir-p opt-viewer-share-dir)
-               (rename-file (string-append out "/share/opt-viewer")
+                    (opt-viewer-dir (string-append opt-viewer-out "/share/opt-viewer")))
+               (mkdir-p (dirname opt-viewer-dir))
+               (rename-file (string-append lib-output "/share/opt-viewer")
                             opt-viewer-dir))
              #t)))))
     (home-page "https://www.llvm.org")

base-commit: 0e1428ac5dc3a7f1aa68988dd88885009e9706a6
-- 
2.27.0





             reply	other threads:[~2020-07-28  9:59 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-28  9:58 Pierre Neidhardt [this message]
2020-07-28 10:03 ` [bug#42576] [PATCH 2/2] gnu: llvm-3.9.1: Move libraries to " Pierre Neidhardt
     [not found] ` <handler.42576.B.159593032321168.ack@debbugs.gnu.org>
2020-07-28 10:07   ` [bug#42576] Acknowledgement ([PATCH 1/2] gnu: llvm: Move dynamic libraries to a separate "lib" output.) Pierre Neidhardt
2020-08-01 10:59 ` [bug#42576] [PATCH 1/2] gnu: llvm: Move dynamic libraries to a separate "lib" output Danny Milosavljevic
2020-08-01 11:18   ` Pierre Neidhardt
2020-08-07 18:09 ` Jakub Kądziołka
2020-08-08  8:49   ` Pierre Neidhardt

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://guix.gnu.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200728095822.28375-1-mail@ambrevar.xyz \
    --to=mail@ambrevar.xyz \
    --cc=42576@debbugs.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

unofficial mirror of guix-patches@gnu.org 

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://yhetil.org/guix-patches/1 guix-patches/git/1.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 guix-patches guix-patches/ https://yhetil.org/guix-patches \
		guix-patches@gnu.org
	public-inbox-index guix-patches

Example config snippet for mirrors.
Newsgroup available over NNTP:
	nntp://news.yhetil.org/yhetil.gnu.guix.patches


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git