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 Ricardo Wurmus <rekado@elephly.net>
7 ;;; Copyright © 2017 Roel Janssen <roel@gnu.org>
8 ;;; Copyright © 2018, 2019 Marius Bakke <mbakke@fastmail.com>
9 ;;; Copyright © 2018 Tobias Geerinckx-Rice <me@tobias.gr>
10 ;;; Copyright © 2018 Efraim Flashner <efraim@flashner.co.il>
11 ;;; Copyright © 2018 Tim Gesthuizen <tim.gesthuizen@yahoo.de>
12 ;;; Copyright © 2018 Pierre Neidhardt <mail@ambrevar.xyz>
13 ;;; Copyright © 2019 Rutger Helling <rhelling@mykolab.com>
15 ;;; This file is part of GNU Guix.
17 ;;; GNU Guix is free software; you can redistribute it and/or modify it
18 ;;; under the terms of the GNU General Public License as published by
19 ;;; the Free Software Foundation; either version 3 of the License, or (at
20 ;;; your option) any later version.
22 ;;; GNU Guix is distributed in the hope that it will be useful, but
23 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
24 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 ;;; GNU General Public License for more details.
27 ;;; You should have received a copy of the GNU General Public License
28 ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
30 (define-module (gnu packages llvm)
31 #:use-module (guix packages)
32 #:use-module ((guix licenses) #:prefix license:)
33 #:use-module (guix download)
34 #:use-module (guix utils)
35 #:use-module (guix build-system gnu)
36 #:use-module (guix build-system cmake)
37 #:use-module (guix build-system emacs)
38 #:use-module (guix build-system python)
39 #:use-module (gnu packages)
40 #:use-module (gnu packages gcc)
41 #:use-module (gnu packages bootstrap) ;glibc-dynamic-linker
42 #:use-module (gnu packages compression)
43 #:use-module (gnu packages libffi)
44 #:use-module (gnu packages mpi)
45 #:use-module (gnu packages perl)
46 #:use-module (gnu packages pkg-config)
47 #:use-module (gnu packages python)
48 #:use-module (gnu packages xml))
57 (uri (string-append "https://llvm.org/releases/"
58 version "/llvm-" version ".src.tar.xz"))
61 "0k124sxkfhfi1rca6kzkdraf4axhx99x3cw2rk55056628dvwwl8"))))
62 (build-system cmake-build-system)
64 `(("python" ,python-2) ;bytes->str conversion in clang>=3.7 needs python-2
67 `(("libffi" ,libffi)))
69 `(("zlib" ,zlib))) ;to use output from llvm-config
71 `(#:configure-flags '("-DCMAKE_SKIP_BUILD_RPATH=FALSE"
72 "-DCMAKE_BUILD_WITH_INSTALL_RPATH=FALSE"
73 "-DBUILD_SHARED_LIBS:BOOL=TRUE"
74 "-DLLVM_ENABLE_FFI:BOOL=TRUE"
75 "-DLLVM_REQUIRES_RTTI=1" ; For some third-party utilities
76 "-DLLVM_INSTALL_UTILS=ON") ; Needed for rustc.
78 ;; Don't use '-g' during the build, to save space.
79 #:build-type "Release"
80 #:phases (modify-phases %standard-phases
81 (add-before 'build 'shared-lib-workaround
82 ;; Even with CMAKE_SKIP_BUILD_RPATH=FALSE, llvm-tblgen
83 ;; doesn't seem to get the correct rpath to be able to run
84 ;; from the build directory. Set LD_LIBRARY_PATH as a
87 (setenv "LD_LIBRARY_PATH"
88 (string-append (getcwd) "/lib"))
90 (home-page "https://www.llvm.org")
91 (synopsis "Optimizing compiler infrastructure")
93 "LLVM is a compiler infrastructure designed for compile-time, link-time,
94 runtime, and idle-time optimization of programs from arbitrary programming
95 languages. It currently supports compilation of C and C++ programs, using
96 front-ends derived from GCC 4.0.1. A new front-end for the C family of
97 languages is in development. The compiler infrastructure includes mirror sets
98 of programming tools as well as libraries with equivalent functionality.")
99 (license license:ncsa)))
101 (define* (clang-runtime-from-llvm llvm hash
102 #:optional (patches '()))
104 (name "clang-runtime")
105 (version (package-version llvm))
109 (uri (string-append "https://llvm.org/releases/"
110 version "/compiler-rt-" version ".src.tar.xz"))
111 (sha256 (base32 hash))
112 (patches (map search-patch patches))))
113 (build-system cmake-build-system)
114 (native-inputs (package-native-inputs llvm))
118 `(;; Don't use '-g' during the build to save space.
119 #:build-type "Release"
120 #:tests? #f)) ; Tests require gtest
121 (home-page "https://compiler-rt.llvm.org")
122 (synopsis "Runtime library for Clang/LLVM")
124 "The \"clang-runtime\" library provides the implementations of run-time
125 functions for C and C++ programs. It also provides header files that allow C
126 and C++ source code to interface with the \"sanitization\" passes of the clang
127 compiler. In LLVM this library is called \"compiler-rt\".")
128 (license license:ncsa)
130 ;; <https://compiler-rt.llvm.org/> doesn't list MIPS as supported.
131 (supported-systems (delete "mips64el-linux" %supported-systems))))
133 (define* (clang-from-llvm llvm clang-runtime hash
137 (version (package-version llvm))
141 (uri (string-append "https://llvm.org/releases/"
142 version "/cfe-" version ".src.tar.xz"))
143 (sha256 (base32 hash))
144 (patches (map search-patch patches))))
145 ;; Using cmake allows us to treat llvm as an external library. There
146 ;; doesn't seem to be any way to do this with clang's autotools-based
148 (build-system cmake-build-system)
149 (native-inputs (package-native-inputs llvm))
151 `(("libxml2" ,libxml2)
152 ("gcc-lib" ,gcc "lib")
153 ,@(package-inputs llvm)))
156 ("clang-runtime" ,clang-runtime)))
159 (list "-DCLANG_INCLUDE_TESTS=True"
161 ;; Find libgcc_s, crtbegin.o, and crtend.o.
162 (string-append "-DGCC_INSTALL_PREFIX="
163 (assoc-ref %build-inputs "gcc-lib"))
165 ;; Use a sane default include directory.
166 (string-append "-DC_INCLUDE_DIRS="
167 (assoc-ref %build-inputs "libc")
170 ;; Don't use '-g' during the build to save space.
171 #:build-type "Release"
173 #:phases (modify-phases %standard-phases
175 'unpack 'set-glibc-file-names
176 (lambda* (#:key inputs #:allow-other-keys)
177 (let ((libc (assoc-ref inputs "libc"))
178 (compiler-rt (assoc-ref inputs "clang-runtime")))
179 (case (string->number ,(version-major
180 (package-version clang-runtime)))
182 ;; Link to libclang_rt files from clang-runtime.
183 (substitute* "lib/Driver/ToolChain.cpp"
184 (("getDriver\\(\\)\\.ResourceDir")
185 (string-append "\"" compiler-rt "\"")))
187 ;; Make "LibDir" refer to <glibc>/lib so that it
188 ;; uses the right dynamic linker file name.
189 (substitute* "lib/Driver/ToolChains/Linux.cpp"
190 (("(^[[:blank:]]+LibDir = ).*" _ declaration)
191 (string-append declaration "\"" libc "/lib\";\n"))
193 ;; Make sure libc's libdir is on the search path, to
194 ;; allow crt1.o & co. to be found.
196 (string-append libc "/lib"))))
198 (substitute* "lib/Driver/Tools.cpp"
199 ;; Patch the 'getLinuxDynamicLinker' function so that
200 ;; it uses the right dynamic linker file name.
201 (("/lib64/ld-linux-x86-64.so.2")
203 ,(glibc-dynamic-linker))))
205 ;; Link to libclang_rt files from clang-runtime.
206 ;; This substitution needed slight adjustment in 3.8.
207 (if (< 3.8 (string->number ,(version-major+minor
210 (substitute* "lib/Driver/Tools.cpp"
211 (("TC\\.getDriver\\(\\)\\.ResourceDir")
212 (string-append "\"" compiler-rt "\"")))
213 (substitute* "lib/Driver/ToolChain.cpp"
214 (("getDriver\\(\\)\\.ResourceDir")
215 (string-append "\"" compiler-rt "\""))))
217 ;; Make sure libc's libdir is on the search path, to
218 ;; allow crt1.o & co. to be found.
219 (substitute* "lib/Driver/ToolChains.cpp"
221 (string-append libc "/lib")))))
223 (add-after 'install 'install-clean-up-/share/clang
224 (lambda* (#:key outputs #:allow-other-keys)
225 (let* ((out (assoc-ref outputs "out"))
226 (compl-dir (string-append
227 out "/etc/bash_completion.d")))
228 (with-directory-excursion (string-append out
232 (when (file-exists? file)
234 ;; Delete extensions for proprietary text editors.
235 '("clang-format-bbedit.applescript"
236 "clang-format-sublime.py"
237 ;; Delete Emacs extensions: see their respective Emacs
238 ;; Guix package instead.
239 "clang-rename.el" "clang-format.el"))
240 ;; Install bash completion.
241 (when (file-exists? "bash-autocomplete.sh")
243 (rename-file "bash-autocomplete.sh"
244 (string-append compl-dir "/clang")))))
247 ;; Clang supports the same environment variables as GCC.
249 (list (search-path-specification
251 (files '("include")))
252 (search-path-specification
253 (variable "LIBRARY_PATH")
254 (files '("lib" "lib64")))))
256 (home-page "https://clang.llvm.org")
257 (synopsis "C language family frontend for LLVM")
259 "Clang is a compiler front end for the C, C++, Objective-C and
260 Objective-C++ programming languages. It uses LLVM as its back end. The Clang
261 project includes the Clang front end, the Clang static analyzer, and several
262 code analysis tools.")
263 (license license:ncsa)))
265 (define-public libcxx
268 (version (package-version llvm))
272 (uri (string-append "http://llvm.org/releases/"
273 version "/libcxx-" version ".src.tar.xz"))
276 "1wdrxg365ig0kngx52pd0n820sncp24blb0zpalc579iidhh4002"))))
277 (build-system cmake-build-system)
281 (home-page "https://libcxx.llvm.org")
282 (synopsis "C++ standard library")
284 "This package provides an implementation of the C++ standard library for
285 use with Clang, targeting C++11, C++14 and above.")
286 (license license:expat)))
288 (define-public libomp
291 (version (package-version llvm))
294 (uri (string-append "http://releases.llvm.org/"
295 version "/openmp-" version
299 "030dkg5cypd7j9hq0mcqb5gs31lxwmzfq52j81l7v9ldcy5bf5mz"))
300 (file-name (string-append "libomp-" version ".tar.xz"))))
301 (build-system cmake-build-system)
302 ;; XXX: Note this gets built with GCC because building with Clang itself
303 ;; fails (missing <atomic>, even when libcxx is added as an input.)
305 '(#:configure-flags '("-DLIBOMP_USE_HWLOC=ON"
306 "-DOPENMP_TEST_C_COMPILER=clang"
307 "-DOPENMP_TEST_CXX_COMPILER=clang++")
308 #:test-target "check-libomptarget"))
313 ("pkg-config" ,pkg-config)))
315 `(("hwloc" ,hwloc "lib")))
316 (home-page "https://openmp.llvm.org")
317 (synopsis "OpenMP run-time support library")
319 "This package provides the run-time support library developed by the LLVM
320 project for the OpenMP multi-theaded programming extension. This package
321 notably provides @file{libgomp.so}, which is has a binary interface compatible
322 with that of libgomp, the GNU Offloading and Multi Processing Library.")
323 (license license:expat)))
325 (define-public clang-runtime
326 (clang-runtime-from-llvm
328 "1c919wsm17xnv7lr8bhpq2wkq8113lzlw6hzhfr737j59x3wfddl"))
331 (clang-from-llvm llvm clang-runtime
332 "0svk1f70hvpwrjp6x5i9kqwrqwxnmcrw5s7f4cxyd100mdd12k08"
333 #:patches '("clang-7.0-libc-search-path.patch")))
335 (define-public llvm-6
341 (uri (string-append "https://llvm.org/releases/"
342 version "/llvm-" version ".src.tar.xz"))
345 "1qpls3vk85lydi5b4axl0809fv932qgsqgdgrk098567z4jc7mmn"))))))
347 (define-public clang-runtime-6
348 (clang-runtime-from-llvm
350 "1fcr3jn24yr8lh36nc0c4ikli4744i2q9m1ik67p1jymwwaixkgl"))
352 (define-public clang-6
353 (clang-from-llvm llvm-6 clang-runtime
354 "0rxn4rh7rrnsqbdgp4gzc8ishbkryhpl1kd3mpnxzpxxhla3y93w"
355 #:patches '("clang-6.0-libc-search-path.patch")))
357 (define-public llvm-3.9.1
358 (package (inherit llvm)
364 (uri (string-append "https://llvm.org/releases/"
365 version "/llvm-" version ".src.tar.xz"))
368 "1vi9sf7rx1q04wj479rsvxayb6z740iaz3qniwp266fgp5a07n8z"))))))
370 (define-public clang-runtime-3.9.1
371 (clang-runtime-from-llvm
373 "16gc2gdmp5c800qvydrdhsp0bzb97s8wrakl6i8a4lgslnqnf2fk"
374 '("clang-runtime-asan-build-fixes.patch"
375 "clang-runtime-esan-build-fixes.patch"
376 "clang-3.5-libsanitizer-ustat-fix.patch")))
378 (define-public clang-3.9.1
379 (clang-from-llvm llvm-3.9.1 clang-runtime-3.9.1
380 "0qsyyb40iwifhhlx9a3drf8z6ni6zwyk3bvh0kx2gs6yjsxwxi76"
381 #:patches '("clang-3.8-libc-search-path.patch")))
383 (define-public llvm-3.8
384 (package (inherit llvm)
390 (uri (string-append "https://llvm.org/releases/"
391 version "/llvm-" version ".src.tar.xz"))
394 "1ybmnid4pw2hxn12ax5qa5kl1ldfns0njg8533y3mzslvd5cx0kf"))))))
396 (define-public clang-runtime-3.8
397 (clang-runtime-from-llvm
399 "0p0y85c7izndbpg2l816z7z7558axq11d5pwkm4h11sdw7d13w0d"
400 '("clang-runtime-asan-build-fixes.patch"
401 "clang-3.5-libsanitizer-ustat-fix.patch")))
403 (define-public clang-3.8
404 (clang-from-llvm llvm-3.8 clang-runtime-3.8
405 "1prc72xmkgx8wrzmrr337776676nhsp1qd3mw2bvb22bzdnq7lsc"
406 #:patches '("clang-3.8-libc-search-path.patch")))
408 (define-public llvm-3.7
409 (package (inherit llvm)
414 (uri (string-append "https://llvm.org/releases/"
415 version "/llvm-" version ".src.tar.xz"))
418 "1masakdp9g2dan1yrazg7md5am2vacbkb3nahb3dchpc1knr8xxy"))))))
420 (define-public clang-runtime-3.7
421 (clang-runtime-from-llvm
423 "10c1mz2q4bdq9bqfgr3dirc6hz1h3sq8573srd5q5lr7m7j6jiwx"
424 '("clang-runtime-asan-build-fixes.patch"
425 "clang-3.5-libsanitizer-ustat-fix.patch")))
427 (define-public clang-3.7
428 (clang-from-llvm llvm-3.7 clang-runtime-3.7
429 "0x065d0w9b51xvdjxwfzjxng0gzpbx45fgiaxpap45ragi61dqjn"
430 #:patches '("clang-3.5-libc-search-path.patch")))
432 (define-public llvm-3.6
433 (package (inherit llvm)
438 (uri (string-append "https://llvm.org/releases/"
439 version "/llvm-" version ".src.tar.xz"))
442 "153vcvj8gvgwakzr4j0kndc0b7wn91c2g1vy2vg24s6spxcc23gn"))))))
444 (define-public clang-runtime-3.6
445 (clang-runtime-from-llvm
447 "11qx8d3pbfqjaj2x207pvlvzihbs1z2xbw4crpz7aid6h1yz6bqg"
448 '("clang-runtime-asan-build-fixes.patch")))
450 (define-public clang-3.6
451 (clang-from-llvm llvm-3.6 clang-runtime-3.6
452 "1wwr8s6lzr324hv4s1k6na4j5zv6n9kdhi14s4kb9b13d93814df"
453 #:patches '("clang-3.5-libc-search-path.patch")))
455 (define-public llvm-3.5
456 (package (inherit llvm)
461 (uri (string-append "https://llvm.org/releases/"
462 version "/llvm-" version ".src.tar.xz"))
464 (search-patches "llvm-3.5-fix-clang-build-with-gcc5.patch"))
467 "0xf5q17kkxsrm2gsi93h4pwlv663kji73r2g4asb97klsmb626a4"))))))
469 (define-public clang-runtime-3.5
470 (clang-runtime-from-llvm
472 "1hsdnzzdr5kglz6fnv3lcsjs222zjsy14y8ax9dy6zqysanplbal"
473 '("clang-runtime-asan-build-fixes.patch"
474 "clang-3.5-libsanitizer-ustat-fix.patch")))
476 (define-public clang-3.5
477 (clang-from-llvm llvm-3.5 clang-runtime-3.5
478 "0846h8vn3zlc00jkmvrmy88gc6ql6014c02l4jv78fpvfigmgssg"
479 #:patches '("clang-3.5-libc-search-path.patch")))
481 (define-public llvm-for-extempore
482 (package (inherit llvm-3.7)
483 (name "llvm-for-extempore")
486 (inherit (package-source llvm-3.7))
487 (patches (list (search-patch "llvm-for-extempore.patch")))))
488 ;; Extempore refuses to build on architectures other than x86_64
489 (supported-systems '("x86_64-linux"))))
491 (define-public python-llvmlite
493 (name "python-llvmlite")
498 (uri (pypi-uri "llvmlite" version))
501 "1aq003zbyjnz4q1118h6qx5lfimc8s5fvgskl75j12gxd6pc78a8"))))
502 (build-system python-build-system)
508 (inherit (package-source llvm))
513 (uri (string-append "https://raw.githubusercontent.com/numba/"
514 "llvmlite/v" version "/conda-recipes/"
515 "D47188-svml-VF.patch"))
518 "0wxhgb61k17f0zg2m0726sf3hppm41f8jar2kkg2n8sl5cnjj9mr")))
521 (uri (string-append "https://raw.githubusercontent.com/numba/"
522 "llvmlite/v" version "/conda-recipes/"
523 "twine_cfg_undefined_behavior.patch"))
526 "07h71n2m1mn9zcfgw04zglffknplb233zqbcd6pckq0wygkrxflp")))))))))))
527 (home-page "http://llvmlite.pydata.org")
528 (synopsis "Wrapper around basic LLVM functionality")
530 "This package provides a Python binding to LLVM for use in Numba.")
531 (license license:bsd-3)))
533 (define (package-elisp-from-package source-package package-name
535 "Return a package definition named PACKAGE-NAME that packages the Emacs Lisp
536 SOURCE-FILES found in SOURCE-PACKAGE."
537 (let ((orig (package-source source-package)))
539 (inherit source-package)
541 (build-system emacs-build-system)
543 (method (origin-method orig))
544 (uri (origin-uri orig))
545 (sha256 (origin-sha256 orig))
546 (file-name (string-append package-name "-"
547 (package-version source-package)))
548 (modules '((guix build utils)
552 `(let* ((source-files (quote ,source-files))
553 (basenames (map basename source-files)))
555 source-files basenames)
556 (map delete-file-recursively
559 (append '("." "..") basenames)))
562 (define-public emacs-clang-format
565 (name "emacs-clang-format")
566 (build-system emacs-build-system)
571 (modify-phases %standard-phases
572 (add-after 'unpack 'configure
573 (lambda* (#:key inputs #:allow-other-keys)
574 (let ((clang (assoc-ref inputs "clang")))
575 (copy-file "tools/clang-format/clang-format.el" "clang-format.el")
576 (emacs-substitute-variables "clang-format.el"
577 ("clang-format-executable"
578 (string-append clang "/bin/clang-format"))))
580 (synopsis "Format code using clang-format")
581 (description "This package allows to filter code through @code{clang-format}
582 to fix its formatting. @code{clang-format} is a tool that formats
583 C/C++/Obj-C code according to a set of style options, see
584 @url{https://clang.llvm.org/docs/ClangFormatStyleOptions.html}.")))
586 (define-public emacs-clang-rename
589 (name "emacs-clang-rename")
590 (build-system emacs-build-system)
595 (modify-phases %standard-phases
596 (add-after 'unpack 'configure
597 (lambda* (#:key inputs #:allow-other-keys)
598 (let ((clang (assoc-ref inputs "clang")))
599 (copy-file "tools/clang-rename/clang-rename.el" "clang-rename.el")
600 (emacs-substitute-variables "clang-rename.el"
601 ("clang-rename-binary"
602 (string-append clang "/bin/clang-rename"))))
604 (synopsis "Rename every occurrence of a symbol using clang-rename")
605 (description "This package renames every occurrence of a symbol at point
606 using @code{clang-rename}.")))