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 Ricardo Wurmus <rekado@elephly.net>
7 ;;; Copyright © 2017 Roel Janssen <roel@gnu.org>
8 ;;; Copyright © 2018 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>
14 ;;; This file is part of GNU Guix.
16 ;;; GNU Guix is free software; you can redistribute it and/or modify it
17 ;;; under the terms of the GNU General Public License as published by
18 ;;; the Free Software Foundation; either version 3 of the License, or (at
19 ;;; your option) any later version.
21 ;;; GNU Guix is distributed in the hope that it will be useful, but
22 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
23 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 ;;; GNU General Public License for more details.
26 ;;; You should have received a copy of the GNU General Public License
27 ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
29 (define-module (gnu packages llvm)
30 #:use-module (guix packages)
31 #:use-module ((guix licenses) #:prefix license:)
32 #:use-module (guix download)
33 #:use-module (guix utils)
34 #:use-module (guix build-system gnu)
35 #:use-module (guix build-system cmake)
36 #:use-module (guix build-system emacs)
37 #:use-module (guix build-system python)
38 #:use-module (gnu packages)
39 #:use-module (gnu packages gcc)
40 #:use-module (gnu packages bootstrap) ;glibc-dynamic-linker
41 #:use-module (gnu packages compression)
42 #:use-module (gnu packages libffi)
43 #:use-module (gnu packages perl)
44 #:use-module (gnu packages python)
45 #:use-module (gnu packages xml))
54 (uri (string-append "http://llvm.org/releases/"
55 version "/llvm-" version ".src.tar.xz"))
58 "1qpls3vk85lydi5b4axl0809fv932qgsqgdgrk098567z4jc7mmn"))))
59 (build-system cmake-build-system)
61 `(("python" ,python-2) ;bytes->str conversion in clang>=3.7 needs python-2
64 `(("libffi" ,libffi)))
66 `(("zlib" ,zlib))) ;to use output from llvm-config
68 `(#:configure-flags '("-DCMAKE_SKIP_BUILD_RPATH=FALSE"
69 "-DCMAKE_BUILD_WITH_INSTALL_RPATH=FALSE"
70 "-DBUILD_SHARED_LIBS:BOOL=TRUE"
71 "-DLLVM_ENABLE_FFI:BOOL=TRUE"
72 "-DLLVM_REQUIRES_RTTI=1" ; For some third-party utilities
73 "-DLLVM_INSTALL_UTILS=ON") ; Needed for rustc.
75 ;; Don't use '-g' during the build, to save space.
76 #:build-type "Release"
77 #:phases (modify-phases %standard-phases
78 (add-before 'build 'shared-lib-workaround
79 ;; Even with CMAKE_SKIP_BUILD_RPATH=FALSE, llvm-tblgen
80 ;; doesn't seem to get the correct rpath to be able to run
81 ;; from the build directory. Set LD_LIBRARY_PATH as a
84 (setenv "LD_LIBRARY_PATH"
85 (string-append (getcwd) "/lib"))
87 (home-page "https://www.llvm.org")
88 (synopsis "Optimizing compiler infrastructure")
90 "LLVM is a compiler infrastructure designed for compile-time, link-time,
91 runtime, and idle-time optimization of programs from arbitrary programming
92 languages. It currently supports compilation of C and C++ programs, using
93 front-ends derived from GCC 4.0.1. A new front-end for the C family of
94 languages is in development. The compiler infrastructure includes mirror sets
95 of programming tools as well as libraries with equivalent functionality.")
96 (license license:ncsa)))
98 ;; TODO: Build Mesa with LLVM 7 in the next staging cycle.
99 ;; TODO: Make LLVM 7 the default LLVM once Clang is also upgraded.
100 (define-public llvm-7.0.1
101 (package (inherit llvm)
107 (uri (string-append "http://llvm.org/releases/"
108 version "/llvm-" version ".src.tar.xz"))
111 "16s196wqzdw4pmri15hadzqgdi926zln3an2viwyq0kini6zr3d3"))))))
113 ;; FIXME: This package is here to prevent many rebuilds on x86_64 and i686
114 ;; from commit fc9dbf41311d99d0fd8befc789ea7c0e35911890. Update users of
115 ;; this in the next rebuild cycle.
116 (define-public llvm-without-rtti
120 `(#:configure-flags '("-DCMAKE_SKIP_BUILD_RPATH=FALSE"
121 "-DCMAKE_BUILD_WITH_INSTALL_RPATH=FALSE"
122 "-DBUILD_SHARED_LIBS:BOOL=TRUE"
123 "-DLLVM_ENABLE_FFI:BOOL=TRUE"
124 "-DLLVM_INSTALL_UTILS=ON")
125 #:build-type "Release"
126 #:phases (modify-phases %standard-phases
127 (add-before 'build 'shared-lib-workaround
129 (setenv "LD_LIBRARY_PATH"
130 (string-append (getcwd) "/lib"))
133 (define* (clang-runtime-from-llvm llvm hash
134 #:optional (patches '()))
136 (name "clang-runtime")
137 (version (package-version llvm))
141 (uri (string-append "http://llvm.org/releases/"
142 version "/compiler-rt-" version ".src.tar.xz"))
143 (sha256 (base32 hash))
144 (patches (map search-patch patches))))
145 (build-system cmake-build-system)
146 (native-inputs (package-native-inputs llvm))
150 `(;; Don't use '-g' during the build to save space.
151 #:build-type "Release"
152 #:tests? #f)) ; Tests require gtest
153 (home-page "https://compiler-rt.llvm.org")
154 (synopsis "Runtime library for Clang/LLVM")
156 "The \"clang-runtime\" library provides the implementations of run-time
157 functions for C and C++ programs. It also provides header files that allow C
158 and C++ source code to interface with the \"sanitization\" passes of the clang
159 compiler. In LLVM this library is called \"compiler-rt\".")
160 (license license:ncsa)
162 ;; <https://compiler-rt.llvm.org/> doesn't list MIPS as supported.
163 (supported-systems (delete "mips64el-linux" %supported-systems))))
165 (define* (clang-from-llvm llvm clang-runtime hash
169 (version (package-version llvm))
173 (uri (string-append "http://llvm.org/releases/"
174 version "/cfe-" version ".src.tar.xz"))
175 (sha256 (base32 hash))
176 (patches (map search-patch patches))))
177 ;; Using cmake allows us to treat llvm as an external library. There
178 ;; doesn't seem to be any way to do this with clang's autotools-based
180 (build-system cmake-build-system)
181 (native-inputs (package-native-inputs llvm))
183 `(("libxml2" ,libxml2)
184 ("gcc-lib" ,gcc "lib")
185 ,@(package-inputs llvm)))
188 ("clang-runtime" ,clang-runtime)))
191 (list "-DCLANG_INCLUDE_TESTS=True"
193 ;; Find libgcc_s, crtbegin.o, and crtend.o.
194 (string-append "-DGCC_INSTALL_PREFIX="
195 (assoc-ref %build-inputs "gcc-lib"))
197 ;; Use a sane default include directory.
198 (string-append "-DC_INCLUDE_DIRS="
199 (assoc-ref %build-inputs "libc")
202 ;; Don't use '-g' during the build to save space.
203 #:build-type "Release"
205 #:phases (modify-phases %standard-phases
207 'unpack 'set-glibc-file-names
208 (lambda* (#:key inputs #:allow-other-keys)
209 (let ((libc (assoc-ref inputs "libc"))
210 (compiler-rt (assoc-ref inputs "clang-runtime")))
211 (case (string->number ,(version-major
212 (package-version clang-runtime)))
214 ;; Link to libclang_rt files from clang-runtime.
215 (substitute* "lib/Driver/ToolChain.cpp"
216 (("getDriver\\(\\)\\.ResourceDir")
217 (string-append "\"" compiler-rt "\"")))
219 ;; Make "LibDir" refer to <glibc>/lib so that it
220 ;; uses the right dynamic linker file name.
221 (substitute* "lib/Driver/ToolChains/Linux.cpp"
222 (("(^[[:blank:]]+LibDir = ).*" _ declaration)
223 (string-append declaration "\"" libc "/lib\";\n"))
225 ;; Make sure libc's libdir is on the search path, to
226 ;; allow crt1.o & co. to be found.
228 (string-append libc "/lib"))))
230 (substitute* "lib/Driver/Tools.cpp"
231 ;; Patch the 'getLinuxDynamicLinker' function so that
232 ;; it uses the right dynamic linker file name.
233 (("/lib64/ld-linux-x86-64.so.2")
235 ,(glibc-dynamic-linker))))
237 ;; Link to libclang_rt files from clang-runtime.
238 ;; This substitution needed slight adjustment in 3.8.
239 (if (< 3.8 (string->number ,(version-major+minor
242 (substitute* "lib/Driver/Tools.cpp"
243 (("TC\\.getDriver\\(\\)\\.ResourceDir")
244 (string-append "\"" compiler-rt "\"")))
245 (substitute* "lib/Driver/ToolChain.cpp"
246 (("getDriver\\(\\)\\.ResourceDir")
247 (string-append "\"" compiler-rt "\""))))
249 ;; Make sure libc's libdir is on the search path, to
250 ;; allow crt1.o & co. to be found.
251 (substitute* "lib/Driver/ToolChains.cpp"
253 (string-append libc "/lib")))))
255 (add-after 'install 'install-clean-up-/share/clang
256 (lambda* (#:key outputs #:allow-other-keys)
257 (let* ((out (assoc-ref outputs "out"))
258 (compl-dir (string-append
259 out "/etc/bash_completion.d")))
260 (with-directory-excursion (string-append out
264 (when (file-exists? file)
266 ;; Delete extensions for proprietary text editors.
267 '("clang-format-bbedit.applescript"
268 "clang-format-sublime.py"
269 ;; Delete Emacs extensions: see their respective Emacs
270 ;; Guix package instead.
271 "clang-rename.el" "clang-format.el"))
272 ;; Install bash completion.
273 (when (file-exists? "bash-autocomplete.sh")
275 (rename-file "bash-autocomplete.sh"
276 (string-append compl-dir "/clang")))))
279 ;; Clang supports the same environment variables as GCC.
281 (list (search-path-specification
283 (files '("include")))
284 (search-path-specification
285 (variable "LIBRARY_PATH")
286 (files '("lib" "lib64")))))
288 (home-page "https://clang.llvm.org")
289 (synopsis "C language family frontend for LLVM")
291 "Clang is a compiler front end for the C, C++, Objective-C and
292 Objective-C++ programming languages. It uses LLVM as its back end. The Clang
293 project includes the Clang front end, the Clang static analyzer, and several
294 code analysis tools.")
295 (license license:ncsa)))
297 (define-public clang-runtime
298 (clang-runtime-from-llvm
300 "1fcr3jn24yr8lh36nc0c4ikli4744i2q9m1ik67p1jymwwaixkgl"))
303 (clang-from-llvm llvm clang-runtime
304 "0rxn4rh7rrnsqbdgp4gzc8ishbkryhpl1kd3mpnxzpxxhla3y93w"
305 #:patches '("clang-6.0-libc-search-path.patch")))
307 (define-public llvm-3.9.1
308 (package (inherit llvm)
314 (uri (string-append "http://llvm.org/releases/"
315 version "/llvm-" version ".src.tar.xz"))
318 "1vi9sf7rx1q04wj479rsvxayb6z740iaz3qniwp266fgp5a07n8z"))))))
320 (define-public clang-runtime-3.9.1
321 (clang-runtime-from-llvm
323 "16gc2gdmp5c800qvydrdhsp0bzb97s8wrakl6i8a4lgslnqnf2fk"
324 '("clang-runtime-asan-build-fixes.patch"
325 "clang-runtime-esan-build-fixes.patch"
326 "clang-3.5-libsanitizer-ustat-fix.patch")))
328 (define-public clang-3.9.1
329 (clang-from-llvm llvm-3.9.1 clang-runtime-3.9.1
330 "0qsyyb40iwifhhlx9a3drf8z6ni6zwyk3bvh0kx2gs6yjsxwxi76"
331 #:patches '("clang-3.8-libc-search-path.patch")))
333 (define-public llvm-3.8
334 (package (inherit llvm)
340 (uri (string-append "https://llvm.org/releases/"
341 version "/llvm-" version ".src.tar.xz"))
344 "1ybmnid4pw2hxn12ax5qa5kl1ldfns0njg8533y3mzslvd5cx0kf"))))))
346 (define-public clang-runtime-3.8
347 (clang-runtime-from-llvm
349 "0p0y85c7izndbpg2l816z7z7558axq11d5pwkm4h11sdw7d13w0d"
350 '("clang-runtime-asan-build-fixes.patch"
351 "clang-3.5-libsanitizer-ustat-fix.patch")))
353 (define-public clang-3.8
354 (clang-from-llvm llvm-3.8 clang-runtime-3.8
355 "1prc72xmkgx8wrzmrr337776676nhsp1qd3mw2bvb22bzdnq7lsc"
356 #:patches '("clang-3.8-libc-search-path.patch")))
358 (define-public llvm-3.7
359 (package (inherit llvm)
364 (uri (string-append "http://llvm.org/releases/"
365 version "/llvm-" version ".src.tar.xz"))
368 "1masakdp9g2dan1yrazg7md5am2vacbkb3nahb3dchpc1knr8xxy"))))))
370 (define-public clang-runtime-3.7
371 (clang-runtime-from-llvm
373 "10c1mz2q4bdq9bqfgr3dirc6hz1h3sq8573srd5q5lr7m7j6jiwx"
374 '("clang-runtime-asan-build-fixes.patch"
375 "clang-3.5-libsanitizer-ustat-fix.patch")))
377 (define-public clang-3.7
378 (clang-from-llvm llvm-3.7 clang-runtime-3.7
379 "0x065d0w9b51xvdjxwfzjxng0gzpbx45fgiaxpap45ragi61dqjn"
380 #:patches '("clang-3.5-libc-search-path.patch")))
382 (define-public llvm-3.6
383 (package (inherit llvm)
388 (uri (string-append "http://llvm.org/releases/"
389 version "/llvm-" version ".src.tar.xz"))
392 "153vcvj8gvgwakzr4j0kndc0b7wn91c2g1vy2vg24s6spxcc23gn"))))))
394 (define-public clang-runtime-3.6
395 (clang-runtime-from-llvm
397 "11qx8d3pbfqjaj2x207pvlvzihbs1z2xbw4crpz7aid6h1yz6bqg"
398 '("clang-runtime-asan-build-fixes.patch")))
400 (define-public clang-3.6
401 (clang-from-llvm llvm-3.6 clang-runtime-3.6
402 "1wwr8s6lzr324hv4s1k6na4j5zv6n9kdhi14s4kb9b13d93814df"
403 #:patches '("clang-3.5-libc-search-path.patch")))
405 (define-public llvm-3.5
406 (package (inherit llvm)
411 (uri (string-append "http://llvm.org/releases/"
412 version "/llvm-" version ".src.tar.xz"))
414 (search-patches "llvm-3.5-fix-clang-build-with-gcc5.patch"))
417 "0xf5q17kkxsrm2gsi93h4pwlv663kji73r2g4asb97klsmb626a4"))))))
419 (define-public clang-runtime-3.5
420 (clang-runtime-from-llvm
422 "1hsdnzzdr5kglz6fnv3lcsjs222zjsy14y8ax9dy6zqysanplbal"
423 '("clang-runtime-asan-build-fixes.patch"
424 "clang-3.5-libsanitizer-ustat-fix.patch")))
426 (define-public clang-3.5
427 (clang-from-llvm llvm-3.5 clang-runtime-3.5
428 "0846h8vn3zlc00jkmvrmy88gc6ql6014c02l4jv78fpvfigmgssg"
429 #:patches '("clang-3.5-libc-search-path.patch")))
431 (define-public llvm-for-extempore
432 (package (inherit llvm-3.7)
433 (name "llvm-for-extempore")
436 (inherit (package-source llvm-3.7))
437 (patches (list (search-patch "llvm-for-extempore.patch")))))
438 ;; Extempore refuses to build on architectures other than x86_64
439 (supported-systems '("x86_64-linux"))))
441 (define-public python-llvmlite
443 (name "python-llvmlite")
448 (uri (pypi-uri "llvmlite" version))
451 "01zwjlc3c5mhrwmv4b73zgbskwqps9ly0nrh54bbj1f1l72f839j"))))
452 (build-system python-build-system)
458 (inherit (package-source llvm))
463 (uri (string-append "https://raw.githubusercontent.com/numba/"
464 "llvmlite/v" version "/conda-recipes/"
465 "D47188-svml.patch"))
468 "0mrj24jvkv3hjcmyg98zmvmyl1znlh2j63rdr69f6g7s96d2pfv1")))
471 (uri (string-append "https://raw.githubusercontent.com/numba/"
472 "llvmlite/v" version "/conda-recipes/"
473 "twine_cfg_undefined_behavior.patch"))
476 "07h71n2m1mn9zcfgw04zglffknplb233zqbcd6pckq0wygkrxflp")))))))))))
477 (home-page "http://llvmlite.pydata.org")
478 (synopsis "Wrapper around basic LLVM functionality")
480 "This package provides a Python binding to LLVM for use in Numba.")
481 (license license:bsd-3)))
483 (define (package-elisp-from-package source-package package-name
485 "Return a package definition named PACKAGE-NAME that packages the Emacs Lisp
486 SOURCE-FILES found in SOURCE-PACKAGE."
487 (let ((orig (package-source source-package)))
489 (inherit source-package)
491 (build-system emacs-build-system)
493 (method (origin-method orig))
494 (uri (origin-uri orig))
495 (sha256 (origin-sha256 orig))
496 (file-name (string-append package-name "-"
497 (package-version source-package)))
498 (modules '((guix build utils)
502 `(let* ((source-files (quote ,source-files))
503 (basenames (map basename source-files)))
505 source-files basenames)
506 (map delete-file-recursively
509 (append '("." "..") basenames)))
512 (define-public emacs-clang-format
515 (name "emacs-clang-format")
516 (build-system emacs-build-system)
521 (modify-phases %standard-phases
522 (add-after 'unpack 'configure
523 (lambda* (#:key inputs #:allow-other-keys)
524 (let ((clang (assoc-ref inputs "clang")))
525 (copy-file "tools/clang-format/clang-format.el" "clang-format.el")
526 (emacs-substitute-variables "clang-format.el"
527 ("clang-format-executable"
528 (string-append clang "/bin/clang-format"))))
530 (synopsis "Format code using clang-format")
531 (description "This package allows to filter code through @code{clang-format}
532 to fix its formatting. @code{clang-format} is a tool that formats
533 C/C++/Obj-C code according to a set of style options, see
534 @url{http://clang.llvm.org/docs/ClangFormatStyleOptions.html}.")))
536 (define-public emacs-clang-rename
539 (name "emacs-clang-rename")
540 (build-system emacs-build-system)
545 (modify-phases %standard-phases
546 (add-after 'unpack 'configure
547 (lambda* (#:key inputs #:allow-other-keys)
548 (let ((clang (assoc-ref inputs "clang")))
549 (copy-file "tools/clang-rename/clang-rename.el" "clang-rename.el")
550 (emacs-substitute-variables "clang-rename.el"
551 ("clang-rename-binary"
552 (string-append clang "/bin/clang-rename"))))
554 (synopsis "Rename every occurrence of a symbol using clang-rename")
555 (description "This package renames every occurrence of a symbol at point
556 using @code{clang-rename}.")))