Merge branch 'master' into core-updates
[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, 2020 Ludovic Courtès <ludo@gnu.org>
5 ;;; Copyright © 2016 Dennis Mungai <dmngaie@gmail.com>
6 ;;; Copyright © 2016, 2018, 2019, 2020 Ricardo Wurmus <rekado@elephly.net>
7 ;;; Copyright © 2017 Roel Janssen <roel@gnu.org>
8 ;;; Copyright © 2018, 2019, 2020 Marius Bakke <mbakke@fastmail.com>
9 ;;; Copyright © 2018, 2019 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 ;;; Copyright © 2019 Rutger Helling <rhelling@mykolab.com>
14 ;;; Copyright © 2019 Arm Ltd <David.Truby@arm.com>
15 ;;; Copyright © 2019 Mathieu Othacehe <m.othacehe@gmail.com>
16 ;;; Copyright © 2019 Brett Gilio <brettg@gnu.org>
17 ;;;
18 ;;; This file is part of GNU Guix.
19 ;;;
20 ;;; GNU Guix is free software; you can redistribute it and/or modify it
21 ;;; under the terms of the GNU General Public License as published by
22 ;;; the Free Software Foundation; either version 3 of the License, or (at
23 ;;; your option) any later version.
24 ;;;
25 ;;; GNU Guix is distributed in the hope that it will be useful, but
26 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
27 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28 ;;; GNU General Public License for more details.
29 ;;;
30 ;;; You should have received a copy of the GNU General Public License
31 ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
32
33 (define-module (gnu packages llvm)
34 #:use-module (guix packages)
35 #:use-module ((guix licenses) #:prefix license:)
36 #:use-module (guix download)
37 #:use-module (guix git-download)
38 #:use-module (guix utils)
39 #:use-module (guix build-system gnu)
40 #:use-module (guix build-system cmake)
41 #:use-module (guix build-system emacs)
42 #:use-module (guix build-system python)
43 #:use-module (guix build-system trivial)
44 #:use-module (gnu packages)
45 #:use-module (gnu packages base)
46 #:use-module (gnu packages gcc)
47 #:use-module (gnu packages bootstrap) ;glibc-dynamic-linker
48 #:use-module (gnu packages compression)
49 #:use-module (gnu packages libffi)
50 #:use-module (gnu packages mpi)
51 #:use-module (gnu packages onc-rpc)
52 #:use-module (gnu packages perl)
53 #:use-module (gnu packages pkg-config)
54 #:use-module (gnu packages python)
55 #:use-module (gnu packages xml)
56 #:export (system->llvm-target))
57
58 (define* (system->llvm-target #:optional
59 (system (or (and=> (%current-target-system)
60 gnu-triplet->nix-system)
61 (%current-system))))
62 "Return the LLVM target name that corresponds to SYSTEM, a system type such
63 as \"x86_64-linux\"."
64 ;; See the 'lib/Target' directory of LLVM for a list of supported targets.
65 (letrec-syntax ((matches (syntax-rules (=>)
66 ((_ (system-prefix => target) rest ...)
67 (if (string-prefix? system-prefix system)
68 target
69 (matches rest ...)))
70 ((_)
71 (error "LLVM target for system is unknown" system)))))
72 (matches ("aarch64" => "AArch64")
73 ("armhf" => "ARM")
74 ("mips64el" => "Mips")
75 ("powerpc" => "PowerPC")
76 ("riscv" => "RISCV")
77 ("x86_64" => "X86")
78 ("i686" => "X86")
79 ("i586" => "X86"))))
80
81 (define (llvm-download-uri component version)
82 (if (version>=? version "9.0.1")
83 (string-append "https://github.com/llvm/llvm-project/releases/download"
84 "/llvmorg-" version "/" component "-" version ".src.tar.xz")
85 (string-append "https://releases.llvm.org/" version "/" component "-"
86 version ".src.tar.xz")))
87
88 (define-public llvm-10
89 (package
90 (name "llvm")
91 (version "10.0.0")
92 (source
93 (origin
94 (method url-fetch)
95 (uri (llvm-download-uri "llvm" version))
96 (sha256
97 (base32
98 "1pwgm6cr0xr5a0hrbqs1zvsvvjvy0yq1y47c96804wcs795s90yz"))))
99 (build-system cmake-build-system)
100 (outputs '("out" "opt-viewer"))
101 (native-inputs
102 `(("python" ,python-2) ;bytes->str conversion in clang>=3.7 needs python-2
103 ("perl" ,perl)))
104 (inputs
105 `(("libffi" ,libffi)))
106 (propagated-inputs
107 `(("zlib" ,zlib))) ;to use output from llvm-config
108 (arguments
109 `(#:configure-flags '("-DCMAKE_SKIP_BUILD_RPATH=FALSE"
110 "-DCMAKE_BUILD_WITH_INSTALL_RPATH=FALSE"
111 "-DBUILD_SHARED_LIBS:BOOL=TRUE"
112 "-DLLVM_ENABLE_FFI:BOOL=TRUE"
113 "-DLLVM_REQUIRES_RTTI=1" ; For some third-party utilities
114 "-DLLVM_INSTALL_UTILS=ON") ; Needed for rustc.
115
116 ;; Don't use '-g' during the build, to save space.
117 #:build-type "Release"
118 #:phases
119 (modify-phases %standard-phases
120 (add-before 'build 'shared-lib-workaround
121 ;; Even with CMAKE_SKIP_BUILD_RPATH=FALSE, llvm-tblgen
122 ;; doesn't seem to get the correct rpath to be able to run
123 ;; from the build directory. Set LD_LIBRARY_PATH as a
124 ;; workaround.
125 (lambda _
126 (setenv "LD_LIBRARY_PATH"
127 (string-append (getcwd) "/lib"))
128 #t))
129 (add-after 'install 'install-opt-viewer
130 (lambda* (#:key outputs #:allow-other-keys)
131 (let* ((out (assoc-ref outputs "out"))
132 (opt-viewer-out (assoc-ref outputs "opt-viewer"))
133 (opt-viewer-share-dir (string-append opt-viewer-out "/share"))
134 (opt-viewer-dir (string-append opt-viewer-share-dir "/opt-viewer")))
135 (mkdir-p opt-viewer-share-dir)
136 (rename-file (string-append out "/share/opt-viewer")
137 opt-viewer-dir))
138 #t)))))
139 (home-page "https://www.llvm.org")
140 (synopsis "Optimizing compiler infrastructure")
141 (description
142 "LLVM is a compiler infrastructure designed for compile-time, link-time,
143 runtime, and idle-time optimization of programs from arbitrary programming
144 languages. It currently supports compilation of C and C++ programs, using
145 front-ends derived from GCC 4.0.1. A new front-end for the C family of
146 languages is in development. The compiler infrastructure includes mirror sets
147 of programming tools as well as libraries with equivalent functionality.")
148 (license license:asl2.0))) ;with LLVM exceptions, see LICENSE.txt
149
150 (define* (clang-runtime-from-llvm llvm hash
151 #:optional (patches '()))
152 (package
153 (name "clang-runtime")
154 (version (package-version llvm))
155 (source
156 (origin
157 (method url-fetch)
158 (uri (llvm-download-uri "compiler-rt" version))
159 (sha256 (base32 hash))
160 (patches (map search-patch patches))))
161 (build-system cmake-build-system)
162 (native-inputs (package-native-inputs llvm))
163 (inputs
164 `(("llvm" ,llvm)))
165 (arguments
166 `(;; Don't use '-g' during the build to save space.
167 #:build-type "Release"
168 #:tests? #f ; Tests require gtest
169 #:modules ((srfi srfi-1)
170 (ice-9 match)
171 ,@%cmake-build-system-modules)
172 #:phases (modify-phases (@ (guix build cmake-build-system) %standard-phases)
173 (add-after 'set-paths 'hide-glibc
174 ;; Work around https://issues.guix.info/issue/36882. We need to
175 ;; remove glibc from CPLUS_INCLUDE_PATH so that the one hardcoded
176 ;; in GCC, at the bottom of GCC include search-path is used.
177 (lambda* (#:key inputs #:allow-other-keys)
178 (let* ((filters '("libc"))
179 (input-directories
180 (filter-map (lambda (input)
181 (match input
182 ((name . dir)
183 (and (not (member name filters))
184 dir))))
185 inputs)))
186 (set-path-environment-variable "CPLUS_INCLUDE_PATH"
187 '("include")
188 input-directories)
189 #t))))))
190 (home-page "https://compiler-rt.llvm.org")
191 (synopsis "Runtime library for Clang/LLVM")
192 (description
193 "The \"clang-runtime\" library provides the implementations of run-time
194 functions for C and C++ programs. It also provides header files that allow C
195 and C++ source code to interface with the \"sanitization\" passes of the clang
196 compiler. In LLVM this library is called \"compiler-rt\".")
197 (license (package-license llvm))
198
199 ;; <https://compiler-rt.llvm.org/> doesn't list MIPS as supported.
200 (supported-systems (delete "mips64el-linux" %supported-systems))))
201
202 (define* (clang-from-llvm llvm clang-runtime hash
203 #:key (patches '()))
204 (package
205 (name "clang")
206 (version (package-version llvm))
207 (source
208 (origin
209 (method url-fetch)
210 (uri (llvm-download-uri (if (version>=? version "9.0.1")
211 "clang"
212 "cfe")
213 version))
214 (sha256 (base32 hash))
215 (patches (map search-patch patches))))
216 ;; Using cmake allows us to treat llvm as an external library. There
217 ;; doesn't seem to be any way to do this with clang's autotools-based
218 ;; build system.
219 (build-system cmake-build-system)
220 (native-inputs (package-native-inputs llvm))
221 (inputs
222 `(("libxml2" ,libxml2)
223 ("gcc-lib" ,gcc "lib")
224 ,@(package-inputs llvm)))
225 (propagated-inputs
226 `(("llvm" ,llvm)
227 ("clang-runtime" ,clang-runtime)))
228 (arguments
229 `(#:configure-flags
230 (list "-DCLANG_INCLUDE_TESTS=True"
231
232 ;; Find libgcc_s, crtbegin.o, and crtend.o.
233 (string-append "-DGCC_INSTALL_PREFIX="
234 (assoc-ref %build-inputs "gcc-lib"))
235
236 ;; Use a sane default include directory.
237 (string-append "-DC_INCLUDE_DIRS="
238 (assoc-ref %build-inputs "libc")
239 "/include"))
240
241 ;; Don't use '-g' during the build to save space.
242 #:build-type "Release"
243
244 #:phases (modify-phases %standard-phases
245 (add-after 'unpack 'add-missing-triplets
246 (lambda _
247 ;; Clang iterates through known triplets to search for
248 ;; GCC's headers, but does not recognize some of the
249 ;; triplets that are used in Guix.
250 (substitute* ,@(if (version>=? version "6.0")
251 '("lib/Driver/ToolChains/Gnu.cpp")
252 '("lib/Driver/ToolChains.cpp"))
253 (("\"aarch64-linux-gnu\"," all)
254 (string-append "\"aarch64-unknown-linux-gnu\", "
255 all))
256 (("\"arm-linux-gnueabihf\"," all)
257 (string-append all
258 " \"arm-unknown-linux-gnueabihf\","))
259 (("\"i686-pc-linux-gnu\"," all)
260 (string-append "\"i686-unknown-linux-gnu\", "
261 all)))
262 #t))
263 (add-after 'unpack 'set-glibc-file-names
264 (lambda* (#:key inputs #:allow-other-keys)
265 (let ((libc (assoc-ref inputs "libc"))
266 (compiler-rt (assoc-ref inputs "clang-runtime"))
267 (gcc (assoc-ref inputs "gcc")))
268 ,@(cond
269 ((version>=? version "6.0")
270 `(;; Link to libclang_rt files from clang-runtime.
271 (substitute* "lib/Driver/ToolChain.cpp"
272 (("getDriver\\(\\)\\.ResourceDir")
273 (string-append "\"" compiler-rt "\"")))
274
275 ;; Make "LibDir" refer to <glibc>/lib so that it
276 ;; uses the right dynamic linker file name.
277 (substitute* "lib/Driver/ToolChains/Linux.cpp"
278 (("(^[[:blank:]]+LibDir = ).*" _ declaration)
279 (string-append declaration "\"" libc "/lib\";\n"))
280
281 ;; Make clang look for libstdc++ in the right
282 ;; location.
283 (("LibStdCXXIncludePathCandidates\\[\\] = \\{")
284 (string-append
285 "LibStdCXXIncludePathCandidates[] = { \"" gcc
286 "/include/c++\","))
287
288 ;; Make sure libc's libdir is on the search path, to
289 ;; allow crt1.o & co. to be found.
290 (("@GLIBC_LIBDIR@")
291 (string-append libc "/lib")))))
292 (else
293 `((substitute* "lib/Driver/Tools.cpp"
294 ;; Patch the 'getLinuxDynamicLinker' function so that
295 ;; it uses the right dynamic linker file name.
296 (("/lib64/ld-linux-x86-64.so.2")
297 (string-append libc
298 ,(glibc-dynamic-linker))))
299
300 ;; Link to libclang_rt files from clang-runtime.
301 ;; This substitution needed slight adjustment in 3.8.
302 ,@(if (version>=? version "3.8")
303 '((substitute* "lib/Driver/Tools.cpp"
304 (("TC\\.getDriver\\(\\)\\.ResourceDir")
305 (string-append "\"" compiler-rt "\""))))
306 '((substitute* "lib/Driver/ToolChain.cpp"
307 (("getDriver\\(\\)\\.ResourceDir")
308 (string-append "\"" compiler-rt "\"")))))
309
310 ;; Make sure libc's libdir is on the search path, to
311 ;; allow crt1.o & co. to be found.
312 (substitute* "lib/Driver/ToolChains.cpp"
313 (("@GLIBC_LIBDIR@")
314 (string-append libc "/lib"))))))
315 #t)))
316 (add-after 'install 'install-clean-up-/share/clang
317 (lambda* (#:key outputs #:allow-other-keys)
318 (let* ((out (assoc-ref outputs "out"))
319 (compl-dir (string-append
320 out "/etc/bash_completion.d")))
321 (with-directory-excursion (string-append out
322 "/share/clang")
323 (for-each
324 (lambda (file)
325 (when (file-exists? file)
326 (delete-file file)))
327 ;; Delete extensions for proprietary text editors.
328 '("clang-format-bbedit.applescript"
329 "clang-format-sublime.py"
330 ;; Delete Emacs extensions: see their respective Emacs
331 ;; Guix package instead.
332 "clang-rename.el" "clang-format.el"))
333 ;; Install bash completion.
334 (when (file-exists? "bash-autocomplete.sh")
335 (mkdir-p compl-dir)
336 (rename-file "bash-autocomplete.sh"
337 (string-append compl-dir "/clang")))))
338 #t)))))
339
340 ;; Clang supports the same environment variables as GCC.
341 (native-search-paths
342 (list (search-path-specification
343 (variable "C_INCLUDE_PATH")
344 (files '("include")))
345 (search-path-specification
346 (variable "CPLUS_INCLUDE_PATH")
347 (files '("include/c++" "include")))
348 (search-path-specification
349 (variable "LIBRARY_PATH")
350 (files '("lib" "lib64")))))
351
352 (home-page "https://clang.llvm.org")
353 (synopsis "C language family frontend for LLVM")
354 (description
355 "Clang is a compiler front end for the C, C++, Objective-C and
356 Objective-C++ programming languages. It uses LLVM as its back end. The Clang
357 project includes the Clang front end, the Clang static analyzer, and several
358 code analysis tools.")
359 (license (if (version>=? version "9.0")
360 license:asl2.0 ;with LLVM exceptions
361 license:ncsa))))
362
363 (define (make-clang-toolchain clang)
364 (package
365 (name (string-append (package-name clang) "-toolchain"))
366 (version (package-version clang))
367 (source #f)
368 (build-system trivial-build-system)
369 (arguments
370 '(#:modules ((guix build union))
371 #:builder (begin
372 (use-modules (ice-9 match)
373 (srfi srfi-26)
374 (guix build union))
375
376 (let ((out (assoc-ref %outputs "out")))
377
378 (match %build-inputs
379 (((names . directories) ...)
380 (union-build out directories)))
381
382 (union-build (assoc-ref %outputs "debug")
383 (list (assoc-ref %build-inputs
384 "libc-debug")))
385 (union-build (assoc-ref %outputs "static")
386 (list (assoc-ref %build-inputs
387 "libc-static")))
388 #t))))
389
390 (native-search-paths (package-native-search-paths clang))
391 (search-paths (package-search-paths clang))
392
393 (license (package-license clang))
394 (home-page "https://clang.llvm.org")
395 (synopsis "Complete Clang toolchain for C/C++ development")
396 (description "This package provides a complete Clang toolchain for C/C++
397 development to be installed in user profiles. This includes Clang, as well as
398 libc (headers and binaries, plus debugging symbols in the @code{debug}
399 output), and Binutils.")
400 (outputs '("out" "debug" "static"))
401 (inputs `(("clang" ,clang)
402 ("ld-wrapper" ,(car (assoc-ref (%final-inputs) "ld-wrapper")))
403 ("binutils" ,binutils)
404 ("libc" ,glibc)
405 ("libc-debug" ,glibc "debug")
406 ("libc-static" ,glibc "static")))))
407
408 (define-public clang-runtime-10
409 (clang-runtime-from-llvm
410 llvm-10
411 "0x9c531k6ww21s2mkdwqx1vbdjmx6d4wmfb8gdbj0wqa796sczba"))
412
413 (define-public clang-10
414 (clang-from-llvm llvm-10 clang-runtime-10
415 "08fbxa2a0kr3ni35ckppj0kyvlcyaywrhpqwcdrdy0z900mhcnw8"
416 #:patches '("clang-10.0-libc-search-path.patch")))
417
418 (define-public clang-toolchain-10
419 (make-clang-toolchain clang-10))
420
421 (define-public llvm-9
422 (package
423 (inherit llvm-10)
424 (version "9.0.1")
425 (source
426 (origin
427 (method url-fetch)
428 (uri (llvm-download-uri "llvm" version))
429 (sha256
430 (base32
431 "16hwp3qa54c3a3v7h8nlw0fh5criqh0hlr1skybyk0cz70gyx880"))))))
432
433 (define-public clang-runtime-9
434 (clang-runtime-from-llvm
435 llvm-9
436 "0xwh79g3zggdabxgnd0bphry75asm1qz7mv3hcqihqwqr6aspgy2"
437 '("clang-runtime-9-libsanitizer-mode-field.patch")))
438
439 (define-public clang-9
440 (clang-from-llvm llvm-9 clang-runtime-9
441 "0ls2h3iv4finqyflyhry21qhc9cm9ga7g1zq21020p065qmm2y2p"
442 #:patches '("clang-9.0-libc-search-path.patch")))
443
444 (define-public clang-toolchain-9
445 (make-clang-toolchain clang-9))
446
447 ;; Default LLVM and Clang version.
448 (define-public llvm llvm-9)
449 (define-public clang-runtime clang-runtime-9)
450 (define-public clang clang-9)
451 (define-public clang-toolchain clang-toolchain-9)
452
453 (define-public llvm-8
454 (package
455 (inherit llvm)
456 (version "8.0.0")
457 (source (origin
458 (method url-fetch)
459 (uri (llvm-download-uri "llvm" version))
460 (sha256
461 (base32
462 "0k124sxkfhfi1rca6kzkdraf4axhx99x3cw2rk55056628dvwwl8"))))
463 (license license:ncsa)))
464
465 (define-public clang-runtime-8
466 (clang-runtime-from-llvm
467 llvm-8
468 "1c919wsm17xnv7lr8bhpq2wkq8113lzlw6hzhfr737j59x3wfddl"
469 '("clang-runtime-9-libsanitizer-mode-field.patch")))
470
471 (define-public clang-8
472 (clang-from-llvm llvm-8 clang-runtime-8
473 "0svk1f70hvpwrjp6x5i9kqwrqwxnmcrw5s7f4cxyd100mdd12k08"
474 #:patches '("clang-7.0-libc-search-path.patch")))
475
476 (define-public clang-toolchain-8
477 (make-clang-toolchain clang-8))
478
479 (define-public llvm-7
480 (package
481 (inherit llvm-8)
482 (version "7.0.1")
483 (source (origin
484 (method url-fetch)
485 (uri (llvm-download-uri "llvm" version))
486 (sha256
487 (base32
488 "16s196wqzdw4pmri15hadzqgdi926zln3an2viwyq0kini6zr3d3"))))))
489
490 (define-public clang-runtime-7
491 (clang-runtime-from-llvm
492 llvm-7
493 "065ybd8fsc4h2hikbdyricj6pyv4r7r7kpcikhb2y5zf370xybkq"
494 '("clang-runtime-9-libsanitizer-mode-field.patch")))
495
496 (define-public clang-7
497 (clang-from-llvm llvm-7 clang-runtime-7
498 "067lwggnbg0w1dfrps790r5l6k8n5zwhlsw7zb6zvmfpwpfn4nx4"
499 #:patches '("clang-7.0-libc-search-path.patch")))
500
501 (define-public clang-toolchain-7
502 (make-clang-toolchain clang-7))
503
504 (define-public llvm-6
505 (package
506 (inherit llvm-7)
507 (version "6.0.1")
508 (source (origin
509 (method url-fetch)
510 (uri (llvm-download-uri "llvm" version))
511 (sha256
512 (base32
513 "1qpls3vk85lydi5b4axl0809fv932qgsqgdgrk098567z4jc7mmn"))))))
514
515 (define-public clang-runtime-6
516 (clang-runtime-from-llvm
517 llvm-6
518 "1fcr3jn24yr8lh36nc0c4ikli4744i2q9m1ik67p1jymwwaixkgl"
519 '("clang-runtime-9-libsanitizer-mode-field.patch")))
520
521 (define-public clang-6
522 (clang-from-llvm llvm-6 clang-runtime-6
523 "0rxn4rh7rrnsqbdgp4gzc8ishbkryhpl1kd3mpnxzpxxhla3y93w"
524 #:patches '("clang-6.0-libc-search-path.patch")))
525
526 (define-public clang-toolchain-6
527 (make-clang-toolchain clang-6))
528
529 (define-public llvm-3.9.1
530 (package (inherit llvm-6)
531 (name "llvm")
532 (version "3.9.1")
533 (source
534 (origin
535 (method url-fetch)
536 (uri (llvm-download-uri "llvm" version))
537 (sha256
538 (base32
539 "1vi9sf7rx1q04wj479rsvxayb6z740iaz3qniwp266fgp5a07n8z"))))
540 (outputs '("out"))
541 (arguments
542 (substitute-keyword-arguments (package-arguments llvm)
543 ((#:phases phases)
544 `(modify-phases ,phases
545 (delete 'install-opt-viewer)))))))
546
547 (define-public clang-runtime-3.9.1
548 (clang-runtime-from-llvm
549 llvm-3.9.1
550 "16gc2gdmp5c800qvydrdhsp0bzb97s8wrakl6i8a4lgslnqnf2fk"
551 '("clang-runtime-3.9-libsanitizer-mode-field.patch"
552 "clang-runtime-asan-build-fixes.patch"
553 "clang-runtime-esan-build-fixes.patch"
554 "clang-3.5-libsanitizer-ustat-fix.patch")))
555
556 (define-public clang-3.9.1
557 (clang-from-llvm llvm-3.9.1 clang-runtime-3.9.1
558 "0qsyyb40iwifhhlx9a3drf8z6ni6zwyk3bvh0kx2gs6yjsxwxi76"
559 #:patches '("clang-3.8-libc-search-path.patch")))
560
561 (define-public llvm-3.8
562 (package (inherit llvm-3.9.1)
563 (name "llvm")
564 (version "3.8.1")
565 (source
566 (origin
567 (method url-fetch)
568 (uri (llvm-download-uri "llvm" version))
569 (sha256
570 (base32
571 "1ybmnid4pw2hxn12ax5qa5kl1ldfns0njg8533y3mzslvd5cx0kf"))))))
572
573 (define-public clang-runtime-3.8
574 (clang-runtime-from-llvm
575 llvm-3.8
576 "0p0y85c7izndbpg2l816z7z7558axq11d5pwkm4h11sdw7d13w0d"
577 '("clang-runtime-asan-build-fixes.patch"
578 "clang-runtime-3.8-libsanitizer-mode-field.patch"
579 "clang-3.5-libsanitizer-ustat-fix.patch")))
580
581 (define-public clang-3.8
582 (clang-from-llvm llvm-3.8 clang-runtime-3.8
583 "1prc72xmkgx8wrzmrr337776676nhsp1qd3mw2bvb22bzdnq7lsc"
584 #:patches '("clang-3.8-libc-search-path.patch")))
585
586 (define-public llvm-3.7
587 (package (inherit llvm-3.8)
588 (version "3.7.1")
589 (source
590 (origin
591 (method url-fetch)
592 (uri (llvm-download-uri "llvm" version))
593 (sha256
594 (base32
595 "1masakdp9g2dan1yrazg7md5am2vacbkb3nahb3dchpc1knr8xxy"))))))
596
597 (define-public clang-runtime-3.7
598 (clang-runtime-from-llvm
599 llvm-3.7
600 "10c1mz2q4bdq9bqfgr3dirc6hz1h3sq8573srd5q5lr7m7j6jiwx"
601 '("clang-runtime-asan-build-fixes.patch"
602 "clang-runtime-3.8-libsanitizer-mode-field.patch"
603 "clang-3.5-libsanitizer-ustat-fix.patch")))
604
605 (define-public clang-3.7
606 (clang-from-llvm llvm-3.7 clang-runtime-3.7
607 "0x065d0w9b51xvdjxwfzjxng0gzpbx45fgiaxpap45ragi61dqjn"
608 #:patches '("clang-3.5-libc-search-path.patch")))
609
610 (define-public llvm-3.6
611 (package (inherit llvm-3.7)
612 (version "3.6.2")
613 (source
614 (origin
615 (method url-fetch)
616 (uri (llvm-download-uri "llvm" version))
617 (sha256
618 (base32
619 "153vcvj8gvgwakzr4j0kndc0b7wn91c2g1vy2vg24s6spxcc23gn"))))))
620
621 (define-public clang-runtime-3.6
622 (clang-runtime-from-llvm
623 llvm-3.6
624 "11qx8d3pbfqjaj2x207pvlvzihbs1z2xbw4crpz7aid6h1yz6bqg"
625 '("clang-runtime-asan-build-fixes.patch")))
626
627 (define-public clang-3.6
628 (clang-from-llvm llvm-3.6 clang-runtime-3.6
629 "1wwr8s6lzr324hv4s1k6na4j5zv6n9kdhi14s4kb9b13d93814df"
630 #:patches '("clang-3.5-libc-search-path.patch")))
631
632 (define-public llvm-3.5
633 (package (inherit llvm-3.6)
634 (version "3.5.2")
635 (source
636 (origin
637 (method url-fetch)
638 (uri (llvm-download-uri "llvm" version))
639 (patches
640 (search-patches "llvm-3.5-fix-clang-build-with-gcc5.patch"))
641 (sha256
642 (base32
643 "0xf5q17kkxsrm2gsi93h4pwlv663kji73r2g4asb97klsmb626a4"))))))
644
645 (define-public clang-runtime-3.5
646 (let ((runtime (clang-runtime-from-llvm
647 llvm-3.5
648 "1hsdnzzdr5kglz6fnv3lcsjs222zjsy14y8ax9dy6zqysanplbal"
649 '("clang-runtime-asan-build-fixes.patch"
650 "clang-3.5-libsanitizer-ustat-fix.patch"))))
651 (package
652 (inherit runtime)
653 (arguments
654 (substitute-keyword-arguments (package-arguments runtime)
655 ((#:phases phases '%standard-phases)
656 `(modify-phases ,phases
657 ;; glibc no longer includes rpc/xdr.h, so we use the headers from
658 ;; libtirpc.
659 (add-after 'unpack 'find-rpc-includes
660 (lambda* (#:key inputs #:allow-other-keys)
661 (setenv "CPATH"
662 (string-append (assoc-ref inputs "libtirpc")
663 "/include/tirpc/:"
664 (or (getenv "CPATH") "")))
665 (setenv "CPLUS_INCLUDE_PATH"
666 (string-append (assoc-ref inputs "libtirpc")
667 "/include/tirpc/:"
668 (or (getenv "CPLUS_INCLUDE_PATH") "")))
669 #t))))))
670 (inputs
671 `(("libtirpc" ,libtirpc)
672 ("llvm" ,llvm-3.5))))))
673
674 (define-public clang-3.5
675 (clang-from-llvm llvm-3.5 clang-runtime-3.5
676 "0846h8vn3zlc00jkmvrmy88gc6ql6014c02l4jv78fpvfigmgssg"
677 #:patches '("clang-3.5-libc-search-path.patch")))
678
679 (define-public llvm-for-extempore
680 (package (inherit llvm-3.7)
681 (name "llvm-for-extempore")
682 (source
683 (origin
684 (inherit (package-source llvm-3.7))
685 (patches (list (search-patch "llvm-for-extempore.patch")))))
686 ;; Extempore refuses to build on architectures other than x86_64
687 (supported-systems '("x86_64-linux"))))
688
689 (define-public libcxx
690 (package
691 (name "libcxx")
692 (version "9.0.1")
693 (source
694 (origin
695 (method url-fetch)
696 (uri (llvm-download-uri "libcxx" version))
697 (sha256
698 (base32
699 "0d2bj5i6mk4caq7skd5nsdmz8c2m5w5anximl5wz3x32p08zz089"))))
700 (build-system cmake-build-system)
701 (arguments
702 `(#:phases
703 (modify-phases (@ (guix build cmake-build-system) %standard-phases)
704 (add-after 'set-paths 'adjust-CPLUS_INCLUDE_PATH
705 (lambda* (#:key inputs #:allow-other-keys)
706 (let ((gcc (assoc-ref inputs "gcc")))
707 ;; Hide GCC's C++ headers so that they do not interfere with
708 ;; the ones we are attempting to build.
709 (setenv "CPLUS_INCLUDE_PATH"
710 (string-join (delete (string-append gcc "/include/c++")
711 (string-split (getenv "CPLUS_INCLUDE_PATH")
712 #\:))
713 ":"))
714 (format #t
715 "environment variable `CPLUS_INCLUDE_PATH' changed to ~a~%"
716 (getenv "CPLUS_INCLUDE_PATH"))
717 #t))))))
718 (native-inputs
719 `(("clang" ,clang)
720 ("llvm" ,llvm)))
721 (home-page "https://libcxx.llvm.org")
722 (synopsis "C++ standard library")
723 (description
724 "This package provides an implementation of the C++ standard library for
725 use with Clang, targeting C++11, C++14 and above.")
726 (license license:expat)))
727
728 ;; Libcxx files specifically used by PySide2.
729 (define-public libcxx-6
730 (package
731 (inherit libcxx)
732 (version (package-version llvm-6))
733 (source
734 (origin
735 (inherit (package-source libcxx))
736 (uri (llvm-download-uri "libcxx" version))
737 (sha256
738 (base32
739 "0rzw4qvxp6qx4l4h9amrq02gp7hbg8lw4m0sy3k60f50234gnm3n"))))
740 (native-inputs
741 `(("clang" ,clang-6)
742 ("llvm" ,llvm-6)))))
743
744 (define-public libclc
745 (package
746 (name "libclc")
747 (version "9.0.1")
748 (source
749 (origin
750 (method git-fetch)
751 (uri (git-reference
752 (url "https://github.com/llvm/llvm-project.git")
753 (commit (string-append "llvmorg-" version))))
754 (file-name (git-file-name name version))
755 (sha256
756 (base32
757 "1d1qayvrvvc1di7s7jfxnjvxq2az4lwq1sw1b2gq2ic0nksvajz0"))))
758 (build-system cmake-build-system)
759 (arguments
760 `(#:configure-flags
761 (list (string-append "-DLLVM_CLANG="
762 (assoc-ref %build-inputs "clang")
763 "/bin/clang")
764 (string-append "-DPYTHON="
765 (assoc-ref %build-inputs "python")
766 "/bin/python3"))
767 #:phases
768 (modify-phases %standard-phases
769 (add-after 'unpack 'chdir
770 (lambda _ (chdir "libclc") #t)))))
771 (native-inputs
772 `(("clang" ,clang)
773 ("llvm" ,llvm)
774 ("python" ,python)))
775 (home-page "https://libclc.llvm.org")
776 (synopsis "Libraries for the OpenCL programming language")
777 (description
778 "This package provides an implementation of the OpenCL library
779 requirements according to version 1.1 of the OpenCL specification.")
780 ;; Apache license 2.0 with LLVM exception
781 (license license:asl2.0)))
782
783 (define-public libomp
784 (package
785 (name "libomp")
786 (version "9.0.1")
787 (source (origin
788 (method url-fetch)
789 (uri (llvm-download-uri "openmp" version))
790 (sha256
791 (base32
792 "1knafnpp0f7hylx8q20lkd6g1sf0flly572dayc5d5kghh7hd52w"))
793 (file-name (string-append "libomp-" version ".tar.xz"))))
794 (build-system cmake-build-system)
795 ;; XXX: Note this gets built with GCC because building with Clang itself
796 ;; fails (missing <atomic>, even when libcxx is added as an input.)
797 (arguments
798 '(#:configure-flags '("-DLIBOMP_USE_HWLOC=ON"
799 "-DOPENMP_TEST_C_COMPILER=clang"
800 "-DOPENMP_TEST_CXX_COMPILER=clang++")
801 #:test-target "check-libomp"))
802 (native-inputs
803 `(("clang" ,clang)
804 ("llvm" ,llvm)
805 ("perl" ,perl)
806 ("pkg-config" ,pkg-config)))
807 (inputs
808 `(("hwloc" ,hwloc "lib")))
809 (home-page "https://openmp.llvm.org")
810 (synopsis "OpenMP run-time support library")
811 (description
812 "This package provides the run-time support library developed by the LLVM
813 project for the OpenMP multi-theaded programming extension. This package
814 notably provides @file{libgomp.so}, which is has a binary interface compatible
815 with that of libgomp, the GNU Offloading and Multi Processing Library.")
816 (license license:expat)))
817
818 (define-public python-llvmlite
819 (package
820 (name "python-llvmlite")
821 (version "0.30.0")
822 (source
823 (origin
824 (method url-fetch)
825 (uri (pypi-uri "llvmlite" version))
826 (sha256
827 (base32
828 "01wspdc0xhnydl66jyhyr4ii16h3fnw6mjihiwnnxdxg9j6kkajf"))))
829 (build-system python-build-system)
830 (arguments
831 ;; FIXME: One test fails unable to find libm.so
832 ;; https://github.com/numba/llvmlite/issues/537
833 `(#:tests? #f))
834 (inputs
835 `(("llvm"
836 ,(package
837 (inherit llvm-7)
838 (source (origin
839 (inherit (package-source llvm-7))
840 (patches
841 (list
842 (origin
843 (method url-fetch)
844 (uri (string-append "https://raw.githubusercontent.com/numba/"
845 "llvmlite/v" version "/conda-recipes/"
846 "D47188-svml-VF.patch"))
847 (sha256
848 (base32
849 "0wxhgb61k17f0zg2m0726sf3hppm41f8jar2kkg2n8sl5cnjj9mr")))
850 (origin
851 (method url-fetch)
852 (uri (string-append "https://raw.githubusercontent.com/numba/"
853 "llvmlite/v" version "/conda-recipes/"
854 "twine_cfg_undefined_behavior.patch"))
855 (sha256
856 (base32
857 "07h71n2m1mn9zcfgw04zglffknplb233zqbcd6pckq0wygkrxflp")))))))))))
858 (home-page "http://llvmlite.pydata.org")
859 (synopsis "Wrapper around basic LLVM functionality")
860 (description
861 "This package provides a Python binding to LLVM for use in Numba.")
862 (license license:bsd-3)))
863
864 (define (package-elisp-from-package source-package package-name
865 source-files)
866 "Return a package definition named PACKAGE-NAME that packages the Emacs Lisp
867 SOURCE-FILES found in SOURCE-PACKAGE."
868 (let ((orig (package-source source-package)))
869 (package
870 (inherit source-package)
871 (name package-name)
872 (build-system emacs-build-system)
873 (source (origin
874 (method (origin-method orig))
875 (uri (origin-uri orig))
876 (sha256 (origin-sha256 orig))
877 (file-name (string-append package-name "-"
878 (package-version source-package)))
879 (modules '((guix build utils)
880 (srfi srfi-1)
881 (ice-9 ftw)))
882 (snippet
883 `(let* ((source-files (quote ,source-files))
884 (basenames (map basename source-files)))
885 (map copy-file
886 source-files basenames)
887 (map delete-file-recursively
888 (fold delete
889 (scandir ".")
890 (append '("." "..") basenames)))
891 #t)))))))
892
893 (define-public emacs-clang-format
894 (package
895 (inherit clang)
896 (name "emacs-clang-format")
897 (build-system emacs-build-system)
898 (inputs
899 `(("clang" ,clang)))
900 (arguments
901 `(#:phases
902 (modify-phases %standard-phases
903 (add-after 'unpack 'configure
904 (lambda* (#:key inputs #:allow-other-keys)
905 (let ((clang (assoc-ref inputs "clang")))
906 (copy-file "tools/clang-format/clang-format.el" "clang-format.el")
907 (emacs-substitute-variables "clang-format.el"
908 ("clang-format-executable"
909 (string-append clang "/bin/clang-format"))))
910 #t)))))
911 (synopsis "Format code using clang-format")
912 (description "This package filters code through @code{clang-format}
913 to fix its formatting. @code{clang-format} is a tool that formats
914 C/C++/Obj-C code according to a set of style options, see
915 @url{https://clang.llvm.org/docs/ClangFormatStyleOptions.html}.")))
916
917 (define-public emacs-clang-rename
918 (package
919 (inherit clang)
920 (name "emacs-clang-rename")
921 (build-system emacs-build-system)
922 (inputs
923 `(("clang" ,clang)))
924 (arguments
925 `(#:phases
926 (modify-phases %standard-phases
927 (add-after 'unpack 'configure
928 (lambda* (#:key inputs #:allow-other-keys)
929 (let ((clang (assoc-ref inputs "clang")))
930 (copy-file "tools/clang-rename/clang-rename.el" "clang-rename.el")
931 (emacs-substitute-variables "clang-rename.el"
932 ("clang-rename-binary"
933 (string-append clang "/bin/clang-rename"))))
934 #t)))))
935 (synopsis "Rename every occurrence of a symbol using clang-rename")
936 (description "This package renames every occurrence of a symbol at point
937 using @code{clang-rename}.")))