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 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
89 (package
90 (name "llvm")
91 (version "9.0.1")
92 (source
93 (origin
94 (method url-fetch)
95 (uri (llvm-download-uri "llvm" version))
96 (sha256
97 (base32
98 "16hwp3qa54c3a3v7h8nlw0fh5criqh0hlr1skybyk0cz70gyx880"))))
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
409 (clang-runtime-from-llvm
410 llvm
411 "0xwh79g3zggdabxgnd0bphry75asm1qz7mv3hcqihqwqr6aspgy2"
412 '("clang-runtime-9-libsanitizer-mode-field.patch")))
413
414 (define-public clang
415 (clang-from-llvm llvm clang-runtime
416 "0ls2h3iv4finqyflyhry21qhc9cm9ga7g1zq21020p065qmm2y2p"
417 #:patches '("clang-9.0-libc-search-path.patch")))
418
419 (define-public clang-toolchain
420 (make-clang-toolchain clang))
421
422 (define-public llvm-9 llvm)
423 (define-public clang-runtime-9 clang-runtime)
424 (define-public clang-9 clang)
425 (define-public clang-toolchain-9 clang-toolchain)
426
427 (define-public llvm-8
428 (package
429 (inherit llvm)
430 (version "8.0.0")
431 (source (origin
432 (method url-fetch)
433 (uri (llvm-download-uri "llvm" version))
434 (sha256
435 (base32
436 "0k124sxkfhfi1rca6kzkdraf4axhx99x3cw2rk55056628dvwwl8"))))
437 (license license:ncsa)))
438
439 (define-public clang-runtime-8
440 (clang-runtime-from-llvm
441 llvm-8
442 "1c919wsm17xnv7lr8bhpq2wkq8113lzlw6hzhfr737j59x3wfddl"
443 '("clang-runtime-9-libsanitizer-mode-field.patch")))
444
445 (define-public clang-8
446 (clang-from-llvm llvm-8 clang-runtime-8
447 "0svk1f70hvpwrjp6x5i9kqwrqwxnmcrw5s7f4cxyd100mdd12k08"
448 #:patches '("clang-7.0-libc-search-path.patch")))
449
450 (define-public clang-toolchain-8
451 (make-clang-toolchain clang-8))
452
453 (define-public llvm-7
454 (package
455 (inherit llvm-8)
456 (version "7.0.1")
457 (source (origin
458 (method url-fetch)
459 (uri (llvm-download-uri "llvm" version))
460 (sha256
461 (base32
462 "16s196wqzdw4pmri15hadzqgdi926zln3an2viwyq0kini6zr3d3"))))))
463
464 (define-public clang-runtime-7
465 (clang-runtime-from-llvm
466 llvm-7
467 "065ybd8fsc4h2hikbdyricj6pyv4r7r7kpcikhb2y5zf370xybkq"
468 '("clang-runtime-9-libsanitizer-mode-field.patch")))
469
470 (define-public clang-7
471 (clang-from-llvm llvm-7 clang-runtime-7
472 "067lwggnbg0w1dfrps790r5l6k8n5zwhlsw7zb6zvmfpwpfn4nx4"
473 #:patches '("clang-7.0-libc-search-path.patch")))
474
475 (define-public clang-toolchain-7
476 (make-clang-toolchain clang-7))
477
478 (define-public llvm-6
479 (package
480 (inherit llvm-7)
481 (version "6.0.1")
482 (source (origin
483 (method url-fetch)
484 (uri (llvm-download-uri "llvm" version))
485 (sha256
486 (base32
487 "1qpls3vk85lydi5b4axl0809fv932qgsqgdgrk098567z4jc7mmn"))))))
488
489 (define-public clang-runtime-6
490 (clang-runtime-from-llvm
491 llvm-6
492 "1fcr3jn24yr8lh36nc0c4ikli4744i2q9m1ik67p1jymwwaixkgl"
493 '("clang-runtime-9-libsanitizer-mode-field.patch")))
494
495 (define-public clang-6
496 (clang-from-llvm llvm-6 clang-runtime-6
497 "0rxn4rh7rrnsqbdgp4gzc8ishbkryhpl1kd3mpnxzpxxhla3y93w"
498 #:patches '("clang-6.0-libc-search-path.patch")))
499
500 (define-public clang-toolchain-6
501 (make-clang-toolchain clang-6))
502
503 (define-public llvm-3.9.1
504 (package (inherit llvm-6)
505 (name "llvm")
506 (version "3.9.1")
507 (source
508 (origin
509 (method url-fetch)
510 (uri (llvm-download-uri "llvm" version))
511 (sha256
512 (base32
513 "1vi9sf7rx1q04wj479rsvxayb6z740iaz3qniwp266fgp5a07n8z"))))
514 (outputs '("out"))
515 (arguments
516 (substitute-keyword-arguments (package-arguments llvm)
517 ((#:phases phases)
518 `(modify-phases ,phases
519 (delete 'install-opt-viewer)))))))
520
521 (define-public clang-runtime-3.9.1
522 (clang-runtime-from-llvm
523 llvm-3.9.1
524 "16gc2gdmp5c800qvydrdhsp0bzb97s8wrakl6i8a4lgslnqnf2fk"
525 '("clang-runtime-3.9-libsanitizer-mode-field.patch"
526 "clang-runtime-asan-build-fixes.patch"
527 "clang-runtime-esan-build-fixes.patch"
528 "clang-3.5-libsanitizer-ustat-fix.patch")))
529
530 (define-public clang-3.9.1
531 (clang-from-llvm llvm-3.9.1 clang-runtime-3.9.1
532 "0qsyyb40iwifhhlx9a3drf8z6ni6zwyk3bvh0kx2gs6yjsxwxi76"
533 #:patches '("clang-3.8-libc-search-path.patch")))
534
535 (define-public llvm-3.8
536 (package (inherit llvm-3.9.1)
537 (name "llvm")
538 (version "3.8.1")
539 (source
540 (origin
541 (method url-fetch)
542 (uri (llvm-download-uri "llvm" version))
543 (sha256
544 (base32
545 "1ybmnid4pw2hxn12ax5qa5kl1ldfns0njg8533y3mzslvd5cx0kf"))))))
546
547 (define-public clang-runtime-3.8
548 (clang-runtime-from-llvm
549 llvm-3.8
550 "0p0y85c7izndbpg2l816z7z7558axq11d5pwkm4h11sdw7d13w0d"
551 '("clang-runtime-asan-build-fixes.patch"
552 "clang-runtime-3.8-libsanitizer-mode-field.patch"
553 "clang-3.5-libsanitizer-ustat-fix.patch")))
554
555 (define-public clang-3.8
556 (clang-from-llvm llvm-3.8 clang-runtime-3.8
557 "1prc72xmkgx8wrzmrr337776676nhsp1qd3mw2bvb22bzdnq7lsc"
558 #:patches '("clang-3.8-libc-search-path.patch")))
559
560 (define-public llvm-3.7
561 (package (inherit llvm-3.8)
562 (version "3.7.1")
563 (source
564 (origin
565 (method url-fetch)
566 (uri (llvm-download-uri "llvm" version))
567 (sha256
568 (base32
569 "1masakdp9g2dan1yrazg7md5am2vacbkb3nahb3dchpc1knr8xxy"))))))
570
571 (define-public clang-runtime-3.7
572 (clang-runtime-from-llvm
573 llvm-3.7
574 "10c1mz2q4bdq9bqfgr3dirc6hz1h3sq8573srd5q5lr7m7j6jiwx"
575 '("clang-runtime-asan-build-fixes.patch"
576 "clang-runtime-3.8-libsanitizer-mode-field.patch"
577 "clang-3.5-libsanitizer-ustat-fix.patch")))
578
579 (define-public clang-3.7
580 (clang-from-llvm llvm-3.7 clang-runtime-3.7
581 "0x065d0w9b51xvdjxwfzjxng0gzpbx45fgiaxpap45ragi61dqjn"
582 #:patches '("clang-3.5-libc-search-path.patch")))
583
584 (define-public llvm-3.6
585 (package (inherit llvm-3.7)
586 (version "3.6.2")
587 (source
588 (origin
589 (method url-fetch)
590 (uri (llvm-download-uri "llvm" version))
591 (sha256
592 (base32
593 "153vcvj8gvgwakzr4j0kndc0b7wn91c2g1vy2vg24s6spxcc23gn"))))))
594
595 (define-public clang-runtime-3.6
596 (clang-runtime-from-llvm
597 llvm-3.6
598 "11qx8d3pbfqjaj2x207pvlvzihbs1z2xbw4crpz7aid6h1yz6bqg"
599 '("clang-runtime-asan-build-fixes.patch")))
600
601 (define-public clang-3.6
602 (clang-from-llvm llvm-3.6 clang-runtime-3.6
603 "1wwr8s6lzr324hv4s1k6na4j5zv6n9kdhi14s4kb9b13d93814df"
604 #:patches '("clang-3.5-libc-search-path.patch")))
605
606 (define-public llvm-3.5
607 (package (inherit llvm-3.6)
608 (version "3.5.2")
609 (source
610 (origin
611 (method url-fetch)
612 (uri (llvm-download-uri "llvm" version))
613 (patches
614 (search-patches "llvm-3.5-fix-clang-build-with-gcc5.patch"))
615 (sha256
616 (base32
617 "0xf5q17kkxsrm2gsi93h4pwlv663kji73r2g4asb97klsmb626a4"))))))
618
619 (define-public clang-runtime-3.5
620 (let ((runtime (clang-runtime-from-llvm
621 llvm-3.5
622 "1hsdnzzdr5kglz6fnv3lcsjs222zjsy14y8ax9dy6zqysanplbal"
623 '("clang-runtime-asan-build-fixes.patch"
624 "clang-3.5-libsanitizer-ustat-fix.patch"))))
625 (package
626 (inherit runtime)
627 (arguments
628 (substitute-keyword-arguments (package-arguments runtime)
629 ((#:phases phases '%standard-phases)
630 `(modify-phases ,phases
631 ;; glibc no longer includes rpc/xdr.h, so we use the headers from
632 ;; libtirpc.
633 (add-after 'unpack 'find-rpc-includes
634 (lambda* (#:key inputs #:allow-other-keys)
635 (setenv "CPATH"
636 (string-append (assoc-ref inputs "libtirpc")
637 "/include/tirpc/:"
638 (or (getenv "CPATH") "")))
639 (setenv "CPLUS_INCLUDE_PATH"
640 (string-append (assoc-ref inputs "libtirpc")
641 "/include/tirpc/:"
642 (or (getenv "CPLUS_INCLUDE_PATH") "")))
643 #t))))))
644 (inputs
645 `(("libtirpc" ,libtirpc)
646 ("llvm" ,llvm-3.5))))))
647
648 (define-public clang-3.5
649 (clang-from-llvm llvm-3.5 clang-runtime-3.5
650 "0846h8vn3zlc00jkmvrmy88gc6ql6014c02l4jv78fpvfigmgssg"
651 #:patches '("clang-3.5-libc-search-path.patch")))
652
653 (define-public llvm-for-extempore
654 (package (inherit llvm-3.7)
655 (name "llvm-for-extempore")
656 (source
657 (origin
658 (inherit (package-source llvm-3.7))
659 (patches (list (search-patch "llvm-for-extempore.patch")))))
660 ;; Extempore refuses to build on architectures other than x86_64
661 (supported-systems '("x86_64-linux"))))
662
663 (define-public libcxx
664 (package
665 (name "libcxx")
666 (version "9.0.1")
667 (source
668 (origin
669 (method url-fetch)
670 (uri (llvm-download-uri "libcxx" version))
671 (sha256
672 (base32
673 "0d2bj5i6mk4caq7skd5nsdmz8c2m5w5anximl5wz3x32p08zz089"))))
674 (build-system cmake-build-system)
675 (arguments
676 `(#:phases
677 (modify-phases (@ (guix build cmake-build-system) %standard-phases)
678 (add-after 'set-paths 'adjust-CPLUS_INCLUDE_PATH
679 (lambda* (#:key inputs #:allow-other-keys)
680 (let ((gcc (assoc-ref inputs "gcc")))
681 ;; Hide GCC's C++ headers so that they do not interfere with
682 ;; the ones we are attempting to build.
683 (setenv "CPLUS_INCLUDE_PATH"
684 (string-join (delete (string-append gcc "/include/c++")
685 (string-split (getenv "CPLUS_INCLUDE_PATH")
686 #\:))
687 ":"))
688 (format #t
689 "environment variable `CPLUS_INCLUDE_PATH' changed to ~a~%"
690 (getenv "CPLUS_INCLUDE_PATH"))
691 #t))))))
692 (native-inputs
693 `(("clang" ,clang)
694 ("llvm" ,llvm)))
695 (home-page "https://libcxx.llvm.org")
696 (synopsis "C++ standard library")
697 (description
698 "This package provides an implementation of the C++ standard library for
699 use with Clang, targeting C++11, C++14 and above.")
700 (license license:expat)))
701
702 ;; Libcxx files specifically used by PySide2.
703 (define-public libcxx-6
704 (package
705 (inherit libcxx)
706 (version (package-version llvm-6))
707 (source
708 (origin
709 (inherit (package-source libcxx))
710 (uri (llvm-download-uri "libcxx" version))
711 (sha256
712 (base32
713 "0rzw4qvxp6qx4l4h9amrq02gp7hbg8lw4m0sy3k60f50234gnm3n"))))
714 (native-inputs
715 `(("clang" ,clang-6)
716 ("llvm" ,llvm-6)))))
717
718 (define-public libclc
719 (package
720 (name "libclc")
721 (version "9.0.1")
722 (source
723 (origin
724 (method git-fetch)
725 (uri (git-reference
726 (url "https://github.com/llvm/llvm-project.git")
727 (commit (string-append "llvmorg-" version))))
728 (file-name (git-file-name name version))
729 (sha256
730 (base32
731 "1d1qayvrvvc1di7s7jfxnjvxq2az4lwq1sw1b2gq2ic0nksvajz0"))))
732 (build-system cmake-build-system)
733 (arguments
734 `(#:configure-flags
735 (list (string-append "-DLLVM_CLANG="
736 (assoc-ref %build-inputs "clang")
737 "/bin/clang")
738 (string-append "-DPYTHON="
739 (assoc-ref %build-inputs "python")
740 "/bin/python3"))
741 #:phases
742 (modify-phases %standard-phases
743 (add-after 'unpack 'chdir
744 (lambda _ (chdir "libclc") #t)))))
745 (native-inputs
746 `(("clang" ,clang)
747 ("llvm" ,llvm)
748 ("python" ,python)))
749 (home-page "https://libclc.llvm.org")
750 (synopsis "Libraries for the OpenCL programming language")
751 (description
752 "This package provides an implementation of the OpenCL library
753 requirements according to version 1.1 of the OpenCL specification.")
754 ;; Apache license 2.0 with LLVM exception
755 (license license:asl2.0)))
756
757 (define-public libomp
758 (package
759 (name "libomp")
760 (version "9.0.1")
761 (source (origin
762 (method url-fetch)
763 (uri (llvm-download-uri "openmp" version))
764 (sha256
765 (base32
766 "1knafnpp0f7hylx8q20lkd6g1sf0flly572dayc5d5kghh7hd52w"))
767 (file-name (string-append "libomp-" version ".tar.xz"))))
768 (build-system cmake-build-system)
769 ;; XXX: Note this gets built with GCC because building with Clang itself
770 ;; fails (missing <atomic>, even when libcxx is added as an input.)
771 (arguments
772 '(#:configure-flags '("-DLIBOMP_USE_HWLOC=ON"
773 "-DOPENMP_TEST_C_COMPILER=clang"
774 "-DOPENMP_TEST_CXX_COMPILER=clang++")
775 #:test-target "check-libomp"))
776 (native-inputs
777 `(("clang" ,clang)
778 ("llvm" ,llvm)
779 ("perl" ,perl)
780 ("pkg-config" ,pkg-config)))
781 (inputs
782 `(("hwloc" ,hwloc "lib")))
783 (home-page "https://openmp.llvm.org")
784 (synopsis "OpenMP run-time support library")
785 (description
786 "This package provides the run-time support library developed by the LLVM
787 project for the OpenMP multi-theaded programming extension. This package
788 notably provides @file{libgomp.so}, which is has a binary interface compatible
789 with that of libgomp, the GNU Offloading and Multi Processing Library.")
790 (license license:expat)))
791
792 (define-public python-llvmlite
793 (package
794 (name "python-llvmlite")
795 (version "0.30.0")
796 (source
797 (origin
798 (method url-fetch)
799 (uri (pypi-uri "llvmlite" version))
800 (sha256
801 (base32
802 "01wspdc0xhnydl66jyhyr4ii16h3fnw6mjihiwnnxdxg9j6kkajf"))))
803 (build-system python-build-system)
804 (arguments
805 ;; FIXME: One test fails unable to find libm.so
806 ;; https://github.com/numba/llvmlite/issues/537
807 `(#:tests? #f))
808 (inputs
809 `(("llvm"
810 ,(package
811 (inherit llvm-7)
812 (source (origin
813 (inherit (package-source llvm-7))
814 (patches
815 (list
816 (origin
817 (method url-fetch)
818 (uri (string-append "https://raw.githubusercontent.com/numba/"
819 "llvmlite/v" version "/conda-recipes/"
820 "D47188-svml-VF.patch"))
821 (sha256
822 (base32
823 "0wxhgb61k17f0zg2m0726sf3hppm41f8jar2kkg2n8sl5cnjj9mr")))
824 (origin
825 (method url-fetch)
826 (uri (string-append "https://raw.githubusercontent.com/numba/"
827 "llvmlite/v" version "/conda-recipes/"
828 "twine_cfg_undefined_behavior.patch"))
829 (sha256
830 (base32
831 "07h71n2m1mn9zcfgw04zglffknplb233zqbcd6pckq0wygkrxflp")))))))))))
832 (home-page "http://llvmlite.pydata.org")
833 (synopsis "Wrapper around basic LLVM functionality")
834 (description
835 "This package provides a Python binding to LLVM for use in Numba.")
836 (license license:bsd-3)))
837
838 (define (package-elisp-from-package source-package package-name
839 source-files)
840 "Return a package definition named PACKAGE-NAME that packages the Emacs Lisp
841 SOURCE-FILES found in SOURCE-PACKAGE."
842 (let ((orig (package-source source-package)))
843 (package
844 (inherit source-package)
845 (name package-name)
846 (build-system emacs-build-system)
847 (source (origin
848 (method (origin-method orig))
849 (uri (origin-uri orig))
850 (sha256 (origin-sha256 orig))
851 (file-name (string-append package-name "-"
852 (package-version source-package)))
853 (modules '((guix build utils)
854 (srfi srfi-1)
855 (ice-9 ftw)))
856 (snippet
857 `(let* ((source-files (quote ,source-files))
858 (basenames (map basename source-files)))
859 (map copy-file
860 source-files basenames)
861 (map delete-file-recursively
862 (fold delete
863 (scandir ".")
864 (append '("." "..") basenames)))
865 #t)))))))
866
867 (define-public emacs-clang-format
868 (package
869 (inherit clang)
870 (name "emacs-clang-format")
871 (build-system emacs-build-system)
872 (inputs
873 `(("clang" ,clang)))
874 (arguments
875 `(#:phases
876 (modify-phases %standard-phases
877 (add-after 'unpack 'configure
878 (lambda* (#:key inputs #:allow-other-keys)
879 (let ((clang (assoc-ref inputs "clang")))
880 (copy-file "tools/clang-format/clang-format.el" "clang-format.el")
881 (emacs-substitute-variables "clang-format.el"
882 ("clang-format-executable"
883 (string-append clang "/bin/clang-format"))))
884 #t)))))
885 (synopsis "Format code using clang-format")
886 (description "This package filters code through @code{clang-format}
887 to fix its formatting. @code{clang-format} is a tool that formats
888 C/C++/Obj-C code according to a set of style options, see
889 @url{https://clang.llvm.org/docs/ClangFormatStyleOptions.html}.")))
890
891 (define-public emacs-clang-rename
892 (package
893 (inherit clang)
894 (name "emacs-clang-rename")
895 (build-system emacs-build-system)
896 (inputs
897 `(("clang" ,clang)))
898 (arguments
899 `(#:phases
900 (modify-phases %standard-phases
901 (add-after 'unpack 'configure
902 (lambda* (#:key inputs #:allow-other-keys)
903 (let ((clang (assoc-ref inputs "clang")))
904 (copy-file "tools/clang-rename/clang-rename.el" "clang-rename.el")
905 (emacs-substitute-variables "clang-rename.el"
906 ("clang-rename-binary"
907 (string-append clang "/bin/clang-rename"))))
908 #t)))))
909 (synopsis "Rename every occurrence of a symbol using clang-rename")
910 (description "This package renames every occurrence of a symbol at point
911 using @code{clang-rename}.")))