gnu: mono: Make build reproducible.
[jackhill/guix/guix.git] / gnu / packages / llvm.scm
CommitLineData
3e4249ce 1;;; GNU Guix --- Functional package management for GNU
fc9dbf41 2;;; Copyright © 2014, 2016, 2018 Eric Bavier <bavier@member.fsf.org>
1204c510 3;;; Copyright © 2015 Mark H Weaver <mhw@netris.org>
6b26f915 4;;; Copyright © 2015, 2017, 2018 Ludovic Courtès <ludo@gnu.org>
ee077430 5;;; Copyright © 2016 Dennis Mungai <dmngaie@gmail.com>
8892cac3 6;;; Copyright © 2016, 2018 Ricardo Wurmus <rekado@elephly.net>
584da12d 7;;; Copyright © 2017 Roel Janssen <roel@gnu.org>
9bdbabe9 8;;; Copyright © 2018 Marius Bakke <mbakke@fastmail.com>
148df605 9;;; Copyright © 2018 Tobias Geerinckx-Rice <me@tobias.gr>
0627f93d 10;;; Copyright © 2018 Efraim Flashner <efraim@flashner.co.il>
3e4249ce
EB
11;;;
12;;; This file is part of GNU Guix.
13;;;
14;;; GNU Guix is free software; you can redistribute it and/or modify it
15;;; under the terms of the GNU General Public License as published by
16;;; the Free Software Foundation; either version 3 of the License, or (at
17;;; your option) any later version.
18;;;
19;;; GNU Guix is distributed in the hope that it will be useful, but
20;;; WITHOUT ANY WARRANTY; without even the implied warranty of
21;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22;;; GNU General Public License for more details.
23;;;
24;;; You should have received a copy of the GNU General Public License
25;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
26
27(define-module (gnu packages llvm)
28 #:use-module (guix packages)
ac00973c 29 #:use-module ((guix licenses) #:prefix license:)
3e4249ce
EB
30 #:use-module (guix download)
31 #:use-module (guix utils)
32 #:use-module (guix build-system gnu)
33 #:use-module (guix build-system cmake)
8892cac3 34 #:use-module (guix build-system python)
3e4249ce 35 #:use-module (gnu packages)
fd6ae1b9
LC
36 #:use-module (gnu packages gcc)
37 #:use-module (gnu packages bootstrap) ;glibc-dynamic-linker
ee077430
EB
38 #:use-module (gnu packages compression)
39 #:use-module (gnu packages libffi)
3e4249ce
EB
40 #:use-module (gnu packages perl)
41 #:use-module (gnu packages python)
42 #:use-module (gnu packages xml))
43
44(define-public llvm
45 (package
46 (name "llvm")
148df605 47 (version "6.0.1")
3e4249ce
EB
48 (source
49 (origin
50 (method url-fetch)
51 (uri (string-append "http://llvm.org/releases/"
52 version "/llvm-" version ".src.tar.xz"))
53 (sha256
54 (base32
148df605 55 "1qpls3vk85lydi5b4axl0809fv932qgsqgdgrk098567z4jc7mmn"))))
3e4249ce
EB
56 (build-system cmake-build-system)
57 (native-inputs
3ebc0905 58 `(("python" ,python-2) ;bytes->str conversion in clang>=3.7 needs python-2
3e4249ce 59 ("perl" ,perl)))
ee077430 60 (inputs
44e8559d
EB
61 `(("libffi" ,libffi)))
62 (propagated-inputs
63 `(("zlib" ,zlib))) ;to use output from llvm-config
3e4249ce 64 (arguments
22d0e9b7 65 `(#:configure-flags '("-DCMAKE_SKIP_BUILD_RPATH=FALSE"
ee077430 66 "-DCMAKE_BUILD_WITH_INSTALL_RPATH=FALSE"
ab78618f 67 "-DBUILD_SHARED_LIBS:BOOL=TRUE"
22897187 68 "-DLLVM_ENABLE_FFI:BOOL=TRUE"
fc9dbf41 69 "-DLLVM_REQUIRES_RTTI=1" ; For some third-party utilities
22897187 70 "-DLLVM_INSTALL_UTILS=ON") ; Needed for rustc.
0935fb27
EB
71
72 ;; Don't use '-g' during the build, to save space.
ab78618f
EB
73 #:build-type "Release"
74 #:phases (modify-phases %standard-phases
75 (add-before 'build 'shared-lib-workaround
76 ;; Even with CMAKE_SKIP_BUILD_RPATH=FALSE, llvm-tblgen
77 ;; doesn't seem to get the correct rpath to be able to run
78 ;; from the build directory. Set LD_LIBRARY_PATH as a
79 ;; workaround.
80 (lambda _
81 (setenv "LD_LIBRARY_PATH"
82 (string-append (getcwd) "/lib"))
83 #t)))))
ac97dce1 84 (home-page "https://www.llvm.org")
3e4249ce
EB
85 (synopsis "Optimizing compiler infrastructure")
86 (description
e881752c
AK
87 "LLVM is a compiler infrastructure designed for compile-time, link-time,
88runtime, and idle-time optimization of programs from arbitrary programming
89languages. It currently supports compilation of C and C++ programs, using
90front-ends derived from GCC 4.0.1. A new front-end for the C family of
91languages is in development. The compiler infrastructure includes mirror sets
92of programming tools as well as libraries with equivalent functionality.")
ac00973c 93 (license license:ncsa)))
3e4249ce 94
f8cba3ff
MB
95;; FIXME: This package is here to prevent many rebuilds on x86_64 and i686
96;; from commit fc9dbf41311d99d0fd8befc789ea7c0e35911890. Update users of
97;; this in the next rebuild cycle.
98(define-public llvm-without-rtti
99 (package
100 (inherit llvm)
101 (arguments
102 `(#:configure-flags '("-DCMAKE_SKIP_BUILD_RPATH=FALSE"
103 "-DCMAKE_BUILD_WITH_INSTALL_RPATH=FALSE"
104 "-DBUILD_SHARED_LIBS:BOOL=TRUE"
105 "-DLLVM_ENABLE_FFI:BOOL=TRUE"
106 "-DLLVM_INSTALL_UTILS=ON")
107 #:build-type "Release"
108 #:phases (modify-phases %standard-phases
109 (add-before 'build 'shared-lib-workaround
110 (lambda _
111 (setenv "LD_LIBRARY_PATH"
112 (string-append (getcwd) "/lib"))
113 #t)))))))
114
6b26f915
LC
115(define* (clang-runtime-from-llvm llvm hash
116 #:optional (patches '()))
b81f5693
AW
117 (package
118 (name "clang-runtime")
119 (version (package-version llvm))
120 (source
121 (origin
122 (method url-fetch)
123 (uri (string-append "http://llvm.org/releases/"
124 version "/compiler-rt-" version ".src.tar.xz"))
6b26f915
LC
125 (sha256 (base32 hash))
126 (patches (map search-patch patches))))
b81f5693
AW
127 (build-system cmake-build-system)
128 (native-inputs (package-native-inputs llvm))
129 (inputs
130 `(("llvm" ,llvm)))
131 (arguments
132 `(;; Don't use '-g' during the build to save space.
3b956a33
EB
133 #:build-type "Release"
134 #:tests? #f)) ; Tests require gtest
ac97dce1 135 (home-page "https://compiler-rt.llvm.org")
b81f5693
AW
136 (synopsis "Runtime library for Clang/LLVM")
137 (description
138 "The \"clang-runtime\" library provides the implementations of run-time
139functions for C and C++ programs. It also provides header files that allow C
140and C++ source code to interface with the \"sanitization\" passes of the clang
141compiler. In LLVM this library is called \"compiler-rt\".")
ac00973c 142 (license license:ncsa)
9e6b9ea4 143
ac97dce1 144 ;; <https://compiler-rt.llvm.org/> doesn't list MIPS as supported.
9e6b9ea4 145 (supported-systems (delete "mips64el-linux" %supported-systems))))
b81f5693 146
3b956a33 147(define* (clang-from-llvm llvm clang-runtime hash
9bdbabe9 148 #:key (patches '()))
3e4249ce
EB
149 (package
150 (name "clang")
151 (version (package-version llvm))
152 (source
153 (origin
154 (method url-fetch)
155 (uri (string-append "http://llvm.org/releases/"
156 version "/cfe-" version ".src.tar.xz"))
fd6ae1b9 157 (sha256 (base32 hash))
3b956a33 158 (patches (map search-patch patches))))
3e4249ce
EB
159 ;; Using cmake allows us to treat llvm as an external library. There
160 ;; doesn't seem to be any way to do this with clang's autotools-based
161 ;; build system.
162 (build-system cmake-build-system)
163 (native-inputs (package-native-inputs llvm))
164 (inputs
165 `(("libxml2" ,libxml2)
c92f1c0a 166 ("gcc-lib" ,gcc "lib")
3e4249ce
EB
167 ,@(package-inputs llvm)))
168 (propagated-inputs
b81f5693
AW
169 `(("llvm" ,llvm)
170 ("clang-runtime" ,clang-runtime)))
fd6ae1b9
LC
171 (arguments
172 `(#:configure-flags
173 (list "-DCLANG_INCLUDE_TESTS=True"
174
175 ;; Find libgcc_s, crtbegin.o, and crtend.o.
176 (string-append "-DGCC_INSTALL_PREFIX="
177 (assoc-ref %build-inputs "gcc-lib"))
178
179 ;; Use a sane default include directory.
180 (string-append "-DC_INCLUDE_DIRS="
181 (assoc-ref %build-inputs "libc")
182 "/include"))
183
94585e88
LC
184 ;; Don't use '-g' during the build to save space.
185 #:build-type "Release"
186
fd6ae1b9
LC
187 #:phases (modify-phases %standard-phases
188 (add-after
189 'unpack 'set-glibc-file-names
190 (lambda* (#:key inputs #:allow-other-keys)
b81f5693
AW
191 (let ((libc (assoc-ref inputs "libc"))
192 (compiler-rt (assoc-ref inputs "clang-runtime")))
9bdbabe9
MB
193 (case (string->number ,(version-major
194 (package-version clang-runtime)))
195 ((6)
196 ;; Link to libclang_rt files from clang-runtime.
197 (substitute* "lib/Driver/ToolChain.cpp"
198 (("getDriver\\(\\)\\.ResourceDir")
199 (string-append "\"" compiler-rt "\"")))
200
201 ;; Make "LibDir" refer to <glibc>/lib so that it
202 ;; uses the right dynamic linker file name.
203 (substitute* "lib/Driver/ToolChains/Linux.cpp"
204 (("(^[[:blank:]]+LibDir = ).*" _ declaration)
205 (string-append declaration "\"" libc "/lib\";\n"))
206
207 ;; Make sure libc's libdir is on the search path, to
208 ;; allow crt1.o & co. to be found.
209 (("@GLIBC_LIBDIR@")
210 (string-append libc "/lib"))))
211 ((3)
212 (substitute* "lib/Driver/Tools.cpp"
213 ;; Patch the 'getLinuxDynamicLinker' function so that
214 ;; it uses the right dynamic linker file name.
215 (("/lib64/ld-linux-x86-64.so.2")
216 (string-append libc
217 ,(glibc-dynamic-linker))))
218
219 ;; Link to libclang_rt files from clang-runtime.
220 ;; This substitution needed slight adjustment in 3.8.
221 (if (< 3.8 (string->number ,(version-major+minor
222 (package-version
223 clang-runtime))))
224 (substitute* "lib/Driver/Tools.cpp"
225 (("TC\\.getDriver\\(\\)\\.ResourceDir")
226 (string-append "\"" compiler-rt "\"")))
227 (substitute* "lib/Driver/ToolChain.cpp"
228 (("getDriver\\(\\)\\.ResourceDir")
229 (string-append "\"" compiler-rt "\""))))
230
231 ;; Make sure libc's libdir is on the search path, to
232 ;; allow crt1.o & co. to be found.
233 (substitute* "lib/Driver/ToolChains.cpp"
234 (("@GLIBC_LIBDIR@")
235 (string-append libc "/lib")))))
236 #t))))))
ef11ac87
LC
237
238 ;; Clang supports the same environment variables as GCC.
239 (native-search-paths
240 (list (search-path-specification
241 (variable "CPATH")
242 (files '("include")))
243 (search-path-specification
244 (variable "LIBRARY_PATH")
245 (files '("lib" "lib64")))))
246
ac97dce1 247 (home-page "https://clang.llvm.org")
3e4249ce
EB
248 (synopsis "C language family frontend for LLVM")
249 (description
250 "Clang is a compiler front end for the C, C++, Objective-C and
251Objective-C++ programming languages. It uses LLVM as its back end. The Clang
252project includes the Clang front end, the Clang static analyzer, and several
253code analysis tools.")
ac00973c 254 (license license:ncsa)))
1204c510 255
b81f5693
AW
256(define-public clang-runtime
257 (clang-runtime-from-llvm
258 llvm
148df605 259 "1fcr3jn24yr8lh36nc0c4ikli4744i2q9m1ik67p1jymwwaixkgl"))
b81f5693 260
1204c510 261(define-public clang
b81f5693 262 (clang-from-llvm llvm clang-runtime
148df605 263 "0rxn4rh7rrnsqbdgp4gzc8ishbkryhpl1kd3mpnxzpxxhla3y93w"
9bdbabe9 264 #:patches '("clang-6.0-libc-search-path.patch")))
3b956a33 265
584da12d
RJ
266(define-public llvm-3.9.1
267 (package (inherit llvm)
268 (name "llvm")
269 (version "3.9.1")
270 (source
271 (origin
272 (method url-fetch)
273 (uri (string-append "http://llvm.org/releases/"
274 version "/llvm-" version ".src.tar.xz"))
275 (sha256
276 (base32
277 "1vi9sf7rx1q04wj479rsvxayb6z740iaz3qniwp266fgp5a07n8z"))))))
278
279(define-public clang-runtime-3.9.1
280 (clang-runtime-from-llvm
281 llvm-3.9.1
6b26f915
LC
282 "16gc2gdmp5c800qvydrdhsp0bzb97s8wrakl6i8a4lgslnqnf2fk"
283 '("clang-runtime-asan-build-fixes.patch"
0627f93d 284 "clang-runtime-esan-build-fixes.patch"
1a2d8d06 285 "clang-3.5-libsanitizer-ustat-fix.patch")))
584da12d
RJ
286
287(define-public clang-3.9.1
288 (clang-from-llvm llvm-3.9.1 clang-runtime-3.9.1
289 "0qsyyb40iwifhhlx9a3drf8z6ni6zwyk3bvh0kx2gs6yjsxwxi76"
9bdbabe9
MB
290 #:patches '("clang-3.8-libc-search-path.patch")))
291
292(define-public llvm-3.8
293 (package (inherit llvm)
294 (name "llvm")
295 (version "3.8.1")
296 (source
297 (origin
298 (method url-fetch)
299 (uri (string-append "https://llvm.org/releases/"
300 version "/llvm-" version ".src.tar.xz"))
301 (sha256
302 (base32
303 "1ybmnid4pw2hxn12ax5qa5kl1ldfns0njg8533y3mzslvd5cx0kf"))))))
304
305(define-public clang-runtime-3.8
306 (clang-runtime-from-llvm
307 llvm-3.8
308 "0p0y85c7izndbpg2l816z7z7558axq11d5pwkm4h11sdw7d13w0d"
0627f93d 309 '("clang-runtime-asan-build-fixes.patch"
1a2d8d06 310 "clang-3.5-libsanitizer-ustat-fix.patch")))
9bdbabe9
MB
311
312(define-public clang-3.8
313 (clang-from-llvm llvm-3.8 clang-runtime-3.8
314 "1prc72xmkgx8wrzmrr337776676nhsp1qd3mw2bvb22bzdnq7lsc"
315 #:patches '("clang-3.8-libc-search-path.patch")))
584da12d 316
3b956a33
EB
317(define-public llvm-3.7
318 (package (inherit llvm)
319 (version "3.7.1")
320 (source
321 (origin
322 (method url-fetch)
323 (uri (string-append "http://llvm.org/releases/"
324 version "/llvm-" version ".src.tar.xz"))
325 (sha256
326 (base32
327 "1masakdp9g2dan1yrazg7md5am2vacbkb3nahb3dchpc1knr8xxy"))))))
328
329(define-public clang-runtime-3.7
330 (clang-runtime-from-llvm
331 llvm-3.7
6b26f915 332 "10c1mz2q4bdq9bqfgr3dirc6hz1h3sq8573srd5q5lr7m7j6jiwx"
0627f93d 333 '("clang-runtime-asan-build-fixes.patch"
1a2d8d06 334 "clang-3.5-libsanitizer-ustat-fix.patch")))
3b956a33
EB
335
336(define-public clang-3.7
337 (clang-from-llvm llvm-3.7 clang-runtime-3.7
9bdbabe9
MB
338 "0x065d0w9b51xvdjxwfzjxng0gzpbx45fgiaxpap45ragi61dqjn"
339 #:patches '("clang-3.5-libc-search-path.patch")))
3ebc0905
EB
340
341(define-public llvm-3.6
342 (package (inherit llvm)
343 (version "3.6.2")
344 (source
345 (origin
346 (method url-fetch)
347 (uri (string-append "http://llvm.org/releases/"
348 version "/llvm-" version ".src.tar.xz"))
349 (sha256
350 (base32
351 "153vcvj8gvgwakzr4j0kndc0b7wn91c2g1vy2vg24s6spxcc23gn"))))))
352
353(define-public clang-runtime-3.6
354 (clang-runtime-from-llvm
355 llvm-3.6
6b26f915
LC
356 "11qx8d3pbfqjaj2x207pvlvzihbs1z2xbw4crpz7aid6h1yz6bqg"
357 '("clang-runtime-asan-build-fixes.patch")))
3ebc0905
EB
358
359(define-public clang-3.6
360 (clang-from-llvm llvm-3.6 clang-runtime-3.6
9bdbabe9
MB
361 "1wwr8s6lzr324hv4s1k6na4j5zv6n9kdhi14s4kb9b13d93814df"
362 #:patches '("clang-3.5-libc-search-path.patch")))
1204c510
MW
363
364(define-public llvm-3.5
365 (package (inherit llvm)
a53c486d 366 (version "3.5.2")
1204c510
MW
367 (source
368 (origin
369 (method url-fetch)
370 (uri (string-append "http://llvm.org/releases/"
371 version "/llvm-" version ".src.tar.xz"))
6ba4eca2
RW
372 (patches
373 (search-patches "llvm-3.5-fix-clang-build-with-gcc5.patch"))
1204c510
MW
374 (sha256
375 (base32
a53c486d 376 "0xf5q17kkxsrm2gsi93h4pwlv663kji73r2g4asb97klsmb626a4"))))))
1204c510 377
b81f5693
AW
378(define-public clang-runtime-3.5
379 (clang-runtime-from-llvm
380 llvm-3.5
6b26f915
LC
381 "1hsdnzzdr5kglz6fnv3lcsjs222zjsy14y8ax9dy6zqysanplbal"
382 '("clang-runtime-asan-build-fixes.patch")))
b81f5693 383
1204c510 384(define-public clang-3.5
b81f5693 385 (clang-from-llvm llvm-3.5 clang-runtime-3.5
9bdbabe9
MB
386 "0846h8vn3zlc00jkmvrmy88gc6ql6014c02l4jv78fpvfigmgssg"
387 #:patches '("clang-3.5-libc-search-path.patch")))
921cb13a
RW
388
389(define-public llvm-for-extempore
390 (package (inherit llvm-3.7)
7355634d 391 (name "llvm-for-extempore")
921cb13a
RW
392 (source
393 (origin
394 (inherit (package-source llvm-3.7))
39162ee4
RW
395 (patches (list (search-patch "llvm-for-extempore.patch")))))
396 ;; Extempore refuses to build on architectures other than x86_64
397 (supported-systems '("x86_64-linux"))))
8892cac3
RW
398
399(define-public python-llvmlite
400 (package
401 (name "python-llvmlite")
402 (version "0.24.0")
403 (source
404 (origin
405 (method url-fetch)
406 (uri (pypi-uri "llvmlite" version))
407 (sha256
408 (base32
409 "01zwjlc3c5mhrwmv4b73zgbskwqps9ly0nrh54bbj1f1l72f839j"))))
410 (build-system python-build-system)
411 (inputs
412 `(("llvm"
413 ,(package
414 (inherit llvm)
415 (source (origin
416 (inherit (package-source llvm))
417 (patches
418 (list
419 (origin
420 (method url-fetch)
421 (uri (string-append "https://raw.githubusercontent.com/numba/"
422 "llvmlite/v" version "/conda-recipes/"
423 "D47188-svml.patch"))
424 (sha256
425 (base32
426 "0mrj24jvkv3hjcmyg98zmvmyl1znlh2j63rdr69f6g7s96d2pfv1")))
427 (origin
428 (method url-fetch)
429 (uri (string-append "https://raw.githubusercontent.com/numba/"
430 "llvmlite/v" version "/conda-recipes/"
431 "twine_cfg_undefined_behavior.patch"))
432 (sha256
433 (base32
7a20877a 434 "07h71n2m1mn9zcfgw04zglffknplb233zqbcd6pckq0wygkrxflp")))))))))))
8892cac3
RW
435 (home-page "http://llvmlite.pydata.org")
436 (synopsis "Wrapper around basic LLVM functionality")
437 (description
438 "This package provides a Python binding to LLVM for use in Numba.")
439 (license license:bsd-3)))