gnu: igt-gpu-tools: Don't use NAME in source URI.
[jackhill/guix/guix.git] / gnu / packages / llvm.scm
1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2014, 2016, 2018 Eric Bavier <bavier@member.fsf.org>
3 ;;; Copyright © 2015 Mark H Weaver <mhw@netris.org>
4 ;;; Copyright © 2015, 2017, 2018, 2019 Ludovic Courtès <ludo@gnu.org>
5 ;;; Copyright © 2016 Dennis Mungai <dmngaie@gmail.com>
6 ;;; Copyright © 2016, 2018 Ricardo Wurmus <rekado@elephly.net>
7 ;;; Copyright © 2017 Roel Janssen <roel@gnu.org>
8 ;;; Copyright © 2018 Marius Bakke <mbakke@fastmail.com>
9 ;;; Copyright © 2018 Tobias Geerinckx-Rice <me@tobias.gr>
10 ;;; Copyright © 2018 Efraim Flashner <efraim@flashner.co.il>
11 ;;; Copyright © 2018 Tim Gesthuizen <tim.gesthuizen@yahoo.de>
12 ;;; Copyright © 2018 Pierre Neidhardt <mail@ambrevar.xyz>
13 ;;;
14 ;;; This file is part of GNU Guix.
15 ;;;
16 ;;; GNU Guix is free software; you can redistribute it and/or modify it
17 ;;; under the terms of the GNU General Public License as published by
18 ;;; the Free Software Foundation; either version 3 of the License, or (at
19 ;;; your option) any later version.
20 ;;;
21 ;;; GNU Guix is distributed in the hope that it will be useful, but
22 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
23 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 ;;; GNU General Public License for more details.
25 ;;;
26 ;;; You should have received a copy of the GNU General Public License
27 ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
28
29 (define-module (gnu packages llvm)
30 #:use-module (guix packages)
31 #:use-module ((guix licenses) #:prefix license:)
32 #:use-module (guix download)
33 #:use-module (guix utils)
34 #:use-module (guix build-system gnu)
35 #:use-module (guix build-system cmake)
36 #:use-module (guix build-system emacs)
37 #:use-module (guix build-system python)
38 #:use-module (gnu packages)
39 #:use-module (gnu packages gcc)
40 #:use-module (gnu packages bootstrap) ;glibc-dynamic-linker
41 #:use-module (gnu packages compression)
42 #:use-module (gnu packages libffi)
43 #:use-module (gnu packages perl)
44 #:use-module (gnu packages python)
45 #:use-module (gnu packages xml))
46
47 (define-public llvm
48 (package
49 (name "llvm")
50 (version "6.0.1")
51 (source
52 (origin
53 (method url-fetch)
54 (uri (string-append "http://llvm.org/releases/"
55 version "/llvm-" version ".src.tar.xz"))
56 (sha256
57 (base32
58 "1qpls3vk85lydi5b4axl0809fv932qgsqgdgrk098567z4jc7mmn"))))
59 (build-system cmake-build-system)
60 (native-inputs
61 `(("python" ,python-2) ;bytes->str conversion in clang>=3.7 needs python-2
62 ("perl" ,perl)))
63 (inputs
64 `(("libffi" ,libffi)))
65 (propagated-inputs
66 `(("zlib" ,zlib))) ;to use output from llvm-config
67 (arguments
68 `(#:configure-flags '("-DCMAKE_SKIP_BUILD_RPATH=FALSE"
69 "-DCMAKE_BUILD_WITH_INSTALL_RPATH=FALSE"
70 "-DBUILD_SHARED_LIBS:BOOL=TRUE"
71 "-DLLVM_ENABLE_FFI:BOOL=TRUE"
72 "-DLLVM_REQUIRES_RTTI=1" ; For some third-party utilities
73 "-DLLVM_INSTALL_UTILS=ON") ; Needed for rustc.
74
75 ;; Don't use '-g' during the build, to save space.
76 #:build-type "Release"
77 #:phases (modify-phases %standard-phases
78 (add-before 'build 'shared-lib-workaround
79 ;; Even with CMAKE_SKIP_BUILD_RPATH=FALSE, llvm-tblgen
80 ;; doesn't seem to get the correct rpath to be able to run
81 ;; from the build directory. Set LD_LIBRARY_PATH as a
82 ;; workaround.
83 (lambda _
84 (setenv "LD_LIBRARY_PATH"
85 (string-append (getcwd) "/lib"))
86 #t)))))
87 (home-page "https://www.llvm.org")
88 (synopsis "Optimizing compiler infrastructure")
89 (description
90 "LLVM is a compiler infrastructure designed for compile-time, link-time,
91 runtime, and idle-time optimization of programs from arbitrary programming
92 languages. It currently supports compilation of C and C++ programs, using
93 front-ends derived from GCC 4.0.1. A new front-end for the C family of
94 languages is in development. The compiler infrastructure includes mirror sets
95 of programming tools as well as libraries with equivalent functionality.")
96 (license license:ncsa)))
97
98 ;; TODO: Build Mesa with LLVM 7 in the next staging cycle.
99 ;; TODO: Make LLVM 7 the default LLVM once Clang is also upgraded.
100 (define-public llvm-7.0.1
101 (package (inherit llvm)
102 (name "llvm")
103 (version "7.0.1")
104 (source
105 (origin
106 (method url-fetch)
107 (uri (string-append "http://llvm.org/releases/"
108 version "/llvm-" version ".src.tar.xz"))
109 (sha256
110 (base32
111 "16s196wqzdw4pmri15hadzqgdi926zln3an2viwyq0kini6zr3d3"))))))
112
113 ;; FIXME: This package is here to prevent many rebuilds on x86_64 and i686
114 ;; from commit fc9dbf41311d99d0fd8befc789ea7c0e35911890. Update users of
115 ;; this in the next rebuild cycle.
116 (define-public llvm-without-rtti
117 (package
118 (inherit llvm)
119 (arguments
120 `(#:configure-flags '("-DCMAKE_SKIP_BUILD_RPATH=FALSE"
121 "-DCMAKE_BUILD_WITH_INSTALL_RPATH=FALSE"
122 "-DBUILD_SHARED_LIBS:BOOL=TRUE"
123 "-DLLVM_ENABLE_FFI:BOOL=TRUE"
124 "-DLLVM_INSTALL_UTILS=ON")
125 #:build-type "Release"
126 #:phases (modify-phases %standard-phases
127 (add-before 'build 'shared-lib-workaround
128 (lambda _
129 (setenv "LD_LIBRARY_PATH"
130 (string-append (getcwd) "/lib"))
131 #t)))))))
132
133 (define* (clang-runtime-from-llvm llvm hash
134 #:optional (patches '()))
135 (package
136 (name "clang-runtime")
137 (version (package-version llvm))
138 (source
139 (origin
140 (method url-fetch)
141 (uri (string-append "http://llvm.org/releases/"
142 version "/compiler-rt-" version ".src.tar.xz"))
143 (sha256 (base32 hash))
144 (patches (map search-patch patches))))
145 (build-system cmake-build-system)
146 (native-inputs (package-native-inputs llvm))
147 (inputs
148 `(("llvm" ,llvm)))
149 (arguments
150 `(;; Don't use '-g' during the build to save space.
151 #:build-type "Release"
152 #:tests? #f)) ; Tests require gtest
153 (home-page "https://compiler-rt.llvm.org")
154 (synopsis "Runtime library for Clang/LLVM")
155 (description
156 "The \"clang-runtime\" library provides the implementations of run-time
157 functions for C and C++ programs. It also provides header files that allow C
158 and C++ source code to interface with the \"sanitization\" passes of the clang
159 compiler. In LLVM this library is called \"compiler-rt\".")
160 (license license:ncsa)
161
162 ;; <https://compiler-rt.llvm.org/> doesn't list MIPS as supported.
163 (supported-systems (delete "mips64el-linux" %supported-systems))))
164
165 (define* (clang-from-llvm llvm clang-runtime hash
166 #:key (patches '()))
167 (package
168 (name "clang")
169 (version (package-version llvm))
170 (source
171 (origin
172 (method url-fetch)
173 (uri (string-append "http://llvm.org/releases/"
174 version "/cfe-" version ".src.tar.xz"))
175 (sha256 (base32 hash))
176 (patches (map search-patch patches))))
177 ;; Using cmake allows us to treat llvm as an external library. There
178 ;; doesn't seem to be any way to do this with clang's autotools-based
179 ;; build system.
180 (build-system cmake-build-system)
181 (native-inputs (package-native-inputs llvm))
182 (inputs
183 `(("libxml2" ,libxml2)
184 ("gcc-lib" ,gcc "lib")
185 ,@(package-inputs llvm)))
186 (propagated-inputs
187 `(("llvm" ,llvm)
188 ("clang-runtime" ,clang-runtime)))
189 (arguments
190 `(#:configure-flags
191 (list "-DCLANG_INCLUDE_TESTS=True"
192
193 ;; Find libgcc_s, crtbegin.o, and crtend.o.
194 (string-append "-DGCC_INSTALL_PREFIX="
195 (assoc-ref %build-inputs "gcc-lib"))
196
197 ;; Use a sane default include directory.
198 (string-append "-DC_INCLUDE_DIRS="
199 (assoc-ref %build-inputs "libc")
200 "/include"))
201
202 ;; Don't use '-g' during the build to save space.
203 #:build-type "Release"
204
205 #:phases (modify-phases %standard-phases
206 (add-after
207 'unpack 'set-glibc-file-names
208 (lambda* (#:key inputs #:allow-other-keys)
209 (let ((libc (assoc-ref inputs "libc"))
210 (compiler-rt (assoc-ref inputs "clang-runtime")))
211 (case (string->number ,(version-major
212 (package-version clang-runtime)))
213 ((6)
214 ;; Link to libclang_rt files from clang-runtime.
215 (substitute* "lib/Driver/ToolChain.cpp"
216 (("getDriver\\(\\)\\.ResourceDir")
217 (string-append "\"" compiler-rt "\"")))
218
219 ;; Make "LibDir" refer to <glibc>/lib so that it
220 ;; uses the right dynamic linker file name.
221 (substitute* "lib/Driver/ToolChains/Linux.cpp"
222 (("(^[[:blank:]]+LibDir = ).*" _ declaration)
223 (string-append declaration "\"" libc "/lib\";\n"))
224
225 ;; Make sure libc's libdir is on the search path, to
226 ;; allow crt1.o & co. to be found.
227 (("@GLIBC_LIBDIR@")
228 (string-append libc "/lib"))))
229 ((3)
230 (substitute* "lib/Driver/Tools.cpp"
231 ;; Patch the 'getLinuxDynamicLinker' function so that
232 ;; it uses the right dynamic linker file name.
233 (("/lib64/ld-linux-x86-64.so.2")
234 (string-append libc
235 ,(glibc-dynamic-linker))))
236
237 ;; Link to libclang_rt files from clang-runtime.
238 ;; This substitution needed slight adjustment in 3.8.
239 (if (< 3.8 (string->number ,(version-major+minor
240 (package-version
241 clang-runtime))))
242 (substitute* "lib/Driver/Tools.cpp"
243 (("TC\\.getDriver\\(\\)\\.ResourceDir")
244 (string-append "\"" compiler-rt "\"")))
245 (substitute* "lib/Driver/ToolChain.cpp"
246 (("getDriver\\(\\)\\.ResourceDir")
247 (string-append "\"" compiler-rt "\""))))
248
249 ;; Make sure libc's libdir is on the search path, to
250 ;; allow crt1.o & co. to be found.
251 (substitute* "lib/Driver/ToolChains.cpp"
252 (("@GLIBC_LIBDIR@")
253 (string-append libc "/lib")))))
254 #t)))
255 (add-after 'install 'install-clean-up-/share/clang
256 (lambda* (#:key outputs #:allow-other-keys)
257 (let* ((out (assoc-ref outputs "out"))
258 (compl-dir (string-append
259 out "/etc/bash_completion.d")))
260 (with-directory-excursion (string-append out
261 "/share/clang")
262 (for-each
263 (lambda (file)
264 (when (file-exists? file)
265 (delete-file file)))
266 ;; Delete extensions for proprietary text editors.
267 '("clang-format-bbedit.applescript"
268 "clang-format-sublime.py"
269 ;; Delete Emacs extensions: see their respective Emacs
270 ;; Guix package instead.
271 "clang-rename.el" "clang-format.el"))
272 ;; Install bash completion.
273 (when (file-exists? "bash-autocomplete.sh")
274 (mkdir-p compl-dir)
275 (rename-file "bash-autocomplete.sh"
276 (string-append compl-dir "/clang")))))
277 #t)))))
278
279 ;; Clang supports the same environment variables as GCC.
280 (native-search-paths
281 (list (search-path-specification
282 (variable "CPATH")
283 (files '("include")))
284 (search-path-specification
285 (variable "LIBRARY_PATH")
286 (files '("lib" "lib64")))))
287
288 (home-page "https://clang.llvm.org")
289 (synopsis "C language family frontend for LLVM")
290 (description
291 "Clang is a compiler front end for the C, C++, Objective-C and
292 Objective-C++ programming languages. It uses LLVM as its back end. The Clang
293 project includes the Clang front end, the Clang static analyzer, and several
294 code analysis tools.")
295 (license license:ncsa)))
296
297 (define-public clang-runtime
298 (clang-runtime-from-llvm
299 llvm
300 "1fcr3jn24yr8lh36nc0c4ikli4744i2q9m1ik67p1jymwwaixkgl"))
301
302 (define-public clang
303 (clang-from-llvm llvm clang-runtime
304 "0rxn4rh7rrnsqbdgp4gzc8ishbkryhpl1kd3mpnxzpxxhla3y93w"
305 #:patches '("clang-6.0-libc-search-path.patch")))
306
307 (define-public llvm-3.9.1
308 (package (inherit llvm)
309 (name "llvm")
310 (version "3.9.1")
311 (source
312 (origin
313 (method url-fetch)
314 (uri (string-append "http://llvm.org/releases/"
315 version "/llvm-" version ".src.tar.xz"))
316 (sha256
317 (base32
318 "1vi9sf7rx1q04wj479rsvxayb6z740iaz3qniwp266fgp5a07n8z"))))))
319
320 (define-public clang-runtime-3.9.1
321 (clang-runtime-from-llvm
322 llvm-3.9.1
323 "16gc2gdmp5c800qvydrdhsp0bzb97s8wrakl6i8a4lgslnqnf2fk"
324 '("clang-runtime-asan-build-fixes.patch"
325 "clang-runtime-esan-build-fixes.patch"
326 "clang-3.5-libsanitizer-ustat-fix.patch")))
327
328 (define-public clang-3.9.1
329 (clang-from-llvm llvm-3.9.1 clang-runtime-3.9.1
330 "0qsyyb40iwifhhlx9a3drf8z6ni6zwyk3bvh0kx2gs6yjsxwxi76"
331 #:patches '("clang-3.8-libc-search-path.patch")))
332
333 (define-public llvm-3.8
334 (package (inherit llvm)
335 (name "llvm")
336 (version "3.8.1")
337 (source
338 (origin
339 (method url-fetch)
340 (uri (string-append "https://llvm.org/releases/"
341 version "/llvm-" version ".src.tar.xz"))
342 (sha256
343 (base32
344 "1ybmnid4pw2hxn12ax5qa5kl1ldfns0njg8533y3mzslvd5cx0kf"))))))
345
346 (define-public clang-runtime-3.8
347 (clang-runtime-from-llvm
348 llvm-3.8
349 "0p0y85c7izndbpg2l816z7z7558axq11d5pwkm4h11sdw7d13w0d"
350 '("clang-runtime-asan-build-fixes.patch"
351 "clang-3.5-libsanitizer-ustat-fix.patch")))
352
353 (define-public clang-3.8
354 (clang-from-llvm llvm-3.8 clang-runtime-3.8
355 "1prc72xmkgx8wrzmrr337776676nhsp1qd3mw2bvb22bzdnq7lsc"
356 #:patches '("clang-3.8-libc-search-path.patch")))
357
358 (define-public llvm-3.7
359 (package (inherit llvm)
360 (version "3.7.1")
361 (source
362 (origin
363 (method url-fetch)
364 (uri (string-append "http://llvm.org/releases/"
365 version "/llvm-" version ".src.tar.xz"))
366 (sha256
367 (base32
368 "1masakdp9g2dan1yrazg7md5am2vacbkb3nahb3dchpc1knr8xxy"))))))
369
370 (define-public clang-runtime-3.7
371 (clang-runtime-from-llvm
372 llvm-3.7
373 "10c1mz2q4bdq9bqfgr3dirc6hz1h3sq8573srd5q5lr7m7j6jiwx"
374 '("clang-runtime-asan-build-fixes.patch"
375 "clang-3.5-libsanitizer-ustat-fix.patch")))
376
377 (define-public clang-3.7
378 (clang-from-llvm llvm-3.7 clang-runtime-3.7
379 "0x065d0w9b51xvdjxwfzjxng0gzpbx45fgiaxpap45ragi61dqjn"
380 #:patches '("clang-3.5-libc-search-path.patch")))
381
382 (define-public llvm-3.6
383 (package (inherit llvm)
384 (version "3.6.2")
385 (source
386 (origin
387 (method url-fetch)
388 (uri (string-append "http://llvm.org/releases/"
389 version "/llvm-" version ".src.tar.xz"))
390 (sha256
391 (base32
392 "153vcvj8gvgwakzr4j0kndc0b7wn91c2g1vy2vg24s6spxcc23gn"))))))
393
394 (define-public clang-runtime-3.6
395 (clang-runtime-from-llvm
396 llvm-3.6
397 "11qx8d3pbfqjaj2x207pvlvzihbs1z2xbw4crpz7aid6h1yz6bqg"
398 '("clang-runtime-asan-build-fixes.patch")))
399
400 (define-public clang-3.6
401 (clang-from-llvm llvm-3.6 clang-runtime-3.6
402 "1wwr8s6lzr324hv4s1k6na4j5zv6n9kdhi14s4kb9b13d93814df"
403 #:patches '("clang-3.5-libc-search-path.patch")))
404
405 (define-public llvm-3.5
406 (package (inherit llvm)
407 (version "3.5.2")
408 (source
409 (origin
410 (method url-fetch)
411 (uri (string-append "http://llvm.org/releases/"
412 version "/llvm-" version ".src.tar.xz"))
413 (patches
414 (search-patches "llvm-3.5-fix-clang-build-with-gcc5.patch"))
415 (sha256
416 (base32
417 "0xf5q17kkxsrm2gsi93h4pwlv663kji73r2g4asb97klsmb626a4"))))))
418
419 (define-public clang-runtime-3.5
420 (clang-runtime-from-llvm
421 llvm-3.5
422 "1hsdnzzdr5kglz6fnv3lcsjs222zjsy14y8ax9dy6zqysanplbal"
423 '("clang-runtime-asan-build-fixes.patch"
424 "clang-3.5-libsanitizer-ustat-fix.patch")))
425
426 (define-public clang-3.5
427 (clang-from-llvm llvm-3.5 clang-runtime-3.5
428 "0846h8vn3zlc00jkmvrmy88gc6ql6014c02l4jv78fpvfigmgssg"
429 #:patches '("clang-3.5-libc-search-path.patch")))
430
431 (define-public llvm-for-extempore
432 (package (inherit llvm-3.7)
433 (name "llvm-for-extempore")
434 (source
435 (origin
436 (inherit (package-source llvm-3.7))
437 (patches (list (search-patch "llvm-for-extempore.patch")))))
438 ;; Extempore refuses to build on architectures other than x86_64
439 (supported-systems '("x86_64-linux"))))
440
441 (define-public python-llvmlite
442 (package
443 (name "python-llvmlite")
444 (version "0.24.0")
445 (source
446 (origin
447 (method url-fetch)
448 (uri (pypi-uri "llvmlite" version))
449 (sha256
450 (base32
451 "01zwjlc3c5mhrwmv4b73zgbskwqps9ly0nrh54bbj1f1l72f839j"))))
452 (build-system python-build-system)
453 (inputs
454 `(("llvm"
455 ,(package
456 (inherit llvm)
457 (source (origin
458 (inherit (package-source llvm))
459 (patches
460 (list
461 (origin
462 (method url-fetch)
463 (uri (string-append "https://raw.githubusercontent.com/numba/"
464 "llvmlite/v" version "/conda-recipes/"
465 "D47188-svml.patch"))
466 (sha256
467 (base32
468 "0mrj24jvkv3hjcmyg98zmvmyl1znlh2j63rdr69f6g7s96d2pfv1")))
469 (origin
470 (method url-fetch)
471 (uri (string-append "https://raw.githubusercontent.com/numba/"
472 "llvmlite/v" version "/conda-recipes/"
473 "twine_cfg_undefined_behavior.patch"))
474 (sha256
475 (base32
476 "07h71n2m1mn9zcfgw04zglffknplb233zqbcd6pckq0wygkrxflp")))))))))))
477 (home-page "http://llvmlite.pydata.org")
478 (synopsis "Wrapper around basic LLVM functionality")
479 (description
480 "This package provides a Python binding to LLVM for use in Numba.")
481 (license license:bsd-3)))
482
483 (define (package-elisp-from-package source-package package-name
484 source-files)
485 "Return a package definition named PACKAGE-NAME that packages the Emacs Lisp
486 SOURCE-FILES found in SOURCE-PACKAGE."
487 (let ((orig (package-source source-package)))
488 (package
489 (inherit source-package)
490 (name package-name)
491 (build-system emacs-build-system)
492 (source (origin
493 (method (origin-method orig))
494 (uri (origin-uri orig))
495 (sha256 (origin-sha256 orig))
496 (file-name (string-append package-name "-"
497 (package-version source-package)))
498 (modules '((guix build utils)
499 (srfi srfi-1)
500 (ice-9 ftw)))
501 (snippet
502 `(let* ((source-files (quote ,source-files))
503 (basenames (map basename source-files)))
504 (map copy-file
505 source-files basenames)
506 (map delete-file-recursively
507 (fold delete
508 (scandir ".")
509 (append '("." "..") basenames)))
510 #t)))))))
511
512 (define-public emacs-clang-format
513 (package
514 (inherit clang)
515 (name "emacs-clang-format")
516 (build-system emacs-build-system)
517 (inputs
518 `(("clang" ,clang)))
519 (arguments
520 `(#:phases
521 (modify-phases %standard-phases
522 (add-after 'unpack 'configure
523 (lambda* (#:key inputs #:allow-other-keys)
524 (let ((clang (assoc-ref inputs "clang")))
525 (copy-file "tools/clang-format/clang-format.el" "clang-format.el")
526 (emacs-substitute-variables "clang-format.el"
527 ("clang-format-executable"
528 (string-append clang "/bin/clang-format"))))
529 #t)))))
530 (synopsis "Format code using clang-format")
531 (description "This package allows to filter code through @code{clang-format}
532 to fix its formatting. @code{clang-format} is a tool that formats
533 C/C++/Obj-C code according to a set of style options, see
534 @url{http://clang.llvm.org/docs/ClangFormatStyleOptions.html}.")))
535
536 (define-public emacs-clang-rename
537 (package
538 (inherit clang)
539 (name "emacs-clang-rename")
540 (build-system emacs-build-system)
541 (inputs
542 `(("clang" ,clang)))
543 (arguments
544 `(#:phases
545 (modify-phases %standard-phases
546 (add-after 'unpack 'configure
547 (lambda* (#:key inputs #:allow-other-keys)
548 (let ((clang (assoc-ref inputs "clang")))
549 (copy-file "tools/clang-rename/clang-rename.el" "clang-rename.el")
550 (emacs-substitute-variables "clang-rename.el"
551 ("clang-rename-binary"
552 (string-append clang "/bin/clang-rename"))))
553 #t)))))
554 (synopsis "Rename every occurrence of a symbol using clang-rename")
555 (description "This package renames every occurrence of a symbol at point
556 using @code{clang-rename}.")))