projects/guix·blob javascript-team · refs

2975 lines · 121.8 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 ("23.1.1" . "0nyr1k7324qv7xa4r1sn4mvw47y7sswhax6fgmq3lnh4x7qbavnw")))
613
614(define %llvm-patches
615 '(("14.0.6" . ("clang-14.0-libc-search-path.patch"
616 "clang-runtime-14-glibc-2.36-compat.patch"
617 "clang-14-remove-crypt-interceptors.patch"))
618 ("15.0.7" . ("clang-15.0-libc-search-path.patch"
619 "clang-16-remove-crypt-interceptors.patch"))
620 ("16.0.6" . ("clang-16.0-libc-search-path.patch"
621 "clang-16-remove-crypt-interceptors.patch"))
622 ("17.0.6" . ("clang-17.0-libc-search-path.patch"
623 "clang-17.0-link-dsymutil-latomic.patch"))
624 ("18.1.8" . ("clang-18.0-libc-search-path.patch"
625 "clang-17.0-link-dsymutil-latomic.patch"))
626 ("19.1.7" . ("clang-18.0-libc-search-path.patch"
627 "clang-17.0-link-dsymutil-latomic.patch"))
628 ("20.1.8" . ("clang-18.0-libc-search-path.patch"
629 "clang-17.0-link-dsymutil-latomic.patch"))
630 ("21.1.8" . ("clang-18.0-libc-search-path.patch"
631 "clang-17.0-link-dsymutil-latomic.patch"))
632 ("22.1.8" . ("clang-18.0-libc-search-path.patch"
633 "clang-17.0-link-dsymutil-latomic.patch"
634 "llvm-22-cfloat128-detection.patch"))
635 ("23.1.1" . ("clang-18.0-libc-search-path.patch"
636 "clang-17.0-link-dsymutil-latomic.patch"))))
637
638(define (llvm-monorepo version)
639 (origin
640 (method git-fetch)
641 (uri (git-reference
642 (url "https://github.com/llvm/llvm-project")
643 (commit (string-append "llvmorg-" version))))
644 (file-name (git-file-name "llvm-project" version))
645 (sha256 (base32 (assoc-ref %llvm-monorepo-hashes version)))
646 (patches (map search-patch (assoc-ref %llvm-patches version)))))
647
648;; A base llvm package that can be used for creating other llvm packages.
649(define make-llvm
650 (mlambda (version)
651 (package
652 (name "llvm")
653 (version version)
654 (source (llvm-monorepo version))
655 (build-system cmake-build-system)
656 (outputs '("out" "opt-viewer"))
657 (arguments
658 (list
659 #:tests? (not (or (%current-target-system)
660 (target-x86-32?)))
661 #:configure-flags
662 #~(list
663 ;; These options are required for cross-compiling LLVM according
664 ;; to <https://llvm.org/docs/HowToCrossCompileLLVM.html>.
665 #$@(if (%current-target-system)
666 (or (and=>
667 (system->llvm-target-arch)
668 (lambda (llvm-target-arch)
669 #~((string-append "-DLLVM_TABLEGEN="
670 #+(file-append this-package
671 "/bin/llvm-tblgen"))
672 #$@(if (version>=? version "16.0")
673 #~((string-append
674 "-DLLVM_NATIVE_TOOL_DIR="
675 #+(file-append this-package "/bin")))
676 #~())
677 #$@(if (version>=? version "17.0")
678 #~((string-append "-DLLVM_HOST_TRIPLE="
679 #$(%current-target-system)))
680 #~((string-append "-DLLVM_DEFAULT_TARGET_TRIPLE="
681 #$(%current-target-system))
682 (string-append "-DLLVM_TARGET_ARCH="
683 #$llvm-target-arch)))
684 #$(string-append "-DLLVM_TARGETS_TO_BUILD="
685 (system->llvm-target)))))
686 (raise (condition
687 (&package-unsupported-target-error
688 (package this-package)
689 (target (%current-target-system))))))
690 '())
691 ;; Note: sadly, the build system refuses the use of
692 ;; -DBUILD_SHARED_LIBS=ON and the large static archives are needed to
693 ;; build clang-runtime, so we cannot delete them.
694 "-DLLVM_BUILD_LLVM_DYLIB=ON"
695 "-DLLVM_LINK_LLVM_DYLIB=ON"
696 "-DLLVM_ENABLE_FFI=ON"
697 "-DLLVM_ENABLE_RTTI=ON" ;for some third-party utilities
698 "-DLLVM_INSTALL_UTILS=ON" ;needed for rustc
699 "-DLLVM_PARALLEL_LINK_JOBS=1") ;cater to smaller build machines
700 ;; Don't use '-g' during the build, to save space.
701 #:build-type "Release"
702 #:modules '((guix build cmake-build-system)
703 ((guix build gnu-build-system) #:prefix gnu:)
704 (guix build utils))
705 #:phases
706 #~(modify-phases %standard-phases
707 (add-after 'unpack 'change-directory
708 (lambda _
709 (chdir "llvm")))
710 (replace 'check
711 (lambda* (#:rest args)
712 (setenv "HOME" "/tmp")
713 (apply (assoc-ref gnu:%standard-phases 'check)
714 #:test-target "check-llvm" args)))
715 (add-after 'install 'install-opt-viewer
716 (lambda* (#:key outputs #:allow-other-keys)
717 (let* ((opt-viewer-share (string-append #$output:opt-viewer
718 "/share")))
719 (mkdir-p opt-viewer-share)
720 (rename-file (string-append #$output "/share/opt-viewer")
721 opt-viewer-share))))
722 ;; The build daemon goes OOM on i686-linux on this phase.
723 #$@(if (and (version>=? version "15.0")
724 (target-x86-32?))
725 #~((delete 'make-dynamic-linker-cache))
726 #~()))))
727 (native-inputs (list python-wrapper perl))
728 (inputs (list libffi))
729 (propagated-inputs (list zlib)) ;to use output from llvm-config
730 (home-page "https://www.llvm.org")
731 (synopsis "Optimizing compiler infrastructure")
732 (description
733 "LLVM is a compiler infrastructure designed for compile-time, link-time,
734runtime, and idle-time optimization of programs from arbitrary programming
735languages. It currently supports compilation of C and C++ programs, using
736front-ends derived from GCC 4.0.1. A new front-end for the C family of
737languages is in development. The compiler infrastructure includes mirror sets
738of programming tools as well as libraries with equivalent functionality.")
739 (license license:asl2.0)
740 (properties `((release-monitoring-url . ,%llvm-release-monitoring-url))))))
741
742(define-public llvm-15
743 (make-llvm "15.0.7"))
744
745(define-public llvm-14
746 (package
747 (inherit llvm-15)
748 (version "14.0.6")
749 (source (llvm-monorepo version))
750 (arguments
751 (list
752 #:modules '((guix build cmake-build-system)
753 ((guix build gnu-build-system) #:prefix gnu:)
754 (guix build utils))
755 #:tests? (not (or (%current-target-system)
756 (target-x86-32?)))
757 #:configure-flags
758 #~(list
759 ;; These options are required for cross-compiling LLVM according
760 ;; to <https://llvm.org/docs/HowToCrossCompileLLVM.html>.
761 #$@(if (%current-target-system)
762 (or (and=>
763 (system->llvm-target-arch)
764 (lambda (llvm-target-arch)
765 #~((string-append "-DLLVM_TABLEGEN="
766 #+(file-append this-package
767 "/bin/llvm-tblgen"))
768 #$(string-append "-DLLVM_DEFAULT_TARGET_TRIPLE="
769 (%current-target-system))
770 #$(string-append "-DLLVM_TARGET_ARCH=" llvm-target-arch)
771 #$(string-append "-DLLVM_TARGETS_TO_BUILD="
772 (system->llvm-target)))))
773 (raise (condition
774 (&package-unsupported-target-error
775 (package this-package)
776 (target (%current-target-system))))))
777 '())
778 ;; undefined reference to `__atomic_fetch_add_8' in lib/libLLVMOrcJIT.so.14
779 #$@(if (target-ppc32?)
780 (list "-DCMAKE_SHARED_LINKER_FLAGS=-latomic")
781 `())
782 "-DCMAKE_SKIP_BUILD_RPATH=FALSE"
783 "-DCMAKE_BUILD_WITH_INSTALL_RPATH=FALSE"
784 "-DBUILD_SHARED_LIBS:BOOL=TRUE"
785 "-DLLVM_ENABLE_FFI:BOOL=TRUE"
786 "-DLLVM_ENABLE_RTTI:BOOL=TRUE" ;for some third-party utilities
787 "-DLLVM_INSTALL_UTILS=ON") ;needed for rustc
788 ;; Don't use '-g' during the build, to save space.
789 #:build-type "Release"
790 #:phases
791 #~(modify-phases %standard-phases
792 (add-after 'unpack 'change-directory
793 (lambda _
794 (chdir "llvm")))
795 (replace 'check
796 (lambda* (#:rest args)
797 (setenv "HOME" "/tmp")
798 (apply (assoc-ref gnu:%standard-phases 'check)
799 #:test-target "check-llvm" args)))
800 (add-after 'install 'install-opt-viewer
801 (lambda* (#:key outputs #:allow-other-keys)
802 (let* ((out (assoc-ref outputs "out"))
803 (opt-viewer-out (assoc-ref outputs "opt-viewer"))
804 (opt-viewer-share-dir (string-append opt-viewer-out "/share"))
805 (opt-viewer-dir (string-append opt-viewer-share-dir "/opt-viewer")))
806 (mkdir-p opt-viewer-share-dir)
807 (rename-file (string-append out "/share/opt-viewer")
808 opt-viewer-dir)))))))
809
810 (native-inputs (list perl python-wrapper which))))
811
812(define-public clang-runtime-15
813 (clang-runtime-from-llvm llvm-15))
814
815(define-public clang-runtime-14
816 (clang-runtime-from-llvm llvm-14))
817
818(define-public clang-15
819 (clang-from-llvm
820 llvm-15 clang-runtime-15
821 #:tools-extra
822 (origin
823 (method url-fetch)
824 (uri (llvm-uri "clang-tools-extra"
825 (package-version llvm-15)))
826 (sha256
827 (base32
828 "1lagnspm5limxh1cp5jlixnzlhf09905d4rqra1kpgj6dps2x6l0")))))
829
830(define-public clang-14
831 (clang-from-llvm
832 llvm-14 clang-runtime-14
833 #:legacy-build-shared-libs? #t
834 #:tools-extra
835 (origin
836 (method url-fetch)
837 (uri (llvm-uri "clang-tools-extra"
838 (package-version llvm-14)))
839 (sha256
840 (base32
841 "0rhq4wkmvr369nkk059skzzw7jx6qhzqhmiwmqg4sp66avzviwvw")))))
842
843(define-public libomp-15
844 (package
845 (name "libomp")
846 (version (package-version llvm-15))
847 (source (llvm-monorepo version))
848 (build-system cmake-build-system)
849 ;; XXX: Note this gets built with GCC because building with Clang itself
850 ;; fails (missing <atomic>, even when libcxx is added as an input.)
851 (arguments
852 (list
853 #:configure-flags
854 #~(list "-DLIBOMP_USE_HWLOC=ON"
855 "-DOPENMP_TEST_C_COMPILER=clang"
856 "-DOPENMP_TEST_CXX_COMPILER=clang++")
857 #:modules '((guix build cmake-build-system)
858 ((guix build gnu-build-system) #:prefix gnu:)
859 (guix build utils))
860 #:phases
861 #~(modify-phases %standard-phases
862 (add-after 'unpack 'chdir-to-source-and-install-license
863 (lambda _
864 (chdir "openmp")
865 (install-file "LICENSE.TXT"
866 (string-append #$output "/share/doc"))))
867 (replace 'check
868 (lambda* (#:rest args)
869 (apply (assoc-ref gnu:%standard-phases 'check)
870 #:test-target "check-libomp" args))))))
871 (native-inputs (list clang-15 llvm-15 perl pkg-config python))
872 (inputs (list `(,hwloc "lib")))
873 (home-page "https://openmp.llvm.org")
874 (synopsis "OpenMP run-time support library")
875 (description "This package provides the run-time support library developed
876by the LLVM project for the OpenMP multi-theaded programming extension. This
877package notably provides @file{libgomp.so}, which is has a binary interface
878compatible with that of libgomp, the GNU Offloading and Multi Processing
879Library.")
880 (properties `((release-monitoring-url . ,%llvm-release-monitoring-url)
881 (upstream-name . "openmp")))
882 (license license:expat)))
883
884(define-public clang-toolchain-15
885 (make-clang-toolchain clang-15 libomp-15))
886
887(define-public libomp-14
888 (package
889 (inherit libomp-15)
890 (version (package-version llvm-14))
891 (source (origin
892 (method url-fetch)
893 (uri (llvm-uri "openmp" version))
894 (sha256
895 (base32
896 "07zby3gwy5c8jssabrhjk3nsxlwipnm6sk4dsvck1l5d0br1ywsg"))
897 (file-name (string-append "libomp-" version ".tar.xz"))))
898 (arguments
899 (substitute-keyword-arguments arguments
900 ((#:phases phases)
901 #~(modify-phases #$phases
902 (replace 'chdir-to-source-and-install-license
903 (lambda _
904 (chdir #$(string-append "../openmp-" version ".src"))
905 (install-file "LICENSE.TXT"
906 (string-append #$output "/share/doc"))))))))
907 (native-inputs
908 (modify-inputs native-inputs
909 (replace "clang" clang-14)
910 (replace "llvm" llvm-14)))))
911
912(define-public clang-toolchain-14
913 (make-clang-toolchain clang-14 libomp-14))
914
915(define-public llvm-13
916 (package
917 (inherit llvm-14)
918 (version "13.0.1")
919 (source
920 (origin
921 (method url-fetch)
922 (uri (llvm-uri "llvm" version))
923 (sha256
924 (base32
925 "0d681xiixmx9inwvz14vi3xsznrcryk06a8rvk9cljiq5kc80szc"))
926 (patches (search-patches "llvm-13-gcc-14.patch"))))
927 (arguments
928 (substitute-keyword-arguments arguments
929 ((#:tests? _ #t)
930 ;; The tests on riscv64 error on the differences between
931 ;; generic and generic-rv64.
932 (not (or (%current-target-system)
933 (target-x86-32?)
934 (target-riscv64?))))
935 ((#:phases phases '%standard-phases)
936 #~(modify-phases #$phases
937 (delete 'change-directory)))))
938 (properties `((release-monitoring-url . ,%llvm-release-monitoring-url)))))
939
940(define-public clang-runtime-13
941 (clang-runtime-from-llvm
942 llvm-13
943 "1z2xr9nn4mgc3hn9ark2k5y4wznpk47xppkp63bcbagr6589acvv"
944 '("clang-runtime-13-glibc-2.36-compat.patch"
945 "clang-13-remove-crypt-interceptors.patch")))
946
947(define-public clang-13
948 (clang-from-llvm llvm-13 clang-runtime-13
949 "1j8pr5kk8iqyb4jds3yl7c6x672617h4ngkpl4575j7mk4nrwykq"
950 #:legacy-build-shared-libs? #t
951 #:patches '("clang-13.0-libc-search-path.patch")
952 #:tools-extra
953 (origin
954 (method url-fetch)
955 (uri (llvm-uri "clang-tools-extra"
956 (package-version llvm-13)))
957 (sha256
958 (base32
959 "1l4jjdqfl9hrh0fwzv27hc263zc6x61h09vs4ni3yla8i1cwhayc")))))
960
961(define-public libomp-13
962 (package
963 (inherit libomp-14)
964 (version (package-version llvm-13))
965 (source (origin
966 (method url-fetch)
967 (uri (llvm-uri "openmp" version))
968 (sha256
969 (base32
970 "0kvbr4j6ldpssiv7chgqra5y77n7jwbyxlwcl7z32v31f49jcybb"))
971 (file-name (string-append "libomp-" version ".tar.xz"))))
972 (arguments
973 (substitute-keyword-arguments arguments
974 ((#:configure-flags flags)
975 ;; Work around faulty target detection, fixed in 14:
976 ;; https://github.com/llvm/llvm-project/issues/52910
977 #~(cons* "-DLIBOMPTARGET_BUILD_AMDGCN_BCLIB=OFF" #$flags))
978 ((#:phases phases)
979 #~(modify-phases #$phases
980 (delete 'chdir-to-source-and-install-license)))))
981 (native-inputs
982 (modify-inputs native-inputs
983 (replace "clang" clang-13)
984 (replace "llvm" llvm-13)))))
985
986(define-public clang-toolchain-13
987 (make-clang-toolchain clang-13 libomp-13))
988
989(define-public llvm-12
990 (package
991 (inherit llvm-13)
992 (version "12.0.1")
993 (source
994 (origin
995 (method url-fetch)
996 (uri (llvm-uri "llvm" version))
997 (sha256
998 (base32
999 "1pzx9zrmd7r3481sbhwvkms68fwhffpp4mmz45dgrkjpyl2q96kx"))
1000 (patches (search-patches "llvm-13-gcc-14.patch"))))
1001 (arguments
1002 (substitute-keyword-arguments arguments
1003 ;; Disable tests for old releases now compiled with newer GCC.
1004 ((#:tests? _ #false) #false)
1005 ((#:phases phases)
1006 #~(modify-phases #$phases
1007 #$@(if (assoc "config" (package-native-inputs this-package))
1008 #~((add-after 'unpack 'update-config
1009 (lambda* (#:key inputs native-inputs #:allow-other-keys)
1010 (let ((config.guess (search-input-file
1011 (or inputs native-inputs)
1012 "/bin/config.guess")))
1013 (copy-file config.guess "cmake/config.guess")))))
1014 #~())
1015 (add-after 'unpack 'delete-failing-tests
1016 (lambda _
1017 (delete-file "test/DebugInfo/X86/vla-multi.ll")))
1018 (add-before 'build 'shared-lib-workaround
1019 ;; Even with CMAKE_SKIP_BUILD_RPATH=FALSE, llvm-tblgen
1020 ;; doesn't seem to get the correct rpath to be able to run
1021 ;; from the build directory. Set LD_LIBRARY_PATH as a
1022 ;; workaround.
1023 (lambda _
1024 (setenv "LD_LIBRARY_PATH"
1025 (string-append (getcwd) "/lib"))))))))))
1026
1027(define-public llvm-16
1028 (make-llvm "16.0.6"))
1029
1030(define-public clang-runtime-16
1031 (clang-runtime-from-llvm llvm-16))
1032
1033(define-public clang-16
1034 (clang-from-llvm
1035 llvm-16 clang-runtime-16
1036 #:tools-extra
1037 (origin
1038 (method url-fetch)
1039 (uri (llvm-uri "clang-tools-extra"
1040 (package-version llvm-16)))
1041 (sha256
1042 (base32
1043 "0cbgffciql06a1i0ybyyqbnkkr4g7x8cxaar5a5v3415vd27hk0p")))))
1044
1045(define-public libomp-16
1046 (package
1047 (inherit libomp-15)
1048 (version (package-version llvm-16))
1049 (source (llvm-monorepo version))
1050 (native-inputs
1051 (modify-inputs native-inputs
1052 (replace "clang" clang-16)
1053 (replace "llvm" llvm-16)))))
1054
1055(define-public clang-toolchain-16
1056 (make-clang-toolchain clang-16 libomp-16))
1057
1058(define-public llvm-17
1059 (make-llvm "17.0.6"))
1060
1061(define-public clang-runtime-17
1062 (clang-runtime-from-llvm llvm-17))
1063
1064(define-public clang-17
1065 (clang-from-llvm
1066 llvm-17 clang-runtime-17
1067 #:patches '("clang-17.0-fix-build-with-gcc-14-on-arm.patch")
1068 #:tools-extra
1069 (origin
1070 (method url-fetch)
1071 (uri (llvm-uri "clang-tools-extra"
1072 (package-version llvm-17)))
1073 (sha256
1074 (base32
1075 "1f8szx762c325916gjxb5lw7zxyidynwnvx6fxxqscsx8514cxxa")))))
1076
1077(define-public libomp-17
1078 (package
1079 (inherit libomp-15)
1080 (version (package-version llvm-17))
1081 (source (llvm-monorepo version))
1082 (native-inputs
1083 (modify-inputs native-inputs
1084 (replace "clang" clang-17)
1085 (replace "llvm" llvm-17)))))
1086
1087(define-public clang-toolchain-17
1088 (make-clang-toolchain clang-17 libomp-17))
1089
1090(define-public llvm-18
1091 (package
1092 (inherit llvm-15)
1093 (version "18.1.8")
1094 (source (llvm-monorepo version))
1095 (arguments
1096 (substitute-keyword-arguments arguments
1097 ((#:modules modules '((guix build cmake-build-system)
1098 (guix build utils)))
1099 (if (%current-target-system)
1100 `((ice-9 regex)
1101 (srfi srfi-1)
1102 (srfi srfi-26)
1103 ,@modules)
1104 modules))
1105 ;; TODO: Figure out why some tests fail on some architectures.
1106 ((#:tests? current-test-config #t)
1107 (and current-test-config
1108 (not (target-ppc64le?))
1109 (not (target-arm32?))))
1110 ((#:configure-flags cf #~'())
1111 (if (%current-target-system)
1112 ;; Use a newer version of llvm-tblgen and add the new
1113 ;; configure-flag needed for cross-building.
1114 #~(cons* (string-append "-DLLVM_TABLEGEN="
1115 #+(file-append this-package
1116 "/bin/llvm-tblgen"))
1117 (string-append "-DLLVM_NATIVE_TOOL_DIR="
1118 #+(file-append this-package "/bin"))
1119 (string-append "-DLLVM_HOST_TRIPLE="
1120 #$(%current-target-system))
1121 (remove
1122 (cut string-match
1123 "-DLLVM_(DEFAULT_TARGET|TARGET_ARCH|TABLEGEN).*" <>)
1124 #$cf))
1125 cf))
1126 ;; The build daemon goes OOM on i686-linux on this phase.
1127 ((#:phases phases #~'%standard-phases)
1128 (if (target-x86-32?)
1129 #~(modify-phases #$phases
1130 (delete 'make-dynamic-linker-cache))
1131 phases))))))
1132
1133(define-public clang-runtime-18
1134 (clang-runtime-from-llvm llvm-18))
1135
1136(define-public clang-18
1137 (clang-from-llvm
1138 llvm-18 clang-runtime-18
1139 #:tools-extra
1140 (origin
1141 (method url-fetch)
1142 (uri (llvm-uri "clang-tools-extra"
1143 (package-version llvm-18)))
1144 (sha256
1145 (base32
1146 "1wd7y1a0db4y51swlq6dmm9hrv8pvmv158yi9f10dlayv7y7g275")))))
1147
1148(define-public libomp-18
1149 (package
1150 (inherit libomp-15)
1151 (version (package-version llvm-18))
1152 (source (llvm-monorepo version))
1153 (native-inputs
1154 (modify-inputs native-inputs
1155 (replace "clang" clang-18)
1156 (replace "llvm" llvm-18)))))
1157
1158(define-public clang-toolchain-18
1159 (make-clang-toolchain clang-18 libomp-18))
1160
1161(define-public llvm-19
1162 (make-llvm "19.1.7"))
1163
1164(define-public clang-runtime-19
1165 (clang-runtime-from-llvm llvm-19))
1166
1167(define-public clang-19
1168 (clang-from-llvm
1169 llvm-19 clang-runtime-19
1170 #:tools-extra
1171 (origin
1172 (method url-fetch)
1173 (uri (llvm-uri "clang-tools-extra"
1174 (package-version llvm-19)))
1175 (sha256
1176 (base32
1177 "1rqv769nvr07a9n1sgwbq5rm411x31kyq3ngls800m90z25hh2s3")))))
1178
1179(define-public libomp-19
1180 (package
1181 (inherit libomp-15)
1182 (version (package-version llvm-19))
1183 (source (llvm-monorepo version))
1184 (native-inputs
1185 (modify-inputs native-inputs
1186 (replace "clang" clang-19)
1187 (replace "llvm" llvm-19)))))
1188
1189(define-public clang-toolchain-19
1190 (make-clang-toolchain clang-19 libomp-19))
1191
1192(define-public llvm-20
1193 (make-llvm "20.1.8"))
1194
1195(define-public clang-runtime-20
1196 (clang-runtime-from-llvm llvm-20))
1197
1198(define-public clang-20
1199 (clang-from-llvm
1200 llvm-20 clang-runtime-20
1201 #:tools-extra
1202 (origin
1203 (method url-fetch)
1204 (uri (llvm-uri "clang-tools-extra"
1205 (package-version llvm-20)))
1206 (sha256
1207 (base32
1208 "1z52ka12mg74n445yhzkn8ybqnh6awwc1lv9afdxg650higy2p3x")))))
1209
1210(define-public libomp-20
1211 (package
1212 (inherit libomp-15)
1213 (version (package-version llvm-20))
1214 (source (llvm-monorepo version))
1215 (native-inputs
1216 (modify-inputs native-inputs
1217 (replace "clang" clang-20)
1218 (replace "llvm" llvm-20)))))
1219
1220(define-public clang-toolchain-20
1221 (make-clang-toolchain clang-20 libomp-20))
1222
1223(define-public llvm-21
1224 (make-llvm "21.1.8"))
1225
1226(define-public clang-runtime-21
1227 (clang-runtime-from-llvm llvm-21))
1228
1229(define-public clang-21
1230 (clang-from-llvm
1231 llvm-21 clang-runtime-21
1232 #:tools-extra
1233 (origin
1234 (method url-fetch)
1235 (uri (llvm-uri "clang-tools-extra"
1236 (package-version llvm-21)))
1237 (sha256
1238 (base32
1239 "0ac8qb3ajxh9xnlyk71ar599qvbbf0y8lbif2chvi6ph3drpxnvd")))))
1240
1241(define-public libomp-21
1242 (package
1243 (inherit libomp-15)
1244 (version (package-version llvm-21))
1245 (source (llvm-monorepo version))
1246 (native-inputs
1247 (modify-inputs native-inputs
1248 (replace "clang" clang-21)
1249 (replace "llvm" llvm-21)))))
1250
1251(define-public clang-toolchain-21
1252 (make-clang-toolchain clang-21 libomp-21))
1253
1254(define-public llvm-22
1255 (make-llvm "22.1.8"))
1256
1257(define-public clang-runtime-22
1258 (clang-runtime-from-llvm llvm-22))
1259
1260(define-public clang-22
1261 (clang-from-llvm
1262 llvm-22 clang-runtime-22
1263 ;; The upstream no longer releases clang-tools-extra, but instead recommends
1264 ;; using the version in the monorepo.
1265 ;; See https://discourse.llvm.org/t/rfc-do-something-with-the-subproject-tarballs-in-the-release-page/75024
1266 #:tools-extra #t))
1267
1268(define-public libomp-22
1269 (package
1270 (inherit libomp-15)
1271 (version (package-version llvm-22))
1272 (source (llvm-monorepo version))
1273 (native-inputs
1274 (modify-inputs (package-native-inputs libomp-15)
1275 (replace "clang" clang-22)
1276 (replace "llvm" llvm-22)))))
1277
1278(define-public clang-toolchain-22
1279 (make-clang-toolchain clang-22 libomp-22))
1280
1281
1282(define-public llvm-23
1283 (make-llvm "23.1.1"))
1284
1285(define-public clang-runtime-23
1286 (clang-runtime-from-llvm llvm-23))
1287
1288(define-public clang-23
1289 (clang-from-llvm
1290 llvm-23 clang-runtime-23
1291 #:tools-extra #t))
1292
1293(define-public libomp-23
1294 (package
1295 (inherit libomp-15)
1296 (version (package-version llvm-23))
1297 (source (llvm-monorepo version))
1298 (arguments (substitute-keyword-arguments arguments
1299 ((#:configure-flags configure-flag #~())
1300 #~(cons* "-DLLVM_ENABLE_RUNTIMES=openmp"
1301 #$configure-flag))
1302 ((#:phases phases)
1303 #~(modify-phases #$phases
1304 (replace 'chdir-to-source-and-install-license
1305 (lambda _
1306 (install-file "openmp/LICENSE.TXT"
1307 (string-append #$output "/share/doc"))
1308 (chdir "runtimes")))))))
1309 (native-inputs
1310 (modify-inputs (package-native-inputs libomp-15)
1311 (replace "clang" clang-23)
1312 (replace "llvm" llvm-23)))))
1313
1314(define-public clang-toolchain-23
1315 (make-clang-toolchain clang-23 libomp-23))
1316
1317;; Default LLVM and Clang version.
1318(define-public libomp libomp-22)
1319(define-public llvm llvm-22)
1320(define-public clang-runtime clang-runtime-22)
1321(define-public clang clang-22)
1322(define-public clang-toolchain clang-toolchain-22)
1323
1324
1325
1326;; ROCm compiler infrastructure elements are compiled from a monorepo at
1327;; https://github.com/ROCm/llvm-project. Due to some of these parts
1328;; referencing both a common origin and llvm helpers (in particular related to
1329;; patches and base packages). Other ROCm elements are part of rocm.scm
1330
1331;; This must match '%rocm-version' in rocm.scm. They cannot be shared because
1332;; toplevel variables cannot be called from one file to another.
1333(define %rocm-llvm-version "7.1.1")
1334
1335(define %clang-rocm-supported-gpu-targets
1336 ;; List of supported GPU targets for the current version of clang-rocm.
1337 ;; This list can be obtained by running:
1338 ;;
1339 ;; guix shell clang-rocm -- \
1340 ;; clang --target=amdgcn-amd-amdhsa -mcpu=help -nogpulib
1341 ;;
1342 ;; See also <https://llvm.org/docs/AMDGPUUsage.html#amdgpu-processor-table>.
1343 ;; Update this list when upgrading clang-rocm.
1344 '("bonaire"
1345 "carrizo"
1346 "fiji"
1347 "generic"
1348 "generic-hsa"
1349 "gfx10-1-generic"
1350 "gfx10-3-generic"
1351 "gfx1010"
1352 "gfx1011"
1353 "gfx1012"
1354 "gfx1013"
1355 "gfx1030"
1356 "gfx1031"
1357 "gfx1032"
1358 "gfx1033"
1359 "gfx1034"
1360 "gfx1035"
1361 "gfx1036"
1362 "gfx11-generic"
1363 "gfx1100"
1364 "gfx1101"
1365 "gfx1102"
1366 "gfx1103"
1367 "gfx1150"
1368 "gfx1151"
1369 "gfx1152"
1370 "gfx1153"
1371 "gfx12-generic"
1372 "gfx1200"
1373 "gfx1201"
1374 "gfx600"
1375 "gfx601"
1376 "gfx602"
1377 "gfx700"
1378 "gfx701"
1379 "gfx702"
1380 "gfx703"
1381 "gfx704"
1382 "gfx705"
1383 "gfx801"
1384 "gfx802"
1385 "gfx803"
1386 "gfx805"
1387 "gfx810"
1388 "gfx9-4-generic"
1389 "gfx9-generic"
1390 "gfx900"
1391 "gfx902"
1392 "gfx904"
1393 "gfx906"
1394 "gfx908"
1395 "gfx909"
1396 "gfx90a"
1397 "gfx90c"
1398 "gfx940"
1399 "gfx941"
1400 "gfx942"
1401 "gfx950"
1402 "hainan"
1403 "hawaii"
1404 "iceland"
1405 "kabini"
1406 "kaveri"
1407 "mullins"
1408 "oland"
1409 "pitcairn"
1410 "polaris10"
1411 "polaris11"
1412 "stoney"
1413 "tahiti"
1414 "tonga"
1415 "tongapro"
1416 "verde"))
1417
1418(define (make-llvm-rocm llvm-base)
1419 (package
1420 (inherit llvm-base)
1421 ;; XXX A lot of llvm package phases are dependent on llvm version. Are
1422 ;; these resolved early, so that we can override the package version easily?
1423 (version %rocm-llvm-version)
1424 (name "llvm-rocm")
1425 (source (origin
1426 (method git-fetch)
1427 (uri (git-reference
1428 (url "https://github.com/ROCm/llvm-project")
1429 (commit (string-append "rocm-" %rocm-llvm-version))))
1430 (file-name (git-file-name "rocm-llvm" %rocm-llvm-version))
1431 (sha256
1432 (base32
1433 "0ni9s9sd8hlgmj34nkqn96kmbs6xlmrcsw8x5b15cisy2lhjgy89"))
1434 ;; Some of these patches require a further dynamic substitution during
1435 ;; package build. Therefore, it is important to derive from the base
1436 ;; packages or to duplicate such substitutions. Additionally, some of
1437 ;; those substitutions are only applied on specific subcomponents
1438 ;; (llvm-clang), so duplicating the base-llvm structure with subcomponents
1439 ;; is necessary.
1440 (patches
1441 (map search-patch
1442 (cons
1443 "clang-rocm-default-new-dtags.patch"
1444 (assoc-ref %llvm-patches (package-version llvm-base)))))))
1445 (arguments
1446 (substitute-keyword-arguments arguments
1447 ((#:configure-flags flags)
1448 #~(append #$flags
1449 (list #$(string-append
1450 "-DLLVM_TARGETS_TO_BUILD=AMDGPU;X86"
1451 (if (string=? "X86" (system->llvm-target))
1452 ""
1453 (string-append ";" (system->llvm-target))))
1454 "-DLLVM_VERSION_SUFFIX=")))))
1455 (properties `((hidden? . #t)
1456 ,@(package-properties llvm-base)))
1457 (home-page "https://github.com/ROCm/llvm-project")
1458 (synopsis
1459 (string-append (package-synopsis llvm-base) " (AMD fork)"))
1460 (description
1461 (string-append (package-description llvm-base) "
1462
1463This AMD fork includes AMD-specific additions."))))
1464
1465(define-public llvm-rocm (make-llvm-rocm llvm-20))
1466
1467(define (make-clang-runtime-rocm clang-runtime-base)
1468 (package
1469 (inherit clang-runtime-base)
1470 (name "clang-runtime-rocm")
1471 (version (package-version llvm-rocm))
1472 (source (package-source llvm-rocm))
1473 (inputs (modify-inputs inputs
1474 (replace "llvm" llvm-rocm)))))
1475
1476(define-public clang-runtime-rocm (make-clang-runtime-rocm clang-runtime-20))
1477
1478(define (make-clang-rocm clang-base)
1479 ;; note: tools-extra is embedded in the checkout
1480 (package
1481 (inherit clang-base)
1482 (name "clang-rocm")
1483 (version (package-version llvm-rocm))
1484 (source (package-source llvm-rocm))
1485 (inputs (modify-inputs inputs
1486 (delete "clang-tools-extra")))
1487 (propagated-inputs
1488 (modify-inputs propagated-inputs
1489 (replace "llvm" llvm-rocm)
1490 (replace "clang-runtime" clang-runtime-rocm)
1491 (append python-lit)))
1492 (arguments
1493 (substitute-keyword-arguments arguments
1494 ;; The tests can be run, as allowed by check phase rewrite and
1495 ;; LLVM_EXTERNAL_LIT setting. However, 84/46171 are failing. Most
1496 ;; should probably be disabled.
1497 ;;
1498 ;; - CUDA tests are failing.
1499 ;;
1500 ;; - Checking for some -L[[SYSROOT]] is failing, which I guess is
1501 ;; expected, given the patches we apply, which are mangling directory
1502 ;; searching for libraries.
1503 ;;
1504 ;; Getting the test suite to pass doesn't seem out of reach. We
1505 ;; probably should start with the standard llvm-clang-20x package.
1506 ((#:tests? _ #t) #f)
1507 ((#:configure-flags flags)
1508 #~(append #$flags
1509 (list
1510 "-DLLVM_TARGETS_TO_BUILD=AMDGPU;X86"
1511 ;; WARNING: we could patch
1512 ;; #$llvm-rocm/lib/cmake/llvm/AddLLVM.cmake to simplify, by
1513 ;; substituting set(LIT_COMMAND
1514 ;; "${Python3_EXECUTABLE};${lit_base_dir}/${lit_file_name}")
1515 ;; pending this, having a correct python script here is a
1516 ;; must-have.
1517 ;; TODO: test this on llvm-rocm.
1518 (string-append
1519 "-DLLVM_EXTERNAL_LIT="
1520 (search-input-file %build-inputs "bin/.lit-real")))))
1521 ((#:phases phases '%standard-phases)
1522 #~(modify-phases #$phases
1523 (replace 'check
1524 (lambda* (#:rest args)
1525 (setenv "HOME" "/tmp")
1526 (apply (assoc-ref
1527 (@ (guix build gnu-build-system) %standard-phases)
1528 'check)
1529 #:test-target "check-clang" args)))
1530 (replace 'add-tools-extra
1531 (lambda _
1532 (copy-recursively "../clang-tools-extra" "tools/extra")))))))
1533
1534 (properties
1535 `((compiler-amd-gpu-targets . ,%clang-rocm-supported-gpu-targets)
1536 ,@(package-properties clang-base)))))
1537
1538(define-public clang-rocm (make-clang-rocm clang-20))
1539
1540(define-public rocm-device-libs
1541 (package
1542 (name "rocm-device-libs")
1543 (version (package-version llvm-rocm))
1544 (source (package-source llvm-rocm))
1545 (build-system cmake-build-system)
1546 (arguments
1547 (list
1548 #:tests? #f ; Not sure how to run them.
1549 #:build-type "Release"
1550 #:phases
1551 #~(modify-phases %standard-phases
1552 (add-after 'unpack 'chdir
1553 (lambda _
1554 (chdir "amd/device-libs")))
1555 (add-after 'install 'copy-include-directories
1556 (lambda _
1557 ;; at this point we're within amd/build; i guess the build
1558 ;; directory should be at the same level as source, but due to
1559 ;; the chdir above...
1560 (with-directory-excursion "../device-libs"
1561 (for-each
1562 (lambda (directory)
1563 (let ((include-directory (string-append directory "/inc")))
1564 (copy-recursively
1565 include-directory
1566 (string-append #$output "/" include-directory))))
1567 (list "irif" "oclc" "ockl" "ocml"))))))))
1568 (inputs (list clang-rocm))
1569 (home-page "https://github.com/ROCm/llvm-project/")
1570 (synopsis "ROCm Device libraries")
1571 (description "ROCm device libraries provide AMD-specific device-side language runtime
1572libraries, namely oclc, ocml, ockl, opencl, hip and hc.")
1573 (license license:ncsa)))
1574
1575;; Usage note from amd/comgr/src/comgr-env.cpp: at runtime, comgr either needs
1576;; the awful ROCM_PATH set, or the more palatable LLVM_PATH and HIP_PATH, set.
1577(define-public rocm-comgr
1578 (package
1579 (name "rocm-comgr")
1580 (version (package-version llvm-rocm))
1581 (source (package-source llvm-rocm))
1582 (build-system cmake-build-system)
1583 (arguments
1584 (list
1585 #:build-type "Release"
1586 #:phases
1587 #~(modify-phases %standard-phases
1588 (add-after 'unpack 'prepare-to-build
1589 (lambda _
1590 (chdir "amd/comgr")
1591 (setenv "ROCM_PATH"
1592 #$(this-package-input "rocm-device-libs")))))))
1593 (inputs (list libffi rocm-device-libs))
1594 (native-inputs (list
1595 clang-rocm
1596 lld-rocm
1597 python))
1598 (home-page "https://github.com/ROCm/ROCm-CompilerSupport")
1599 (synopsis "ROCm Code Object Manager")
1600 (description "The Comgr library provides APIs for compiling and inspecting
1601AMDGPU code objects.")
1602 (license license:ncsa)))
1603
1604(define-public rocm-hipcc
1605 ;; Hiding because users are not meant to use 'rocm-hipcc' directly, they
1606 ;; should use 'rocm-toolchain' as that package provides all the necessary
1607 ;; scafolding to use the 'hipcc' compiler.
1608 (hidden-package
1609 (package
1610 (name "rocm-hipcc")
1611 (version (package-version llvm-rocm))
1612 (source (package-source llvm-rocm))
1613 (build-system cmake-build-system)
1614 (arguments
1615 (list
1616 #:tests? #f ; Not sure how to run them.
1617 #:build-type "Release"
1618 #:phases
1619 #~(modify-phases %standard-phases
1620 (add-after 'unpack 'chdir
1621 (lambda _
1622 (chdir "amd/hipcc")))
1623 (add-after 'chdir 'patch-paths
1624 (lambda* (#:key inputs #:allow-other-keys)
1625 (substitute* (find-files "src" "\\.h$")
1626 (("roccmPath \\+ \"/bin/rocm_agent_enumerator\"")
1627 (format #f "~s" (search-input-file
1628 inputs
1629 "/bin/rocm_agent_enumerator"))))
1630 (substitute* "src/hipBin_amd.h"
1631 (("which hipconfig")
1632 (string-append (search-input-file inputs "/bin/which")
1633 " hipconfig"))
1634 ;; Ensure the construction of the `HSA_PATH' from the
1635 ;; environment.
1636 (("constructHipPath\\(\\);\n" all)
1637 (string-append all " constructHsaPath();\n")))))
1638 ;; This version file very important, as it is parsed under
1639 ;; $#{llvm-rocm}/clang/lib/Driver/ToolChains/AMDGPU.cpp and its
1640 ;; contents decides on some includes for hipcc.
1641 (add-after 'install 'info-version
1642 (lambda _
1643 (let ((hip-version-dir (string-append #$output "/share/hip")))
1644 (mkdir hip-version-dir)
1645 (with-directory-excursion hip-version-dir
1646 (with-output-to-file "version"
1647 (lambda _
1648 (apply format #t
1649 "HIP_VERSION_MAJOR=~a~%~
1650 HIP_VERSION_MINOR=~a~%~
1651 HIP_VERSION_PATCH=~a~%~
1652 HIP_VERSION_GITHASH=0~%"
1653 (string-split
1654 #$(version-major+minor+point version) #\.))))))))
1655 (add-after 'install 'wrap-programs
1656 (lambda* (#:key inputs outputs #:allow-other-keys)
1657 (let ((output-bindir (string-append (assoc-ref outputs "out") "/bin")))
1658 (for-each
1659 (lambda (file)
1660 (wrap-program (string-append output-bindir "/" file)
1661 ;; The following definitions and their meaning can be
1662 ;; found in hibBin_base.h. We've defined neither
1663 ;; HIP_RUNTIME nor HIP_ROCCLR_HOME.
1664
1665 ;; HIP_ROCCLR_HOME unfortunately cannot be set here
1666 ;; (circular dependency problem) -- it should be set to
1667 ;; #$rocm-hip-runtime.
1668
1669 ;;(list "HIP_ROCCLR_HOME" '= (list #$rocm-hip-runtime))
1670
1671 ;; HACK: allow other packages (eg: `rocm-hip-runtime' or
1672 ;; `rocm-toolchain') to wrap this program with its own
1673 ;; paths.
1674 (list "HIP_PATH" '= (list (string-append "${HIP_PATH:-" #$output "}")))
1675 ;; XXX: `hipconfig' searches for `llc' which is provided
1676 ;; by `llvm-rocm', we cannot wrap that here since it
1677 ;; searches it from the `HIP_CLANG_PATH'. At this level
1678 ;; we don't have the complete `rocm-toolchain' which will
1679 ;; have the union of `llvm-rocm' and `clang-rocm', the
1680 ;; contents of both derivation outputs are expected to
1681 ;; live under `HIP_CLANG_PATH'.
1682 (list "HIP_CLANG_PATH"
1683 '=
1684 (list
1685 (string-append "${HIP_CLANG_PATH:-"
1686 #$(file-append (this-package-input "clang-rocm")
1687 "/bin")
1688 "}")))
1689 (list "DEVICE_LIB_PATH"
1690 '=
1691 (list
1692 (string-append "${DEVICE_LIB_PATH:-"
1693 #$(file-append (this-package-input "rocm-device-libs")
1694 "/amdgcn/bitcode")
1695 "}")))
1696
1697 ;; This is done in order to please check_config, which
1698 ;; checks that HSA_PATH is in LD_LIBRARY_PATH
1699 (list "LD_LIBRARY_PATH"
1700 'suffix
1701 (list #$(this-package-input "rocr-runtime")))
1702 ;; checks hipconfig is in PATH
1703 (list "PATH" 'suffix (list output-bindir))))
1704 '( "hipcc" "hipconfig" ))))))))
1705 (inputs (list clang-rocm
1706 rocm-device-libs
1707 rocr-runtime
1708 rocminfo
1709 perl
1710 bash-minimal
1711 which))
1712 (home-page "https://github.com/ROCm/llvm-project/")
1713 (synopsis "ROCm HIP compiler driver (@command{hipcc})")
1714 (description "The HIP compiler driver (@command{hipcc}) is a compiler utility that will
1715call @command{clang} and pass the appropriate include and library options for
1716the target compiler and HIP infrastructure.")
1717 (license license:expat))))
1718
1719
1720
1721(define-public libunwind-headers
1722 (package
1723 (name "libunwind-headers")
1724 (version "13.0.0")
1725 (source (origin
1726 (method url-fetch)
1727 (uri (llvm-uri "libunwind" version))
1728 (sha256
1729 (base32
1730 "1qb5ickp7qims5q7sxacj3fwq1kklvnl94k3v9hpl5qn284iky1n"))))
1731 (build-system cmake-build-system)
1732 (arguments
1733 '(#:phases (modify-phases (map (lambda (phase)
1734 (assq phase %standard-phases))
1735 '(set-paths unpack))
1736 (add-after 'unpack 'install
1737 (lambda* (#:key outputs #:allow-other-keys)
1738 (let ((out (assoc-ref outputs "out")))
1739 (mkdir out)
1740 (copy-recursively "include"
1741 (string-append out "/include"))))))))
1742 (home-page "https://clang.llvm.org/docs/Toolchain.html")
1743 (synopsis "LLVM libunwind header files")
1744 (description
1745 "This package contains header files for the LLVM C++ unwinding library.")
1746 (properties `((release-monitoring-url . ,%llvm-release-monitoring-url)))
1747 (license license:asl2.0))) ;with LLVM exceptions
1748
1749(define-public lld-15
1750 (package
1751 (name "lld")
1752 (version (package-version llvm-15))
1753 (source (llvm-monorepo version))
1754 (build-system cmake-build-system)
1755 (inputs
1756 (list llvm-15))
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 #:phases (modify-phases %standard-phases
1763 (add-after 'unpack 'change-directory
1764 (lambda _
1765 (chdir "lld"))))))
1766 (home-page "https://lld.llvm.org/")
1767 (synopsis "Linker from the LLVM project")
1768 (description "LLD is a high-performance linker, built as a set of reusable
1769components which highly leverage existing libraries in the larger LLVM Project.")
1770 (license license:asl2.0))) ; With LLVM exception
1771
1772(define-public lld-14
1773 (package
1774 (inherit lld-15)
1775 (version "14.0.6")
1776 (source (llvm-monorepo version))
1777 (inputs
1778 (list llvm-14))))
1779
1780(define-public lld-13
1781 (package
1782 (inherit lld-14)
1783 (version "13.0.1")
1784 (source (origin
1785 (method url-fetch)
1786 (uri (llvm-uri "lld" version))
1787 (sha256
1788 (base32
1789 "1yscckcszfr234k4svhybdbsnz6w65x8pldl6c2nhyxzx12zfsk6"))))
1790 (native-inputs
1791 ;; Note: check <https://bugs.llvm.org/show_bug.cgi?id=49228> to see
1792 ;; whether this is still necessary.
1793 (list libunwind-headers))
1794 (inputs
1795 (list llvm-13))
1796 (arguments
1797 '(#:build-type "Release"
1798 ;; TODO: Tests require the lit tool, which isn't installed by the LLVM
1799 ;; package.
1800 #:tests? #f))
1801 (properties `((release-monitoring-url . ,%llvm-release-monitoring-url)))))
1802
1803(define-public lld-16
1804 (package
1805 (inherit lld-15)
1806 (version (package-version llvm-16))
1807 (source (llvm-monorepo version))
1808 (inputs (list llvm-16))))
1809
1810(define-public lld-17
1811 (package
1812 (inherit lld-15)
1813 (version (package-version llvm-17))
1814 (source (llvm-monorepo version))
1815 (inputs (list llvm-17))))
1816
1817(define-public lld-18
1818 (package
1819 (inherit lld-15)
1820 (version (package-version llvm-18))
1821 (source (llvm-monorepo version))
1822 (inputs (list llvm-18))))
1823
1824(define-public lld-19
1825 (package
1826 (inherit lld-15)
1827 (version (package-version llvm-19))
1828 (source (llvm-monorepo version))
1829 (inputs (list llvm-19))))
1830
1831(define-public lld-20
1832 (package
1833 (inherit lld-15)
1834 (version (package-version llvm-20))
1835 (source (llvm-monorepo version))
1836 (inputs (list llvm-20))))
1837
1838(define-public lld-21
1839 (package
1840 (inherit lld-15)
1841 (version (package-version llvm-21))
1842 (source (llvm-monorepo version))
1843 (inputs (list llvm-21))))
1844
1845(define-public lld-22
1846 (package
1847 (inherit lld-15)
1848 (version (package-version llvm-22))
1849 (source (llvm-monorepo version))
1850 (inputs (list llvm-22))))
1851
1852(define-public lld-23
1853 (package
1854 (inherit lld-15)
1855 (version (package-version llvm-23))
1856 (source (llvm-monorepo version))
1857 (inputs (list llvm-23))))
1858
1859(define-public lld lld-22)
1860
1861(define* (make-lld-wrapper lld #:key lld-as-ld?)
1862 "Return a LLD wrapper. When LLD-AS-LD? is true, create a 'ld' symlink that
1863points to 'lld'."
1864 (package
1865 (inherit lld)
1866 (name (if lld-as-ld? "lld-as-ld-wrapper" "lld-wrapper"))
1867 (source #f)
1868 (native-inputs '())
1869 (inputs (list (make-ld-wrapper "ld.lld-wrapper" #:binutils lld
1870 #:linker "ld.lld")
1871 (make-ld-wrapper "lld-wrapper" #:binutils lld #:linker
1872 "lld")))
1873 (propagated-inputs '())
1874 (build-system trivial-build-system)
1875 (arguments
1876 (list #:builder
1877 #~(let ((ld.lld (string-append #$(this-package-input
1878 "ld.lld-wrapper")
1879 "/bin/ld.lld"))
1880 (lld (string-append #$(this-package-input "lld-wrapper")
1881 "/bin/lld")))
1882 (mkdir #$output)
1883 (mkdir (string-append #$output "/bin"))
1884 (symlink ld.lld (string-append #$output "/bin/ld.lld"))
1885 (symlink lld (string-append #$output "/bin/lld"))
1886 (when #$lld-as-ld?
1887 (symlink ld.lld (string-append #$output "/bin/ld"))))))
1888 (synopsis "LLD linker wrapper")
1889 (description "This is a linker wrapper for LLD; like @code{ld-wrapper}, it
1890wraps the linker to add any missing @code{-rpath} flags, and to detect any
1891misuse of libraries outside of the store.")))
1892
1893;;; A LLD wrapper suitable to use with -fuse-ld and GCC or with Clang.
1894(define-public lld-wrapper
1895 (make-lld-wrapper lld))
1896
1897;;; A LLD wrapper that can be used as a (near) drop-in replacement to GNU ld.
1898(define-public lld-as-ld-wrapper-18
1899 (make-lld-wrapper lld-18 #:lld-as-ld? #t))
1900
1901(define-public lld-as-ld-wrapper
1902 (make-lld-wrapper lld #:lld-as-ld? #t))
1903
1904(define-public lldb
1905 (package
1906 (name "lldb")
1907 (version (package-version llvm-23))
1908 (source (llvm-monorepo version))
1909 (build-system cmake-build-system)
1910 (arguments
1911 (list
1912 ;; No access to a compiled llvm-lit since compiled separately from llvm.
1913 #:tests? #f
1914 #:configure-flags #~(list "-DOPENMP_TEST_CXX_COMPILER=clang++")
1915 #:phases
1916 #~(modify-phases %standard-phases
1917 (add-after 'unpack 'chdir-to-source
1918 (lambda _
1919 (chdir "lldb"))))))
1920 (native-inputs
1921 (list pkg-config swig-4.0))
1922 (inputs
1923 (list clang-23
1924 llvm-23
1925 ;; Optional (but recommended) inputs.
1926 ncurses
1927 libedit
1928 xz
1929 libxml2
1930 lua
1931 python))
1932 (home-page "https://lldb.llvm.org/")
1933 (synopsis "Low level debugger")
1934 (description
1935 "LLDB is a high performance debugger built as a set of reusable components
1936which highly leverage existing libraries in the larger LLVM project.")
1937 (properties `((release-monitoring-url . ,%llvm-release-monitoring-url)))
1938 (license license:asl2.0))) ;with LLVM exceptions
1939
1940(define-public libcxx
1941 (package
1942 (name "libcxx")
1943 (version (package-version llvm))
1944 (source (llvm-monorepo version))
1945 (build-system cmake-build-system)
1946 (arguments
1947 (list
1948 #:tests? #f ;prohibitively expensive to run
1949 #:implicit-inputs? #f ;to avoid conflicting GCC headers
1950 #:configure-flags
1951 #~(list "-DLLVM_ENABLE_RUNTIMES=libcxx;libcxxabi;libunwind"
1952 "-DCMAKE_C_COMPILER=clang"
1953 "-DCMAKE_CXX_COMPILER=clang++"
1954 ;; libc++.so is actually a GNU ld style linker script, however,
1955 ;; CMake still tries to fix the RUNPATH of it during the install
1956 ;; step. This argument tells CMake to use the install directory
1957 ;; as RUNPATH and don't attempt to patch it.
1958 ;; See also: https://gitlab.kitware.com/cmake/cmake/-/issues/22963
1959 "-DCMAKE_BUILD_WITH_INSTALL_RPATH=TRUE")
1960 #:modules '((guix build cmake-build-system)
1961 ((guix build gnu-build-system) #:prefix gnu:)
1962 (guix build utils))
1963 #:phases
1964 #~(modify-phases %standard-phases
1965 (add-after 'unpack 'disable-tidy-checks
1966 (lambda _
1967 ;; This target breaks our build while trying to include memory.h
1968 ;; then cstdlib and stdlib.h from gcc using #include_next
1969 ;; directive, even though gcc is not part of native-inputs.
1970 ;; See: https://gitlab.kitware.com/cmake/cmake/-/work_items/16919
1971 ;; and https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70129.
1972 (substitute* "libcxx/test/tools/clang_tidy_checks/CMakeLists.txt"
1973 (("NOT Clang_FOUND")
1974 "1"))))
1975 (add-after 'disable-tidy-checks 'enter-subdirectory
1976 (lambda _
1977 (chdir "runtimes")))
1978 (replace 'check
1979 (lambda* (#:rest args)
1980 (apply (assoc-ref gnu:%standard-phases 'check)
1981 #:test-target "check-cxx" args))))))
1982 (native-inputs
1983 (modify-inputs (standard-packages)
1984 ;; Remove GCC from the build environment, to avoid its C++
1985 ;; headers (include/c++), which would interfere and cause build
1986 ;; failures.
1987 (delete "gcc")
1988 (prepend clang python-minimal)))
1989 (home-page "https://libcxx.llvm.org")
1990 (synopsis "C++ standard library")
1991 (description
1992 "This package provides an implementation of the C++ standard library for
1993use with Clang, targeting C++11, C++14 and above.")
1994 (properties `((release-monitoring-url . ,%llvm-release-monitoring-url)))
1995 (license license:expat)))
1996
1997;; WARNING: This package is a dependency of mesa.
1998(define-public libclc
1999 (package
2000 (name "libclc")
2001 (version (package-version llvm-18))
2002 (source (llvm-monorepo version))
2003 (build-system cmake-build-system)
2004 (arguments
2005 (list
2006 #:configure-flags
2007 #~(list (string-append "-DLLVM_CLANG="
2008 (assoc-ref %build-inputs "clang")
2009 "/bin/clang")
2010 (string-append "-DLLVM_SPIRV="
2011 (assoc-ref %build-inputs "spirv-llvm-translator")
2012 "/bin/llvm-spirv"))
2013 #:phases
2014 #~(modify-phases %standard-phases
2015 (add-after 'unpack 'enter-subdirectory
2016 (lambda _
2017 (chdir "libclc")))
2018 (add-after 'enter-subdirectory 'skip-clspv-tests
2019 (lambda _
2020 (substitute* "CMakeLists.txt"
2021 (("ptx\\.\\*") "[ptx|clspv].*")))))))
2022 (propagated-inputs
2023 (list spirv-llvm-translator spirv-tools))
2024 (native-inputs
2025 (list clang-18 llvm-18 python))
2026 (home-page "https://libclc.llvm.org")
2027 (synopsis "Libraries for the OpenCL programming language")
2028 (description
2029 "This package provides an implementation of the OpenCL library
2030requirements according to version 1.1 of the OpenCL specification.")
2031 (properties `((release-monitoring-url . ,%llvm-release-monitoring-url)))
2032 ;; Apache license 2.0 with LLVM exception
2033 (license license:asl2.0)))
2034
2035(define (mlir-from-llvm llvm)
2036 "Produce MLIR with dependencies on LLVM."
2037 (package
2038 (name "mlir")
2039 (version (package-version llvm))
2040 (source (llvm-monorepo version))
2041 (build-system cmake-build-system)
2042 (native-inputs (package-native-inputs llvm))
2043 (inputs
2044 (list llvm))
2045 (arguments
2046 (list #:build-type "Release"
2047 #:configure-flags
2048 #~(list "-DMLIR_BUILD_MLIR_C_DYLIB=ON"
2049 "-DLLVM_BUILD_LLVM_DYLIB=ON"
2050 "-DLLVM_LINK_LLVM_DYLIB=ON"
2051 ;; The two following options install mlir-tblgen (which is
2052 ;; used by some dependent projects such as flang).
2053 "-DLLVM_INSTALL_TOOLCHAIN_ONLY=OFF"
2054 "-DLLVM_BUILD_UTILS=ON")
2055 #:tests? #f ; Tests require gtest
2056 #:phases #~(modify-phases %standard-phases
2057 (add-after 'unpack 'change-directory
2058 (lambda _
2059 (chdir "mlir"))))))
2060 (home-page "https://mlir.llvm.org/")
2061 (synopsis "Multi-Level Intermediate Representation")
2062 (description "This package is a novel approach to building reusable
2063and extensible compiler infrastructure. MLIR aims to address software
2064fragmentation, improve compilation for heterogeneous hardware, significantly
2065reduce the cost of building domain specific compilers, and aid in connecting
2066existing compilers together.")
2067 (license license:asl2.0))) ; With LLVM exception
2068
2069(define-public mlir-19
2070 (mlir-from-llvm llvm-19))
2071
2072(define-public mlir-15
2073 (mlir-from-llvm llvm-15))
2074
2075(define-public rocmlir
2076 (package
2077 (name "rocmlir")
2078 (version %rocm-llvm-version)
2079 (source (origin
2080 (method git-fetch)
2081 (uri (git-reference
2082 (url "https://github.com/ROCm/rocMLIR")
2083 (commit (string-append "rocm-" version))))
2084 (file-name (git-file-name name version))
2085 (sha256
2086 (base32
2087 "0yr76dj465rw4ck9dk1mjjn3rgp8gb0v273f256rkb8rq6zd9nq3"))))
2088 (build-system cmake-build-system)
2089 (arguments
2090 (list
2091 #:build-type "Release"
2092 #:configure-flags
2093 #~(list
2094 "-DCMAKE_C_COMPILER=clang"
2095 "-DCMAKE_CXX_COMPILER=clang++"
2096 "-DBUILD_FAT_LIBROCKCOMPILER=ON")
2097 ;; Tests require hip-python, which depends on several ROCm libraries
2098 #:tests? #f))
2099 (native-inputs (list clang-rocm rocm-hip-runtime python rocm-cmake))
2100 (home-page "https://github.com/ROCm/rocMLIR")
2101 (synopsis "MLIR-based convolution and GEMM kernel generator")
2102 (description "rocMLIR is a MLIR-based convolution and GEMM kernel
2103generator targetting AMD hardware.")
2104 (license license:expat)))
2105
2106(define-public python-llvmlite
2107 (package
2108 (name "python-llvmlite")
2109 (version "0.48.0")
2110 (source
2111 (origin
2112 ;; XXX: Switching to git require versioneer from python-xyz.
2113 (method url-fetch)
2114 (uri (pypi-uri "llvmlite" version))
2115 (sha256
2116 (base32
2117 "1lpdjbg9ip8d9kv5cgcakyzkf58vxvj930a6s5h7qg4gxzwijfsl"))))
2118 (build-system pyproject-build-system)
2119 (arguments
2120 (list
2121 #:test-backend #~'custom
2122 #:test-flags #~(list "-m" "llvmlite.tests")
2123 #:phases
2124 #~(modify-phases %standard-phases
2125 (add-after 'unpack 'skip-test
2126 (lambda _
2127 (substitute* "llvmlite/tests/test_binding.py"
2128 ;; This test tries to ensure all dependencies are expected by
2129 ;; parsing output of objdump with regex which might not
2130 ;; matching Guix variants.
2131 (("test_linux" all)
2132 (string-append "__off_" all)))))
2133 (add-before 'build 'set-compiler/linker-flags
2134 (lambda _
2135 (let ((llvm #$(this-package-input "llvm")))
2136 ;; Refer to ffi/Makefile.linux.
2137 (setenv "CPPFLAGS" "-fPIC")
2138 (setenv "LDFLAGS" (string-append "-Wl,-rpath="
2139 llvm "/lib")))))
2140 (add-before 'check 'pre-check
2141 (lambda _
2142 (setenv "LLVMLITE_DIST_TEST" "1"))))))
2143 (native-inputs
2144 (list cmake-minimal
2145 python-setuptools))
2146 (inputs
2147 (list llvm))
2148 (home-page "https://llvmlite.pydata.org")
2149 (synopsis "Wrapper around basic LLVM functionality")
2150 (description
2151 "This package provides a Python binding to LLVM for use in Numba.")
2152 (license (list license:asl2.0 license:bsd-2))))
2153
2154(define-public (clang-python-bindings clang)
2155 "Return a package for the Python bindings of CLANG."
2156 (package
2157 (inherit clang)
2158 (name "python-clang")
2159 (build-system pyproject-build-system)
2160 (outputs '("out"))
2161 (arguments
2162 (list
2163 #:test-backend #~'unittest
2164 #:phases #~(modify-phases %standard-phases
2165 (add-before 'build 'change-directory
2166 (lambda _
2167 (chdir "bindings/python")))
2168 (add-before 'build 'set-libclang-file-name
2169 (lambda* (#:key inputs #:allow-other-keys)
2170 ;; Record the absolute file name of libclang.so.
2171 (let ((libclang (search-input-file inputs
2172 "/lib/libclang.so")))
2173 (substitute* "clang/cindex.py"
2174 (("libclang\\.so") libclang))))))))
2175 (native-inputs (list python-setuptools))
2176 (inputs (list clang))
2177 (native-inputs (modify-inputs (package-native-inputs clang)
2178 (append python-setuptools)))
2179 (synopsis "Python bindings to libclang")))
2180
2181(define-public python-clang-13
2182 (clang-python-bindings clang-13))
2183
2184;; XXX
2185;; I would move all of rocm packages here and define a ROCm section.
2186
2187(define (make-lld-rocm lld-base)
2188 (package
2189 (inherit lld-base)
2190 (name "lld-rocm")
2191 (version (package-version llvm-rocm))
2192 (source (package-source llvm-rocm))
2193 (inputs (list llvm-rocm))
2194 (arguments
2195 (substitute-keyword-arguments arguments
2196 ((#:configure-flags flags)
2197 #~(append #$flags
2198 '("-DLLVM_TARGETS_TO_BUILD=AMDGPU;X86")))))))
2199
2200(define-public lld-rocm (make-lld-rocm lld-20))
2201
2202(define-public lld-wrapper-rocm
2203 (package
2204 (inherit (make-lld-wrapper lld-rocm))
2205 (name "lld-wrapper-rocm")))
2206
2207(define-public libomp-rocm
2208 (package
2209 (inherit libomp-20)
2210 (name "libomp-rocm")
2211 (version (package-version llvm-rocm))
2212 (source (package-source llvm-rocm))
2213 (arguments
2214 (substitute-keyword-arguments arguments
2215 ((#:configure-flags flags '())
2216 #~(cons
2217 (string-append "-DOPENMP_LIT_ARGS="
2218 "-sv --show-unsupported --show-xfail"
2219 ;; This test fails
2220 " --filter-out tasking/task_teams_stress_test.cpp")
2221 #$flags))
2222 ((#:phases phases)
2223 #~(modify-phases #$phases
2224 (add-after 'unpack 'fix-lit
2225 (lambda _
2226 (substitute* "openmp/cmake/OpenMPTesting.cmake"
2227 (((string-append "COMMAND \\$\\{Python3_EXECUTABLE\\}"
2228 " \\$\\{OPENMP_LLVM_LIT_EXECUTABLE\\}"))
2229 "COMMAND ${OPENMP_LLVM_LIT_EXECUTABLE}"))
2230 (substitute* "openmp/runtime/test/lit.cfg"
2231 (("config\\.name =.*" orig)
2232 (string-append
2233 orig
2234 "\nconfig.environment['C_INCLUDE_PATH']"
2235 " = os.environ['C_INCLUDE_PATH']\n"
2236 "config.environment['CPLUS_INCLUDE_PATH']"
2237 " = os.environ['CPLUS_INCLUDE_PATH']\n")))))))))
2238 (native-inputs
2239 (modify-inputs native-inputs
2240 (replace "clang" clang-rocm)
2241 (replace "llvm" llvm-rocm)))))
2242
2243(define-public clang-rocm-toolchain
2244 (make-clang-toolchain clang-rocm libomp-rocm))
2245
2246(define-public offload-rocm
2247 (package
2248 (name "offload-rocm")
2249 (version (package-version llvm-rocm))
2250 (source (package-source llvm-rocm))
2251 (build-system cmake-build-system)
2252 (arguments
2253 (list
2254 #:configure-flags
2255 #~(list
2256 "-DCMAKE_EXE_LINKER_FLAGS=-fuse-ld=lld"
2257 "-DCMAKE_SHARED_LINKER_FLAGS=-fuse-ld=lld")
2258 #:phases
2259 #~(modify-phases %standard-phases
2260 (add-after 'unpack 'chdir
2261 (lambda _
2262 (chdir "offload")))
2263 (add-after 'chdir 'libffi-dynamic-link
2264 (lambda _
2265 (substitute* "plugins-nextgen/host/CMakeLists.txt"
2266 (("if\\(FFI_STATIC.*") "if(FALSE)\n"))))
2267 (add-after 'install 'install-license
2268 (lambda _
2269 (install-file "../LICENSE.TXT"
2270 (string-append #$output "/share/doc/"
2271 #$name "-" #$version)))))
2272 ;; XXX: Tests cannot be built with ROCm version 7.1.1:
2273 ;; https://github.com/ROCm/llvm-project/blob/27682a16360e33e37c4f3cc6adf9a620733f8fe1/offload/CMakeLists.txt#L443
2274 #:tests? #f))
2275 (native-inputs
2276 (list clang-rocm-toolchain
2277 lld-wrapper-rocm
2278 python))
2279 (inputs
2280 (list libffi
2281 libomp-rocm
2282 rocm-device-libs
2283 rocr-runtime))
2284 (home-page "https://github.com/ROCm/llvm-project/")
2285 (synopsis "LLVM offloading library")
2286 (description "This LLVM component provides tooling, runtimes and APIs for
2287executing code on accelerators which may have a different architecture than
2288the host.")
2289 ;; Apache license 2.0 with LLVM exception
2290 (license license:asl2.0)))
2291
2292(define-public rocm-toolchain
2293 (package
2294 (inherit clang-rocm-toolchain)
2295 (name "rocm-toolchain")
2296 (inputs
2297 (modify-inputs inputs
2298 (append bash-minimal ;for 'wrap-program'.
2299 lld-wrapper-rocm
2300 offload-rocm
2301 rocr-runtime
2302 rocm-hipcc
2303 rocm-device-libs)))
2304 (arguments
2305 (substitute-keyword-arguments arguments
2306 ((#:modules modules)
2307 `(,@modules
2308 (guix build utils)))
2309 ((#:builder _)
2310 #~(begin
2311 (use-modules (ice-9 match)
2312 (guix build union)
2313 (guix build utils))
2314
2315 (define (unionize output inputs)
2316 (union-build output inputs
2317 #:symlink (lambda (old new)
2318 ;; Ignoring wrappers since
2319 ;; 'wrap-program' will not be able to
2320 ;; create the wrapper if it already
2321 ;; exits.
2322 (unless (wrapped-program? old)
2323 (symlink old new)))
2324 ;; Make sure directories are created instead of
2325 ;; symlinks so after creating the union
2326 ;; 'wrap-program' can create new files.
2327 #:create-all-directories? #t))
2328
2329 ;; Required for 'wrap-program'.
2330 (setenv "PATH" #$(file-append (this-package-input "bash-minimal")
2331 "/bin"))
2332
2333 (match %build-inputs
2334 (((names . directories) ...)
2335 (unionize #$output directories)))
2336
2337 (unionize #$output:debug
2338 (list #$(this-package-input "libc-debug")))
2339 (unionize #$output:static
2340 (list #$(this-package-input "libc-static")))
2341
2342 ;; Wrap programs.
2343 (let ((bin (string-append #$output "/bin")))
2344 (for-each
2345 (lambda (file)
2346 (wrap-program file
2347 ;; 'hipconfig' check that the 'LD_LIBRARY_PATH' of some
2348 ;; binaries contains 'HSA_PATH'. Since that path is set
2349 ;; during compilation, this 'rocm-toolchain' meta package
2350 ;; needs to point to 'rocr-runtime' rather than '#$output'.
2351 `("HSA_PATH" = ,(list #$(this-package-input "rocr-runtime")))
2352 `("HIP_PATH" = ,(list #$output))
2353 `("HIP_CLANG_PATH" = ,(list bin))))
2354 (find-files bin ".")))))))
2355 (native-search-paths
2356 (append (package-native-search-paths clang-rocm-toolchain)
2357 (list (search-path-specification
2358 (variable "HIP_DEVICE_LIB_PATH")
2359 (files '("amdgcn/bitcode"))))))
2360 (synopsis "Clang-based ROCm toolchain for C/C++ development")
2361 (description
2362 "This package provides a complete ROCm toolchain for C/C++ development to
2363be installed in user profiles. This includes Clang, as well as libc (headers
2364and binaries, plus debugging symbols in the @code{debug} output), Binutils,
2365the ROCm device libraries, and the ROCr runtime.")))
2366
2367
2368
2369(define-public include-what-you-use
2370 (package
2371 (name "include-what-you-use")
2372 ;; Ensure LLVM/Clang input versions match the version declared in the release
2373 ;; https://github.com/include-what-you-use/include-what-you-use/blob/master/README.md#clang-compatibility
2374 (version "0.24")
2375 (source
2376 (origin
2377 (method git-fetch)
2378 (uri (git-reference
2379 (url "https://github.com/include-what-you-use/include-what-you-use")
2380 (commit version)))
2381 (file-name (git-file-name name version))
2382 (sha256
2383 (base32 "0dkk65y6abf7bzv10q1ch3dyzj4d5y89qhh43jn189l861d6pzs0"))))
2384 (build-system cmake-build-system)
2385 (inputs (list llvm-20 clang-20 python-3))
2386 (synopsis
2387 "Tool for use with clang to analyze #includes in C and C++ source files")
2388 (home-page "https://github.com/include-what-you-use/include-what-you-use")
2389 (description
2390 "@code{include-what-you-use} lints C and C++ sources to ensure
2391@code{#include}s declaring every symbol used in a given file are present.
2392When every file directly includes what it uses rather than relying on
2393transitive inclusions, builds tend to be more efficient and refactoring
2394dependency relationships is easier, particularly for large projects.")
2395 ;; The project has not relicensed from the old LLVM license:
2396 ;; https://github.com/include-what-you-use/include-what-you-use/issues/849
2397 ;; The iwyu_getopt.* files are BSD-3.
2398 (license (list license:ncsa license:bsd-3))))
2399
2400(define-public emacs-clang-format
2401 (package
2402 (inherit clang)
2403 (name "emacs-clang-format")
2404 (build-system emacs-build-system)
2405 (inputs
2406 (list clang))
2407 (propagated-inputs '())
2408 (arguments
2409 (list
2410 #:lisp-directory "clang/tools/clang-format"
2411 #:phases
2412 #~(modify-phases %standard-phases
2413 (add-after 'unpack 'configure
2414 (lambda* (#:key inputs #:allow-other-keys)
2415 (let ((clang-format (search-input-file inputs "/bin/clang-format")))
2416 (emacs-substitute-variables "clang-format.el"
2417 ("clang-format-executable"
2418 clang-format))))))
2419 #:test-command #~(list "emacs" "-Q" "--batch"
2420 "-l" "clang-format.el"
2421 "-l" "clang-format-test.el"
2422 "-f" "ert-run-tests-batch-and-exit")))
2423 (synopsis "Format code using clang-format")
2424 (description "This package filters code through @code{clang-format}
2425to fix its formatting. @code{clang-format} is a tool that formats
2426C/C++/Obj-C code according to a set of style options, see
2427@url{https://clang.llvm.org/docs/ClangFormatStyleOptions.html}.")))
2428
2429(define-public emacs-clang-include-fixer
2430 (package
2431 (inherit clang)
2432 (name "emacs-clang-include-fixer")
2433 (build-system emacs-build-system)
2434 (inputs
2435 (list clang))
2436 (propagated-inputs '())
2437 (arguments
2438 (list
2439 #:lisp-directory "clang-tools-extra/clang-include-fixer/tool"
2440 #:phases
2441 #~(modify-phases %standard-phases
2442 (add-after 'unpack 'configure
2443 (lambda* (#:key inputs #:allow-other-keys)
2444 (let ((clang-include-fixer
2445 (search-input-file inputs "/bin/clang-include-fixer")))
2446 (emacs-substitute-variables "clang-include-fixer.el"
2447 ("clang-include-fixer-executable"
2448 clang-include-fixer))))))
2449 #:test-command #~(list "emacs" "-Q" "--batch"
2450 "-l" "clang-include-fixer.el"
2451 "-l" "clang-include-fixer-test.el"
2452 "-f" "ert-run-tests-batch-and-exit")))
2453 (synopsis "Emacs interface to @code{clang-include-fixer}")
2454 (description "This package provides an automated way of adding #include
2455directives for missing symbols in one translation unit, see
2456@url{http://clang.llvm.org/extra/clang-include-fixer.html}.")))
2457
2458(define-public emacs-clang-rename
2459 (package
2460 (inherit clang-19)
2461 (name "emacs-clang-rename")
2462 (build-system emacs-build-system)
2463 (inputs
2464 (list clang-19))
2465 (propagated-inputs '())
2466 (arguments
2467 (list #:lisp-directory "clang/tools/clang-rename"
2468 #:tests? #f ;no tests
2469 #:phases
2470 #~(modify-phases %standard-phases
2471 (add-after 'unpack 'configure
2472 (lambda* (#:key inputs #:allow-other-keys)
2473 (let ((clang-rename (search-input-file inputs "/bin/clang-rename")))
2474 (emacs-substitute-variables "clang-rename.el"
2475 ("clang-rename-binary" clang-rename))))))))
2476 (synopsis "Rename every occurrence of a symbol using clang-rename")
2477 (description "This package renames every occurrence of a symbol at point
2478using @code{clang-rename}.")))
2479
2480
2481;;;
2482;;; LLVM variants.
2483;;;
2484
2485(define-public llvm-for-mesa
2486 ;; Note: update the 'clang' input of mesa-opencl when bumping this.
2487 (let ((base-llvm llvm-18))
2488 (package
2489 (inherit base-llvm)
2490 (name "llvm-for-mesa")
2491 (arguments
2492 (substitute-keyword-arguments arguments
2493 ((#:modules modules '((guix build cmake-build-system)
2494 (guix build utils)))
2495 `((ice-9 regex)
2496 (srfi srfi-1)
2497 (srfi srfi-26)
2498 ,@modules))
2499 ((#:configure-flags cf ''())
2500 #~(cons*
2501 #$@(if (%current-target-system)
2502 '("-DBUILD_SHARED_LIBS:BOOL=TRUE"
2503 "-DCMAKE_BUILD_WITH_INSTALL_RPATH=TRUE")
2504 '())
2505 ;; Skipping tools and utils decreases the output by ~100 MiB.
2506 "-DLLVM_BUILD_TOOLS=NO"
2507 (remove
2508 (cut string-match
2509 #$(if (%current-target-system)
2510 "-DLLVM_(LINK_LLVM_DYLIB|INSTALL_UTILS).*"
2511 "-DLLVM_INSTALL_UTILS.*") <>)
2512 #$cf)))
2513 ((#:phases phases '%standard-phases)
2514 #~(modify-phases #$phases
2515 #$@(if (%current-target-system)
2516 '()
2517 #~((add-after 'install 'delete-static-libraries
2518 ;; If these are just relocated then llvm-config
2519 ;; can't find them.
2520 (lambda* (#:key outputs #:allow-other-keys)
2521 (for-each delete-file
2522 (find-files
2523 (string-append
2524 (assoc-ref outputs "out") "/lib")
2525 "\\.a$"))))))
2526 ;; llvm-config is how mesa and others find the various
2527 ;; libraries and headers they use.
2528 (add-after 'install 'build-and-install-llvm-config
2529 (lambda* (#:key outputs #:allow-other-keys)
2530 (let ((out (assoc-ref outputs "out")))
2531 (substitute*
2532 "tools/llvm-config/CMakeFiles/llvm-config.dir/link.txt"
2533 (((string-append (getcwd) "/build/lib"))
2534 (string-append out "/lib")))
2535 (invoke "make" "llvm-config")
2536 (install-file "bin/llvm-config"
2537 (string-append out "/bin"))))))))))))
2538
2539(define make-ocaml-llvm
2540 ;; Make it a memoizing procedure so its callers below don't end up defining
2541 ;; two equal-but-not-eq "ocaml-llvm" packages for the default LLVM.
2542 (mlambdaq (llvm)
2543 (package
2544 (inherit llvm)
2545 (name "ocaml-llvm")
2546 (outputs '("out"))
2547 (arguments
2548 `(#:configure-flags
2549 (list
2550 (string-append "-DLLVM_OCAML_EXTERNAL_LLVM_LIBDIR="
2551 (assoc-ref %build-inputs "llvm") "/lib")
2552 "-DBUILD_SHARED_LIBS=TRUE"
2553 "-DLLVM_OCAML_OUT_OF_TREE=TRUE"
2554 (string-append "-DLLVM_OCAML_INSTALL_PATH="
2555 (assoc-ref %outputs "out") "/lib/ocaml/site-lib"))
2556 #:tests? #f ;no tests
2557 #:phases
2558 (modify-phases %standard-phases
2559 (replace 'build
2560 (lambda _
2561 (invoke "make" "ocaml_all")))
2562 (replace 'install
2563 (lambda _
2564 (invoke "cmake" "-P" "bindings/ocaml/cmake_install.cmake"))))))
2565 (inputs
2566 (list llvm))
2567 (native-inputs
2568 (list ocaml ocaml-findlib ocaml-ounit python))
2569 (propagated-inputs
2570 (list ocaml-integers ocaml-ctypes))
2571 (synopsis "OCaml bindings to LLVM")
2572 (description "This package contains the OCaml bindings distributed with
2573LLVM."))))
2574
2575(define-public ocaml-llvm (make-ocaml-llvm llvm-13))
2576
2577(define-public wllvm
2578 (package
2579 (name "wllvm")
2580 (properties '((commit . "948cdb8bd8fb446c700a6aefc218153db5ce2591")
2581 (revision . "0")))
2582 (version (git-version "1.3.1"
2583 (assoc-ref properties 'revision)
2584 (assoc-ref properties 'commit)))
2585 (source
2586 (origin
2587 (method git-fetch)
2588 (uri (git-reference
2589 ;; Maintained fork.
2590 (url "https://github.com/travitch/whole-program-llvm")
2591 (commit (assoc-ref properties 'commit))))
2592 (file-name (git-file-name name version))
2593 (sha256
2594 (base32 "0ksasakx0ihg86j0qdla0zy14ljdhzpgi11as4kkgj51v4haihn4"))))
2595 (build-system pyproject-build-system)
2596 (arguments
2597 (list
2598 #:test-flags
2599 ;; This test requires access to binary llvm-gcc.
2600 #~(list "--ignore=test/test_dragonegg_driver.py")
2601 #:phases
2602 #~(modify-phases %standard-phases
2603 (add-after 'unpack 'fix-paths
2604 (lambda* (#:key inputs #:allow-other-keys)
2605 (let ((pystr (lambda (s) (string-append "'" s "'"))))
2606 (substitute* "wllvm/compilers.py"
2607 (("'objcopy'")
2608 (pystr (search-input-file inputs "/bin/objcopy"))))
2609 (substitute* "wllvm/extraction.py"
2610 (("'objdump'")
2611 (pystr (search-input-file inputs "/bin/objdump")))
2612 (("'ar'")
2613 (pystr (search-input-file inputs "/bin/ar"))))
2614 (substitute* "wllvm/filetype.py"
2615 (("'file'")
2616 (pystr (search-input-file inputs "/bin/file"))))))))))
2617 (inputs (list binutils file))
2618 (native-inputs (list clang-13 procps python-pytest python-setuptools))
2619 (home-page "https://github.com/SRI-CSL/whole-program-llvm")
2620 (synopsis "Whole Program LLVM")
2621 (description "This package provides a toolkit for building whole-program
2622LLVM bitcode files.")
2623 (license license:expat)))
2624
2625(define-public llvm-julia
2626 (package
2627 (inherit llvm-13)
2628 (arguments
2629 (substitute-keyword-arguments arguments
2630 ((#:configure-flags flags ''())
2631 #~(cons* "-DLLVM_BUILD_LLVM_DYLIB=ON"
2632 "-DLLVM_LINK_LLVM_DYLIB=ON"
2633 ;; "-DLLVM_EXPERIMENTAL_TARGETS_TO_BUILD=NVPTX"
2634 "-DLLVM_VERSION_SUFFIX:STRING=jl" ; Perhaps not needed.
2635 #$(string-append "-DLLVM_TARGETS_TO_BUILD="
2636 (system->llvm-target))
2637 (delete "-DBUILD_SHARED_LIBS:BOOL=TRUE" #$flags)))
2638 ((#:build-type _) "Release")))
2639 (properties `((hidden? . #t)
2640 ,@(package-properties llvm-13)))))
2641
2642(define llvm-cling-base llvm-16)
2643
2644(define llvm-cling
2645 (let ((base llvm-cling-base))
2646 (package/inherit base
2647 (name "llvm-cling")
2648 ;; Use the latest tag for the major LLVM version currently targeted by
2649 ;; Cling (often mentioned in Cling's release notes).
2650 (version "16-20240621-02")
2651 (source
2652 (origin
2653 (inherit (package-source base))
2654 (method git-fetch)
2655 (uri (git-reference
2656 (url "https://github.com/root-project/llvm-project")
2657 (commit (string-append "cling-llvm" version))))
2658 (file-name (git-file-name "llvm-cling" version))
2659 (sha256
2660 (base32
2661 "05libb4mc385n8sq0bilalvidwzzrcyiqsfkn7j179kkx66a8rzy"))))
2662 (arguments
2663 ;; This reduces the package size on disk from 547 MiB to 311 MiB.
2664 ;; Cling is intended to be used as a REPL on the host machine, not as a
2665 ;; cross-compiling toolchain.
2666 (substitute-keyword-arguments arguments
2667 ((#:configure-flags cf ''())
2668 #~(cons* "-DLLVM_TARGETS_TO_BUILD=host;NVPTX" #$cf)))))))
2669
2670(define clang-cling-runtime
2671 (let ((base clang-runtime-16))
2672 (package/inherit base
2673 (name "clang-cling-runtime")
2674 (version (package-version llvm-cling))
2675 (source (package-source llvm-cling))
2676 (arguments
2677 (substitute-keyword-arguments arguments
2678 ((#:phases phases '%standard-phases)
2679 #~(modify-phases #$phases
2680 (add-after 'install 'delete-static-libraries
2681 ;; This reduces the size from 22 MiB to 4 MiB.
2682 (lambda _
2683 (for-each delete-file (find-files #$output "\\.a$"))))))))
2684 (inputs (modify-inputs inputs
2685 (replace "llvm" llvm-cling))))))
2686
2687(define clang-cling
2688 (let ((base clang-16))
2689 (package/inherit base
2690 (name "clang-cling")
2691 (version (package-version llvm-cling))
2692 (source (package-source llvm-cling))
2693 (propagated-inputs
2694 (modify-inputs propagated-inputs
2695 (replace "llvm" llvm-cling)
2696 (replace "clang-runtime" clang-cling-runtime))))))
2697
2698(define-public cling
2699 (package
2700 (name "cling")
2701 (version "1.1")
2702 (source (origin
2703 (method git-fetch)
2704 (uri (git-reference
2705 (url "https://github.com/root-project/cling")
2706 (commit (string-append "v" version))))
2707 (file-name (git-file-name name version))
2708 (sha256
2709 (base32
2710 "13ghbqjppvbmkhjgfk9xggxh17xpmx18ghdqgkkg9a3mh19hf69h"))))
2711 (build-system cmake-build-system)
2712 (arguments
2713 (list
2714 #:build-type "Release" ;keep the build as lean as possible
2715 ;; FIXME: 79 tests fail, out of ~200 (see:
2716 ;; https://github.com/root-project/cling/issues/534)
2717 #:tests? #f
2718 #:configure-flags
2719 #~(list (string-append "-DCLING_CXX_PATH="
2720 (search-input-file %build-inputs "bin/g++"))
2721 ;; XXX: The AddLLVM.cmake module expects LLVM_EXTERNAL_LIT to
2722 ;; be a Python script, not a shell executable.
2723 (string-append "-DLLVM_EXTERNAL_LIT="
2724 (search-input-file %build-inputs "bin/.lit-real")))
2725 #:phases
2726 #~(modify-phases %standard-phases
2727 (add-after 'unpack 'set-version
2728 (lambda _
2729 (make-file-writable "VERSION")
2730 (call-with-output-file "VERSION"
2731 (lambda (port)
2732 (format port "~a~%" #$version)))))
2733 (add-after 'unpack 'patch-paths
2734 (lambda* (#:key inputs #:allow-other-keys)
2735 (substitute* "lib/Interpreter/CIFactory.cpp"
2736 (("\\bsed\\b")
2737 (which "sed"))
2738 ;; Cling uses libclang's CompilerInvocation::GetResourcesPath
2739 ;; to resolve Clang's library prefix, but this fails on Guix
2740 ;; because it is relative to the output of cling rather than
2741 ;; clang (see:
2742 ;; https://github.com/root-project/cling/issues/434). Fully
2743 ;; shortcut the logic in this method to return the correct
2744 ;; static location.
2745 (("static std::string getResourceDir.*" all)
2746 (string-append all
2747 " return std::string(\""
2748 #$(this-package-input "clang-cling")
2749 "/lib/clang/"
2750 #$(first
2751 (take (string-split
2752 (package-version clang-cling) #\-)
2753 1)) ;e.g. 16.0.6 -> 16
2754 "\");")))
2755 ;; Check for the 'lit' command for the tests, not 'lit.py'
2756 ;; (see: https://github.com/root-project/cling/issues/432).
2757 (substitute* "CMakeLists.txt"
2758 (("lit.py")
2759 "lit"))))
2760 (add-after 'unpack 'adjust-lit.cfg
2761 ;; See: https://github.com/root-project/cling/issues/435.
2762 (lambda _
2763 (substitute* "test/lit.cfg"
2764 (("config.llvm_tools_dir \\+ '")
2765 "config.cling_obj_root + '/bin"))))
2766 (add-before 'check 'set-CLANG
2767 (lambda* (#:key native-inputs inputs #:allow-other-keys)
2768 ;; Otherwise, lit fails with "fatal: couldn't find 'clang'
2769 ;; program, try setting CLANG in your environment".
2770 (setenv "CLANG" (search-input-file (or native-inputs inputs)
2771 "bin/clang"))))
2772 (add-after 'install 'delete-static-libraries
2773 ;; This reduces the size from 17 MiB to 5.4 MiB.
2774 (lambda _
2775 (for-each delete-file (find-files #$output "\\.a$"))))
2776 (add-after 'install 'wrap-with-include-paths
2777 ;; Cling is sensitive to miss-matched include directives; ensure
2778 ;; the GCC includes used match that of the GCC used to build
2779 ;; Cling.
2780 (lambda* (#:key inputs #:allow-other-keys)
2781 (let ((gcc-toolchain #$(this-package-input "gcc-toolchain")))
2782 (wrap-program (string-append #$output "/bin/cling")
2783 `("C_INCLUDE_PATH" prefix
2784 (,(string-append gcc-toolchain "/include")))
2785 `("CPLUS_INCLUDE_PATH" prefix
2786 (,(string-append gcc-toolchain "/include/c++")
2787 ,(string-append gcc-toolchain "/include")))))))
2788 (add-after 'wrap-with-include-paths 'fix-wrapper
2789 (lambda _
2790 ;; When -a $0 is used, the cling executable segfauts (see:
2791 ;; https://issues.guix.gnu.org/73405).
2792 (substitute* (string-append #$output "/bin/cling")
2793 (("\"\\$0\"")
2794 "\"${0##*/}\"")))))))
2795 (native-inputs (list clang-cling python python-lit))
2796 (inputs (list clang-cling (force gcc-toolchain*) llvm-cling libxcrypt))
2797 (home-page "https://root.cern/cling/")
2798 (synopsis "Interactive C++ interpreter")
2799 (description "Cling is an interactive C++17 standard compliant
2800interpreter, built on top of LLVM and Clang. Cling can be used as a
2801read-eval-print loop (REPL) to assist with rapid application development.
2802Here's how to print @samp{\"Hello World!\"} using @command{cling}:
2803
2804@example
2805cling '#include <stdio.h>' 'printf(\"Hello World!\\n\");'
2806@end example")
2807 (license license:lgpl2.1+))) ;for the combined work
2808
2809(define %swift-llvm-clang-version "5.7.3")
2810
2811(define-public swift-llvm
2812 (package
2813 (name "swift-llvm")
2814 (version %swift-llvm-clang-version)
2815 (source (origin
2816 (method git-fetch)
2817 (uri (git-reference
2818 (url "https://github.com/apple/llvm-project.git")
2819 (commit (string-append "swift-" %swift-llvm-clang-version
2820 "-RELEASE"))))
2821 (file-name (git-file-name "swift-llvm" %swift-llvm-clang-version))
2822 (sha256
2823 (base32
2824 "0ai460v5kqq3mhp0vz1f5rr2fcwqmx91bnwbkaksjp9cxlylnfr0"))
2825 (patches (search-patches "swift-llvm-5.7.3-linux.patch"))))
2826 (build-system cmake-build-system)
2827 (arguments
2828 (list
2829 ;; Upstream build script doesn't test LLVM.
2830 ;; LLVM_INCLUDE_TESTS=ON (default) builds test tools like FileCheck,
2831 ;; but LLVM_BUILD_TESTS=OFF (default) means no tests run via ctest.
2832 #:tests? #f
2833 #:build-type "Release"
2834 #:configure-flags
2835 #~(list "-DCMAKE_C_FLAGS=-fno-stack-protector"
2836 "-DCMAKE_CXX_FLAGS=-fno-stack-protector"
2837 "-DCMAKE_C_FLAGS_RELWITHDEBINFO=-O2 -DNDEBUG"
2838 "-DCMAKE_CXX_FLAGS_RELWITHDEBINFO=-O2 -DNDEBUG"
2839 "-DLLVM_TOOL_SWIFT_BUILD:BOOL=NO"
2840 "-DINTERNAL_INSTALL_PREFIX=local"
2841 "-DLLVM_INCLUDE_DOCS=YES"
2842 "-DLLVM_ENABLE_LTO="
2843 "-DLLVM_ENABLE_DUMP=ON"
2844 "-DLLVM_ENABLE_PROJECTS=clang"
2845 "-DLLVM_TARGETS_TO_BUILD=X86;ARM;AArch64;PowerPC;SystemZ;Mips"
2846 ;; Python llvm.py adds this (not build-script-impl).
2847 ;; This would also enable dump() by undefining NDEBUG.
2848 "-DLLVM_ENABLE_ASSERTIONS=TRUE"
2849 "-DLLVM_LIT_ARGS=-sv -j 16"
2850 (string-append "-DGCC_INSTALL_PREFIX="
2851 (assoc-ref %build-inputs "gcc-lib"))
2852 (string-append "-DC_INCLUDE_DIRS="
2853 (assoc-ref %build-inputs "libc")
2854 "/include")
2855 (string-append "-DCMAKE_INSTALL_PREFIX=" #$output))
2856 #:phases
2857 #~(modify-phases %standard-phases
2858 (add-after 'unpack 'enter-llvm-directory
2859 (lambda _
2860 (chdir "llvm")))
2861 (add-after 'enter-llvm-directory 'allow-config-h-install
2862 (lambda _
2863 ;; Swift needs llvm/Config/config.h, so remove the EXCLUDE.
2864 (substitute* "CMakeLists.txt"
2865 (("PATTERN \"config\\.h\" EXCLUDE")
2866 ""))))
2867 (add-after 'allow-config-h-install 'fix-demangle-includes
2868 (lambda _
2869 (substitute* "include/llvm/Demangle/MicrosoftDemangleNodes.h"
2870 (("#include <array>")
2871 "#include <array>\n#include <cstdint>\n#include <string>"))
2872 (substitute* "utils/benchmark/src/benchmark_register.h"
2873 (("#include <vector>")
2874 "#include <vector>\n#include <limits>"))
2875 (substitute* "include/llvm/Support/Signals.h"
2876 (("#include <string>")
2877 "#include <string>
2878#include <cstdint>"))
2879 ;; Work around Guix bug: libstdc++ was built without fenv.h support,
2880 ;; so _GLIBCXX_HAVE_FENV_H is undefined, causing <fenv.h> wrapper to
2881 ;; not include the actual header. Define it to bypass the wrapper.
2882 ;; See <https://issues.guix.gnu.org/43579>
2883 (substitute* "lib/Analysis/ConstantFolding.cpp"
2884 (("#include \"llvm/Config/config.h\"")
2885 "#include \"llvm/Config/config.h\"\n#define _GLIBCXX_HAVE_FENV_H 1\n#include <fenv.h>"))))
2886 (add-after 'fix-demangle-includes 'set-glibc-file-names
2887 (lambda* (#:key inputs #:allow-other-keys)
2888 (let ((libc (assoc-ref inputs "libc"))
2889 (gcc (assoc-ref inputs "gcc")))
2890 (substitute* "../clang/lib/Driver/ToolChains/Linux.cpp"
2891 ;; Make "LibDir" refer to <glibc>/lib so that it
2892 ;; uses the right dynamic linker file name.
2893 (("(^[[:blank:]]+LibDir = ).*" _ declaration)
2894 (string-append declaration "\"" libc "/lib\";\n"))
2895 ;; Make clang look for libstdc++ in the right location.
2896 (("LibStdCXXIncludePathCandidates\\[\\] = \\{")
2897 (string-append
2898 "LibStdCXXIncludePathCandidates[] = { \"" gcc
2899 "/include/c++\","))
2900 ;; Make sure libc's libdir is on the search path, to
2901 ;; allow crt1.o & co. to be found.
2902 (("@GLIBC_LIBDIR@")
2903 (string-append libc "/lib"))))))
2904 (add-after 'install 'install-filecheck
2905 (lambda _
2906 ;; FileCheck is built but not installed by default.
2907 ;; Swift needs it--so install it manually.
2908 (install-file "bin/FileCheck"
2909 (string-append #$output "/bin")))))))
2910 (native-inputs
2911 (list python-3))
2912 (inputs
2913 `(("libxml2" ,libxml2)
2914 ("gcc-lib" ,gcc "lib")
2915 ("gcc" ,gcc)
2916 ("libc" ,glibc)
2917 ("libffi" ,libffi)))
2918 (propagated-inputs
2919 (list zlib))
2920 (home-page "https://swift.org/")
2921 (synopsis "LLVM for Swift (Apple's fork)")
2922 (description
2923 "This is Apple's fork of LLVM with Swift-specific modifications,
2924required to build Swift.")
2925 (license license:ncsa)))
2926
2927;(define-public swift-clang-runtime
2928; (package
2929; (inherit (clang-runtime-from-llvm swift-llvm))
2930; (arguments
2931; (substitute-keyword-arguments (package-arguments (clang-runtime-from-llvm swift-llvm))
2932; ((#:configure-flags flags)
2933; #~(cons "-DCOMPILER_RT_INTERCEPT_LIBDISPATCH=ON"
2934; #$flags))))))
2935
2936(define-public swift-llvm-6.2
2937 (package
2938 (inherit swift-llvm)
2939 (version "6.2")
2940 (source (origin
2941 (method git-fetch)
2942 (uri (git-reference
2943 (url "https://github.com/apple/llvm-project.git")
2944 (commit (string-append "swift-" version "-RELEASE"))))
2945 (file-name (git-file-name "swift-llvm" version))
2946 (sha256
2947 (base32
2948 "00bpplh8zd495n7dw5a64ncy23r2sgj7071kyhw7r9s53ihw1k1m"))
2949 (patches (search-patches "clang-18.0-libc-search-path.patch"))))
2950 (arguments
2951 (substitute-keyword-arguments arguments
2952 ((#:configure-flags flags)
2953 #~(cons "-DUSE_DEPRECATED_GCC_INSTALL_PREFIX=ON" #$flags))
2954 ((#:phases phases)
2955 #~(modify-phases #$phases
2956 (replace 'fix-demangle-includes
2957 (lambda _
2958 (substitute* "include/llvm/Demangle/MicrosoftDemangleNodes.h"
2959 (("#include <array>")
2960 "#include <array>
2961#include <cstdint>
2962#include <string>"))
2963 (substitute* "../third-party/benchmark/src/benchmark_register.h"
2964 (("#include <vector>")
2965 "#include <vector>
2966#include <limits>"))
2967 (substitute* "include/llvm/Support/Signals.h"
2968 (("#include <string>")
2969 "#include <string>
2970#include <cstdint>"))
2971 (substitute* "lib/Analysis/ConstantFolding.cpp"
2972 (("#include \"llvm/Config/config.h\"")
2973 "#include \"llvm/Config/config.h\"
2974#define _GLIBCXX_HAVE_FENV_H 1
2975#include <fenv.h>"))))))))))