projects/guix·blob javascript-team · refs

135 lines · 5.5 KiB

1;;; GNU Guix --- Functional package management for GNU
2;;; Copyright © 2023 Zhu Zihao <[email protected]>
3;;; Copyright © 2023, 2024 Efraim Flashner <[email protected]>
4;;; Copyright © 2024-2026 Ashish SHUKLA <[email protected]>
5;;;
6;;; This file is part of GNU Guix.
7;;;
8;;; GNU Guix is free software; you can redistribute it and/or modify it
9;;; under the terms of the GNU General Public License as published by
10;;; the Free Software Foundation; either version 3 of the License, or (at
11;;; your option) any later version.
12;;;
13;;; GNU Guix is distributed in the hope that it will be useful, but
14;;; WITHOUT ANY WARRANTY; without even the implied warranty of
15;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16;;; GNU General Public License for more details.
17;;;
18;;; You should have received a copy of the GNU General Public License
19;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
20
21(define-module (gnu packages mold)
22 #:use-module (guix gexp)
23 #:use-module (guix packages)
24 #:use-module (guix utils)
25 #:use-module (guix git-download)
26 #:use-module (guix build-system cmake)
27 #:use-module (guix build-system trivial)
28 #:use-module (gnu packages base)
29 #:use-module (gnu packages c)
30 #:use-module (gnu packages crypto)
31 #:use-module (gnu packages digest)
32 #:use-module (gnu packages oneapi)
33 #:use-module (gnu packages tls)
34 #:use-module (gnu packages compression)
35 #:use-module ((guix licenses) #:prefix license:))
36
37(define-public mold
38 (package
39 (name "mold")
40 (version "2.42.1")
41 (source
42 (origin
43 (method git-fetch)
44 (uri (git-reference
45 (url "https://github.com/rui314/mold")
46 (commit (string-append "v" version))))
47 (file-name (git-file-name name version))
48 (sha256
49 (base32 "0bymmnsxpgzg6p4gygq0h7kil36izqqh5mhaa3bwkqdg258rdfyx"))
50 (modules '((guix build utils)))
51 (snippet
52 #~(begin
53 (for-each
54 (lambda (x)
55 (delete-file-recursively (string-append "third-party/" x)))
56 '("blake3" "mimalloc" "tbb" "xxhash" "zlib" "zstd"))))))
57 (build-system cmake-build-system)
58 (arguments
59 (list
60 ;; Mold only uses mimalloc on 64-bit systems, even with the
61 ;; configure flag set, saying it is unstable on 32-bit systems.
62 #:configure-flags #~(list #$@(if (target-64bit?)
63 '("-DMOLD_USE_SYSTEM_MIMALLOC=ON")
64 '("-DMOLD_USE_MIMALLOC=OFF"))
65 "-DMOLD_USE_SYSTEM_TBB=ON")
66 #:phases
67 #~(modify-phases %standard-phases
68 (add-before 'configure 'force-system-xxhash
69 (lambda _
70 (substitute* "lib/lib.h"
71 (("#include \"../third-party/xxhash/xxhash.h\"")
72 "#include <xxhash.h>"))))
73 (add-before 'configure 'fix-compiler-name-in-test
74 (lambda _
75 (substitute* "test/common.inc"
76 (("CC=\"\\$\\{TEST_CC:-cc\\}\"") "CC=gcc")
77 (("CXX=\"\\$\\{TEST_CXX:-c\\+\\+\\}\"")
78 "CXX=g++"))))
79 (add-before 'configure 'disable-rpath-test
80 (lambda _
81 ;; This test fails because mold expect the RUNPATH as-is,
82 ;; but compiler in Guix will insert the path of gcc-lib and
83 ;; glibc into the output binary.
84 (delete-file "test/rpath.sh"))))))
85 (inputs
86 (append
87 (if (target-64bit?)
88 (list mimalloc)
89 '())
90 (list libblake3 onetbb xxhash zlib `(,zstd "lib"))))
91 (home-page "https://github.com/rui314/mold")
92 (synopsis "Fast linker")
93 (description
94 "Mold is a faster drop-in replacement for existing linkers.
95It is designed to increase developer productivity by reducing build time,
96especially in rapid debug-edit-rebuild cycles.")
97 (license license:agpl3)))
98
99(define* (make-mold-wrapper mold #:key mold-as-ld?)
100 "Return a MOLD wrapper. When MOLD-AS-LD? is true, create a 'ld' symlink that
101points to 'mold'."
102 (package
103 (inherit mold)
104 (name (if mold-as-ld? "mold-as-ld-wrapper" "mold-wrapper"))
105 (source #f)
106 (native-inputs '())
107 (inputs (list (make-ld-wrapper "ld.mold-wrapper" #:binutils mold
108 #:linker "ld.mold")
109 (make-ld-wrapper "mold-wrapper" #:binutils mold #:linker
110 "mold")))
111 (propagated-inputs '())
112 (build-system trivial-build-system)
113 (arguments
114 (list #:builder
115 #~(let ((ld.mold (string-append #$(this-package-input
116 "ld.mold-wrapper")
117 "/bin/ld.mold"))
118 (mold (string-append #$(this-package-input "mold-wrapper")
119 "/bin/mold")))
120 (mkdir #$output)
121 (mkdir (string-append #$output "/bin"))
122 (symlink ld.mold (string-append #$output "/bin/ld.mold"))
123 (symlink mold (string-append #$output "/bin/mold"))
124 (when #$mold-as-ld?
125 (symlink ld.mold (string-append #$output "/bin/ld"))))))
126 (synopsis "Mold linker wrapper")
127 (description "This is a linker wrapper for Mold; like @code{ld-wrapper}, it
128wraps the linker to add any missing @code{-rpath} flags, and to detect any
129misuse of libraries outside of the store.")))
130
131(define-public mold-wrapper
132 (make-mold-wrapper mold))
133
134(define-public mold-as-ld-wrapper
135 (make-mold-wrapper mold #:mold-as-ld? #t))