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