projects/guix·blob ruby-team · refs

2919 lines · 119.7 KiB

1;;; GNU Guix --- Functional package management for GNU
2;;; Copyright © 2014, 2016, 2018 Eric Bavier <[email protected]>
3;;; Copyright © 2015 Mark H Weaver <[email protected]>
4;;; Copyright © 2015, 2017, 2018, 2019, 2020, 2021 Ludovic Courtès <[email protected]>
5;;; Copyright © 2016 Dennis Mungai <[email protected]>
6;;; Copyright © 2016, 2018, 2019, 2020, 2021, 2023, 2025 Ricardo Wurmus <[email protected]>
7;;; Copyright © 2017 Roel Janssen <[email protected]>
8;;; Copyright © 2018–2022 Marius Bakke <[email protected]>
9;;; Copyright © 2018, 2019 Tobias Geerinckx-Rice <[email protected]>
10;;; Copyright © 2018, 2021-2026 Efraim Flashner <[email protected]>
11;;; Copyright © 2018 Tim Gesthuizen <[email protected]>
12;;; Copyright © 2018 Pierre Neidhardt <[email protected]>
13;;; Copyright © 2019 Rutger Helling <[email protected]>
14;;; Copyright © 2019 Arm Ltd <[email protected]>
15;;; Copyright © 2019 Mathieu Othacehe <[email protected]>
16;;; Copyright © 2019 Brett Gilio <[email protected]>
17;;; Copyright © 2020 Giacomo Leidi <[email protected]>
18;;; Copyright © 2020 Jakub Kądziołka <[email protected]>
19;;; Copyright © 2021, 2022 Maxime Devos <[email protected]>
20;;; Copyright © 2020-2022, 2024-2025 Maxim Cournoyer <[email protected]>
21;;; Copyright © 2021 Julien Lepiller <[email protected]>
22;;; Copyright © 2021 Lars-Dominik Braun <[email protected]>
23;;; Copyright © 2021, 2022 Guillaume Le Vaillant <[email protected]>
24;;; Copyright © 2022, 2024 Greg Hogan <[email protected]>
25;;; Copyright © 2022, 2024, 2025 John Kehayias <[email protected]>
26;;; Copyright © 2022 Clément Lassieur <[email protected]>
27;;; Copyright © 2022 Zhu Zihao <[email protected]>
28;;; Copyright © 2023 Hilton Chain <[email protected]>
29;;; Copyright © 2023-2026 Zheng Junjie <[email protected]>
30;;; Copyright © 2024, 2025 Janneke Nieuwenhuizen <[email protected]>
31;;; Copyright © 2025 Andreas Enge <[email protected]>
32;;; Copyright © 2025 Liam Hupfer <[email protected]>
33;;; Copyright © 2025 dan <[email protected]>
34;;; Copyright © 2026 Sharlatan Hellseher <[email protected]>
35;;; Copyright © 2026 David Elsing <[email protected]>
36;;;
37;;; This file is part of GNU Guix.
38;;;
39;;; GNU Guix is free software; you can redistribute it and/or modify it
40;;; under the terms of the GNU General Public License as published by
41;;; the Free Software Foundation; either version 3 of the License, or (at
42;;; your option) any later version.
43;;;
44;;; GNU Guix is distributed in the hope that it will be useful, but
45;;; WITHOUT ANY WARRANTY; without even the implied warranty of
46;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
47;;; GNU General Public License for more details.
48;;;
49;;; You should have received a copy of the GNU General Public License
50;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
51
52(define-module (gnu packages llvm)
53 #:use-module (guix packages)
54 #:use-module ((guix licenses) #:prefix license:)
55 #:use-module (guix download)
56 #:use-module (guix gexp)
57 #:use-module (guix git-download)
58 #:use-module (guix memoization)
59 #:use-module (guix search-paths)
60 #:use-module (guix utils)
61 #:use-module (guix build-system cmake)
62 #:use-module (guix build-system emacs)
63 #:use-module (guix build-system gnu)
64 #:use-module (guix build-system pyproject)
65 #:use-module (guix build-system trivial)
66 #:use-module (gnu packages)
67 #:use-module (gnu packages autotools)
68 #:use-module (gnu packages base)
69 #:use-module (gnu packages cmake)
70 #:use-module (gnu packages bash)
71 #:use-module (gnu packages crypto)
72 #:use-module (gnu packages gcc)
73 #:use-module (gnu packages bootstrap) ;glibc-dynamic-linker
74 #:use-module (gnu packages check) ;python-lit
75 #:use-module (gnu packages compression)
76 #:use-module (gnu packages file)
77 #:use-module (gnu packages libedit)
78 #:use-module (gnu packages libffi)
79 #:use-module (gnu packages linux)
80 #:use-module (gnu packages llvm-meta)
81 #:use-module (gnu packages lua)
82 #:use-module (gnu packages mpi)
83 #:use-module (gnu packages ncurses)
84 #:use-module (gnu packages ocaml)
85 #:use-module (gnu packages onc-rpc)
86 #:use-module (gnu packages perl)
87 #:use-module (gnu packages pkg-config)
88 #:use-module (gnu packages python)
89 #:use-module (gnu packages python-build)
90 #:use-module (gnu packages rocm)
91 #:use-module (gnu packages swig)
92 #:use-module (gnu packages vulkan)
93 #:use-module (gnu packages xml)
94 #:use-module (srfi srfi-1)
95 #:use-module (srfi srfi-34)
96 #:use-module (srfi srfi-35)
97 #:use-module (ice-9 match)
98 #:export (make-lld-wrapper
99 system->llvm-target))
100
101;; Lazily resolve the gcc-toolchain to avoid a circular dependency.
102(define gcc-toolchain*
103 (delay (module-ref (resolve-interface '(gnu packages commencement))
104 'gcc-toolchain)))
105
106(define* (system->llvm-target #:optional
107 (system (or (and=> (%current-target-system)
108 gnu-triplet->nix-system)
109 (%current-system))))
110 "Return the LLVM target name that corresponds to SYSTEM, a system type such
111as \"x86_64-linux\"."
112 ;; See the 'lib/Target' directory of LLVM for a list of supported targets.
113 (match (system->llvm-target-arch system)
114 ("RISCV64" "RISCV")
115 ("X86_64" "X86")
116 (x x)))
117
118(define* (system->llvm-target-arch #:optional
119 (system (or (and=> (%current-target-system)
120 gnu-triplet->nix-system)
121 (%current-system))))
122 "Return the LLVM target arch name that corresponds to SYSTEM, a system type such
123as \"x86_64-linux\"."
124 ;; See the 'cmake/config-ix.cmake' file of LLVM for a list of supported targets arch.
125 ;; start with # Determine the native architecture.
126 (letrec-syntax ((matches (syntax-rules (=>)
127 ((_ (system-prefix => target) rest ...)
128 (if (string-prefix? system-prefix system)
129 target
130 (matches rest ...)))
131 ((_) #f))))
132 (matches ("aarch64" => "AArch64")
133 ("armhf" => "ARM")
134 ("mips64el" => "Mips")
135 ("powerpc" => "PowerPC")
136 ("riscv64" => "RISCV64")
137 ("x86_64" => "X86_64")
138 ("i686" => "X86")
139 ("i586" => "X86")
140 ("avr" => "AVR")
141 ("loongarch64" => "LoongArch"))))
142
143(define (llvm-uri component version)
144 ;; LLVM release candidate file names are formatted 'tool-A.B.C-rcN/tool-A.B.CrcN.src.tar.xz'
145 ;; so we specify the version as A.B.C-rcN and delete the hyphen when referencing the file name.
146 (string-append "https://github.com/llvm/llvm-project/releases/download"
147 "/llvmorg-" version "/" component "-" (string-delete #\- version) ".src.tar.xz"))
148
149(define %llvm-release-monitoring-url
150 "https://github.com/llvm/llvm-project/releases")
151
152(define* (clang-runtime-from-llvm llvm
153 #:optional
154 hash
155 (patches '()))
156 (package
157 (name "clang-runtime")
158 (version (package-version llvm))
159 (source
160 (if hash
161 (origin
162 (method url-fetch)
163 (uri (llvm-uri "compiler-rt" version))
164 (sha256 (base32 hash))
165 (patches (map search-patch patches)))
166 (llvm-monorepo (package-version llvm))))
167 (build-system cmake-build-system)
168 (native-inputs
169 (let ((native-inputs (modify-inputs (package-native-inputs llvm)
170 (prepend python-setuptools))))
171 (cond ((version>=? version "21")
172 (modify-inputs native-inputs
173 (prepend gcc-15)))
174 ((version>=? version "19")
175 native-inputs)
176 ((version>=? version "18")
177 ;; clang-18.1.8 doesn't build with gcc-14
178 ;; source/build/lib/fuzzer/libcxx_fuzzer_x86_64/include/c++/v1/__filesystem/path.h:534:52: error: use of built-in trait ‘__remove_pointer(typename std::__Fuzzer::decay<_Tp>::type)’ in function signature; use library traits instead
179 ;; clang-18.1.8 doesn't build with gcc-12
180 ;; source/build/lib/fuzzer/libcxx_fuzzer_x86_64/include/c++/v1/__type_traits/is_convertible.h:28:77: error: there are no arguments to ‘__is_convertible’ that depend on a template parameter, so a declaration of ‘__is_convertible’ must be available [-fpermissive]
181 (modify-inputs native-inputs
182 (prepend gcc-13)))
183 ((version>=? version "17")
184 ;; clang-17.0.6 doesn't build with gcc-14
185 ;; source/build/lib/fuzzer/libcxx_fuzzer_x86_64/include/c++/v1/__filesystem/path.h:623:30: error: use of built-in trait '__remove_pointer(typename std::__Fuzzer::decay<_Tp>::type)’ in function signature; use library traits instead
186 (modify-inputs native-inputs
187 (prepend gcc-13)))
188 ((version>=? version "16")
189 ;; clang-16.0.6 doesn't build with gcc-14:
190 ;; source/build/lib/fuzzer/libcxx_fuzzer_x86_64/include/c++/v1/__type_traits/make_unsigned.h:89:24: error: use of built-in trait ‘__remove_cv(_Tp)’ in function signature; use library traits instead
191 ;; clang-16.0.6 doesn't build with gcc-13:
192 ;; source/build/lib/fuzzer/libcxx_fuzzer_x86_64/include/c++/v1/__chrono/duration.h:202:28: note: no known conversion for argument 1 from ‘std::__Fuzzer::chrono::duration<long long int, std::__Fuzzer::ratio<1, 1000000000> >::rep’ {aka ‘long long int’} to ‘std::__Fuzzer::chrono::duration<long long int, std::__Fuzzer::ratio<1, 1000000000> >&&’
193 (modify-inputs native-inputs
194 (prepend gcc-12)))
195 (else native-inputs))))
196 (inputs
197 (append
198 (list llvm)
199 (if (version>=? version "15")
200 (list libffi)
201 '())
202 (if (member (version-major version) (list "10" "11"))
203 (list libxcrypt)
204 '())))
205 (arguments
206 `(;; Don't use '-g' during the build to save space.
207 #:build-type "Release"
208 #:tests? #f ; Tests require gtest
209 #:modules ((srfi srfi-1)
210 (ice-9 match)
211 ,@%cmake-build-system-modules)
212 #:phases (modify-phases (@ (guix build cmake-build-system) %standard-phases)
213 ,@(if hash
214 '()
215 '((add-after 'unpack 'change-directory
216 (lambda _
217 (chdir "compiler-rt")))))
218 (add-after 'set-paths 'hide-glibc
219 ;; Work around https://issues.guix.info/issue/36882. We need to
220 ;; remove glibc from CPLUS_INCLUDE_PATH so that the one hardcoded
221 ;; in GCC, at the bottom of GCC include search-path is used.
222 (lambda* (#:key inputs #:allow-other-keys)
223 (let* ((filters '("libc"))
224 (input-directories
225 (filter-map (lambda (input)
226 (match input
227 ((name . dir)
228 (and (not (member name filters))
229 dir))))
230 inputs)))
231 (set-path-environment-variable "CPLUS_INCLUDE_PATH"
232 '("include")
233 input-directories)
234 #t))))))
235 (home-page "https://compiler-rt.llvm.org")
236 (synopsis "Runtime library for Clang/LLVM")
237 (description
238 "The \"clang-runtime\" library provides the implementations of run-time
239functions for C and C++ programs. It also provides header files that allow C
240and C++ source code to interface with the \"sanitization\" passes of the clang
241compiler. In LLVM this library is called \"compiler-rt\".")
242 (license (package-license llvm))
243 (properties `((release-monitoring-url . ,%llvm-release-monitoring-url)
244 (upstream-name . "compiler-rt")))
245
246 ;; <https://compiler-rt.llvm.org/> doesn't list MIPS as supported.
247 (supported-systems (delete "mips64el-linux" %supported-systems))))
248
249(define* (clang-from-llvm llvm clang-runtime
250 #:optional hash
251 #:key (patches '()) tools-extra
252 (properties
253 (append `((release-monitoring-url
254 . ,%llvm-release-monitoring-url))
255 (clang-properties (package-version llvm))))
256 (legacy-build-shared-libs? #f))
257 "Produce Clang with dependencies on LLVM and CLANG-RUNTIME, and applying the
258given PATCHES. When TOOLS-EXTRA is given, And the version is less than 22, it
259must point to the 'clang-tools-extra' tarball, which contains code for
260'clang-tidy', 'pp-trace', 'modularize', and other tools, when the LLVM version
261is greater than 22, if TOOLS-EXTRA exists, the build process will use
262clang-tools-extra from the monorepo.
263LEGACY-BUILD-SHARED-LIBS? is used to configure the package to use the legacy
264BUILD_SHARED_LIBS CMake option, which was used until LLVM/Clang 14."
265 (package
266 (name "clang")
267 (version (package-version llvm))
268 (source
269 (if hash
270 (origin
271 (method url-fetch)
272 (uri (llvm-uri (if (version>=? version "9.0.1")
273 "clang"
274 "cfe")
275 version))
276 (sha256 (base32 hash))
277 (patches (map search-patch patches)))
278 (if patches
279 (let ((llvm-source (llvm-monorepo (package-version llvm))))
280 (origin
281 (inherit llvm-source)
282 (patches
283 (append (origin-patches llvm-source)
284 (map search-patch patches)))))
285 (llvm-monorepo (package-version llvm)))))
286 ;; Using cmake allows us to treat llvm as an external library. There
287 ;; doesn't seem to be any way to do this with clang's autotools-based
288 ;; build system.
289 (build-system cmake-build-system)
290 (native-inputs (package-native-inputs llvm))
291 (inputs
292 `(("libxml2" ,libxml2)
293 ("gcc-lib" ,gcc "lib")
294 ,@(package-inputs llvm)
295 ,@(if (and tools-extra (not (version>=? version "22")))
296 `(("clang-tools-extra" ,tools-extra))
297 '())))
298 (propagated-inputs
299 (list llvm clang-runtime))
300 (arguments
301 `(;; TODO: enable tests.
302 #:tests? #f
303
304 #:configure-flags
305 (list "-DCLANG_INCLUDE_TESTS=True"
306
307 ;; TODO: Use --gcc-install-dir when GCC_INSTALL_PREFIX is
308 ;; removed. See: https://github.com/llvm/llvm-project/pull/77537
309 ,@(if (version>=? version "19")
310 '("-DUSE_DEPRECATED_GCC_INSTALL_PREFIX=ON")
311 '())
312 ;; Find libgcc_s, crtbegin.o, and crtend.o.
313 (string-append "-DGCC_INSTALL_PREFIX="
314 (assoc-ref %build-inputs "gcc-lib"))
315
316 ;; Use a sane default include directory.
317 (string-append "-DC_INCLUDE_DIRS="
318 (assoc-ref %build-inputs "libc")
319 "/include")
320 ,@(if (target-riscv64?)
321 (list "-DLIBOMP_LIBFLAGS=-latomic"
322 "-DCMAKE_SHARED_LINKER_FLAGS=-latomic")
323 `())
324 ,@(if legacy-build-shared-libs?
325 '()
326 (list "-DCLANG_LINK_CLANG_DYLIB=ON")))
327
328 ,@(if (target-riscv64?)
329 `(#:make-flags '("LDFLAGS=-latomic"))
330 '())
331
332 ;; Don't use '-g' during the build to save space.
333 #:build-type "Release"
334
335 #:phases (modify-phases %standard-phases
336 ,@(if tools-extra
337 (if (version>=? version "22")
338 `((add-after 'unpack 'add-tools-extra
339 (lambda* (#:key inputs #:allow-other-keys)
340 (copy-recursively "../clang-tools-extra" "tools/extra"))))
341 `((add-after 'unpack 'add-tools-extra
342 (lambda* (#:key inputs #:allow-other-keys)
343 ;; Unpack the 'clang-tools-extra' tarball under
344 ;; tools/.
345 (let ((extra (assoc-ref inputs
346 "clang-tools-extra")))
347 (invoke "tar" "xf" extra)
348 (rename-file ,(string-append
349 "clang-tools-extra-"
350 (string-delete #\- (package-version llvm))
351 ".src")
352 "tools/extra")
353 ,@(if legacy-build-shared-libs?
354 ;; Build and link to shared libraries.
355 '((substitute* "cmake/modules/AddClang.cmake"
356 (("BUILD_SHARED_LIBS") "True")))
357 '())
358 #t)))))
359 '())
360 (add-after 'unpack 'add-missing-triplets
361 (lambda _
362 ;; Clang iterates through known triplets to search for
363 ;; GCC's headers, but does not recognize some of the
364 ;; triplets that are used in Guix.
365 (substitute* ,@(if (version>=? version "6.0")
366 '("lib/Driver/ToolChains/Gnu.cpp")
367 '("lib/Driver/ToolChains.cpp"))
368 (("\"aarch64-linux-gnu\"," all)
369 (string-append "\"aarch64-unknown-linux-gnu\", "
370 all))
371 (("\"arm-linux-gnueabihf\"," all)
372 (string-append all
373 " \"arm-unknown-linux-gnueabihf\","))
374 (("\"i686-pc-linux-gnu\"," all)
375 (string-append "\"i686-unknown-linux-gnu\", "
376 all)))
377 #t))
378 (add-after 'unpack 'set-glibc-file-names
379 (lambda* (#:key inputs #:allow-other-keys)
380 (let ((libc (assoc-ref inputs "libc"))
381 (compiler-rt (assoc-ref inputs "clang-runtime"))
382 (gcc (assoc-ref inputs "gcc")))
383 ,@(cond
384 ((version>=? version "6.0")
385 `(;; Link to libclang_rt files from clang-runtime.
386 (substitute* "lib/Driver/ToolChain.cpp"
387 (("getDriver\\(\\)\\.ResourceDir")
388 (string-append "\"" compiler-rt "\"")))
389
390 ;; Make "LibDir" refer to <glibc>/lib so that it
391 ;; uses the right dynamic linker file name.
392 (substitute* "lib/Driver/ToolChains/Linux.cpp"
393 (("(^[[:blank:]]+LibDir = ).*" _ declaration)
394 (string-append declaration "\"" libc "/lib\";\n"))
395
396 ;; Make clang look for libstdc++ in the right
397 ;; location.
398 (("LibStdCXXIncludePathCandidates\\[\\] = \\{")
399 (string-append
400 "LibStdCXXIncludePathCandidates[] = { \"" gcc
401 "/include/c++\","))
402
403 ;; Make sure libc's libdir is on the search path, to
404 ;; allow crt1.o & co. to be found.
405 (("@GLIBC_LIBDIR@")
406 (string-append libc "/lib")))))
407 (else
408 `((substitute* "lib/Driver/Tools.cpp"
409 ;; Patch the 'getLinuxDynamicLinker' function so that
410 ;; it uses the right dynamic linker file name.
411 (("/lib64/ld-linux-x86-64.so.2")
412 (string-append libc
413 ,(glibc-dynamic-linker))))
414
415 ;; Link to libclang_rt files from clang-runtime.
416 ;; This substitution needed slight adjustment in 3.8.
417 ,@(if (version>=? version "3.8")
418 '((substitute* "lib/Driver/Tools.cpp"
419 (("TC\\.getDriver\\(\\)\\.ResourceDir")
420 (string-append "\"" compiler-rt "\""))))
421 '((substitute* "lib/Driver/ToolChain.cpp"
422 (("getDriver\\(\\)\\.ResourceDir")
423 (string-append "\"" compiler-rt "\"")))))
424
425 ;; Make sure libc's libdir is on the search path, to
426 ;; allow crt1.o & co. to be found.
427 (substitute* "lib/Driver/ToolChains.cpp"
428 (("@GLIBC_LIBDIR@")
429 (string-append libc "/lib"))))))
430 #t)))
431 ,@(if (version>=? version "17")
432 '((add-after 'unpack 'include-test-runner
433 (lambda _
434 (substitute* "CMakeLists.txt"
435 ((".*llvm_gtest" line)
436 (string-append
437 "add_subdirectory(${LLVM_THIRD_PARTY_DIR}/uni\
438ttest third-party/unittest)\n" line))))))
439 '())
440 ;; The build daemon goes OOM on i686-linux on this phase.
441 ,@(if (and (version>=? version "15")
442 (target-x86-32?))
443 '((delete 'make-dynamic-linker-cache))
444 '())
445 ;; Awkwardly, multiple phases added after the same phase,
446 ;; e.g. unpack, get applied in the reverse order. In other
447 ;; words, adding 'change-directory last means it occurs
448 ;; first after the unpack phase.
449 ,@(if (version>=? version "14")
450 '((add-after 'unpack 'change-directory
451 (lambda _
452 (chdir "clang"))))
453 '())
454 ,@(if (version>=? version "10")
455 `((add-after 'install 'adjust-cmake-file
456 (lambda* (#:key outputs #:allow-other-keys)
457 (let ((out (assoc-ref outputs "out")))
458 ;; Clang generates a CMake file with "targets"
459 ;; for each installed library file. Downstream
460 ;; consumers of the CMake interface can use this
461 ;; to get absolute library locations. Including
462 ;; this file will needlessly assert that _all_
463 ;; libraries are available, which causes problems
464 ;; in Guix because some are removed (see the
465 ;; move-extra-tools phase). Thus, remove the
466 ;; asserts so that the main functionality works.
467 (substitute*
468 (string-append
469 out
470 "/lib/cmake/clang/ClangTargets-release.cmake")
471 (("list\\(APPEND _IMPORT_CHECK_TARGETS.*" all)
472 (string-append "# Disabled by Guix.\n#" all)))
473 #t))))
474 '())
475 ,@(if (version>? version "3.8")
476 `((add-after 'install 'symlink-cfi_ignorelist
477 (lambda* (#:key inputs outputs #:allow-other-keys)
478 (let* ((out (assoc-ref outputs "out"))
479 (lib-share (string-append out "/lib/clang/"
480 ,version "/share"))
481 (compiler-rt (assoc-ref inputs "clang-runtime"))
482 (file-name ,(if (version>=? version "13")
483 "cfi_ignorelist.txt"
484 "cfi_blacklist.txt"))
485 ;; The location varies between Clang versions.
486 (cfi-ignorelist
487 (cond
488 ((file-exists?
489 (string-append compiler-rt "/" file-name))
490 (string-append compiler-rt "/" file-name))
491 (else (string-append compiler-rt
492 "/share/" file-name)))))
493 (mkdir-p lib-share)
494 ;; Symlink the ignorelist to where Clang expects
495 ;; to find it.
496 ;; Not all architectures support CFI.
497 ;; see: compiler-rt/cmake/config-ix.cmake
498 (when (file-exists? cfi-ignorelist)
499 (symlink cfi-ignorelist
500 (string-append lib-share "/" file-name)))))))
501 '())
502 (add-after 'install 'install-clean-up-/share/clang
503 (lambda* (#:key outputs #:allow-other-keys)
504 (let* ((out (assoc-ref outputs "out"))
505 (compl-dir (string-append
506 out "/etc/bash_completion.d")))
507 (with-directory-excursion (string-append out
508 "/share/clang")
509 (for-each
510 (lambda (file)
511 (when (file-exists? file)
512 (delete-file file)))
513 ;; Delete extensions for proprietary text editors.
514 '("clang-format-bbedit.applescript"
515 "clang-format-sublime.py"
516 ;; Delete Emacs extensions: see their respective Emacs
517 ;; Guix package instead.
518 "clang-rename.el" "clang-format.el"))
519 ;; Install bash completion.
520 (when (file-exists? "bash-autocomplete.sh")
521 (mkdir-p compl-dir)
522 (rename-file "bash-autocomplete.sh"
523 (string-append compl-dir "/clang")))))
524 #t)))))
525
526 ;; Clang supports the same environment variables as GCC.
527 (native-search-paths %gcc-search-paths)
528
529 (home-page "https://clang.llvm.org")
530 (synopsis "C language family frontend for LLVM")
531 (description
532 "Clang is a compiler front end for the C, C++, Objective-C and
533Objective-C++ programming languages. It uses LLVM as its back end. The Clang
534project includes the Clang front end, the Clang static analyzer, and several
535code analysis tools.")
536 (properties properties)
537 (license (if (version>=? version "9.0")
538 license:asl2.0 ;with LLVM exceptions
539 license:ncsa))))
540
541(define (clang-properties version)
542 "Return package properties for Clang VERSION."
543 `((clang-compiler-cpu-architectures version)))
544
545(define-public (make-clang-toolchain clang libomp)
546 (package
547 (name (string-append (package-name clang) "-toolchain"))
548 (version (package-version clang))
549 (source #f)
550 (build-system trivial-build-system)
551 (arguments
552 '(#:modules ((guix build union))
553 #:builder (begin
554 (use-modules (ice-9 match)
555 (srfi srfi-26)
556 (guix build union))
557
558 (let ((out (assoc-ref %outputs "out")))
559
560 (match %build-inputs
561 (((names . directories) ...)
562 (union-build out directories)))
563
564 ;; Create 'cc' and 'c++' so that one can use it as a
565 ;; drop-in replacement for the default tool chain and
566 ;; have configure scripts find the compiler.
567 (symlink "clang" (string-append out "/bin/cc"))
568 (symlink "clang++" (string-append out "/bin/c++"))
569
570 (union-build (assoc-ref %outputs "debug")
571 (list (assoc-ref %build-inputs
572 "libc-debug")))
573 (union-build (assoc-ref %outputs "static")
574 (list (assoc-ref %build-inputs
575 "libc-static")))
576 #t))))
577
578 (native-search-paths
579 (append (package-native-search-paths clang)
580 (list (search-path-specification ;copied from glibc
581 (variable "GUIX_LOCPATH")
582 (files '("lib/locale"))))))
583 (search-paths (package-search-paths clang))
584
585 (license (package-license clang))
586 (properties (package-properties clang)) ;for 'compiler-cpu-architectures'
587 (home-page "https://clang.llvm.org")
588 (synopsis "Complete Clang toolchain for C/C++ development")
589 (description "This package provides a complete Clang toolchain for C/C++
590development to be installed in user profiles. This includes Clang, as well as
591libc (headers and binaries, plus debugging symbols in the @code{debug}
592output), and Binutils.")
593 (outputs '("out" "debug" "static"))
594 (inputs `(("clang" ,clang)
595 ("ld-wrapper" ,(car (assoc-ref (%final-inputs) "ld-wrapper")))
596 ("binutils" ,binutils)
597 ("libomp" ,libomp) ;used when linking with '-fopenmp'
598 ("libc" ,glibc)
599 ("libc-debug" ,glibc "debug")
600 ("libc-static" ,glibc "static")))))
601
602(define %llvm-monorepo-hashes
603 '(("14.0.6" . "14f8nlvnmdkp9a9a79wv67jbmafvabczhah8rwnqrgd5g3hfxxxx")
604 ("15.0.7" . "12sggw15sxq1krh1mfk3c1f07h895jlxbcifpwk3pznh4m1rjfy2")
605 ("16.0.6" . "0jxmapg7shwkl88m4mqgfjv4ziqdmnppxhjz6vz51ycp2x4nmjky")
606 ("17.0.6" . "1a7rq3rgw5vxm8y39fyzr4kv7w97lli4a0c1qrkchwk8p0n07hgh")
607 ("18.1.8" . "1l9wm0g9jrpdf309kxjx7xrzf13h81kz8bbp0md14nrz38qll9la")
608 ("19.1.7" . "18hkfhsm88bh3vnj21q7f118vrcnf7z6q1ylnwbknyb3yvk0343i")
609 ("20.1.8" . "0v0lwf58i96vcwsql3hlgy72z3ncfvqwgyghyn26m2ri8vy83k6a")
610 ("21.1.8" . "0v99a90546lrd3cxgam32c0jcnwzi0ljk0ihdvd9xghzss1pq1x6")
611 ("22.1.8" . "1rww5cs3rw2yyjnz84ywlpkcvh46p1m9ac1nkhwprjbjw2vwv20q")))
612
613(define %llvm-patches
614 '(("14.0.6" . ("clang-14.0-libc-search-path.patch"
615 "clang-runtime-14-glibc-2.36-compat.patch"
616 "clang-14-remove-crypt-interceptors.patch"))
617 ("15.0.7" . ("clang-15.0-libc-search-path.patch"
618 "clang-16-remove-crypt-interceptors.patch"))
619 ("16.0.6" . ("clang-16.0-libc-search-path.patch"
620 "clang-16-remove-crypt-interceptors.patch"))
621 ("17.0.6" . ("clang-17.0-libc-search-path.patch"
622 "clang-17.0-link-dsymutil-latomic.patch"))
623 ("18.1.8" . ("clang-18.0-libc-search-path.patch"
624 "clang-17.0-link-dsymutil-latomic.patch"))
625 ("19.1.7" . ("clang-18.0-libc-search-path.patch"
626 "clang-17.0-link-dsymutil-latomic.patch"))
627 ("20.1.8" . ("clang-18.0-libc-search-path.patch"
628 "clang-17.0-link-dsymutil-latomic.patch"))
629 ("21.1.8" . ("clang-18.0-libc-search-path.patch"
630 "clang-17.0-link-dsymutil-latomic.patch"))
631 ("22.1.8" . ("clang-18.0-libc-search-path.patch"
632 "clang-17.0-link-dsymutil-latomic.patch"
633 "llvm-22-cfloat128-detection.patch"))))
634
635(define (llvm-monorepo version)
636 (origin
637 (method git-fetch)
638 (uri (git-reference
639 (url "https://github.com/llvm/llvm-project")
640 (commit (string-append "llvmorg-" version))))
641 (file-name (git-file-name "llvm-project" version))
642 (sha256 (base32 (assoc-ref %llvm-monorepo-hashes version)))
643 (patches (map search-patch (assoc-ref %llvm-patches version)))))
644
645;; A base llvm package that can be used for creating other llvm packages.
646(define make-llvm
647 (mlambda (version)
648 (package
649 (name "llvm")
650 (version version)
651 (source (llvm-monorepo version))
652 (build-system cmake-build-system)
653 (outputs '("out" "opt-viewer"))
654 (arguments
655 (list
656 #:tests? (not (or (%current-target-system)
657 (target-x86-32?)))
658 #:configure-flags
659 #~(list
660 ;; These options are required for cross-compiling LLVM according
661 ;; to <https://llvm.org/docs/HowToCrossCompileLLVM.html>.
662 #$@(if (%current-target-system)
663 (or (and=>
664 (system->llvm-target-arch)
665 (lambda (llvm-target-arch)
666 #~((string-append "-DLLVM_TABLEGEN="
667 #+(file-append this-package
668 "/bin/llvm-tblgen"))
669 #$@(if (version>=? version "16.0")
670 #~((string-append
671 "-DLLVM_NATIVE_TOOL_DIR="
672 #+(file-append this-package "/bin")))
673 #~())
674 #$@(if (version>=? version "17.0")
675 #~((string-append "-DLLVM_HOST_TRIPLE="
676 #$(%current-target-system)))
677 #~((string-append "-DLLVM_DEFAULT_TARGET_TRIPLE="
678 #$(%current-target-system))
679 (string-append "-DLLVM_TARGET_ARCH="
680 #$llvm-target-arch)))
681 #$(string-append "-DLLVM_TARGETS_TO_BUILD="
682 (system->llvm-target)))))
683 (raise (condition
684 (&package-unsupported-target-error
685 (package this-package)
686 (target (%current-target-system))))))
687 '())
688 ;; Note: sadly, the build system refuses the use of
689 ;; -DBUILD_SHARED_LIBS=ON and the large static archives are needed to
690 ;; build clang-runtime, so we cannot delete them.
691 "-DLLVM_BUILD_LLVM_DYLIB=ON"
692 "-DLLVM_LINK_LLVM_DYLIB=ON"
693 "-DLLVM_ENABLE_FFI=ON"
694 "-DLLVM_ENABLE_RTTI=ON" ;for some third-party utilities
695 "-DLLVM_INSTALL_UTILS=ON" ;needed for rustc
696 "-DLLVM_PARALLEL_LINK_JOBS=1") ;cater to smaller build machines
697 ;; Don't use '-g' during the build, to save space.
698 #:build-type "Release"
699 #:modules '((guix build cmake-build-system)
700 ((guix build gnu-build-system) #:prefix gnu:)
701 (guix build utils))
702 #:phases
703 #~(modify-phases %standard-phases
704 (add-after 'unpack 'change-directory
705 (lambda _
706 (chdir "llvm")))
707 (replace 'check
708 (lambda* (#:rest args)
709 (setenv "HOME" "/tmp")
710 (apply (assoc-ref gnu:%standard-phases 'check)
711 #:test-target "check-llvm" args)))
712 (add-after 'install 'install-opt-viewer
713 (lambda* (#:key outputs #:allow-other-keys)
714 (let* ((opt-viewer-share (string-append #$output:opt-viewer
715 "/share")))
716 (mkdir-p opt-viewer-share)
717 (rename-file (string-append #$output "/share/opt-viewer")
718 opt-viewer-share))))
719 ;; The build daemon goes OOM on i686-linux on this phase.
720 #$@(if (and (version>=? version "15.0")
721 (target-x86-32?))
722 #~((delete 'make-dynamic-linker-cache))
723 #~()))))
724 (native-inputs (list python-wrapper perl))
725 (inputs (list libffi))
726 (propagated-inputs (list zlib)) ;to use output from llvm-config
727 (home-page "https://www.llvm.org")
728 (synopsis "Optimizing compiler infrastructure")
729 (description
730 "LLVM is a compiler infrastructure designed for compile-time, link-time,
731runtime, and idle-time optimization of programs from arbitrary programming
732languages. It currently supports compilation of C and C++ programs, using
733front-ends derived from GCC 4.0.1. A new front-end for the C family of
734languages is in development. The compiler infrastructure includes mirror sets
735of programming tools as well as libraries with equivalent functionality.")
736 (license license:asl2.0)
737 (properties `((release-monitoring-url . ,%llvm-release-monitoring-url))))))
738
739(define-public llvm-15
740 (make-llvm "15.0.7"))
741
742(define-public llvm-14
743 (package
744 (inherit llvm-15)
745 (version "14.0.6")
746 (source (llvm-monorepo version))
747 (arguments
748 (list
749 #:modules '((guix build cmake-build-system)
750 ((guix build gnu-build-system) #:prefix gnu:)
751 (guix build utils))
752 #:tests? (not (or (%current-target-system)
753 (target-x86-32?)))
754 #:configure-flags
755 #~(list
756 ;; These options are required for cross-compiling LLVM according
757 ;; to <https://llvm.org/docs/HowToCrossCompileLLVM.html>.
758 #$@(if (%current-target-system)
759 (or (and=>
760 (system->llvm-target-arch)
761 (lambda (llvm-target-arch)
762 #~((string-append "-DLLVM_TABLEGEN="
763 #+(file-append this-package
764 "/bin/llvm-tblgen"))
765 #$(string-append "-DLLVM_DEFAULT_TARGET_TRIPLE="
766 (%current-target-system))
767 #$(string-append "-DLLVM_TARGET_ARCH=" llvm-target-arch)
768 #$(string-append "-DLLVM_TARGETS_TO_BUILD="
769 (system->llvm-target)))))
770 (raise (condition
771 (&package-unsupported-target-error
772 (package this-package)
773 (target (%current-target-system))))))
774 '())
775 ;; undefined reference to `__atomic_fetch_add_8' in lib/libLLVMOrcJIT.so.14
776 #$@(if (target-ppc32?)
777 (list "-DCMAKE_SHARED_LINKER_FLAGS=-latomic")
778 `())
779 "-DCMAKE_SKIP_BUILD_RPATH=FALSE"
780 "-DCMAKE_BUILD_WITH_INSTALL_RPATH=FALSE"
781 "-DBUILD_SHARED_LIBS:BOOL=TRUE"
782 "-DLLVM_ENABLE_FFI:BOOL=TRUE"
783 "-DLLVM_ENABLE_RTTI:BOOL=TRUE" ;for some third-party utilities
784 "-DLLVM_INSTALL_UTILS=ON") ;needed for rustc
785 ;; Don't use '-g' during the build, to save space.
786 #:build-type "Release"
787 #:phases
788 #~(modify-phases %standard-phases
789 (add-after 'unpack 'change-directory
790 (lambda _
791 (chdir "llvm")))
792 (replace 'check
793 (lambda* (#:rest args)
794 (setenv "HOME" "/tmp")
795 (apply (assoc-ref gnu:%standard-phases 'check)
796 #:test-target "check-llvm" args)))
797 (add-after 'install 'install-opt-viewer
798 (lambda* (#:key outputs #:allow-other-keys)
799 (let* ((out (assoc-ref outputs "out"))
800 (opt-viewer-out (assoc-ref outputs "opt-viewer"))
801 (opt-viewer-share-dir (string-append opt-viewer-out "/share"))
802 (opt-viewer-dir (string-append opt-viewer-share-dir "/opt-viewer")))
803 (mkdir-p opt-viewer-share-dir)
804 (rename-file (string-append out "/share/opt-viewer")
805 opt-viewer-dir)))))))
806
807 (native-inputs (list perl python-wrapper which))))
808
809(define-public clang-runtime-15
810 (clang-runtime-from-llvm llvm-15))
811
812(define-public clang-runtime-14
813 (clang-runtime-from-llvm llvm-14))
814
815(define-public clang-15
816 (clang-from-llvm
817 llvm-15 clang-runtime-15
818 #:tools-extra
819 (origin
820 (method url-fetch)
821 (uri (llvm-uri "clang-tools-extra"
822 (package-version llvm-15)))
823 (sha256
824 (base32
825 "1lagnspm5limxh1cp5jlixnzlhf09905d4rqra1kpgj6dps2x6l0")))))
826
827(define-public clang-14
828 (clang-from-llvm
829 llvm-14 clang-runtime-14
830 #:legacy-build-shared-libs? #t
831 #:tools-extra
832 (origin
833 (method url-fetch)
834 (uri (llvm-uri "clang-tools-extra"
835 (package-version llvm-14)))
836 (sha256
837 (base32
838 "0rhq4wkmvr369nkk059skzzw7jx6qhzqhmiwmqg4sp66avzviwvw")))))
839
840(define-public libomp-15
841 (package
842 (name "libomp")
843 (version (package-version llvm-15))
844 (source (llvm-monorepo version))
845 (build-system cmake-build-system)
846 ;; XXX: Note this gets built with GCC because building with Clang itself
847 ;; fails (missing <atomic>, even when libcxx is added as an input.)
848 (arguments
849 (list
850 #:configure-flags
851 #~(list "-DLIBOMP_USE_HWLOC=ON"
852 "-DOPENMP_TEST_C_COMPILER=clang"
853 "-DOPENMP_TEST_CXX_COMPILER=clang++")
854 #:modules '((guix build cmake-build-system)
855 ((guix build gnu-build-system) #:prefix gnu:)
856 (guix build utils))
857 #:phases
858 #~(modify-phases %standard-phases
859 (add-after 'unpack 'chdir-to-source-and-install-license
860 (lambda _
861 (chdir "openmp")
862 (install-file "LICENSE.TXT"
863 (string-append #$output "/share/doc"))))
864 (replace 'check
865 (lambda* (#:rest args)
866 (apply (assoc-ref gnu:%standard-phases 'check)
867 #:test-target "check-libomp" args))))))
868 (native-inputs (list clang-15 llvm-15 perl pkg-config python))
869 (inputs (list `(,hwloc "lib")))
870 (home-page "https://openmp.llvm.org")
871 (synopsis "OpenMP run-time support library")
872 (description "This package provides the run-time support library developed
873by the LLVM project for the OpenMP multi-theaded programming extension. This
874package notably provides @file{libgomp.so}, which is has a binary interface
875compatible with that of libgomp, the GNU Offloading and Multi Processing
876Library.")
877 (properties `((release-monitoring-url . ,%llvm-release-monitoring-url)
878 (upstream-name . "openmp")))
879 (license license:expat)))
880
881(define-public clang-toolchain-15
882 (make-clang-toolchain clang-15 libomp-15))
883
884(define-public libomp-14
885 (package
886 (inherit libomp-15)
887 (version (package-version llvm-14))
888 (source (origin
889 (method url-fetch)
890 (uri (llvm-uri "openmp" version))
891 (sha256
892 (base32
893 "07zby3gwy5c8jssabrhjk3nsxlwipnm6sk4dsvck1l5d0br1ywsg"))
894 (file-name (string-append "libomp-" version ".tar.xz"))))
895 (arguments
896 (substitute-keyword-arguments arguments
897 ((#:phases phases)
898 #~(modify-phases #$phases
899 (replace 'chdir-to-source-and-install-license
900 (lambda _
901 (chdir #$(string-append "../openmp-" version ".src"))
902 (install-file "LICENSE.TXT"
903 (string-append #$output "/share/doc"))))))))
904 (native-inputs
905 (modify-inputs native-inputs
906 (replace "clang" clang-14)
907 (replace "llvm" llvm-14)))))
908
909(define-public clang-toolchain-14
910 (make-clang-toolchain clang-14 libomp-14))
911
912(define-public llvm-13
913 (package
914 (inherit llvm-14)
915 (version "13.0.1")
916 (source
917 (origin
918 (method url-fetch)
919 (uri (llvm-uri "llvm" version))
920 (sha256
921 (base32
922 "0d681xiixmx9inwvz14vi3xsznrcryk06a8rvk9cljiq5kc80szc"))
923 (patches (search-patches "llvm-13-gcc-14.patch"))))
924 (arguments
925 (substitute-keyword-arguments arguments
926 ((#:tests? _ #t)
927 ;; The tests on riscv64 error on the differences between
928 ;; generic and generic-rv64.
929 (not (or (%current-target-system)
930 (target-x86-32?)
931 (target-riscv64?))))
932 ((#:phases phases '%standard-phases)
933 #~(modify-phases #$phases
934 (delete 'change-directory)))))
935 (properties `((release-monitoring-url . ,%llvm-release-monitoring-url)))))
936
937(define-public clang-runtime-13
938 (clang-runtime-from-llvm
939 llvm-13
940 "1z2xr9nn4mgc3hn9ark2k5y4wznpk47xppkp63bcbagr6589acvv"
941 '("clang-runtime-13-glibc-2.36-compat.patch"
942 "clang-13-remove-crypt-interceptors.patch")))
943
944(define-public clang-13
945 (clang-from-llvm llvm-13 clang-runtime-13
946 "1j8pr5kk8iqyb4jds3yl7c6x672617h4ngkpl4575j7mk4nrwykq"
947 #:legacy-build-shared-libs? #t
948 #:patches '("clang-13.0-libc-search-path.patch")
949 #:tools-extra
950 (origin
951 (method url-fetch)
952 (uri (llvm-uri "clang-tools-extra"
953 (package-version llvm-13)))
954 (sha256
955 (base32
956 "1l4jjdqfl9hrh0fwzv27hc263zc6x61h09vs4ni3yla8i1cwhayc")))))
957
958(define-public libomp-13
959 (package
960 (inherit libomp-14)
961 (version (package-version llvm-13))
962 (source (origin
963 (method url-fetch)
964 (uri (llvm-uri "openmp" version))
965 (sha256
966 (base32
967 "0kvbr4j6ldpssiv7chgqra5y77n7jwbyxlwcl7z32v31f49jcybb"))
968 (file-name (string-append "libomp-" version ".tar.xz"))))
969 (arguments
970 (substitute-keyword-arguments arguments
971 ((#:configure-flags flags)
972 ;; Work around faulty target detection, fixed in 14:
973 ;; https://github.com/llvm/llvm-project/issues/52910
974 #~(cons* "-DLIBOMPTARGET_BUILD_AMDGCN_BCLIB=OFF" #$flags))
975 ((#:phases phases)
976 #~(modify-phases #$phases
977 (delete 'chdir-to-source-and-install-license)))))
978 (native-inputs
979 (modify-inputs native-inputs
980 (replace "clang" clang-13)
981 (replace "llvm" llvm-13)))))
982
983(define-public clang-toolchain-13
984 (make-clang-toolchain clang-13 libomp-13))
985
986(define-public llvm-12
987 (package
988 (inherit llvm-13)
989 (version "12.0.1")
990 (source
991 (origin
992 (method url-fetch)
993 (uri (llvm-uri "llvm" version))
994 (sha256
995 (base32
996 "1pzx9zrmd7r3481sbhwvkms68fwhffpp4mmz45dgrkjpyl2q96kx"))
997 (patches (search-patches "llvm-13-gcc-14.patch"))))
998 (arguments
999 (substitute-keyword-arguments arguments
1000 ;; Disable tests for old releases now compiled with newer GCC.
1001 ((#:tests? _ #false) #false)
1002 ((#:phases phases)
1003 #~(modify-phases #$phases
1004 #$@(if (assoc "config" (package-native-inputs this-package))
1005 #~((add-after 'unpack 'update-config
1006 (lambda* (#:key inputs native-inputs #:allow-other-keys)
1007 (let ((config.guess (search-input-file
1008 (or inputs native-inputs)
1009 "/bin/config.guess")))
1010 (copy-file config.guess "cmake/config.guess")))))
1011 #~())
1012 (add-after 'unpack 'delete-failing-tests
1013 (lambda _
1014 (delete-file "test/DebugInfo/X86/vla-multi.ll")))
1015 (add-before 'build 'shared-lib-workaround
1016 ;; Even with CMAKE_SKIP_BUILD_RPATH=FALSE, llvm-tblgen
1017 ;; doesn't seem to get the correct rpath to be able to run
1018 ;; from the build directory. Set LD_LIBRARY_PATH as a
1019 ;; workaround.
1020 (lambda _
1021 (setenv "LD_LIBRARY_PATH"
1022 (string-append (getcwd) "/lib"))))))))))
1023
1024(define-public llvm-16
1025 (make-llvm "16.0.6"))
1026
1027(define-public clang-runtime-16
1028 (clang-runtime-from-llvm llvm-16))
1029
1030(define-public clang-16
1031 (clang-from-llvm
1032 llvm-16 clang-runtime-16
1033 #:tools-extra
1034 (origin
1035 (method url-fetch)
1036 (uri (llvm-uri "clang-tools-extra"
1037 (package-version llvm-16)))
1038 (sha256
1039 (base32
1040 "0cbgffciql06a1i0ybyyqbnkkr4g7x8cxaar5a5v3415vd27hk0p")))))
1041
1042(define-public libomp-16
1043 (package
1044 (inherit libomp-15)
1045 (version (package-version llvm-16))
1046 (source (llvm-monorepo version))
1047 (native-inputs
1048 (modify-inputs native-inputs
1049 (replace "clang" clang-16)
1050 (replace "llvm" llvm-16)))))
1051
1052(define-public clang-toolchain-16
1053 (make-clang-toolchain clang-16 libomp-16))
1054
1055(define-public llvm-17
1056 (make-llvm "17.0.6"))
1057
1058(define-public clang-runtime-17
1059 (clang-runtime-from-llvm llvm-17))
1060
1061(define-public clang-17
1062 (clang-from-llvm
1063 llvm-17 clang-runtime-17
1064 #:patches '("clang-17.0-fix-build-with-gcc-14-on-arm.patch")
1065 #:tools-extra
1066 (origin
1067 (method url-fetch)
1068 (uri (llvm-uri "clang-tools-extra"
1069 (package-version llvm-17)))
1070 (sha256
1071 (base32
1072 "1f8szx762c325916gjxb5lw7zxyidynwnvx6fxxqscsx8514cxxa")))))
1073
1074(define-public libomp-17
1075 (package
1076 (inherit libomp-15)
1077 (version (package-version llvm-17))
1078 (source (llvm-monorepo version))
1079 (native-inputs
1080 (modify-inputs native-inputs
1081 (replace "clang" clang-17)
1082 (replace "llvm" llvm-17)))))
1083
1084(define-public clang-toolchain-17
1085 (make-clang-toolchain clang-17 libomp-17))
1086
1087(define-public llvm-18
1088 (package
1089 (inherit llvm-15)
1090 (version "18.1.8")
1091 (source (llvm-monorepo version))
1092 (arguments
1093 (substitute-keyword-arguments arguments
1094 ((#:modules modules '((guix build cmake-build-system)
1095 (guix build utils)))
1096 (if (%current-target-system)
1097 `((ice-9 regex)
1098 (srfi srfi-1)
1099 (srfi srfi-26)
1100 ,@modules)
1101 modules))
1102 ;; TODO: Figure out why some tests fail on some architectures.
1103 ((#:tests? current-test-config #t)
1104 (and current-test-config
1105 (not (target-ppc64le?))
1106 (not (target-arm32?))))
1107 ((#:configure-flags cf #~'())
1108 (if (%current-target-system)
1109 ;; Use a newer version of llvm-tblgen and add the new
1110 ;; configure-flag needed for cross-building.
1111 #~(cons* (string-append "-DLLVM_TABLEGEN="
1112 #+(file-append this-package
1113 "/bin/llvm-tblgen"))
1114 (string-append "-DLLVM_NATIVE_TOOL_DIR="
1115 #+(file-append this-package "/bin"))
1116 (string-append "-DLLVM_HOST_TRIPLE="
1117 #$(%current-target-system))
1118 (remove
1119 (cut string-match
1120 "-DLLVM_(DEFAULT_TARGET|TARGET_ARCH|TABLEGEN).*" <>)
1121 #$cf))
1122 cf))
1123 ;; The build daemon goes OOM on i686-linux on this phase.
1124 ((#:phases phases #~'%standard-phases)
1125 (if (target-x86-32?)
1126 #~(modify-phases #$phases
1127 (delete 'make-dynamic-linker-cache))
1128 phases))))))
1129
1130(define-public clang-runtime-18
1131 (clang-runtime-from-llvm llvm-18))
1132
1133(define-public clang-18
1134 (clang-from-llvm
1135 llvm-18 clang-runtime-18
1136 #:tools-extra
1137 (origin
1138 (method url-fetch)
1139 (uri (llvm-uri "clang-tools-extra"
1140 (package-version llvm-18)))
1141 (sha256
1142 (base32
1143 "1wd7y1a0db4y51swlq6dmm9hrv8pvmv158yi9f10dlayv7y7g275")))))
1144
1145(define-public libomp-18
1146 (package
1147 (inherit libomp-15)
1148 (version (package-version llvm-18))
1149 (source (llvm-monorepo version))
1150 (native-inputs
1151 (modify-inputs native-inputs
1152 (replace "clang" clang-18)
1153 (replace "llvm" llvm-18)))))
1154
1155(define-public clang-toolchain-18
1156 (make-clang-toolchain clang-18 libomp-18))
1157
1158(define-public llvm-19
1159 (make-llvm "19.1.7"))
1160
1161(define-public clang-runtime-19
1162 (clang-runtime-from-llvm llvm-19))
1163
1164(define-public clang-19
1165 (clang-from-llvm
1166 llvm-19 clang-runtime-19
1167 #:tools-extra
1168 (origin
1169 (method url-fetch)
1170 (uri (llvm-uri "clang-tools-extra"
1171 (package-version llvm-19)))
1172 (sha256
1173 (base32
1174 "1rqv769nvr07a9n1sgwbq5rm411x31kyq3ngls800m90z25hh2s3")))))
1175
1176(define-public libomp-19
1177 (package
1178 (inherit libomp-15)
1179 (version (package-version llvm-19))
1180 (source (llvm-monorepo version))
1181 (native-inputs
1182 (modify-inputs native-inputs
1183 (replace "clang" clang-19)
1184 (replace "llvm" llvm-19)))))
1185
1186(define-public clang-toolchain-19
1187 (make-clang-toolchain clang-19 libomp-19))
1188
1189(define-public llvm-20
1190 (make-llvm "20.1.8"))
1191
1192(define-public clang-runtime-20
1193 (clang-runtime-from-llvm llvm-20))
1194
1195(define-public clang-20
1196 (clang-from-llvm
1197 llvm-20 clang-runtime-20
1198 #:tools-extra
1199 (origin
1200 (method url-fetch)
1201 (uri (llvm-uri "clang-tools-extra"
1202 (package-version llvm-20)))
1203 (sha256
1204 (base32
1205 "1z52ka12mg74n445yhzkn8ybqnh6awwc1lv9afdxg650higy2p3x")))))
1206
1207(define-public libomp-20
1208 (package
1209 (inherit libomp-15)
1210 (version (package-version llvm-20))
1211 (source (llvm-monorepo version))
1212 (native-inputs
1213 (modify-inputs native-inputs
1214 (replace "clang" clang-20)
1215 (replace "llvm" llvm-20)))))
1216
1217(define-public clang-toolchain-20
1218 (make-clang-toolchain clang-20 libomp-20))
1219
1220(define-public llvm-21
1221 (make-llvm "21.1.8"))
1222
1223(define-public clang-runtime-21
1224 (clang-runtime-from-llvm llvm-21))
1225
1226(define-public clang-21
1227 (clang-from-llvm
1228 llvm-21 clang-runtime-21
1229 #:tools-extra
1230 (origin
1231 (method url-fetch)
1232 (uri (llvm-uri "clang-tools-extra"
1233 (package-version llvm-21)))
1234 (sha256
1235 (base32
1236 "0ac8qb3ajxh9xnlyk71ar599qvbbf0y8lbif2chvi6ph3drpxnvd")))))
1237
1238(define-public libomp-21
1239 (package
1240 (inherit libomp-15)
1241 (version (package-version llvm-21))
1242 (source (llvm-monorepo version))
1243 (native-inputs
1244 (modify-inputs native-inputs
1245 (replace "clang" clang-21)
1246 (replace "llvm" llvm-21)))))
1247
1248(define-public clang-toolchain-21
1249 (make-clang-toolchain clang-21 libomp-21))
1250
1251(define-public llvm-22
1252 (make-llvm "22.1.8"))
1253
1254(define-public clang-runtime-22
1255 (clang-runtime-from-llvm llvm-22))
1256
1257(define-public clang-22
1258 (clang-from-llvm
1259 llvm-22 clang-runtime-22
1260 ;; The upstream no longer releases clang-tools-extra, but instead recommends
1261 ;; using the version in the monorepo.
1262 ;; See https://discourse.llvm.org/t/rfc-do-something-with-the-subproject-tarballs-in-the-release-page/75024
1263 #:tools-extra #t))
1264
1265(define-public libomp-22
1266 (package
1267 (inherit libomp-15)
1268 (version (package-version llvm-22))
1269 (source (llvm-monorepo version))
1270 (native-inputs
1271 (modify-inputs (package-native-inputs libomp-15)
1272 (replace "clang" clang-22)
1273 (replace "llvm" llvm-22)))))
1274
1275(define-public clang-toolchain-22
1276 (make-clang-toolchain clang-22 libomp-22))
1277
1278;; Default LLVM and Clang version.
1279(define-public libomp libomp-22)
1280(define-public llvm llvm-22)
1281(define-public clang-runtime clang-runtime-22)
1282(define-public clang clang-22)
1283(define-public clang-toolchain clang-toolchain-22)
1284
1285
1286
1287;; ROCm compiler infrastructure elements are compiled from a monorepo at
1288;; https://github.com/ROCm/llvm-project. Due to some of these parts
1289;; referencing both a common origin and llvm helpers (in particular related to
1290;; patches and base packages). Other ROCm elements are part of rocm.scm
1291
1292;; This must match '%rocm-version' in rocm.scm. They cannot be shared because
1293;; toplevel variables cannot be called from one file to another.
1294(define %rocm-llvm-version "7.1.1")
1295
1296(define %clang-rocm-supported-gpu-targets
1297 ;; List of supported GPU targets for the current version of clang-rocm.
1298 ;; This list can be obtained by running:
1299 ;;
1300 ;; guix shell clang-rocm -- \
1301 ;; clang --target=amdgcn-amd-amdhsa -mcpu=help -nogpulib
1302 ;;
1303 ;; See also <https://llvm.org/docs/AMDGPUUsage.html#amdgpu-processor-table>.
1304 ;; Update this list when upgrading clang-rocm.
1305 '("bonaire"
1306 "carrizo"
1307 "fiji"
1308 "generic"
1309 "generic-hsa"
1310 "gfx10-1-generic"
1311 "gfx10-3-generic"
1312 "gfx1010"
1313 "gfx1011"
1314 "gfx1012"
1315 "gfx1013"
1316 "gfx1030"
1317 "gfx1031"
1318 "gfx1032"
1319 "gfx1033"
1320 "gfx1034"
1321 "gfx1035"
1322 "gfx1036"
1323 "gfx11-generic"
1324 "gfx1100"
1325 "gfx1101"
1326 "gfx1102"
1327 "gfx1103"
1328 "gfx1150"
1329 "gfx1151"
1330 "gfx1152"
1331 "gfx1153"
1332 "gfx12-generic"
1333 "gfx1200"
1334 "gfx1201"
1335 "gfx600"
1336 "gfx601"
1337 "gfx602"
1338 "gfx700"
1339 "gfx701"
1340 "gfx702"
1341 "gfx703"
1342 "gfx704"
1343 "gfx705"
1344 "gfx801"
1345 "gfx802"
1346 "gfx803"
1347 "gfx805"
1348 "gfx810"
1349 "gfx9-4-generic"
1350 "gfx9-generic"
1351 "gfx900"
1352 "gfx902"
1353 "gfx904"
1354 "gfx906"
1355 "gfx908"
1356 "gfx909"
1357 "gfx90a"
1358 "gfx90c"
1359 "gfx940"
1360 "gfx941"
1361 "gfx942"
1362 "gfx950"
1363 "hainan"
1364 "hawaii"
1365 "iceland"
1366 "kabini"
1367 "kaveri"
1368 "mullins"
1369 "oland"
1370 "pitcairn"
1371 "polaris10"
1372 "polaris11"
1373 "stoney"
1374 "tahiti"
1375 "tonga"
1376 "tongapro"
1377 "verde"))
1378
1379(define (make-llvm-rocm llvm-base)
1380 (package
1381 (inherit llvm-base)
1382 ;; XXX A lot of llvm package phases are dependent on llvm version. Are
1383 ;; these resolved early, so that we can override the package version easily?
1384 (version %rocm-llvm-version)
1385 (name "llvm-rocm")
1386 (source (origin
1387 (method git-fetch)
1388 (uri (git-reference
1389 (url "https://github.com/ROCm/llvm-project")
1390 (commit (string-append "rocm-" %rocm-llvm-version))))
1391 (file-name (git-file-name "rocm-llvm" %rocm-llvm-version))
1392 (sha256
1393 (base32
1394 "0ni9s9sd8hlgmj34nkqn96kmbs6xlmrcsw8x5b15cisy2lhjgy89"))
1395 ;; Some of these patches require a further dynamic substitution during
1396 ;; package build. Therefore, it is important to derive from the base
1397 ;; packages or to duplicate such substitutions. Additionally, some of
1398 ;; those substitutions are only applied on specific subcomponents
1399 ;; (llvm-clang), so duplicating the base-llvm structure with subcomponents
1400 ;; is necessary.
1401 (patches
1402 (map search-patch
1403 (cons
1404 "clang-rocm-default-new-dtags.patch"
1405 (assoc-ref %llvm-patches (package-version llvm-base)))))))
1406 (arguments
1407 (substitute-keyword-arguments arguments
1408 ((#:configure-flags flags)
1409 #~(append #$flags
1410 (list #$(string-append
1411 "-DLLVM_TARGETS_TO_BUILD=AMDGPU;X86"
1412 (if (string=? "X86" (system->llvm-target))
1413 ""
1414 (string-append ";" (system->llvm-target))))
1415 "-DLLVM_VERSION_SUFFIX=")))))
1416 (properties `((hidden? . #t)
1417 ,@(package-properties llvm-base)))
1418 (home-page "https://github.com/ROCm/llvm-project")
1419 (synopsis
1420 (string-append (package-synopsis llvm-base) " (AMD fork)"))
1421 (description
1422 (string-append (package-description llvm-base) "
1423
1424This AMD fork includes AMD-specific additions."))))
1425
1426(define-public llvm-rocm (make-llvm-rocm llvm-20))
1427
1428(define (make-clang-runtime-rocm clang-runtime-base)
1429 (package
1430 (inherit clang-runtime-base)
1431 (name "clang-runtime-rocm")
1432 (version (package-version llvm-rocm))
1433 (source (package-source llvm-rocm))
1434 (inputs (modify-inputs inputs
1435 (replace "llvm" llvm-rocm)))))
1436
1437(define-public clang-runtime-rocm (make-clang-runtime-rocm clang-runtime-20))
1438
1439(define (make-clang-rocm clang-base)
1440 ;; note: tools-extra is embedded in the checkout
1441 (package
1442 (inherit clang-base)
1443 (name "clang-rocm")
1444 (version (package-version llvm-rocm))
1445 (source (package-source llvm-rocm))
1446 (inputs (modify-inputs inputs
1447 (delete "clang-tools-extra")))
1448 (propagated-inputs
1449 (modify-inputs propagated-inputs
1450 (replace "llvm" llvm-rocm)
1451 (replace "clang-runtime" clang-runtime-rocm)
1452 (append python-lit)))
1453 (arguments
1454 (substitute-keyword-arguments arguments
1455 ;; The tests can be run, as allowed by check phase rewrite and
1456 ;; LLVM_EXTERNAL_LIT setting. However, 84/46171 are failing. Most
1457 ;; should probably be disabled.
1458 ;;
1459 ;; - CUDA tests are failing.
1460 ;;
1461 ;; - Checking for some -L[[SYSROOT]] is failing, which I guess is
1462 ;; expected, given the patches we apply, which are mangling directory
1463 ;; searching for libraries.
1464 ;;
1465 ;; Getting the test suite to pass doesn't seem out of reach. We
1466 ;; probably should start with the standard llvm-clang-20x package.
1467 ((#:tests? _ #t) #f)
1468 ((#:configure-flags flags)
1469 #~(append #$flags
1470 (list
1471 "-DLLVM_TARGETS_TO_BUILD=AMDGPU;X86"
1472 ;; WARNING: we could patch
1473 ;; #$llvm-rocm/lib/cmake/llvm/AddLLVM.cmake to simplify, by
1474 ;; substituting set(LIT_COMMAND
1475 ;; "${Python3_EXECUTABLE};${lit_base_dir}/${lit_file_name}")
1476 ;; pending this, having a correct python script here is a
1477 ;; must-have.
1478 ;; TODO: test this on llvm-rocm.
1479 (string-append
1480 "-DLLVM_EXTERNAL_LIT="
1481 (search-input-file %build-inputs "bin/.lit-real")))))
1482 ((#:phases phases '%standard-phases)
1483 #~(modify-phases #$phases
1484 (replace 'check
1485 (lambda* (#:rest args)
1486 (setenv "HOME" "/tmp")
1487 (apply (assoc-ref
1488 (@ (guix build gnu-build-system) %standard-phases)
1489 'check)
1490 #:test-target "check-clang" args)))
1491 (replace 'add-tools-extra
1492 (lambda _
1493 (copy-recursively "../clang-tools-extra" "tools/extra")))))))
1494
1495 (properties
1496 `((compiler-amd-gpu-targets . ,%clang-rocm-supported-gpu-targets)
1497 ,@(package-properties clang-base)))))
1498
1499(define-public clang-rocm (make-clang-rocm clang-20))
1500
1501(define-public rocm-device-libs
1502 (package
1503 (name "rocm-device-libs")
1504 (version (package-version llvm-rocm))
1505 (source (package-source llvm-rocm))
1506 (build-system cmake-build-system)
1507 (arguments
1508 (list
1509 #:tests? #f ; Not sure how to run them.
1510 #:build-type "Release"
1511 #:phases
1512 #~(modify-phases %standard-phases
1513 (add-after 'unpack 'chdir
1514 (lambda _
1515 (chdir "amd/device-libs")))
1516 (add-after 'install 'copy-include-directories
1517 (lambda _
1518 ;; at this point we're within amd/build; i guess the build
1519 ;; directory should be at the same level as source, but due to
1520 ;; the chdir above...
1521 (with-directory-excursion "../device-libs"
1522 (for-each
1523 (lambda (directory)
1524 (let ((include-directory (string-append directory "/inc")))
1525 (copy-recursively
1526 include-directory
1527 (string-append #$output "/" include-directory))))
1528 (list "irif" "oclc" "ockl" "ocml"))))))))
1529 (inputs (list clang-rocm))
1530 (home-page "https://github.com/ROCm/llvm-project/")
1531 (synopsis "ROCm Device libraries")
1532 (description "ROCm device libraries provide AMD-specific device-side language runtime
1533libraries, namely oclc, ocml, ockl, opencl, hip and hc.")
1534 (license license:ncsa)))
1535
1536;; Usage note from amd/comgr/src/comgr-env.cpp: at runtime, comgr either needs
1537;; the awful ROCM_PATH set, or the more palatable LLVM_PATH and HIP_PATH, set.
1538(define-public rocm-comgr
1539 (package
1540 (name "rocm-comgr")
1541 (version (package-version llvm-rocm))
1542 (source (package-source llvm-rocm))
1543 (build-system cmake-build-system)
1544 (arguments
1545 (list
1546 #:build-type "Release"
1547 #:phases
1548 #~(modify-phases %standard-phases
1549 (add-after 'unpack 'prepare-to-build
1550 (lambda _
1551 (chdir "amd/comgr")
1552 (setenv "ROCM_PATH"
1553 #$(this-package-input "rocm-device-libs")))))))
1554 (inputs (list libffi rocm-device-libs))
1555 (native-inputs (list
1556 clang-rocm
1557 lld-rocm
1558 python))
1559 (home-page "https://github.com/ROCm/ROCm-CompilerSupport")
1560 (synopsis "ROCm Code Object Manager")
1561 (description "The Comgr library provides APIs for compiling and inspecting
1562AMDGPU code objects.")
1563 (license license:ncsa)))
1564
1565(define-public rocm-hipcc
1566 ;; Hiding because users are not meant to use 'rocm-hipcc' directly, they
1567 ;; should use 'rocm-toolchain' as that package provides all the necessary
1568 ;; scafolding to use the 'hipcc' compiler.
1569 (hidden-package
1570 (package
1571 (name "rocm-hipcc")
1572 (version (package-version llvm-rocm))
1573 (source (package-source llvm-rocm))
1574 (build-system cmake-build-system)
1575 (arguments
1576 (list
1577 #:tests? #f ; Not sure how to run them.
1578 #:build-type "Release"
1579 #:phases
1580 #~(modify-phases %standard-phases
1581 (add-after 'unpack 'chdir
1582 (lambda _
1583 (chdir "amd/hipcc")))
1584 (add-after 'chdir 'patch-paths
1585 (lambda* (#:key inputs #:allow-other-keys)
1586 (substitute* (find-files "src" "\\.h$")
1587 (("roccmPath \\+ \"/bin/rocm_agent_enumerator\"")
1588 (format #f "~s" (search-input-file
1589 inputs
1590 "/bin/rocm_agent_enumerator"))))
1591 (substitute* "src/hipBin_amd.h"
1592 (("which hipconfig")
1593 (string-append (search-input-file inputs "/bin/which")
1594 " hipconfig"))
1595 ;; Ensure the construction of the `HSA_PATH' from the
1596 ;; environment.
1597 (("constructHipPath\\(\\);\n" all)
1598 (string-append all " constructHsaPath();\n")))))
1599 ;; This version file very important, as it is parsed under
1600 ;; $#{llvm-rocm}/clang/lib/Driver/ToolChains/AMDGPU.cpp and its
1601 ;; contents decides on some includes for hipcc.
1602 (add-after 'install 'info-version
1603 (lambda _
1604 (let ((hip-version-dir (string-append #$output "/share/hip")))
1605 (mkdir hip-version-dir)
1606 (with-directory-excursion hip-version-dir
1607 (with-output-to-file "version"
1608 (lambda _
1609 (apply format #t
1610 "HIP_VERSION_MAJOR=~a~%~
1611 HIP_VERSION_MINOR=~a~%~
1612 HIP_VERSION_PATCH=~a~%~
1613 HIP_VERSION_GITHASH=0~%"
1614 (string-split
1615 #$(version-major+minor+point version) #\.))))))))
1616 (add-after 'install 'wrap-programs
1617 (lambda* (#:key inputs outputs #:allow-other-keys)
1618 (let ((output-bindir (string-append (assoc-ref outputs "out") "/bin")))
1619 (for-each
1620 (lambda (file)
1621 (wrap-program (string-append output-bindir "/" file)
1622 ;; The following definitions and their meaning can be
1623 ;; found in hibBin_base.h. We've defined neither
1624 ;; HIP_RUNTIME nor HIP_ROCCLR_HOME.
1625
1626 ;; HIP_ROCCLR_HOME unfortunately cannot be set here
1627 ;; (circular dependency problem) -- it should be set to
1628 ;; #$rocm-hip-runtime.
1629
1630 ;;(list "HIP_ROCCLR_HOME" '= (list #$rocm-hip-runtime))
1631
1632 ;; HACK: allow other packages (eg: `rocm-hip-runtime' or
1633 ;; `rocm-toolchain') to wrap this program with its own
1634 ;; paths.
1635 (list "HIP_PATH" '= (list (string-append "${HIP_PATH:-" #$output "}")))
1636 ;; XXX: `hipconfig' searches for `llc' which is provided
1637 ;; by `llvm-rocm', we cannot wrap that here since it
1638 ;; searches it from the `HIP_CLANG_PATH'. At this level
1639 ;; we don't have the complete `rocm-toolchain' which will
1640 ;; have the union of `llvm-rocm' and `clang-rocm', the
1641 ;; contents of both derivation outputs are expected to
1642 ;; live under `HIP_CLANG_PATH'.
1643 (list "HIP_CLANG_PATH"
1644 '=
1645 (list
1646 (string-append "${HIP_CLANG_PATH:-"
1647 #$(file-append (this-package-input "clang-rocm")
1648 "/bin")
1649 "}")))
1650 (list "DEVICE_LIB_PATH"
1651 '=
1652 (list
1653 (string-append "${DEVICE_LIB_PATH:-"
1654 #$(file-append (this-package-input "rocm-device-libs")
1655 "/amdgcn/bitcode")
1656 "}")))
1657
1658 ;; This is done in order to please check_config, which
1659 ;; checks that HSA_PATH is in LD_LIBRARY_PATH
1660 (list "LD_LIBRARY_PATH"
1661 'suffix
1662 (list #$(this-package-input "rocr-runtime")))
1663 ;; checks hipconfig is in PATH
1664 (list "PATH" 'suffix (list output-bindir))))
1665 '( "hipcc" "hipconfig" ))))))))
1666 (inputs (list clang-rocm
1667 rocm-device-libs
1668 rocr-runtime
1669 rocminfo
1670 perl
1671 bash-minimal
1672 which))
1673 (home-page "https://github.com/ROCm/llvm-project/")
1674 (synopsis "ROCm HIP compiler driver (@command{hipcc})")
1675 (description "The HIP compiler driver (@command{hipcc}) is a compiler utility that will
1676call @command{clang} and pass the appropriate include and library options for
1677the target compiler and HIP infrastructure.")
1678 (license license:expat))))
1679
1680
1681
1682(define-public libunwind-headers
1683 (package
1684 (name "libunwind-headers")
1685 (version "13.0.0")
1686 (source (origin
1687 (method url-fetch)
1688 (uri (llvm-uri "libunwind" version))
1689 (sha256
1690 (base32
1691 "1qb5ickp7qims5q7sxacj3fwq1kklvnl94k3v9hpl5qn284iky1n"))))
1692 (build-system cmake-build-system)
1693 (arguments
1694 '(#:phases (modify-phases (map (lambda (phase)
1695 (assq phase %standard-phases))
1696 '(set-paths unpack))
1697 (add-after 'unpack 'install
1698 (lambda* (#:key outputs #:allow-other-keys)
1699 (let ((out (assoc-ref outputs "out")))
1700 (mkdir out)
1701 (copy-recursively "include"
1702 (string-append out "/include"))))))))
1703 (home-page "https://clang.llvm.org/docs/Toolchain.html")
1704 (synopsis "LLVM libunwind header files")
1705 (description
1706 "This package contains header files for the LLVM C++ unwinding library.")
1707 (properties `((release-monitoring-url . ,%llvm-release-monitoring-url)))
1708 (license license:asl2.0))) ;with LLVM exceptions
1709
1710(define-public lld-15
1711 (package
1712 (name "lld")
1713 (version (package-version llvm-15))
1714 (source (llvm-monorepo version))
1715 (build-system cmake-build-system)
1716 (inputs
1717 (list llvm-15))
1718 (arguments
1719 '(#:build-type "Release"
1720 ;; TODO: Tests require the lit tool, which isn't installed by the LLVM
1721 ;; package.
1722 #:tests? #f
1723 #:phases (modify-phases %standard-phases
1724 (add-after 'unpack 'change-directory
1725 (lambda _
1726 (chdir "lld"))))))
1727 (home-page "https://lld.llvm.org/")
1728 (synopsis "Linker from the LLVM project")
1729 (description "LLD is a high-performance linker, built as a set of reusable
1730components which highly leverage existing libraries in the larger LLVM Project.")
1731 (license license:asl2.0))) ; With LLVM exception
1732
1733(define-public lld-14
1734 (package
1735 (inherit lld-15)
1736 (version "14.0.6")
1737 (source (llvm-monorepo version))
1738 (inputs
1739 (list llvm-14))))
1740
1741(define-public lld-13
1742 (package
1743 (inherit lld-14)
1744 (version "13.0.1")
1745 (source (origin
1746 (method url-fetch)
1747 (uri (llvm-uri "lld" version))
1748 (sha256
1749 (base32
1750 "1yscckcszfr234k4svhybdbsnz6w65x8pldl6c2nhyxzx12zfsk6"))))
1751 (native-inputs
1752 ;; Note: check <https://bugs.llvm.org/show_bug.cgi?id=49228> to see
1753 ;; whether this is still necessary.
1754 (list libunwind-headers))
1755 (inputs
1756 (list llvm-13))
1757 (arguments
1758 '(#:build-type "Release"
1759 ;; TODO: Tests require the lit tool, which isn't installed by the LLVM
1760 ;; package.
1761 #:tests? #f))
1762 (properties `((release-monitoring-url . ,%llvm-release-monitoring-url)))))
1763
1764(define-public lld-16
1765 (package
1766 (inherit lld-15)
1767 (version (package-version llvm-16))
1768 (source (llvm-monorepo version))
1769 (inputs (list llvm-16))))
1770
1771(define-public lld-17
1772 (package
1773 (inherit lld-15)
1774 (version (package-version llvm-17))
1775 (source (llvm-monorepo version))
1776 (inputs (list llvm-17))))
1777
1778(define-public lld-18
1779 (package
1780 (inherit lld-15)
1781 (version (package-version llvm-18))
1782 (source (llvm-monorepo version))
1783 (inputs (list llvm-18))))
1784
1785(define-public lld-19
1786 (package
1787 (inherit lld-15)
1788 (version (package-version llvm-19))
1789 (source (llvm-monorepo version))
1790 (inputs (list llvm-19))))
1791
1792(define-public lld-20
1793 (package
1794 (inherit lld-15)
1795 (version (package-version llvm-20))
1796 (source (llvm-monorepo version))
1797 (inputs (list llvm-20))))
1798
1799(define-public lld-21
1800 (package
1801 (inherit lld-15)
1802 (version (package-version llvm-21))
1803 (source (llvm-monorepo version))
1804 (inputs (list llvm-21))))
1805
1806(define-public lld-22
1807 (package
1808 (inherit lld-15)
1809 (version (package-version llvm-22))
1810 (source (llvm-monorepo version))
1811 (inputs (list llvm-22))))
1812
1813(define-public lld lld-22)
1814
1815(define* (make-lld-wrapper lld #:key lld-as-ld?)
1816 "Return a LLD wrapper. When LLD-AS-LD? is true, create a 'ld' symlink that
1817points to 'lld'."
1818 (package
1819 (inherit lld)
1820 (name (if lld-as-ld? "lld-as-ld-wrapper" "lld-wrapper"))
1821 (source #f)
1822 (native-inputs '())
1823 (inputs (list (make-ld-wrapper "ld.lld-wrapper" #:binutils lld
1824 #:linker "ld.lld")
1825 (make-ld-wrapper "lld-wrapper" #:binutils lld #:linker
1826 "lld")))
1827 (propagated-inputs '())
1828 (build-system trivial-build-system)
1829 (arguments
1830 (list #:builder
1831 #~(let ((ld.lld (string-append #$(this-package-input
1832 "ld.lld-wrapper")
1833 "/bin/ld.lld"))
1834 (lld (string-append #$(this-package-input "lld-wrapper")
1835 "/bin/lld")))
1836 (mkdir #$output)
1837 (mkdir (string-append #$output "/bin"))
1838 (symlink ld.lld (string-append #$output "/bin/ld.lld"))
1839 (symlink lld (string-append #$output "/bin/lld"))
1840 (when #$lld-as-ld?
1841 (symlink ld.lld (string-append #$output "/bin/ld"))))))
1842 (synopsis "LLD linker wrapper")
1843 (description "This is a linker wrapper for LLD; like @code{ld-wrapper}, it
1844wraps the linker to add any missing @code{-rpath} flags, and to detect any
1845misuse of libraries outside of the store.")))
1846
1847;;; A LLD wrapper suitable to use with -fuse-ld and GCC or with Clang.
1848(define-public lld-wrapper
1849 (make-lld-wrapper lld))
1850
1851;;; A LLD wrapper that can be used as a (near) drop-in replacement to GNU ld.
1852(define-public lld-as-ld-wrapper-18
1853 (make-lld-wrapper lld-18 #:lld-as-ld? #t))
1854
1855(define-public lld-as-ld-wrapper
1856 (make-lld-wrapper lld #:lld-as-ld? #t))
1857
1858(define-public lldb
1859 (package
1860 (name "lldb")
1861 (version (package-version llvm-22))
1862 (source (llvm-monorepo version))
1863 (build-system cmake-build-system)
1864 (arguments
1865 (list
1866 ;; No access to a compiled llvm-lit since compiled separately from llvm.
1867 #:tests? #f
1868 #:configure-flags #~(list "-DOPENMP_TEST_CXX_COMPILER=clang++")
1869 #:phases
1870 #~(modify-phases %standard-phases
1871 (add-after 'unpack 'chdir-to-source
1872 (lambda _
1873 (chdir "lldb"))))))
1874 (native-inputs
1875 (list pkg-config swig-4.0))
1876 (inputs
1877 (list clang-22
1878 llvm-22
1879 ;; Optional (but recommended) inputs.
1880 ncurses
1881 libedit
1882 xz
1883 libxml2
1884 lua
1885 python))
1886 (home-page "https://lldb.llvm.org/")
1887 (synopsis "Low level debugger")
1888 (description
1889 "LLDB is a high performance debugger built as a set of reusable components
1890which highly leverage existing libraries in the larger LLVM project.")
1891 (properties `((release-monitoring-url . ,%llvm-release-monitoring-url)))
1892 (license license:asl2.0))) ;with LLVM exceptions
1893
1894(define-public libcxx
1895 (package
1896 (name "libcxx")
1897 (version (package-version llvm-19))
1898 (source (llvm-monorepo version))
1899 (build-system cmake-build-system)
1900 (arguments
1901 (list
1902 #:tests? #f ;prohibitively expensive to run
1903 #:implicit-inputs? #f ;to avoid conflicting GCC headers
1904 #:configure-flags
1905 #~(list "-DLLVM_ENABLE_RUNTIMES=libcxx;libcxxabi;libunwind"
1906 "-DCMAKE_C_COMPILER=clang"
1907 "-DCMAKE_CXX_COMPILER=clang++"
1908 ;; libc++.so is actually a GNU ld style linker script, however,
1909 ;; CMake still tries to fix the RUNPATH of it during the install
1910 ;; step. This argument tells CMake to use the install directory
1911 ;; as RUNPATH and don't attempt to patch it.
1912 ;; See also: https://gitlab.kitware.com/cmake/cmake/-/issues/22963
1913 "-DCMAKE_BUILD_WITH_INSTALL_RPATH=TRUE")
1914 #:modules '((guix build cmake-build-system)
1915 ((guix build gnu-build-system) #:prefix gnu:)
1916 (guix build utils))
1917 #:phases
1918 #~(modify-phases %standard-phases
1919 (add-after 'unpack 'enter-subdirectory
1920 (lambda _
1921 (chdir "runtimes")))
1922 (replace 'check
1923 (lambda* (#:rest args)
1924 (apply (assoc-ref gnu:%standard-phases 'check)
1925 #:test-target "check-cxx" args))))))
1926 (native-inputs
1927 (modify-inputs (standard-packages)
1928 ;; Remove GCC from the build environment, to avoid its C++
1929 ;; headers (include/c++), which would interfere and cause build
1930 ;; failures.
1931 (delete "gcc")
1932 (prepend clang-19 python-minimal)))
1933 (home-page "https://libcxx.llvm.org")
1934 (synopsis "C++ standard library")
1935 (description
1936 "This package provides an implementation of the C++ standard library for
1937use with Clang, targeting C++11, C++14 and above.")
1938 (properties `((release-monitoring-url . ,%llvm-release-monitoring-url)))
1939 (license license:expat)))
1940
1941;; WARNING: This package is a dependency of mesa.
1942(define-public libclc
1943 (package
1944 (name "libclc")
1945 (version (package-version llvm-18))
1946 (source (llvm-monorepo version))
1947 (build-system cmake-build-system)
1948 (arguments
1949 (list
1950 #:configure-flags
1951 #~(list (string-append "-DLLVM_CLANG="
1952 (assoc-ref %build-inputs "clang")
1953 "/bin/clang")
1954 (string-append "-DLLVM_SPIRV="
1955 (assoc-ref %build-inputs "spirv-llvm-translator")
1956 "/bin/llvm-spirv"))
1957 #:phases
1958 #~(modify-phases %standard-phases
1959 (add-after 'unpack 'enter-subdirectory
1960 (lambda _
1961 (chdir "libclc")))
1962 (add-after 'enter-subdirectory 'skip-clspv-tests
1963 (lambda _
1964 (substitute* "CMakeLists.txt"
1965 (("ptx\\.\\*") "[ptx|clspv].*")))))))
1966 (propagated-inputs
1967 (list spirv-llvm-translator spirv-tools))
1968 (native-inputs
1969 (list clang-18 llvm-18 python))
1970 (home-page "https://libclc.llvm.org")
1971 (synopsis "Libraries for the OpenCL programming language")
1972 (description
1973 "This package provides an implementation of the OpenCL library
1974requirements according to version 1.1 of the OpenCL specification.")
1975 (properties `((release-monitoring-url . ,%llvm-release-monitoring-url)))
1976 ;; Apache license 2.0 with LLVM exception
1977 (license license:asl2.0)))
1978
1979(define (mlir-from-llvm llvm)
1980 "Produce MLIR with dependencies on LLVM."
1981 (package
1982 (name "mlir")
1983 (version (package-version llvm))
1984 (source (llvm-monorepo version))
1985 (build-system cmake-build-system)
1986 (native-inputs (package-native-inputs llvm))
1987 (inputs
1988 (list llvm))
1989 (arguments
1990 (list #:build-type "Release"
1991 #:configure-flags
1992 #~(list "-DMLIR_BUILD_MLIR_C_DYLIB=ON"
1993 "-DLLVM_BUILD_LLVM_DYLIB=ON"
1994 "-DLLVM_LINK_LLVM_DYLIB=ON"
1995 ;; The two following options install mlir-tblgen (which is
1996 ;; used by some dependent projects such as flang).
1997 "-DLLVM_INSTALL_TOOLCHAIN_ONLY=OFF"
1998 "-DLLVM_BUILD_UTILS=ON")
1999 #:tests? #f ; Tests require gtest
2000 #:phases #~(modify-phases %standard-phases
2001 (add-after 'unpack 'change-directory
2002 (lambda _
2003 (chdir "mlir"))))))
2004 (home-page "https://mlir.llvm.org/")
2005 (synopsis "Multi-Level Intermediate Representation")
2006 (description "This package is a novel approach to building reusable
2007and extensible compiler infrastructure. MLIR aims to address software
2008fragmentation, improve compilation for heterogeneous hardware, significantly
2009reduce the cost of building domain specific compilers, and aid in connecting
2010existing compilers together.")
2011 (license license:asl2.0))) ; With LLVM exception
2012
2013(define-public mlir-19
2014 (mlir-from-llvm llvm-19))
2015
2016(define-public mlir-15
2017 (mlir-from-llvm llvm-15))
2018
2019(define-public rocmlir
2020 (package
2021 (name "rocmlir")
2022 (version %rocm-llvm-version)
2023 (source (origin
2024 (method git-fetch)
2025 (uri (git-reference
2026 (url "https://github.com/ROCm/rocMLIR")
2027 (commit (string-append "rocm-" version))))
2028 (file-name (git-file-name name version))
2029 (sha256
2030 (base32
2031 "0yr76dj465rw4ck9dk1mjjn3rgp8gb0v273f256rkb8rq6zd9nq3"))))
2032 (build-system cmake-build-system)
2033 (arguments
2034 (list
2035 #:build-type "Release"
2036 #:configure-flags
2037 #~(list
2038 "-DCMAKE_C_COMPILER=clang"
2039 "-DCMAKE_CXX_COMPILER=clang++"
2040 "-DBUILD_FAT_LIBROCKCOMPILER=ON")
2041 ;; Tests require hip-python, which depends on several ROCm libraries
2042 #:tests? #f))
2043 (native-inputs (list clang-rocm rocm-hip-runtime python rocm-cmake))
2044 (home-page "https://github.com/ROCm/rocMLIR")
2045 (synopsis "MLIR-based convolution and GEMM kernel generator")
2046 (description "rocMLIR is a MLIR-based convolution and GEMM kernel
2047generator targetting AMD hardware.")
2048 (license license:expat)))
2049
2050(define-public python-llvmlite
2051 (package
2052 (name "python-llvmlite")
2053 (version "0.48.0")
2054 (source
2055 (origin
2056 ;; XXX: Switching to git require versioneer from python-xyz.
2057 (method url-fetch)
2058 (uri (pypi-uri "llvmlite" version))
2059 (sha256
2060 (base32
2061 "1lpdjbg9ip8d9kv5cgcakyzkf58vxvj930a6s5h7qg4gxzwijfsl"))))
2062 (build-system pyproject-build-system)
2063 (arguments
2064 (list
2065 #:test-backend #~'custom
2066 #:test-flags #~(list "-m" "llvmlite.tests")
2067 #:phases
2068 #~(modify-phases %standard-phases
2069 (add-after 'unpack 'skip-test
2070 (lambda _
2071 (substitute* "llvmlite/tests/test_binding.py"
2072 ;; This test tries to ensure all dependencies are expected by
2073 ;; parsing output of objdump with regex which might not
2074 ;; matching Guix variants.
2075 (("test_linux" all)
2076 (string-append "__off_" all)))))
2077 (add-before 'build 'set-compiler/linker-flags
2078 (lambda _
2079 (let ((llvm #$(this-package-input "llvm")))
2080 ;; Refer to ffi/Makefile.linux.
2081 (setenv "CPPFLAGS" "-fPIC")
2082 (setenv "LDFLAGS" (string-append "-Wl,-rpath="
2083 llvm "/lib")))))
2084 (add-before 'check 'pre-check
2085 (lambda _
2086 (setenv "LLVMLITE_DIST_TEST" "1"))))))
2087 (native-inputs
2088 (list cmake-minimal
2089 python-setuptools))
2090 (inputs
2091 (list llvm))
2092 (home-page "https://llvmlite.pydata.org")
2093 (synopsis "Wrapper around basic LLVM functionality")
2094 (description
2095 "This package provides a Python binding to LLVM for use in Numba.")
2096 (license (list license:asl2.0 license:bsd-2))))
2097
2098(define-public (clang-python-bindings clang)
2099 "Return a package for the Python bindings of CLANG."
2100 (package
2101 (inherit clang)
2102 (name "python-clang")
2103 (build-system pyproject-build-system)
2104 (outputs '("out"))
2105 (arguments
2106 (list
2107 #:test-backend #~'unittest
2108 #:phases #~(modify-phases %standard-phases
2109 (add-before 'build 'change-directory
2110 (lambda _
2111 (chdir "bindings/python")))
2112 (add-before 'build 'set-libclang-file-name
2113 (lambda* (#:key inputs #:allow-other-keys)
2114 ;; Record the absolute file name of libclang.so.
2115 (let ((libclang (search-input-file inputs
2116 "/lib/libclang.so")))
2117 (substitute* "clang/cindex.py"
2118 (("libclang\\.so") libclang))))))))
2119 (native-inputs (list python-setuptools))
2120 (inputs (list clang))
2121 (native-inputs (modify-inputs (package-native-inputs clang)
2122 (append python-setuptools)))
2123 (synopsis "Python bindings to libclang")))
2124
2125(define-public python-clang-13
2126 (clang-python-bindings clang-13))
2127
2128;; XXX
2129;; I would move all of rocm packages here and define a ROCm section.
2130
2131(define (make-lld-rocm lld-base)
2132 (package
2133 (inherit lld-base)
2134 (name "lld-rocm")
2135 (version (package-version llvm-rocm))
2136 (source (package-source llvm-rocm))
2137 (inputs (list llvm-rocm))
2138 (arguments
2139 (substitute-keyword-arguments arguments
2140 ((#:configure-flags flags)
2141 #~(append #$flags
2142 '("-DLLVM_TARGETS_TO_BUILD=AMDGPU;X86")))))))
2143
2144(define-public lld-rocm (make-lld-rocm lld-20))
2145
2146(define-public lld-wrapper-rocm
2147 (package
2148 (inherit (make-lld-wrapper lld-rocm))
2149 (name "lld-wrapper-rocm")))
2150
2151(define-public libomp-rocm
2152 (package
2153 (inherit libomp-20)
2154 (name "libomp-rocm")
2155 (version (package-version llvm-rocm))
2156 (source (package-source llvm-rocm))
2157 (arguments
2158 (substitute-keyword-arguments arguments
2159 ((#:configure-flags flags '())
2160 #~(cons
2161 (string-append "-DOPENMP_LIT_ARGS="
2162 "-sv --show-unsupported --show-xfail"
2163 ;; This test fails
2164 " --filter-out tasking/task_teams_stress_test.cpp")
2165 #$flags))
2166 ((#:phases phases)
2167 #~(modify-phases #$phases
2168 (add-after 'unpack 'fix-lit
2169 (lambda _
2170 (substitute* "openmp/cmake/OpenMPTesting.cmake"
2171 (((string-append "COMMAND \\$\\{Python3_EXECUTABLE\\}"
2172 " \\$\\{OPENMP_LLVM_LIT_EXECUTABLE\\}"))
2173 "COMMAND ${OPENMP_LLVM_LIT_EXECUTABLE}"))
2174 (substitute* "openmp/runtime/test/lit.cfg"
2175 (("config\\.name =.*" orig)
2176 (string-append
2177 orig
2178 "\nconfig.environment['C_INCLUDE_PATH']"
2179 " = os.environ['C_INCLUDE_PATH']\n"
2180 "config.environment['CPLUS_INCLUDE_PATH']"
2181 " = os.environ['CPLUS_INCLUDE_PATH']\n")))))))))
2182 (native-inputs
2183 (modify-inputs native-inputs
2184 (replace "clang" clang-rocm)
2185 (replace "llvm" llvm-rocm)))))
2186
2187(define-public clang-rocm-toolchain
2188 (make-clang-toolchain clang-rocm libomp-rocm))
2189
2190(define-public offload-rocm
2191 (package
2192 (name "offload-rocm")
2193 (version (package-version llvm-rocm))
2194 (source (package-source llvm-rocm))
2195 (build-system cmake-build-system)
2196 (arguments
2197 (list
2198 #:configure-flags
2199 #~(list
2200 "-DCMAKE_EXE_LINKER_FLAGS=-fuse-ld=lld"
2201 "-DCMAKE_SHARED_LINKER_FLAGS=-fuse-ld=lld")
2202 #:phases
2203 #~(modify-phases %standard-phases
2204 (add-after 'unpack 'chdir
2205 (lambda _
2206 (chdir "offload")))
2207 (add-after 'chdir 'libffi-dynamic-link
2208 (lambda _
2209 (substitute* "plugins-nextgen/host/CMakeLists.txt"
2210 (("if\\(FFI_STATIC.*") "if(FALSE)\n"))))
2211 (add-after 'install 'install-license
2212 (lambda _
2213 (install-file "../LICENSE.TXT"
2214 (string-append #$output "/share/doc/"
2215 #$name "-" #$version)))))
2216 ;; XXX: Tests cannot be built with ROCm version 7.1.1:
2217 ;; https://github.com/ROCm/llvm-project/blob/27682a16360e33e37c4f3cc6adf9a620733f8fe1/offload/CMakeLists.txt#L443
2218 #:tests? #f))
2219 (native-inputs
2220 (list clang-rocm-toolchain
2221 lld-wrapper-rocm
2222 python))
2223 (inputs
2224 (list libffi
2225 libomp-rocm
2226 rocm-device-libs
2227 rocr-runtime))
2228 (home-page "https://github.com/ROCm/llvm-project/")
2229 (synopsis "LLVM offloading library")
2230 (description "This LLVM component provides tooling, runtimes and APIs for
2231executing code on accelerators which may have a different architecture than
2232the host.")
2233 ;; Apache license 2.0 with LLVM exception
2234 (license license:asl2.0)))
2235
2236(define-public rocm-toolchain
2237 (package
2238 (inherit clang-rocm-toolchain)
2239 (name "rocm-toolchain")
2240 (inputs
2241 (modify-inputs inputs
2242 (append bash-minimal ;for 'wrap-program'.
2243 lld-wrapper-rocm
2244 offload-rocm
2245 rocr-runtime
2246 rocm-hipcc
2247 rocm-device-libs)))
2248 (arguments
2249 (substitute-keyword-arguments arguments
2250 ((#:modules modules)
2251 `(,@modules
2252 (guix build utils)))
2253 ((#:builder _)
2254 #~(begin
2255 (use-modules (ice-9 match)
2256 (guix build union)
2257 (guix build utils))
2258
2259 (define (unionize output inputs)
2260 (union-build output inputs
2261 #:symlink (lambda (old new)
2262 ;; Ignoring wrappers since
2263 ;; 'wrap-program' will not be able to
2264 ;; create the wrapper if it already
2265 ;; exits.
2266 (unless (wrapped-program? old)
2267 (symlink old new)))
2268 ;; Make sure directories are created instead of
2269 ;; symlinks so after creating the union
2270 ;; 'wrap-program' can create new files.
2271 #:create-all-directories? #t))
2272
2273 ;; Required for 'wrap-program'.
2274 (setenv "PATH" #$(file-append (this-package-input "bash-minimal")
2275 "/bin"))
2276
2277 (match %build-inputs
2278 (((names . directories) ...)
2279 (unionize #$output directories)))
2280
2281 (unionize #$output:debug
2282 (list #$(this-package-input "libc-debug")))
2283 (unionize #$output:static
2284 (list #$(this-package-input "libc-static")))
2285
2286 ;; Wrap programs.
2287 (let ((bin (string-append #$output "/bin")))
2288 (for-each
2289 (lambda (file)
2290 (wrap-program file
2291 ;; 'hipconfig' check that the 'LD_LIBRARY_PATH' of some
2292 ;; binaries contains 'HSA_PATH'. Since that path is set
2293 ;; during compilation, this 'rocm-toolchain' meta package
2294 ;; needs to point to 'rocr-runtime' rather than '#$output'.
2295 `("HSA_PATH" = ,(list #$(this-package-input "rocr-runtime")))
2296 `("HIP_PATH" = ,(list #$output))
2297 `("HIP_CLANG_PATH" = ,(list bin))))
2298 (find-files bin ".")))))))
2299 (native-search-paths
2300 (append (package-native-search-paths clang-rocm-toolchain)
2301 (list (search-path-specification
2302 (variable "HIP_DEVICE_LIB_PATH")
2303 (files '("amdgcn/bitcode"))))))
2304 (synopsis "Clang-based ROCm toolchain for C/C++ development")
2305 (description
2306 "This package provides a complete ROCm toolchain for C/C++ development to
2307be installed in user profiles. This includes Clang, as well as libc (headers
2308and binaries, plus debugging symbols in the @code{debug} output), Binutils,
2309the ROCm device libraries, and the ROCr runtime.")))
2310
2311
2312
2313(define-public include-what-you-use
2314 (package
2315 (name "include-what-you-use")
2316 ;; Ensure LLVM/Clang input versions match the version declared in the release
2317 ;; https://github.com/include-what-you-use/include-what-you-use/blob/master/README.md#clang-compatibility
2318 (version "0.24")
2319 (source
2320 (origin
2321 (method git-fetch)
2322 (uri (git-reference
2323 (url "https://github.com/include-what-you-use/include-what-you-use")
2324 (commit version)))
2325 (file-name (git-file-name name version))
2326 (sha256
2327 (base32 "0dkk65y6abf7bzv10q1ch3dyzj4d5y89qhh43jn189l861d6pzs0"))))
2328 (build-system cmake-build-system)
2329 (inputs (list llvm-20 clang-20 python-3))
2330 (synopsis
2331 "Tool for use with clang to analyze #includes in C and C++ source files")
2332 (home-page "https://github.com/include-what-you-use/include-what-you-use")
2333 (description
2334 "@code{include-what-you-use} lints C and C++ sources to ensure
2335@code{#include}s declaring every symbol used in a given file are present.
2336When every file directly includes what it uses rather than relying on
2337transitive inclusions, builds tend to be more efficient and refactoring
2338dependency relationships is easier, particularly for large projects.")
2339 ;; The project has not relicensed from the old LLVM license:
2340 ;; https://github.com/include-what-you-use/include-what-you-use/issues/849
2341 ;; The iwyu_getopt.* files are BSD-3.
2342 (license (list license:ncsa license:bsd-3))))
2343
2344(define-public emacs-clang-format
2345 (package
2346 (inherit clang)
2347 (name "emacs-clang-format")
2348 (build-system emacs-build-system)
2349 (inputs
2350 (list clang))
2351 (propagated-inputs '())
2352 (arguments
2353 (list
2354 #:lisp-directory "clang/tools/clang-format"
2355 #:phases
2356 #~(modify-phases %standard-phases
2357 (add-after 'unpack 'configure
2358 (lambda* (#:key inputs #:allow-other-keys)
2359 (let ((clang-format (search-input-file inputs "/bin/clang-format")))
2360 (emacs-substitute-variables "clang-format.el"
2361 ("clang-format-executable"
2362 clang-format))))))
2363 #:test-command #~(list "emacs" "-Q" "--batch"
2364 "-l" "clang-format.el"
2365 "-l" "clang-format-test.el"
2366 "-f" "ert-run-tests-batch-and-exit")))
2367 (synopsis "Format code using clang-format")
2368 (description "This package filters code through @code{clang-format}
2369to fix its formatting. @code{clang-format} is a tool that formats
2370C/C++/Obj-C code according to a set of style options, see
2371@url{https://clang.llvm.org/docs/ClangFormatStyleOptions.html}.")))
2372
2373(define-public emacs-clang-include-fixer
2374 (package
2375 (inherit clang)
2376 (name "emacs-clang-include-fixer")
2377 (build-system emacs-build-system)
2378 (inputs
2379 (list clang))
2380 (propagated-inputs '())
2381 (arguments
2382 (list
2383 #:lisp-directory "clang-tools-extra/clang-include-fixer/tool"
2384 #:phases
2385 #~(modify-phases %standard-phases
2386 (add-after 'unpack 'configure
2387 (lambda* (#:key inputs #:allow-other-keys)
2388 (let ((clang-include-fixer
2389 (search-input-file inputs "/bin/clang-include-fixer")))
2390 (emacs-substitute-variables "clang-include-fixer.el"
2391 ("clang-include-fixer-executable"
2392 clang-include-fixer))))))
2393 #:test-command #~(list "emacs" "-Q" "--batch"
2394 "-l" "clang-include-fixer.el"
2395 "-l" "clang-include-fixer-test.el"
2396 "-f" "ert-run-tests-batch-and-exit")))
2397 (synopsis "Emacs interface to @code{clang-include-fixer}")
2398 (description "This package provides an automated way of adding #include
2399directives for missing symbols in one translation unit, see
2400@url{http://clang.llvm.org/extra/clang-include-fixer.html}.")))
2401
2402(define-public emacs-clang-rename
2403 (package
2404 (inherit clang-19)
2405 (name "emacs-clang-rename")
2406 (build-system emacs-build-system)
2407 (inputs
2408 (list clang-19))
2409 (propagated-inputs '())
2410 (arguments
2411 (list #:lisp-directory "clang/tools/clang-rename"
2412 #:tests? #f ;no tests
2413 #:phases
2414 #~(modify-phases %standard-phases
2415 (add-after 'unpack 'configure
2416 (lambda* (#:key inputs #:allow-other-keys)
2417 (let ((clang-rename (search-input-file inputs "/bin/clang-rename")))
2418 (emacs-substitute-variables "clang-rename.el"
2419 ("clang-rename-binary" clang-rename))))))))
2420 (synopsis "Rename every occurrence of a symbol using clang-rename")
2421 (description "This package renames every occurrence of a symbol at point
2422using @code{clang-rename}.")))
2423
2424
2425;;;
2426;;; LLVM variants.
2427;;;
2428
2429(define-public llvm-for-mesa
2430 ;; Note: update the 'clang' input of mesa-opencl when bumping this.
2431 (let ((base-llvm llvm-18))
2432 (package
2433 (inherit base-llvm)
2434 (name "llvm-for-mesa")
2435 (arguments
2436 (substitute-keyword-arguments arguments
2437 ((#:modules modules '((guix build cmake-build-system)
2438 (guix build utils)))
2439 `((ice-9 regex)
2440 (srfi srfi-1)
2441 (srfi srfi-26)
2442 ,@modules))
2443 ((#:configure-flags cf ''())
2444 #~(cons*
2445 #$@(if (%current-target-system)
2446 '("-DBUILD_SHARED_LIBS:BOOL=TRUE"
2447 "-DCMAKE_BUILD_WITH_INSTALL_RPATH=TRUE")
2448 '())
2449 ;; Skipping tools and utils decreases the output by ~100 MiB.
2450 "-DLLVM_BUILD_TOOLS=NO"
2451 (remove
2452 (cut string-match
2453 #$(if (%current-target-system)
2454 "-DLLVM_(LINK_LLVM_DYLIB|INSTALL_UTILS).*"
2455 "-DLLVM_INSTALL_UTILS.*") <>)
2456 #$cf)))
2457 ((#:phases phases '%standard-phases)
2458 #~(modify-phases #$phases
2459 #$@(if (%current-target-system)
2460 '()
2461 #~((add-after 'install 'delete-static-libraries
2462 ;; If these are just relocated then llvm-config
2463 ;; can't find them.
2464 (lambda* (#:key outputs #:allow-other-keys)
2465 (for-each delete-file
2466 (find-files
2467 (string-append
2468 (assoc-ref outputs "out") "/lib")
2469 "\\.a$"))))))
2470 ;; llvm-config is how mesa and others find the various
2471 ;; libraries and headers they use.
2472 (add-after 'install 'build-and-install-llvm-config
2473 (lambda* (#:key outputs #:allow-other-keys)
2474 (let ((out (assoc-ref outputs "out")))
2475 (substitute*
2476 "tools/llvm-config/CMakeFiles/llvm-config.dir/link.txt"
2477 (((string-append (getcwd) "/build/lib"))
2478 (string-append out "/lib")))
2479 (invoke "make" "llvm-config")
2480 (install-file "bin/llvm-config"
2481 (string-append out "/bin"))))))))))))
2482
2483(define make-ocaml-llvm
2484 ;; Make it a memoizing procedure so its callers below don't end up defining
2485 ;; two equal-but-not-eq "ocaml-llvm" packages for the default LLVM.
2486 (mlambdaq (llvm)
2487 (package
2488 (inherit llvm)
2489 (name "ocaml-llvm")
2490 (outputs '("out"))
2491 (arguments
2492 `(#:configure-flags
2493 (list
2494 (string-append "-DLLVM_OCAML_EXTERNAL_LLVM_LIBDIR="
2495 (assoc-ref %build-inputs "llvm") "/lib")
2496 "-DBUILD_SHARED_LIBS=TRUE"
2497 "-DLLVM_OCAML_OUT_OF_TREE=TRUE"
2498 (string-append "-DLLVM_OCAML_INSTALL_PATH="
2499 (assoc-ref %outputs "out") "/lib/ocaml/site-lib"))
2500 #:tests? #f ;no tests
2501 #:phases
2502 (modify-phases %standard-phases
2503 (replace 'build
2504 (lambda _
2505 (invoke "make" "ocaml_all")))
2506 (replace 'install
2507 (lambda _
2508 (invoke "cmake" "-P" "bindings/ocaml/cmake_install.cmake"))))))
2509 (inputs
2510 (list llvm))
2511 (native-inputs
2512 (list ocaml ocaml-findlib ocaml-ounit python))
2513 (propagated-inputs
2514 (list ocaml-integers ocaml-ctypes))
2515 (synopsis "OCaml bindings to LLVM")
2516 (description "This package contains the OCaml bindings distributed with
2517LLVM."))))
2518
2519(define-public ocaml-llvm (make-ocaml-llvm llvm-13))
2520
2521(define-public wllvm
2522 (package
2523 (name "wllvm")
2524 (properties '((commit . "948cdb8bd8fb446c700a6aefc218153db5ce2591")
2525 (revision . "0")))
2526 (version (git-version "1.3.1"
2527 (assoc-ref properties 'revision)
2528 (assoc-ref properties 'commit)))
2529 (source
2530 (origin
2531 (method git-fetch)
2532 (uri (git-reference
2533 ;; Maintained fork.
2534 (url "https://github.com/travitch/whole-program-llvm")
2535 (commit (assoc-ref properties 'commit))))
2536 (file-name (git-file-name name version))
2537 (sha256
2538 (base32 "0ksasakx0ihg86j0qdla0zy14ljdhzpgi11as4kkgj51v4haihn4"))))
2539 (build-system pyproject-build-system)
2540 (arguments
2541 (list
2542 #:test-flags
2543 ;; This test requires access to binary llvm-gcc.
2544 #~(list "--ignore=test/test_dragonegg_driver.py")
2545 #:phases
2546 #~(modify-phases %standard-phases
2547 (add-after 'unpack 'fix-paths
2548 (lambda* (#:key inputs #:allow-other-keys)
2549 (let ((pystr (lambda (s) (string-append "'" s "'"))))
2550 (substitute* "wllvm/compilers.py"
2551 (("'objcopy'")
2552 (pystr (search-input-file inputs "/bin/objcopy"))))
2553 (substitute* "wllvm/extraction.py"
2554 (("'objdump'")
2555 (pystr (search-input-file inputs "/bin/objdump")))
2556 (("'ar'")
2557 (pystr (search-input-file inputs "/bin/ar"))))
2558 (substitute* "wllvm/filetype.py"
2559 (("'file'")
2560 (pystr (search-input-file inputs "/bin/file"))))))))))
2561 (inputs (list binutils file))
2562 (native-inputs (list clang-13 procps python-pytest python-setuptools))
2563 (home-page "https://github.com/SRI-CSL/whole-program-llvm")
2564 (synopsis "Whole Program LLVM")
2565 (description "This package provides a toolkit for building whole-program
2566LLVM bitcode files.")
2567 (license license:expat)))
2568
2569(define-public llvm-julia
2570 (package
2571 (inherit llvm-13)
2572 (arguments
2573 (substitute-keyword-arguments arguments
2574 ((#:configure-flags flags ''())
2575 #~(cons* "-DLLVM_BUILD_LLVM_DYLIB=ON"
2576 "-DLLVM_LINK_LLVM_DYLIB=ON"
2577 ;; "-DLLVM_EXPERIMENTAL_TARGETS_TO_BUILD=NVPTX"
2578 "-DLLVM_VERSION_SUFFIX:STRING=jl" ; Perhaps not needed.
2579 #$(string-append "-DLLVM_TARGETS_TO_BUILD="
2580 (system->llvm-target))
2581 (delete "-DBUILD_SHARED_LIBS:BOOL=TRUE" #$flags)))
2582 ((#:build-type _) "Release")))
2583 (properties `((hidden? . #t)
2584 ,@(package-properties llvm-13)))))
2585
2586(define llvm-cling-base llvm-16)
2587
2588(define llvm-cling
2589 (let ((base llvm-cling-base))
2590 (package/inherit base
2591 (name "llvm-cling")
2592 ;; Use the latest tag for the major LLVM version currently targeted by
2593 ;; Cling (often mentioned in Cling's release notes).
2594 (version "16-20240621-02")
2595 (source
2596 (origin
2597 (inherit (package-source base))
2598 (method git-fetch)
2599 (uri (git-reference
2600 (url "https://github.com/root-project/llvm-project")
2601 (commit (string-append "cling-llvm" version))))
2602 (file-name (git-file-name "llvm-cling" version))
2603 (sha256
2604 (base32
2605 "05libb4mc385n8sq0bilalvidwzzrcyiqsfkn7j179kkx66a8rzy"))))
2606 (arguments
2607 ;; This reduces the package size on disk from 547 MiB to 311 MiB.
2608 ;; Cling is intended to be used as a REPL on the host machine, not as a
2609 ;; cross-compiling toolchain.
2610 (substitute-keyword-arguments arguments
2611 ((#:configure-flags cf ''())
2612 #~(cons* "-DLLVM_TARGETS_TO_BUILD=host;NVPTX" #$cf)))))))
2613
2614(define clang-cling-runtime
2615 (let ((base clang-runtime-16))
2616 (package/inherit base
2617 (name "clang-cling-runtime")
2618 (version (package-version llvm-cling))
2619 (source (package-source llvm-cling))
2620 (arguments
2621 (substitute-keyword-arguments arguments
2622 ((#:phases phases '%standard-phases)
2623 #~(modify-phases #$phases
2624 (add-after 'install 'delete-static-libraries
2625 ;; This reduces the size from 22 MiB to 4 MiB.
2626 (lambda _
2627 (for-each delete-file (find-files #$output "\\.a$"))))))))
2628 (inputs (modify-inputs inputs
2629 (replace "llvm" llvm-cling))))))
2630
2631(define clang-cling
2632 (let ((base clang-16))
2633 (package/inherit base
2634 (name "clang-cling")
2635 (version (package-version llvm-cling))
2636 (source (package-source llvm-cling))
2637 (propagated-inputs
2638 (modify-inputs propagated-inputs
2639 (replace "llvm" llvm-cling)
2640 (replace "clang-runtime" clang-cling-runtime))))))
2641
2642(define-public cling
2643 (package
2644 (name "cling")
2645 (version "1.1")
2646 (source (origin
2647 (method git-fetch)
2648 (uri (git-reference
2649 (url "https://github.com/root-project/cling")
2650 (commit (string-append "v" version))))
2651 (file-name (git-file-name name version))
2652 (sha256
2653 (base32
2654 "13ghbqjppvbmkhjgfk9xggxh17xpmx18ghdqgkkg9a3mh19hf69h"))))
2655 (build-system cmake-build-system)
2656 (arguments
2657 (list
2658 #:build-type "Release" ;keep the build as lean as possible
2659 ;; FIXME: 79 tests fail, out of ~200 (see:
2660 ;; https://github.com/root-project/cling/issues/534)
2661 #:tests? #f
2662 #:configure-flags
2663 #~(list (string-append "-DCLING_CXX_PATH="
2664 (search-input-file %build-inputs "bin/g++"))
2665 ;; XXX: The AddLLVM.cmake module expects LLVM_EXTERNAL_LIT to
2666 ;; be a Python script, not a shell executable.
2667 (string-append "-DLLVM_EXTERNAL_LIT="
2668 (search-input-file %build-inputs "bin/.lit-real")))
2669 #:phases
2670 #~(modify-phases %standard-phases
2671 (add-after 'unpack 'set-version
2672 (lambda _
2673 (make-file-writable "VERSION")
2674 (call-with-output-file "VERSION"
2675 (lambda (port)
2676 (format port "~a~%" #$version)))))
2677 (add-after 'unpack 'patch-paths
2678 (lambda* (#:key inputs #:allow-other-keys)
2679 (substitute* "lib/Interpreter/CIFactory.cpp"
2680 (("\\bsed\\b")
2681 (which "sed"))
2682 ;; Cling uses libclang's CompilerInvocation::GetResourcesPath
2683 ;; to resolve Clang's library prefix, but this fails on Guix
2684 ;; because it is relative to the output of cling rather than
2685 ;; clang (see:
2686 ;; https://github.com/root-project/cling/issues/434). Fully
2687 ;; shortcut the logic in this method to return the correct
2688 ;; static location.
2689 (("static std::string getResourceDir.*" all)
2690 (string-append all
2691 " return std::string(\""
2692 #$(this-package-input "clang-cling")
2693 "/lib/clang/"
2694 #$(first
2695 (take (string-split
2696 (package-version clang-cling) #\-)
2697 1)) ;e.g. 16.0.6 -> 16
2698 "\");")))
2699 ;; Check for the 'lit' command for the tests, not 'lit.py'
2700 ;; (see: https://github.com/root-project/cling/issues/432).
2701 (substitute* "CMakeLists.txt"
2702 (("lit.py")
2703 "lit"))))
2704 (add-after 'unpack 'adjust-lit.cfg
2705 ;; See: https://github.com/root-project/cling/issues/435.
2706 (lambda _
2707 (substitute* "test/lit.cfg"
2708 (("config.llvm_tools_dir \\+ '")
2709 "config.cling_obj_root + '/bin"))))
2710 (add-before 'check 'set-CLANG
2711 (lambda* (#:key native-inputs inputs #:allow-other-keys)
2712 ;; Otherwise, lit fails with "fatal: couldn't find 'clang'
2713 ;; program, try setting CLANG in your environment".
2714 (setenv "CLANG" (search-input-file (or native-inputs inputs)
2715 "bin/clang"))))
2716 (add-after 'install 'delete-static-libraries
2717 ;; This reduces the size from 17 MiB to 5.4 MiB.
2718 (lambda _
2719 (for-each delete-file (find-files #$output "\\.a$"))))
2720 (add-after 'install 'wrap-with-include-paths
2721 ;; Cling is sensitive to miss-matched include directives; ensure
2722 ;; the GCC includes used match that of the GCC used to build
2723 ;; Cling.
2724 (lambda* (#:key inputs #:allow-other-keys)
2725 (let ((gcc-toolchain #$(this-package-input "gcc-toolchain")))
2726 (wrap-program (string-append #$output "/bin/cling")
2727 `("C_INCLUDE_PATH" prefix
2728 (,(string-append gcc-toolchain "/include")))
2729 `("CPLUS_INCLUDE_PATH" prefix
2730 (,(string-append gcc-toolchain "/include/c++")
2731 ,(string-append gcc-toolchain "/include")))))))
2732 (add-after 'wrap-with-include-paths 'fix-wrapper
2733 (lambda _
2734 ;; When -a $0 is used, the cling executable segfauts (see:
2735 ;; https://issues.guix.gnu.org/73405).
2736 (substitute* (string-append #$output "/bin/cling")
2737 (("\"\\$0\"")
2738 "\"${0##*/}\"")))))))
2739 (native-inputs (list clang-cling python python-lit))
2740 (inputs (list clang-cling (force gcc-toolchain*) llvm-cling libxcrypt))
2741 (home-page "https://root.cern/cling/")
2742 (synopsis "Interactive C++ interpreter")
2743 (description "Cling is an interactive C++17 standard compliant
2744interpreter, built on top of LLVM and Clang. Cling can be used as a
2745read-eval-print loop (REPL) to assist with rapid application development.
2746Here's how to print @samp{\"Hello World!\"} using @command{cling}:
2747
2748@example
2749cling '#include <stdio.h>' 'printf(\"Hello World!\\n\");'
2750@end example")
2751 (license license:lgpl2.1+))) ;for the combined work
2752
2753(define %swift-llvm-clang-version "5.7.3")
2754
2755(define-public swift-llvm
2756 (package
2757 (name "swift-llvm")
2758 (version %swift-llvm-clang-version)
2759 (source (origin
2760 (method git-fetch)
2761 (uri (git-reference
2762 (url "https://github.com/apple/llvm-project.git")
2763 (commit (string-append "swift-" %swift-llvm-clang-version
2764 "-RELEASE"))))
2765 (file-name (git-file-name "swift-llvm" %swift-llvm-clang-version))
2766 (sha256
2767 (base32
2768 "0ai460v5kqq3mhp0vz1f5rr2fcwqmx91bnwbkaksjp9cxlylnfr0"))
2769 (patches (search-patches "swift-llvm-5.7.3-linux.patch"))))
2770 (build-system cmake-build-system)
2771 (arguments
2772 (list
2773 ;; Upstream build script doesn't test LLVM.
2774 ;; LLVM_INCLUDE_TESTS=ON (default) builds test tools like FileCheck,
2775 ;; but LLVM_BUILD_TESTS=OFF (default) means no tests run via ctest.
2776 #:tests? #f
2777 #:build-type "Release"
2778 #:configure-flags
2779 #~(list "-DCMAKE_C_FLAGS=-fno-stack-protector"
2780 "-DCMAKE_CXX_FLAGS=-fno-stack-protector"
2781 "-DCMAKE_C_FLAGS_RELWITHDEBINFO=-O2 -DNDEBUG"
2782 "-DCMAKE_CXX_FLAGS_RELWITHDEBINFO=-O2 -DNDEBUG"
2783 "-DLLVM_TOOL_SWIFT_BUILD:BOOL=NO"
2784 "-DINTERNAL_INSTALL_PREFIX=local"
2785 "-DLLVM_INCLUDE_DOCS=YES"
2786 "-DLLVM_ENABLE_LTO="
2787 "-DLLVM_ENABLE_DUMP=ON"
2788 "-DLLVM_ENABLE_PROJECTS=clang"
2789 "-DLLVM_TARGETS_TO_BUILD=X86;ARM;AArch64;PowerPC;SystemZ;Mips"
2790 ;; Python llvm.py adds this (not build-script-impl).
2791 ;; This would also enable dump() by undefining NDEBUG.
2792 "-DLLVM_ENABLE_ASSERTIONS=TRUE"
2793 "-DLLVM_LIT_ARGS=-sv -j 16"
2794 (string-append "-DGCC_INSTALL_PREFIX="
2795 (assoc-ref %build-inputs "gcc-lib"))
2796 (string-append "-DC_INCLUDE_DIRS="
2797 (assoc-ref %build-inputs "libc")
2798 "/include")
2799 (string-append "-DCMAKE_INSTALL_PREFIX=" #$output))
2800 #:phases
2801 #~(modify-phases %standard-phases
2802 (add-after 'unpack 'enter-llvm-directory
2803 (lambda _
2804 (chdir "llvm")))
2805 (add-after 'enter-llvm-directory 'allow-config-h-install
2806 (lambda _
2807 ;; Swift needs llvm/Config/config.h, so remove the EXCLUDE.
2808 (substitute* "CMakeLists.txt"
2809 (("PATTERN \"config\\.h\" EXCLUDE")
2810 ""))))
2811 (add-after 'allow-config-h-install 'fix-demangle-includes
2812 (lambda _
2813 (substitute* "include/llvm/Demangle/MicrosoftDemangleNodes.h"
2814 (("#include <array>")
2815 "#include <array>\n#include <cstdint>\n#include <string>"))
2816 (substitute* "utils/benchmark/src/benchmark_register.h"
2817 (("#include <vector>")
2818 "#include <vector>\n#include <limits>"))
2819 (substitute* "include/llvm/Support/Signals.h"
2820 (("#include <string>")
2821 "#include <string>
2822#include <cstdint>"))
2823 ;; Work around Guix bug: libstdc++ was built without fenv.h support,
2824 ;; so _GLIBCXX_HAVE_FENV_H is undefined, causing <fenv.h> wrapper to
2825 ;; not include the actual header. Define it to bypass the wrapper.
2826 ;; See <https://issues.guix.gnu.org/43579>
2827 (substitute* "lib/Analysis/ConstantFolding.cpp"
2828 (("#include \"llvm/Config/config.h\"")
2829 "#include \"llvm/Config/config.h\"\n#define _GLIBCXX_HAVE_FENV_H 1\n#include <fenv.h>"))))
2830 (add-after 'fix-demangle-includes 'set-glibc-file-names
2831 (lambda* (#:key inputs #:allow-other-keys)
2832 (let ((libc (assoc-ref inputs "libc"))
2833 (gcc (assoc-ref inputs "gcc")))
2834 (substitute* "../clang/lib/Driver/ToolChains/Linux.cpp"
2835 ;; Make "LibDir" refer to <glibc>/lib so that it
2836 ;; uses the right dynamic linker file name.
2837 (("(^[[:blank:]]+LibDir = ).*" _ declaration)
2838 (string-append declaration "\"" libc "/lib\";\n"))
2839 ;; Make clang look for libstdc++ in the right location.
2840 (("LibStdCXXIncludePathCandidates\\[\\] = \\{")
2841 (string-append
2842 "LibStdCXXIncludePathCandidates[] = { \"" gcc
2843 "/include/c++\","))
2844 ;; Make sure libc's libdir is on the search path, to
2845 ;; allow crt1.o & co. to be found.
2846 (("@GLIBC_LIBDIR@")
2847 (string-append libc "/lib"))))))
2848 (add-after 'install 'install-filecheck
2849 (lambda _
2850 ;; FileCheck is built but not installed by default.
2851 ;; Swift needs it--so install it manually.
2852 (install-file "bin/FileCheck"
2853 (string-append #$output "/bin")))))))
2854 (native-inputs
2855 (list python-3))
2856 (inputs
2857 `(("libxml2" ,libxml2)
2858 ("gcc-lib" ,gcc "lib")
2859 ("gcc" ,gcc)
2860 ("libc" ,glibc)
2861 ("libffi" ,libffi)))
2862 (propagated-inputs
2863 (list zlib))
2864 (home-page "https://swift.org/")
2865 (synopsis "LLVM for Swift (Apple's fork)")
2866 (description
2867 "This is Apple's fork of LLVM with Swift-specific modifications,
2868required to build Swift.")
2869 (license license:ncsa)))
2870
2871;(define-public swift-clang-runtime
2872; (package
2873; (inherit (clang-runtime-from-llvm swift-llvm))
2874; (arguments
2875; (substitute-keyword-arguments (package-arguments (clang-runtime-from-llvm swift-llvm))
2876; ((#:configure-flags flags)
2877; #~(cons "-DCOMPILER_RT_INTERCEPT_LIBDISPATCH=ON"
2878; #$flags))))))
2879
2880(define-public swift-llvm-6.2
2881 (package
2882 (inherit swift-llvm)
2883 (version "6.2")
2884 (source (origin
2885 (method git-fetch)
2886 (uri (git-reference
2887 (url "https://github.com/apple/llvm-project.git")
2888 (commit (string-append "swift-" version "-RELEASE"))))
2889 (file-name (git-file-name "swift-llvm" version))
2890 (sha256
2891 (base32
2892 "00bpplh8zd495n7dw5a64ncy23r2sgj7071kyhw7r9s53ihw1k1m"))
2893 (patches (search-patches "clang-18.0-libc-search-path.patch"))))
2894 (arguments
2895 (substitute-keyword-arguments arguments
2896 ((#:configure-flags flags)
2897 #~(cons "-DUSE_DEPRECATED_GCC_INSTALL_PREFIX=ON" #$flags))
2898 ((#:phases phases)
2899 #~(modify-phases #$phases
2900 (replace 'fix-demangle-includes
2901 (lambda _
2902 (substitute* "include/llvm/Demangle/MicrosoftDemangleNodes.h"
2903 (("#include <array>")
2904 "#include <array>
2905#include <cstdint>
2906#include <string>"))
2907 (substitute* "../third-party/benchmark/src/benchmark_register.h"
2908 (("#include <vector>")
2909 "#include <vector>
2910#include <limits>"))
2911 (substitute* "include/llvm/Support/Signals.h"
2912 (("#include <string>")
2913 "#include <string>
2914#include <cstdint>"))
2915 (substitute* "lib/Analysis/ConstantFolding.cpp"
2916 (("#include \"llvm/Config/config.h\"")
2917 "#include \"llvm/Config/config.h\"
2918#define _GLIBCXX_HAVE_FENV_H 1
2919#include <fenv.h>"))))))))))