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, 2021 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 ;;; Copyright © 2020 Giacomo Leidi <goodoldpaul@autistici.org>
18 ;;; Copyright © 2020 Jakub Kądziołka <kuba@kadziolka.net>
19 ;;; Copyright © 2020 Maxim Cournoyer <maxim.cournoyer@gmail.com>
20 ;;; Copyright © 2021 Julien Lepiller <julien@lepiller.eu>
22 ;;; This file is part of GNU Guix.
24 ;;; GNU Guix is free software; you can redistribute it and/or modify it
25 ;;; under the terms of the GNU General Public License as published by
26 ;;; the Free Software Foundation; either version 3 of the License, or (at
27 ;;; your option) any later version.
29 ;;; GNU Guix is distributed in the hope that it will be useful, but
30 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
31 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
32 ;;; GNU General Public License for more details.
34 ;;; You should have received a copy of the GNU General Public License
35 ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
37 (define-module (gnu packages llvm)
38 #:use-module (guix packages)
39 #:use-module ((guix licenses) #:prefix license:)
40 #:use-module (guix download)
41 #:use-module (guix git-download)
42 #:use-module (guix memoization)
43 #:use-module (guix utils)
44 #:use-module (guix build-system gnu)
45 #:use-module (guix build-system cmake)
46 #:use-module (guix build-system emacs)
47 #:use-module (guix build-system python)
48 #:use-module (guix build-system trivial)
49 #:use-module (gnu packages)
50 #:use-module (gnu packages base)
51 #:use-module (gnu packages gcc)
52 #:use-module (gnu packages bootstrap) ;glibc-dynamic-linker
53 #:use-module (gnu packages compression)
54 #:use-module (gnu packages libedit)
55 #:use-module (gnu packages libffi)
56 #:use-module (gnu packages lua)
57 #:use-module (gnu packages mpi)
58 #:use-module (gnu packages ncurses)
59 #:use-module (gnu packages ocaml)
60 #:use-module (gnu packages onc-rpc)
61 #:use-module (gnu packages perl)
62 #:use-module (gnu packages pkg-config)
63 #:use-module (gnu packages python)
64 #:use-module (gnu packages swig)
65 #:use-module (gnu packages xml)
66 #:export (system->llvm-target))
68 (define* (system->llvm-target #:optional
69 (system (or (and=> (%current-target-system)
70 gnu-triplet->nix-system)
72 "Return the LLVM target name that corresponds to SYSTEM, a system type such
74 ;; See the 'lib/Target' directory of LLVM for a list of supported targets.
75 (letrec-syntax ((matches (syntax-rules (=>)
76 ((_ (system-prefix => target) rest ...)
77 (if (string-prefix? system-prefix system)
81 (error "LLVM target for system is unknown" system)))))
82 (matches ("aarch64" => "AArch64")
84 ("mips64el" => "Mips")
85 ("powerpc" => "PowerPC")
91 (define (llvm-uri component version)
92 (string-append "https://github.com/llvm/llvm-project/releases/download"
93 "/llvmorg-" version "/" component "-" version ".src.tar.xz"))
95 (define* (clang-runtime-from-llvm llvm hash
96 #:optional (patches '()))
98 (name "clang-runtime")
99 (version (package-version llvm))
103 (uri (llvm-uri "compiler-rt" version))
104 (sha256 (base32 hash))
105 (patches (map search-patch patches))))
106 (build-system cmake-build-system)
107 (native-inputs (package-native-inputs llvm))
111 `(;; Don't use '-g' during the build to save space.
112 #:build-type "Release"
113 #:tests? #f ; Tests require gtest
114 #:modules ((srfi srfi-1)
116 ,@%cmake-build-system-modules)
117 #:phases (modify-phases (@ (guix build cmake-build-system) %standard-phases)
118 (add-after 'set-paths 'hide-glibc
119 ;; Work around https://issues.guix.info/issue/36882. We need to
120 ;; remove glibc from CPLUS_INCLUDE_PATH so that the one hardcoded
121 ;; in GCC, at the bottom of GCC include search-path is used.
122 (lambda* (#:key inputs #:allow-other-keys)
123 (let* ((filters '("libc"))
125 (filter-map (lambda (input)
128 (and (not (member name filters))
131 (set-path-environment-variable "CPLUS_INCLUDE_PATH"
135 (home-page "https://compiler-rt.llvm.org")
136 (synopsis "Runtime library for Clang/LLVM")
138 "The \"clang-runtime\" library provides the implementations of run-time
139 functions for C and C++ programs. It also provides header files that allow C
140 and C++ source code to interface with the \"sanitization\" passes of the clang
141 compiler. In LLVM this library is called \"compiler-rt\".")
142 (license (package-license llvm))
144 ;; <https://compiler-rt.llvm.org/> doesn't list MIPS as supported.
145 (supported-systems (delete "mips64el-linux" %supported-systems))))
147 (define* (clang-from-llvm llvm clang-runtime hash
148 #:key (patches '()) tools-extra)
149 "Produce Clang with dependencies on LLVM and CLANG-RUNTIME, and applying the
150 given PATCHES. When TOOLS-EXTRA is given, it must point to the
151 'clang-tools-extra' tarball, which contains code for 'clang-tidy', 'pp-trace',
152 'modularize', and other tools."
155 (version (package-version llvm))
159 (uri (llvm-uri (if (version>=? version "9.0.1")
163 (sha256 (base32 hash))
164 (patches (map search-patch patches))))
165 ;; Using cmake allows us to treat llvm as an external library. There
166 ;; doesn't seem to be any way to do this with clang's autotools-based
168 (build-system cmake-build-system)
169 (outputs (if tools-extra '("out" "extra") '("out")))
170 (native-inputs (package-native-inputs llvm))
172 `(("libxml2" ,libxml2)
173 ("gcc-lib" ,gcc "lib")
174 ,@(package-inputs llvm)
176 `(("clang-tools-extra" ,tools-extra))
180 ("clang-runtime" ,clang-runtime)))
183 (list "-DCLANG_INCLUDE_TESTS=True"
185 ;; Find libgcc_s, crtbegin.o, and crtend.o.
186 (string-append "-DGCC_INSTALL_PREFIX="
187 (assoc-ref %build-inputs "gcc-lib"))
189 ;; Use a sane default include directory.
190 (string-append "-DC_INCLUDE_DIRS="
191 (assoc-ref %build-inputs "libc")
194 ;; Don't use '-g' during the build to save space.
195 #:build-type "Release"
197 #:phases (modify-phases %standard-phases
199 `((add-after 'unpack 'add-tools-extra
200 (lambda* (#:key inputs #:allow-other-keys)
201 ;; Unpack the 'clang-tools-extra' tarball under
203 (let ((extra (assoc-ref inputs
204 "clang-tools-extra")))
205 (invoke "tar" "xf" extra)
206 (rename-file ,(string-append
208 (package-version llvm)
212 (add-after 'install 'move-extra-tools
213 (lambda* (#:key outputs #:allow-other-keys)
214 ;; Move the extra tools to the "extra" output.
215 ;; These programs alone weigh in at 296 MiB,
216 ;; because they statically-link a whole bunch of
218 (let* ((out (assoc-ref outputs "out"))
219 (extra (assoc-ref outputs "extra"))
220 (bin (string-append out "/bin"))
221 (bin* (string-append extra "/bin"))
222 (lib (string-append out "/lib")))
223 (define (move program)
224 (rename-file (string-append bin "/" program)
225 (string-append bin* "/"
230 '("clang-apply-replacements"
231 "clang-change-namespace"
234 "clang-include-fixer"
237 "clang-reorder-fields"
243 ;; Remove MiBs of .a files coming from
244 ;; 'clang-tools-extra'.
245 (for-each (lambda (component)
247 (string-append lib "/libclang"
249 '("ApplyReplacements"
257 (for-each delete-file
260 "^(libfindAllSymbols|libclangTidy)"))
263 (add-after 'unpack 'add-missing-triplets
265 ;; Clang iterates through known triplets to search for
266 ;; GCC's headers, but does not recognize some of the
267 ;; triplets that are used in Guix.
268 (substitute* ,@(if (version>=? version "6.0")
269 '("lib/Driver/ToolChains/Gnu.cpp")
270 '("lib/Driver/ToolChains.cpp"))
271 (("\"aarch64-linux-gnu\"," all)
272 (string-append "\"aarch64-unknown-linux-gnu\", "
274 (("\"arm-linux-gnueabihf\"," all)
276 " \"arm-unknown-linux-gnueabihf\","))
277 (("\"i686-pc-linux-gnu\"," all)
278 (string-append "\"i686-unknown-linux-gnu\", "
281 (add-after 'unpack 'set-glibc-file-names
282 (lambda* (#:key inputs #:allow-other-keys)
283 (let ((libc (assoc-ref inputs "libc"))
284 (compiler-rt (assoc-ref inputs "clang-runtime"))
285 (gcc (assoc-ref inputs "gcc")))
287 ((version>=? version "6.0")
288 `(;; Link to libclang_rt files from clang-runtime.
289 (substitute* "lib/Driver/ToolChain.cpp"
290 (("getDriver\\(\\)\\.ResourceDir")
291 (string-append "\"" compiler-rt "\"")))
293 ;; Make "LibDir" refer to <glibc>/lib so that it
294 ;; uses the right dynamic linker file name.
295 (substitute* "lib/Driver/ToolChains/Linux.cpp"
296 (("(^[[:blank:]]+LibDir = ).*" _ declaration)
297 (string-append declaration "\"" libc "/lib\";\n"))
299 ;; Make clang look for libstdc++ in the right
301 (("LibStdCXXIncludePathCandidates\\[\\] = \\{")
303 "LibStdCXXIncludePathCandidates[] = { \"" gcc
306 ;; Make sure libc's libdir is on the search path, to
307 ;; allow crt1.o & co. to be found.
309 (string-append libc "/lib")))))
311 `((substitute* "lib/Driver/Tools.cpp"
312 ;; Patch the 'getLinuxDynamicLinker' function so that
313 ;; it uses the right dynamic linker file name.
314 (("/lib64/ld-linux-x86-64.so.2")
316 ,(glibc-dynamic-linker))))
318 ;; Link to libclang_rt files from clang-runtime.
319 ;; This substitution needed slight adjustment in 3.8.
320 ,@(if (version>=? version "3.8")
321 '((substitute* "lib/Driver/Tools.cpp"
322 (("TC\\.getDriver\\(\\)\\.ResourceDir")
323 (string-append "\"" compiler-rt "\""))))
324 '((substitute* "lib/Driver/ToolChain.cpp"
325 (("getDriver\\(\\)\\.ResourceDir")
326 (string-append "\"" compiler-rt "\"")))))
328 ;; Make sure libc's libdir is on the search path, to
329 ;; allow crt1.o & co. to be found.
330 (substitute* "lib/Driver/ToolChains.cpp"
332 (string-append libc "/lib"))))))
334 ,@(if (version>=? version "10")
335 `((add-after 'install 'adjust-cmake-file
336 (lambda* (#:key outputs #:allow-other-keys)
337 (let ((out (assoc-ref outputs "out")))
338 ;; Clang generates a CMake file with "targets"
339 ;; for each installed library file. Downstream
340 ;; consumers of the CMake interface can use this
341 ;; to get absolute library locations. Including
342 ;; this file will needlessly assert that _all_
343 ;; libraries are available, which causes problems
344 ;; in Guix because some are removed (see the
345 ;; move-extra-tools phase). Thus, remove the
346 ;; asserts so that the main functionality works.
350 "/lib/cmake/clang/ClangTargets-release.cmake")
351 (("list\\(APPEND _IMPORT_CHECK_TARGETS.*" all)
352 (string-append "# Disabled by Guix.\n#" all)))
355 ,@(if (version>? version "3.8")
356 `((add-after 'install 'symlink-cfi_blacklist
357 (lambda* (#:key inputs outputs #:allow-other-keys)
358 (let* ((out (assoc-ref outputs "out"))
359 (lib-share (string-append out "/lib/clang/"
361 (compiler-rt (assoc-ref inputs "clang-runtime"))
362 ;; The location varies between Clang versions.
366 (string-append compiler-rt "/cfi_blacklist.txt"))
367 (string-append compiler-rt "/cfi_blacklist.txt"))
368 (else (string-append compiler-rt
369 "/share/cfi_blacklist.txt")))))
371 ;; Symlink cfi_blacklist.txt to where Clang expects
373 (symlink cfi-blacklist
374 (string-append lib-share "/cfi_blacklist.txt"))
377 (add-after 'install 'install-clean-up-/share/clang
378 (lambda* (#:key outputs #:allow-other-keys)
379 (let* ((out (assoc-ref outputs "out"))
380 (compl-dir (string-append
381 out "/etc/bash_completion.d")))
382 (with-directory-excursion (string-append out
386 (when (file-exists? file)
388 ;; Delete extensions for proprietary text editors.
389 '("clang-format-bbedit.applescript"
390 "clang-format-sublime.py"
391 ;; Delete Emacs extensions: see their respective Emacs
392 ;; Guix package instead.
393 "clang-rename.el" "clang-format.el"))
394 ;; Install bash completion.
395 (when (file-exists? "bash-autocomplete.sh")
397 (rename-file "bash-autocomplete.sh"
398 (string-append compl-dir "/clang")))))
401 ;; Clang supports the same environment variables as GCC.
403 (list (search-path-specification
404 (variable "C_INCLUDE_PATH")
405 (files '("include")))
406 (search-path-specification
407 (variable "CPLUS_INCLUDE_PATH")
408 (files '("include/c++" "include")))
409 (search-path-specification
410 (variable "LIBRARY_PATH")
411 (files '("lib" "lib64")))))
413 (home-page "https://clang.llvm.org")
414 (synopsis "C language family frontend for LLVM")
416 "Clang is a compiler front end for the C, C++, Objective-C and
417 Objective-C++ programming languages. It uses LLVM as its back end. The Clang
418 project includes the Clang front end, the Clang static analyzer, and several
419 code analysis tools.")
420 (license (if (version>=? version "9.0")
421 license:asl2.0 ;with LLVM exceptions
424 (define (make-clang-toolchain clang)
426 (name (string-append (package-name clang) "-toolchain"))
427 (version (package-version clang))
429 (build-system trivial-build-system)
431 '(#:modules ((guix build union))
433 (use-modules (ice-9 match)
437 (let ((out (assoc-ref %outputs "out")))
440 (((names . directories) ...)
441 (union-build out directories)))
443 ;; Create 'cc' and 'c++' so that one can use it as a
444 ;; drop-in replacement for the default tool chain and
445 ;; have configure scripts find the compiler.
446 (symlink "clang" (string-append out "/bin/cc"))
447 (symlink "clang++" (string-append out "/bin/c++"))
449 (union-build (assoc-ref %outputs "debug")
450 (list (assoc-ref %build-inputs
452 (union-build (assoc-ref %outputs "static")
453 (list (assoc-ref %build-inputs
458 (append (package-native-search-paths clang)
459 (list (search-path-specification ;copied from glibc
460 (variable "GUIX_LOCPATH")
461 (files '("lib/locale"))))))
462 (search-paths (package-search-paths clang))
464 (license (package-license clang))
465 (home-page "https://clang.llvm.org")
466 (synopsis "Complete Clang toolchain for C/C++ development")
467 (description "This package provides a complete Clang toolchain for C/C++
468 development to be installed in user profiles. This includes Clang, as well as
469 libc (headers and binaries, plus debugging symbols in the @code{debug}
470 output), and Binutils.")
471 (outputs '("out" "debug" "static"))
472 (inputs `(("clang" ,clang)
473 ("ld-wrapper" ,(car (assoc-ref (%final-inputs) "ld-wrapper")))
474 ("binutils" ,binutils)
476 ("libc-debug" ,glibc "debug")
477 ("libc-static" ,glibc "static")))))
479 (define-public llvm-11
486 (uri (llvm-uri "llvm" version))
489 "0s94lwil98w7zb7cjrbnxli0z7gklb312pkw74xs1d6zk346hgwi"))))
490 (build-system cmake-build-system)
491 (outputs '("out" "opt-viewer"))
493 `(("python" ,python-2) ;bytes->str conversion in clang>=3.7 needs python-2
496 `(("libffi" ,libffi)))
498 `(("zlib" ,zlib))) ;to use output from llvm-config
500 `(#:configure-flags '("-DCMAKE_SKIP_BUILD_RPATH=FALSE"
501 "-DCMAKE_BUILD_WITH_INSTALL_RPATH=FALSE"
502 "-DBUILD_SHARED_LIBS:BOOL=TRUE"
503 "-DLLVM_ENABLE_FFI:BOOL=TRUE"
504 "-DLLVM_REQUIRES_RTTI=1" ; For some third-party utilities
505 "-DLLVM_INSTALL_UTILS=ON") ; Needed for rustc.
507 ;; Don't use '-g' during the build, to save space.
508 #:build-type "Release"
510 (modify-phases %standard-phases
511 (add-before 'build 'shared-lib-workaround
512 ;; Even with CMAKE_SKIP_BUILD_RPATH=FALSE, llvm-tblgen
513 ;; doesn't seem to get the correct rpath to be able to run
514 ;; from the build directory. Set LD_LIBRARY_PATH as a
517 (setenv "LD_LIBRARY_PATH"
518 (string-append (getcwd) "/lib"))
520 (add-after 'install 'install-opt-viewer
521 (lambda* (#:key outputs #:allow-other-keys)
522 (let* ((out (assoc-ref outputs "out"))
523 (opt-viewer-out (assoc-ref outputs "opt-viewer"))
524 (opt-viewer-share-dir (string-append opt-viewer-out "/share"))
525 (opt-viewer-dir (string-append opt-viewer-share-dir "/opt-viewer")))
526 (mkdir-p opt-viewer-share-dir)
527 (rename-file (string-append out "/share/opt-viewer")
530 (home-page "https://www.llvm.org")
531 (synopsis "Optimizing compiler infrastructure")
533 "LLVM is a compiler infrastructure designed for compile-time, link-time,
534 runtime, and idle-time optimization of programs from arbitrary programming
535 languages. It currently supports compilation of C and C++ programs, using
536 front-ends derived from GCC 4.0.1. A new front-end for the C family of
537 languages is in development. The compiler infrastructure includes mirror sets
538 of programming tools as well as libraries with equivalent functionality.")
539 (license license:asl2.0))) ;with LLVM exceptions, see LICENSE.txt
541 (define-public clang-runtime-11
542 (clang-runtime-from-llvm
544 "0d5j5l8phwqjjscmk8rmqn0i2i0abl537gdbkagl8fjpzy1gyjip"))
546 (define-public clang-11
547 (clang-from-llvm llvm-11 clang-runtime-11
548 "02ajkij85966vd150iy246mv16dsaph1kfi0y8wnncp8w6nar5hg"
549 #:patches '("clang-11.0-libc-search-path.patch")
553 (uri (llvm-uri "clang-tools-extra"
554 (package-version llvm-11)))
557 "02bcwwn54661madhq4nxc069s7p7pj5gpqi8ww50w3anbpviilzy")))))
559 (define-public clang-toolchain-11
560 (make-clang-toolchain clang-11))
562 (define-public llvm-10
569 (uri (llvm-uri "llvm" version))
572 "1pwgm6cr0xr5a0hrbqs1zvsvvjvy0yq1y47c96804wcs795s90yz"))))))
574 (define-public clang-runtime-10
575 (clang-runtime-from-llvm
577 "0x9c531k6ww21s2mkdwqx1vbdjmx6d4wmfb8gdbj0wqa796sczba"))
579 (define-public clang-10
580 (clang-from-llvm llvm-10 clang-runtime-10
581 "08fbxa2a0kr3ni35ckppj0kyvlcyaywrhpqwcdrdy0z900mhcnw8"
582 #:patches '("clang-10.0-libc-search-path.patch")
586 (uri (llvm-uri "clang-tools-extra"
587 (package-version llvm-10)))
590 "074ija5s2jsdn0k035r2dzmryjmqxdnyg4xwvaqych2bazv8rpxc")))))
592 (define-public clang-toolchain-10
593 (make-clang-toolchain clang-10))
595 (define-public llvm-9
602 (uri (llvm-uri "llvm" version))
605 "16hwp3qa54c3a3v7h8nlw0fh5criqh0hlr1skybyk0cz70gyx880"))
606 (patches (search-patches
607 "llvm-9-fix-bitcast-miscompilation.patch"
608 "llvm-9-fix-scev-miscompilation.patch"
609 "llvm-9-fix-lpad-miscompilation.patch"))))))
611 (define-public clang-runtime-9
612 (clang-runtime-from-llvm
614 "0xwh79g3zggdabxgnd0bphry75asm1qz7mv3hcqihqwqr6aspgy2"
615 '("clang-runtime-9-libsanitizer-mode-field.patch")))
617 (define-public clang-9
618 (clang-from-llvm llvm-9 clang-runtime-9
619 "0ls2h3iv4finqyflyhry21qhc9cm9ga7g1zq21020p065qmm2y2p"
620 #:patches '("clang-9.0-libc-search-path.patch")))
622 (define-public clang-toolchain-9
623 (make-clang-toolchain clang-9))
625 (define-public llvm-8
631 (uri (llvm-uri "llvm" version))
634 "0k124sxkfhfi1rca6kzkdraf4axhx99x3cw2rk55056628dvwwl8"))))
635 (license license:ncsa)))
637 (define-public clang-runtime-8
638 (clang-runtime-from-llvm
640 "1c919wsm17xnv7lr8bhpq2wkq8113lzlw6hzhfr737j59x3wfddl"
641 '("clang-runtime-9-libsanitizer-mode-field.patch")))
643 (define-public clang-8
644 (clang-from-llvm llvm-8 clang-runtime-8
645 "0svk1f70hvpwrjp6x5i9kqwrqwxnmcrw5s7f4cxyd100mdd12k08"
646 #:patches '("clang-7.0-libc-search-path.patch")))
648 (define-public clang-toolchain-8
649 (make-clang-toolchain clang-8))
651 (define-public llvm-7
657 (uri (llvm-uri "llvm" version))
660 "16s196wqzdw4pmri15hadzqgdi926zln3an2viwyq0kini6zr3d3"))))))
662 (define-public clang-runtime-7
663 (clang-runtime-from-llvm
665 "065ybd8fsc4h2hikbdyricj6pyv4r7r7kpcikhb2y5zf370xybkq"
666 '("clang-runtime-9-libsanitizer-mode-field.patch")))
668 (define-public clang-7
669 (clang-from-llvm llvm-7 clang-runtime-7
670 "067lwggnbg0w1dfrps790r5l6k8n5zwhlsw7zb6zvmfpwpfn4nx4"
671 #:patches '("clang-7.0-libc-search-path.patch")))
673 (define-public clang-toolchain-7
674 (make-clang-toolchain clang-7))
676 (define-public llvm-6
682 (uri (llvm-uri "llvm" version))
685 "1qpls3vk85lydi5b4axl0809fv932qgsqgdgrk098567z4jc7mmn"))))))
687 (define-public clang-runtime-6
688 (clang-runtime-from-llvm
690 "1fcr3jn24yr8lh36nc0c4ikli4744i2q9m1ik67p1jymwwaixkgl"
691 '("clang-runtime-9-libsanitizer-mode-field.patch")))
693 (define-public clang-6
694 (clang-from-llvm llvm-6 clang-runtime-6
695 "0rxn4rh7rrnsqbdgp4gzc8ishbkryhpl1kd3mpnxzpxxhla3y93w"
696 #:patches '("clang-6.0-libc-search-path.patch")))
698 (define-public clang-toolchain-6
699 (make-clang-toolchain clang-6))
701 (define-public llvm-3.9.1
702 (package (inherit llvm-6)
708 (uri (llvm-uri "llvm" version))
711 "1vi9sf7rx1q04wj479rsvxayb6z740iaz3qniwp266fgp5a07n8z"))))
714 (substitute-keyword-arguments (package-arguments llvm)
716 `(modify-phases ,phases
717 (delete 'install-opt-viewer)))))))
719 (define-public clang-runtime-3.9.1
720 (clang-runtime-from-llvm
722 "16gc2gdmp5c800qvydrdhsp0bzb97s8wrakl6i8a4lgslnqnf2fk"
723 '("clang-runtime-3.9-libsanitizer-mode-field.patch"
724 "clang-runtime-asan-build-fixes.patch"
725 "clang-runtime-esan-build-fixes.patch"
726 "clang-3.5-libsanitizer-ustat-fix.patch")))
728 (define-public clang-3.9.1
729 (clang-from-llvm llvm-3.9.1 clang-runtime-3.9.1
730 "0qsyyb40iwifhhlx9a3drf8z6ni6zwyk3bvh0kx2gs6yjsxwxi76"
731 #:patches '("clang-3.8-libc-search-path.patch")))
733 (define-public llvm-3.8
734 (package (inherit llvm-3.9.1)
740 (uri (llvm-uri "llvm" version))
743 "1ybmnid4pw2hxn12ax5qa5kl1ldfns0njg8533y3mzslvd5cx0kf"))))))
745 (define-public clang-runtime-3.8
746 (clang-runtime-from-llvm
748 "0p0y85c7izndbpg2l816z7z7558axq11d5pwkm4h11sdw7d13w0d"
749 '("clang-runtime-asan-build-fixes.patch"
750 "clang-runtime-3.8-libsanitizer-mode-field.patch"
751 "clang-3.5-libsanitizer-ustat-fix.patch")))
753 (define-public clang-3.8
754 (clang-from-llvm llvm-3.8 clang-runtime-3.8
755 "1prc72xmkgx8wrzmrr337776676nhsp1qd3mw2bvb22bzdnq7lsc"
756 #:patches '("clang-3.8-libc-search-path.patch")))
758 (define-public llvm-3.7
759 (package (inherit llvm-3.8)
764 (uri (llvm-uri "llvm" version))
767 "1masakdp9g2dan1yrazg7md5am2vacbkb3nahb3dchpc1knr8xxy"))))))
769 (define-public clang-runtime-3.7
770 (clang-runtime-from-llvm
772 "10c1mz2q4bdq9bqfgr3dirc6hz1h3sq8573srd5q5lr7m7j6jiwx"
773 '("clang-runtime-asan-build-fixes.patch"
774 "clang-runtime-3.8-libsanitizer-mode-field.patch"
775 "clang-3.5-libsanitizer-ustat-fix.patch")))
777 (define-public clang-3.7
778 (clang-from-llvm llvm-3.7 clang-runtime-3.7
779 "0x065d0w9b51xvdjxwfzjxng0gzpbx45fgiaxpap45ragi61dqjn"
780 #:patches '("clang-3.5-libc-search-path.patch")))
782 (define-public llvm-3.6
783 (package (inherit llvm-3.7)
788 (uri (llvm-uri "llvm" version))
791 "153vcvj8gvgwakzr4j0kndc0b7wn91c2g1vy2vg24s6spxcc23gn"))))))
793 (define-public llvm-3.5
794 (package (inherit llvm-3.6)
799 (uri (llvm-uri "llvm" version))
801 (search-patches "llvm-3.5-fix-clang-build-with-gcc5.patch"))
804 "0xf5q17kkxsrm2gsi93h4pwlv663kji73r2g4asb97klsmb626a4"))))))
806 (define-public clang-runtime-3.5
807 (let ((runtime (clang-runtime-from-llvm
809 "1hsdnzzdr5kglz6fnv3lcsjs222zjsy14y8ax9dy6zqysanplbal"
810 '("clang-runtime-asan-build-fixes.patch"
811 "clang-runtime-3.5-libsanitizer-mode-field.patch"
812 "clang-3.5-libsanitizer-ustat-fix.patch"))))
813 (package/inherit runtime
815 (substitute-keyword-arguments (package-arguments runtime)
816 ((#:phases phases '%standard-phases)
817 `(modify-phases ,phases
818 ;; glibc no longer includes rpc/xdr.h, so we use the headers from
820 (add-after 'unpack 'find-rpc-includes
821 (lambda* (#:key inputs #:allow-other-keys)
823 (string-append (assoc-ref inputs "libtirpc")
825 (or (getenv "CPATH") "")))
826 (setenv "CPLUS_INCLUDE_PATH"
827 (string-append (assoc-ref inputs "libtirpc")
829 (or (getenv "CPLUS_INCLUDE_PATH") "")))
832 `(("libtirpc" ,libtirpc)
833 ("llvm" ,llvm-3.5))))))
835 (define-public clang-3.5
836 (clang-from-llvm llvm-3.5 clang-runtime-3.5
837 "0846h8vn3zlc00jkmvrmy88gc6ql6014c02l4jv78fpvfigmgssg"
838 #:patches '("clang-3.5-libc-search-path.patch")))
840 ;; Default LLVM and Clang version.
841 (define-public llvm llvm-9)
842 (define-public clang-runtime clang-runtime-9)
843 (define-public clang clang-9)
844 (define-public clang-toolchain clang-toolchain-9)
852 (uri (llvm-uri "lld" version))
855 "077xyh7sij6mhp4dc4kdcmp9whrpz332fa12rwxnzp3wgd5bxrzg"))))
856 (build-system cmake-build-system)
858 `(("llvm" ,llvm-11)))
860 `(#:build-type "Release"
861 ;; TODO: Tests require the lit tool, which isn't installed by the LLVM
864 (home-page "https://lld.llvm.org/")
865 (synopsis "Linker from the LLVM project")
866 (description "LLD is a high-performance linker, built as a set of reusable
867 components which highly leverage existing libraries in the larger LLVM Project.")
868 (license license:asl2.0))) ; With LLVM exception
876 (uri (llvm-uri "lldb" version))
879 "0wic9lyb2la9bkzdc13szkm4f793w1mddp50xvh237iraygw0w45"))))
880 (build-system cmake-build-system)
882 `(#:configure-flags '("-DCMAKE_CXX_COMPILER=clang++")))
884 `(("pkg-config" ,pkg-config)
887 `(("clang" ,clang-11)
890 ;; Optional (but recommended) inputs.
892 ("editline" ,libedit)
897 (home-page "https://lldb.llvm.org/")
898 (synopsis "Low level debugger")
900 "LLDB is a high performance debugger built as a set of reusable components
901 which highly leverage existing libraries in the larger LLVM project.")
902 (license license:asl2.0))) ;with LLVM exceptions
904 (define-public libcxx
911 (uri (llvm-uri "libcxx" version))
914 "0d2bj5i6mk4caq7skd5nsdmz8c2m5w5anximl5wz3x32p08zz089"))))
915 (build-system cmake-build-system)
918 (modify-phases (@ (guix build cmake-build-system) %standard-phases)
919 (add-after 'set-paths 'adjust-CPLUS_INCLUDE_PATH
920 (lambda* (#:key inputs #:allow-other-keys)
921 (let ((gcc (assoc-ref inputs "gcc")))
922 ;; Hide GCC's C++ headers so that they do not interfere with
923 ;; the ones we are attempting to build.
924 (setenv "CPLUS_INCLUDE_PATH"
925 (string-join (delete (string-append gcc "/include/c++")
926 (string-split (getenv "CPLUS_INCLUDE_PATH")
930 "environment variable `CPLUS_INCLUDE_PATH' changed to ~a~%"
931 (getenv "CPLUS_INCLUDE_PATH"))
936 (home-page "https://libcxx.llvm.org")
937 (synopsis "C++ standard library")
939 "This package provides an implementation of the C++ standard library for
940 use with Clang, targeting C++11, C++14 and above.")
941 (license license:expat)))
943 ;; Libcxx files specifically used by PySide2.
944 (define-public libcxx-6
947 (version (package-version llvm-6))
950 (inherit (package-source libcxx))
951 (uri (llvm-uri "libcxx" version))
954 "0rzw4qvxp6qx4l4h9amrq02gp7hbg8lw4m0sy3k60f50234gnm3n"))))
959 (define-public libcxxabi-6
967 (url "https://github.com/llvm/llvm-project")
968 (commit (string-append "llvmorg-" version))))
969 (file-name (git-file-name name version))
972 "0ki6796b5z08kh3a3rbysr5wwb2dkl6wal5dzd03i4li5xfkvx1g"))))
973 (build-system cmake-build-system)
976 (list (string-append "-DLIBCXXABI_LIBCXX_INCLUDES="
977 (assoc-ref %build-inputs "libcxx")
979 "-DCMAKE_C_COMPILER=clang"
980 "-DCMAKE_CXX_COMPILER=clang++")
982 (modify-phases (@ (guix build cmake-build-system) %standard-phases)
983 (add-after 'unpack 'chdir
984 (lambda _ (chdir "libcxxabi")))
985 (add-after 'set-paths 'adjust-CPLUS_INCLUDE_PATH
986 (lambda* (#:key inputs #:allow-other-keys)
987 (let ((gcc (assoc-ref inputs "gcc")))
988 ;; Hide GCC's C++ headers so that they do not interfere with
989 ;; the ones we are attempting to build.
990 (setenv "CPLUS_INCLUDE_PATH"
993 (assoc-ref inputs "libcxx") "/include/c++/v1")
994 (delete (string-append gcc "/include/c++")
995 (string-split (getenv "CPLUS_INCLUDE_PATH")
999 "environment variable `CPLUS_INCLUDE_PATH' changed to ~a~%"
1000 (getenv "CPLUS_INCLUDE_PATH")))))
1001 (add-after 'install 'install-headers
1002 (lambda* (#:key outputs #:allow-other-keys)
1003 (let ((include-dir (string-append
1004 (assoc-ref outputs "out") "/include")))
1005 (install-file "../libcxxabi/include/__cxxabi_config.h" include-dir)
1006 (install-file "../libcxxabi/include/cxxabi.h" include-dir)))))))
1008 `(("clang" ,clang-6)
1010 ("libcxx" ,libcxx-6)))
1011 (home-page "https://libcxxabi.llvm.org")
1012 (synopsis "C++ standard library support")
1014 "This package provides an implementation of low level support for a
1015 standard C++ library.")
1016 (license license:expat)))
1018 (define-public libcxx+libcxxabi-6
1021 (name "libcxx+libcxxabi")
1022 (version (package-version libcxx-6))
1025 (list "-DLIBCXX_CXX_ABI=libcxxabi"
1026 (string-append "-DLIBCXX_CXX_ABI_INCLUDE_PATHS="
1027 (assoc-ref %build-inputs "libcxxabi")
1030 (modify-phases (@ (guix build cmake-build-system) %standard-phases)
1031 (add-after 'set-paths 'adjust-CPLUS_INCLUDE_PATH
1032 (lambda* (#:key inputs #:allow-other-keys)
1033 (let ((gcc (assoc-ref inputs "gcc")))
1034 ;; Hide GCC's C++ headers so that they do not interfere with
1035 ;; the ones we are attempting to build.
1036 (setenv "CPLUS_INCLUDE_PATH"
1038 (delete (string-append gcc "/include/c++")
1039 (string-split (getenv "CPLUS_INCLUDE_PATH")
1043 "environment variable `CPLUS_INCLUDE_PATH' changed to ~a~%"
1044 (getenv "CPLUS_INCLUDE_PATH"))))))))
1046 `(("clang" ,clang-6)
1048 ("libcxxabi" ,libcxxabi-6)))))
1050 (define-public libclc
1058 (url "https://github.com/llvm/llvm-project")
1059 (commit (string-append "llvmorg-" version))))
1060 (file-name (git-file-name name version))
1063 "1d1qayvrvvc1di7s7jfxnjvxq2az4lwq1sw1b2gq2ic0nksvajz0"))))
1064 (build-system cmake-build-system)
1067 (list (string-append "-DLLVM_CLANG="
1068 (assoc-ref %build-inputs "clang")
1070 (string-append "-DPYTHON="
1071 (assoc-ref %build-inputs "python")
1074 (modify-phases %standard-phases
1075 (add-after 'unpack 'chdir
1076 (lambda _ (chdir "libclc") #t)))))
1080 ("python" ,python)))
1081 (home-page "https://libclc.llvm.org")
1082 (synopsis "Libraries for the OpenCL programming language")
1084 "This package provides an implementation of the OpenCL library
1085 requirements according to version 1.1 of the OpenCL specification.")
1086 ;; Apache license 2.0 with LLVM exception
1087 (license license:asl2.0)))
1089 (define-public libomp
1095 (uri (llvm-uri "openmp" version))
1098 "1knafnpp0f7hylx8q20lkd6g1sf0flly572dayc5d5kghh7hd52w"))
1099 (file-name (string-append "libomp-" version ".tar.xz"))))
1100 (build-system cmake-build-system)
1101 ;; XXX: Note this gets built with GCC because building with Clang itself
1102 ;; fails (missing <atomic>, even when libcxx is added as an input.)
1104 '(#:configure-flags '("-DLIBOMP_USE_HWLOC=ON"
1105 "-DOPENMP_TEST_C_COMPILER=clang"
1106 "-DOPENMP_TEST_CXX_COMPILER=clang++")
1107 #:test-target "check-libomp"))
1112 ("pkg-config" ,pkg-config)))
1114 `(("hwloc" ,hwloc "lib")))
1115 (home-page "https://openmp.llvm.org")
1116 (synopsis "OpenMP run-time support library")
1118 "This package provides the run-time support library developed by the LLVM
1119 project for the OpenMP multi-theaded programming extension. This package
1120 notably provides @file{libgomp.so}, which is has a binary interface compatible
1121 with that of libgomp, the GNU Offloading and Multi Processing Library.")
1122 (license license:expat)))
1124 (define-public python-llvmlite
1126 (name "python-llvmlite")
1131 (uri (pypi-uri "llvmlite" version))
1134 "0qqzs6h34002ig2jn31vk08q9hh5kn84lhmv4bljz3yakg8y0gph"))))
1135 (build-system python-build-system)
1138 (modify-phases %standard-phases
1139 (add-after 'unpack 'patch-reference-to-llvmlite.so
1140 ;; ctypes.CDLL uses dlopen to load libllvmlite.so, which
1141 ;; fails, so locate it by its absolute path. Change it in
1142 ;; ffi.py, not utils.py, because setup.py relies on the
1143 ;; output of get_library_name for proper installation.
1144 (lambda* (#:key outputs #:allow-other-keys)
1145 (let* ((out (assoc-ref outputs "out"))
1146 (libllvmlite.so (string-append out "/lib/python"
1147 ,(version-major+minor
1148 (package-version python))
1149 "/site-packages/llvmlite/"
1150 "binding/libllvmlite.so")))
1151 (substitute* "llvmlite/binding/ffi.py"
1152 (("_lib_name = get_library_name\\(\\)")
1153 (format #f "_lib_name = ~s" libllvmlite.so)))
1155 (add-after 'unpack 'skip-failing-tests
1157 (substitute* "llvmlite/tests/test_binding.py"
1158 ((" def test_libm\\(self\\).*" all)
1159 (string-append " @unittest.skip('Fails on Guix')\n" all)))
1161 (add-before 'build 'set-compiler/linker-flags
1162 (lambda* (#:key inputs #:allow-other-keys)
1163 (let ((llvm (assoc-ref inputs "llvm")))
1164 ;; Refer to ffi/Makefile.linux.
1165 (setenv "CPPFLAGS" "-fPIC")
1166 (setenv "LDFLAGS" (string-append "-Wl,-rpath="
1171 ,(let* ((patches-commit "061ab39e1d4591f3aa842458252a19ad01858167")
1172 (patch-uri (lambda (name)
1174 "https://raw.githubusercontent.com/numba/"
1175 "llvmlite/" patches-commit "/conda-recipes/"
1177 (patch-origin (lambda (name hash)
1180 (uri (patch-uri name))
1181 (sha256 (base32 hash)))))
1182 (arch-independent-patches
1185 "partial-testing.patch"
1186 "1cwy4jsmijd838q0bylxl77vrwrb7ksijfly5062ay32303jmj86")
1188 "0001-Revert-Limit-size-of-non-GlobalValue-name.patch"
1189 "0n4k7za0smx6qwdipsh6x5lm7bfvzzb3p9r8q1zq1dqi4na21295"))))
1190 (if (string=? "aarch64-linux" (%current-system))
1195 (inherit (package-source llvm-9))
1198 "intel-D47188-svml-VF_LLVM9.patch"
1199 "1f9ld7wc8bn4gbvdsmk07w1rq371h42vy05rxsq9a22f57rljqbd")
1200 ,@arch-independent-patches
1201 ,@(origin-patches (package-source llvm-9)))))))
1206 (inherit (package-source llvm-10))
1209 "intel-D47188-svml-VF.patch"
1210 "0n46qjwfl7i12bl7wp0cyxl277axfvaaz5lxx5kdlgwjcpa582dg")
1212 "expect-fastmath-entrypoints-in-add-TLI-mappings.ll.patch"
1213 "0jxhjkkwwi1cy898l2n57l73ckpw0v73lqnrifp7r1mwpsh624nv")
1214 ,@arch-independent-patches
1215 ,@(origin-patches (package-source llvm-10))))))))))))
1216 (home-page "https://llvmlite.pydata.org")
1217 (synopsis "Wrapper around basic LLVM functionality")
1219 "This package provides a Python binding to LLVM for use in Numba.")
1220 (license license:bsd-3)))
1222 (define-public emacs-clang-format
1225 (name "emacs-clang-format")
1226 (build-system emacs-build-system)
1228 `(("clang" ,clang)))
1231 (modify-phases %standard-phases
1232 (add-after 'unpack 'configure
1233 (lambda* (#:key inputs #:allow-other-keys)
1234 (let ((clang (assoc-ref inputs "clang")))
1235 (copy-file "tools/clang-format/clang-format.el" "clang-format.el")
1236 (emacs-substitute-variables "clang-format.el"
1237 ("clang-format-executable"
1238 (string-append clang "/bin/clang-format"))))
1240 (synopsis "Format code using clang-format")
1241 (description "This package filters code through @code{clang-format}
1242 to fix its formatting. @code{clang-format} is a tool that formats
1243 C/C++/Obj-C code according to a set of style options, see
1244 @url{https://clang.llvm.org/docs/ClangFormatStyleOptions.html}.")))
1246 (define-public emacs-clang-rename
1249 (name "emacs-clang-rename")
1250 (build-system emacs-build-system)
1252 `(("clang" ,clang)))
1255 (modify-phases %standard-phases
1256 (add-after 'unpack 'configure
1257 (lambda* (#:key inputs #:allow-other-keys)
1258 (let ((clang (assoc-ref inputs "clang")))
1259 (copy-file "tools/clang-rename/clang-rename.el" "clang-rename.el")
1260 (emacs-substitute-variables "clang-rename.el"
1261 ("clang-rename-binary"
1262 (string-append clang "/bin/clang-rename"))))
1264 (synopsis "Rename every occurrence of a symbol using clang-rename")
1265 (description "This package renames every occurrence of a symbol at point
1266 using @code{clang-rename}.")))
1268 (define make-ocaml-llvm
1269 ;; Make it a memoizing procedure so its callers below don't end up defining
1270 ;; two equal-but-not-eq "ocaml-llvm" packages for the default LLVM.
1279 (string-append "-DLLVM_OCAML_EXTERNAL_LLVM_LIBDIR="
1280 (assoc-ref %build-inputs "llvm") "/lib")
1281 "-DBUILD_SHARED_LIBS=TRUE"
1282 "-DLLVM_OCAML_OUT_OF_TREE=TRUE"
1283 (string-append "-DLLVM_OCAML_INSTALL_PATH="
1284 (assoc-ref %outputs "out") "/lib/ocaml/site-lib"))
1286 (modify-phases %standard-phases
1289 (invoke "make" "ocaml_all")))
1292 (invoke "cmake" "-P" "bindings/ocaml/cmake_install.cmake"))))))
1297 ("ocaml-findlib" ,ocaml-findlib)
1298 ("ocaml-ounit" ,ocaml-ounit)
1299 ("python" ,python)))
1301 `(("ocaml-integers" ,ocaml-integers)
1302 ("ocaml-ctypes" ,ocaml-ctypes)))
1303 (synopsis "OCaml bindings to LLVM")
1304 (description "This package contains the OCaml bindings distributed with
1307 (define-public ocaml-llvm (make-ocaml-llvm llvm))
1308 (define-public ocaml-llvm-9 (make-ocaml-llvm llvm-9))
1309 (define-public ocaml-llvm-10 (make-ocaml-llvm llvm-10))
1310 (define-public ocaml-llvm-11 (make-ocaml-llvm llvm-11))