1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2014, 2016 Eric Bavier <bavier@member.fsf.org>
3 ;;; Copyright © 2015 Mark H Weaver <mhw@netris.org>
4 ;;; Copyright © 2015 Ludovic Courtès <ludo@gnu.org>
5 ;;; Copyright © 2016 Dennis Mungai <dmngaie@gmail.com>
6 ;;; Copyright © 2016 Ricardo Wurmus <rekado@elephly.net>
8 ;;; This file is part of GNU Guix.
10 ;;; GNU Guix is free software; you can redistribute it and/or modify it
11 ;;; under the terms of the GNU General Public License as published by
12 ;;; the Free Software Foundation; either version 3 of the License, or (at
13 ;;; your option) any later version.
15 ;;; GNU Guix is distributed in the hope that it will be useful, but
16 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;;; GNU General Public License for more details.
20 ;;; You should have received a copy of the GNU General Public License
21 ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
23 (define-module (gnu packages llvm)
24 #:use-module (guix packages)
25 #:use-module ((guix licenses) #:prefix license:)
26 #:use-module (guix download)
27 #:use-module (guix utils)
28 #:use-module (guix build-system gnu)
29 #:use-module (guix build-system cmake)
30 #:use-module (gnu packages)
31 #:use-module (gnu packages gcc)
32 #:use-module (gnu packages bootstrap) ;glibc-dynamic-linker
33 #:use-module (gnu packages compression)
34 #:use-module (gnu packages libffi)
35 #:use-module (gnu packages perl)
36 #:use-module (gnu packages python)
37 #:use-module (gnu packages xml))
46 (uri (string-append "http://llvm.org/releases/"
47 version "/llvm-" version ".src.tar.xz"))
50 "1ybmnid4pw2hxn12ax5qa5kl1ldfns0njg8533y3mzslvd5cx0kf"))))
51 (build-system cmake-build-system)
53 `(("python" ,python-2) ;bytes->str conversion in clang>=3.7 needs python-2
56 `(("libffi" ,libffi)))
58 `(("zlib" ,zlib))) ;to use output from llvm-config
60 `(#:configure-flags '("-DCMAKE_SKIP_BUILD_RPATH=FALSE"
61 "-DCMAKE_BUILD_WITH_INSTALL_RPATH=FALSE"
62 "-DBUILD_SHARED_LIBS:BOOL=TRUE"
63 "-DLLVM_ENABLE_FFI:BOOL=TRUE")
65 ;; Don't use '-g' during the build, to save space.
66 #:build-type "Release"
67 #:phases (modify-phases %standard-phases
68 (add-before 'build 'shared-lib-workaround
69 ;; Even with CMAKE_SKIP_BUILD_RPATH=FALSE, llvm-tblgen
70 ;; doesn't seem to get the correct rpath to be able to run
71 ;; from the build directory. Set LD_LIBRARY_PATH as a
74 (setenv "LD_LIBRARY_PATH"
75 (string-append (getcwd) "/lib"))
77 (home-page "http://www.llvm.org")
78 (synopsis "Optimizing compiler infrastructure")
80 "LLVM is a compiler infrastructure designed for compile-time, link-time,
81 runtime, and idle-time optimization of programs from arbitrary programming
82 languages. It currently supports compilation of C and C++ programs, using
83 front-ends derived from GCC 4.0.1. A new front-end for the C family of
84 languages is in development. The compiler infrastructure includes mirror sets
85 of programming tools as well as libraries with equivalent functionality.")
86 (license license:ncsa)))
88 (define-public llvm-with-rtti
89 (package (inherit llvm)
90 (name "llvm-with-rtti")
92 (substitute-keyword-arguments (package-arguments llvm)
93 ((#:configure-flags flags)
94 `(append '("-DCMAKE_SKIP_BUILD_RPATH=FALSE"
95 "-DCMAKE_BUILD_WITH_INSTALL_RPATH=FALSE"
96 "-DLLVM_REQUIRES_RTTI=1")
99 (define (clang-runtime-from-llvm llvm hash)
101 (name "clang-runtime")
102 (version (package-version llvm))
106 (uri (string-append "http://llvm.org/releases/"
107 version "/compiler-rt-" version ".src.tar.xz"))
108 (sha256 (base32 hash))))
109 (build-system cmake-build-system)
110 (native-inputs (package-native-inputs llvm))
114 `(;; Don't use '-g' during the build to save space.
115 #:build-type "Release"
116 #:tests? #f)) ; Tests require gtest
117 (home-page "http://compiler-rt.llvm.org")
118 (synopsis "Runtime library for Clang/LLVM")
120 "The \"clang-runtime\" library provides the implementations of run-time
121 functions for C and C++ programs. It also provides header files that allow C
122 and C++ source code to interface with the \"sanitization\" passes of the clang
123 compiler. In LLVM this library is called \"compiler-rt\".")
124 (license license:ncsa)
126 ;; <http://compiler-rt.llvm.org/> doesn't list MIPS as supported.
127 (supported-systems (delete "mips64el-linux" %supported-systems))))
129 (define* (clang-from-llvm llvm clang-runtime hash
130 #:key (patches '("clang-libc-search-path.patch")))
133 (version (package-version llvm))
137 (uri (string-append "http://llvm.org/releases/"
138 version "/cfe-" version ".src.tar.xz"))
139 (sha256 (base32 hash))
140 (patches (map search-patch patches))))
141 ;; Using cmake allows us to treat llvm as an external library. There
142 ;; doesn't seem to be any way to do this with clang's autotools-based
144 (build-system cmake-build-system)
145 (native-inputs (package-native-inputs llvm))
147 `(("libxml2" ,libxml2)
148 ("gcc-lib" ,gcc "lib")
149 ,@(package-inputs llvm)))
152 ("clang-runtime" ,clang-runtime)))
155 (list "-DCLANG_INCLUDE_TESTS=True"
157 ;; Find libgcc_s, crtbegin.o, and crtend.o.
158 (string-append "-DGCC_INSTALL_PREFIX="
159 (assoc-ref %build-inputs "gcc-lib"))
161 ;; Use a sane default include directory.
162 (string-append "-DC_INCLUDE_DIRS="
163 (assoc-ref %build-inputs "libc")
166 ;; Don't use '-g' during the build to save space.
167 #:build-type "Release"
169 #:phases (modify-phases %standard-phases
171 'unpack 'set-glibc-file-names
172 (lambda* (#:key inputs #:allow-other-keys)
173 (let ((libc (assoc-ref inputs "libc"))
174 (compiler-rt (assoc-ref inputs "clang-runtime")))
175 (substitute* "lib/Driver/Tools.cpp"
176 ;; Patch the 'getLinuxDynamicLinker' function to that
177 ;; it uses the right dynamic linker file name.
178 (("/lib64/ld-linux-x86-64.so.2")
180 ,(glibc-dynamic-linker)))
182 ;; Link to libclang_rt files from clang-runtime.
183 (("TC\\.getDriver\\(\\)\\.ResourceDir")
184 (string-append "\"" compiler-rt "\"")))
186 ;; Same for libc's libdir, to allow crt1.o & co. to be
188 (substitute* "lib/Driver/ToolChains.cpp"
190 (string-append libc "/lib")))))))))
192 ;; Clang supports the same environment variables as GCC.
194 (list (search-path-specification
196 (files '("include")))
197 (search-path-specification
198 (variable "LIBRARY_PATH")
199 (files '("lib" "lib64")))))
201 (home-page "http://clang.llvm.org")
202 (synopsis "C language family frontend for LLVM")
204 "Clang is a compiler front end for the C, C++, Objective-C and
205 Objective-C++ programming languages. It uses LLVM as its back end. The Clang
206 project includes the Clang front end, the Clang static analyzer, and several
207 code analysis tools.")
208 (license license:ncsa)))
210 (define-public clang-runtime
211 (clang-runtime-from-llvm
213 "0p0y85c7izndbpg2l816z7z7558axq11d5pwkm4h11sdw7d13w0d"))
216 (clang-from-llvm llvm clang-runtime
217 "1prc72xmkgx8wrzmrr337776676nhsp1qd3mw2bvb22bzdnq7lsc"
218 #:patches '("clang-3.8-libc-search-path.patch")))
220 (define-public llvm-3.7
221 (package (inherit llvm)
226 (uri (string-append "http://llvm.org/releases/"
227 version "/llvm-" version ".src.tar.xz"))
230 "1masakdp9g2dan1yrazg7md5am2vacbkb3nahb3dchpc1knr8xxy"))))))
232 (define-public clang-runtime-3.7
233 (clang-runtime-from-llvm
235 "10c1mz2q4bdq9bqfgr3dirc6hz1h3sq8573srd5q5lr7m7j6jiwx"))
237 (define-public clang-3.7
238 (clang-from-llvm llvm-3.7 clang-runtime-3.7
239 "0x065d0w9b51xvdjxwfzjxng0gzpbx45fgiaxpap45ragi61dqjn"))
241 (define-public llvm-3.6
242 (package (inherit llvm)
247 (uri (string-append "http://llvm.org/releases/"
248 version "/llvm-" version ".src.tar.xz"))
251 "153vcvj8gvgwakzr4j0kndc0b7wn91c2g1vy2vg24s6spxcc23gn"))))))
253 (define-public clang-runtime-3.6
254 (clang-runtime-from-llvm
256 "11qx8d3pbfqjaj2x207pvlvzihbs1z2xbw4crpz7aid6h1yz6bqg"))
258 (define-public clang-3.6
259 (clang-from-llvm llvm-3.6 clang-runtime-3.6
260 "1wwr8s6lzr324hv4s1k6na4j5zv6n9kdhi14s4kb9b13d93814df"))
262 (define-public llvm-3.5
263 (package (inherit llvm)
268 (uri (string-append "http://llvm.org/releases/"
269 version "/llvm-" version ".src.tar.xz"))
272 "0xf5q17kkxsrm2gsi93h4pwlv663kji73r2g4asb97klsmb626a4"))))))
274 (define-public clang-runtime-3.5
275 (clang-runtime-from-llvm
277 "1hsdnzzdr5kglz6fnv3lcsjs222zjsy14y8ax9dy6zqysanplbal"))
279 (define-public clang-3.5
280 (clang-from-llvm llvm-3.5 clang-runtime-3.5
281 "0846h8vn3zlc00jkmvrmy88gc6ql6014c02l4jv78fpvfigmgssg"))
283 (define-public llvm-for-extempore
284 (package (inherit llvm-3.7)
287 (inherit (package-source llvm-3.7))
288 (patches (list (search-patch "llvm-for-extempore.patch")))))
289 ;; Extempore refuses to build on architectures other than x86_64
290 (supported-systems '("x86_64-linux"))))